Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Sep 9, 2022
1 parent 761a1f6 commit 8bf7e96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Expand Up @@ -1036,7 +1036,7 @@ private List<Footnote> getTeiNotes(Document doc) {
return footnotes;
}

private Footnote makeFootNote(List<LayoutToken> noteTokens, String footText) {
protected Footnote makeFootNote(List<LayoutToken> noteTokens, String footText) {
// pattern is <note n="1" place="foot" xml:id="no1">
Matcher ma = startNum.matcher(footText);
int currentNumber = -1;
Expand All @@ -1050,8 +1050,9 @@ private Footnote makeFootNote(List<LayoutToken> noteTokens, String footText) {
String toConsume = groupStr;
int start = 0;
for(LayoutToken token : noteTokens) {
if ( (token.getText() == null) || (token.getText().length() == 0) )
if (StringUtils.isEmpty(token.getText())) {
continue;
}
if (toConsume.startsWith(token.getText())) {
start++;
toConsume = toConsume.substring(token.getText().length());
Expand Down
@@ -1,8 +1,5 @@
package org.grobid.core.engines.citations;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down
@@ -1,15 +1,18 @@
package org.grobid.core.document;

import org.grobid.core.analyzers.GrobidAnalyzer;
import org.grobid.core.data.Footnote;
import org.grobid.core.layout.LayoutToken;
import org.grobid.core.utilities.GrobidProperties;
import org.grobid.core.utilities.LayoutTokensUtil;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.File;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;

public class TEIFormatterTest {
Expand All @@ -19,4 +22,17 @@ public static void setInitialContext() throws Exception {
GrobidProperties.getInstance();
}

@Test
public void testMakeFootNote() throws Exception {

String text = "1 This is a footnote";
List<LayoutToken> tokens = GrobidAnalyzer.getInstance().tokenizeWithLayoutToken(text);

Footnote footnote = new TEIFormatter(null, null).makeFootNote(tokens, text);

assertThat(footnote.getText(), is(" This is a footnote"));
assertThat(LayoutTokensUtil.toText(footnote.getTokens()), is(" This is a footnote"));
assertThat(footnote.getNumber(), is(1));
}

}

0 comments on commit 8bf7e96

Please sign in to comment.