Skip to content

Commit

Permalink
fix offsets before default quantified object parser
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Jan 17, 2023
1 parent d9eb9ea commit 26a151b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public List<Measurement> process(List<LayoutToken> tokens, List<Measurement> mea
String text = LayoutTokensUtil.toText(tokens);
TextParser textParser = TextParser.getInstance();
List<Sentence> parsedSentences = textParser.parseText(text);
int firstTokenOffsetStart = tokens.get(0).getOffset();
parsedSentences.stream().forEach( s -> {
s.getOffset().start = s.getOffsetStart() + firstTokenOffsetStart;
s.getOffset().end = s.getOffsetEnd() + firstTokenOffsetStart;
});
int indexMeasurement = 0;
int offset = 0;

Expand All @@ -48,8 +53,8 @@ public List<Measurement> process(List<LayoutToken> tokens, List<Measurement> mea
while (indexMeasurement < measurements.size()) {
Measurement measurement = measurements.get(indexMeasurement);
int position = -1;

// is the measurement quantities in the current sentence?
UnitUtilities.Measurement_Type type = measurement.getType();
if (measurement.getType() == UnitUtilities.Measurement_Type.VALUE) {
Quantity quantity = measurement.getQuantityAtomic();
if (quantity.getOffsetStart() > processedSentence.getOffsetEnd()) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/grobid/core/utilities/TextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @author Patrice Lopez
*/
public class TextParser {
private static final Logger logger = LoggerFactory.getLogger(TextParser.class);
private static final Logger LOGGER = LoggerFactory.getLogger(TextParser.class);

public final String language = AbstractReader.LANG_EN;

Expand Down Expand Up @@ -69,7 +69,7 @@ public static TextParser getInstance() throws Exception {
}

private static synchronized void getNewInstance() throws Exception {
logger.debug("Get new instance of TextParser");
LOGGER.debug("Get new instance of TextParser");
instance = new TextParser();
}

Expand Down Expand Up @@ -172,8 +172,7 @@ public synchronized List<Sentence> parseText(String text) throws GrobidException
if (text == null) {
throw new GrobidException("Cannot parse the sentence, because it is null.");
} else if (text.length() == 0) {
System.out.println("The length of the text to be parsed is 0.");
logger.error("The length of the text to be parsed is 0.");
LOGGER.error("The length of the text to be parsed is 0.");
return null;
}

Expand Down

0 comments on commit 26a151b

Please sign in to comment.