-
Notifications
You must be signed in to change notification settings - Fork 546
Handle weird whitespace unstructured from Crossref #1407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lfoppiano
wants to merge
3
commits into
master
Choose a base branch
from
bugfix/issue-849
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
grobid-core/src/test/java/org/grobid/core/engines/CitationParserNullHandlingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package org.grobid.core.engines; | ||
|
|
||
| import org.grobid.core.GrobidModels; | ||
| import org.grobid.core.data.BiblioItem; | ||
| import org.grobid.core.engines.config.GrobidAnalysisConfig; | ||
| import org.grobid.core.layout.LayoutToken; | ||
| import org.grobid.core.lexicon.Lexicon; | ||
| import org.grobid.core.utilities.GrobidConfig; | ||
| import org.grobid.core.utilities.GrobidProperties; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.easymock.EasyMock; | ||
| import org.powermock.api.easymock.PowerMock; | ||
| import org.powermock.core.classloader.annotations.PrepareForTest; | ||
| import org.powermock.modules.junit4.PowerMockRunner; | ||
| import org.powermock.reflect.Whitebox; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.notNullValue; | ||
| import static org.hamcrest.CoreMatchers.nullValue; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| @RunWith(PowerMockRunner.class) | ||
| @PrepareForTest(Lexicon.class) | ||
| public class CitationParserNullHandlingTest { | ||
|
|
||
| private CitationParser target; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| PowerMock.mockStatic(Lexicon.class); | ||
| Lexicon mockLexicon = EasyMock.createNiceMock(Lexicon.class); | ||
| EasyMock.expect(Lexicon.getInstance()).andReturn(mockLexicon).anyTimes(); | ||
| PowerMock.replay(Lexicon.class); | ||
| GrobidConfig.ModelParameters modelParameters = new GrobidConfig.ModelParameters(); | ||
| modelParameters.name = "bao"; | ||
| GrobidProperties.addModel(modelParameters); | ||
|
|
||
| // Initialize minimal grobidConfig so BiblioItem serialization methods work | ||
| GrobidConfig config = new GrobidConfig(); | ||
| config.grobid = new GrobidConfig.GrobidParameters(); | ||
| config.grobid.languageDetectorFactory = "org.grobid.core.lang.impl.CybozuLanguageDetectorFactory"; | ||
| Whitebox.setInternalState(GrobidProperties.class, "grobidConfig", config); | ||
|
|
||
| target = new CitationParser(null, GrobidModels.DUMMY); | ||
|
lfoppiano marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| Whitebox.setInternalState(GrobidProperties.class, "grobidConfig", (GrobidConfig) null); | ||
| } | ||
|
|
||
| @Test | ||
| public void processingStringMultiple_nullInput_returnsNull() { | ||
| List<BiblioItem> result = target.processingStringMultiple(null, 0); | ||
| assertThat(result, is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void processingStringMultiple_emptyList_returnsNull() { | ||
| List<BiblioItem> result = target.processingStringMultiple(new ArrayList<>(), 0); | ||
| assertThat(result, is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void processingStringMultiple_allBlankStrings_returnsNull() { | ||
| List<String> inputs = Arrays.asList("", " ", "\t"); | ||
| List<BiblioItem> result = target.processingStringMultiple(inputs, 0); | ||
| assertThat(result, is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void processingStringMultiple_nbspOnlyStrings_returnsNull() { | ||
| List<String> inputs = Arrays.asList("\u00A0", "\u00A0\u00A0\u00A0"); | ||
| List<BiblioItem> result = target.processingStringMultiple(inputs, 0); | ||
| assertThat(result, is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void processingLayoutTokenMultiple_allEmptyTokenLists_returnsNull() { | ||
| List<List<LayoutToken>> tokenList = new ArrayList<>(); | ||
| tokenList.add(new ArrayList<>()); | ||
| tokenList.add(new ArrayList<>()); | ||
| List<BiblioItem> result = target.processingLayoutTokenMultiple(tokenList, 0); | ||
| assertThat(result, is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void emptyBiblioItem_serializesSafely() { | ||
| BiblioItem empty = new BiblioItem(); | ||
| GrobidAnalysisConfig config = GrobidAnalysisConfig.defaultInstance(); | ||
|
|
||
| String bibtex = empty.toBibTeX("0", config); | ||
| assertThat(bibtex, is(notNullValue())); | ||
|
|
||
| String tei = empty.toTEI(0, config); | ||
| assertThat(tei, is(notNullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void emptyBiblioItem_isRejectedAsReference() { | ||
| BiblioItem empty = new BiblioItem(); | ||
| assertThat(empty.rejectAsReference(), is(true)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.