Skip to content
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

Fix Deep Learning header classification inconsistency #1211

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d95a1ac
first attempt to fix tables on the fly
lfoppiano Dec 4, 2024
b012665
revise table validation, apply check to figures, move code outside th…
lfoppiano Dec 6, 2024
d2ca7c9
fix figure validation
lfoppiano Dec 6, 2024
575c2fe
move test related to LabelUtils outside
lfoppiano Dec 6, 2024
7780804
fix scope
lfoppiano Dec 6, 2024
e0e217d
remove unnecessary layout tokens list, renaming stuff
lfoppiano Dec 6, 2024
facc35e
fix index mismatch
lfoppiano Dec 6, 2024
17ad425
fix wrong label adjustment
lfoppiano Dec 6, 2024
c830231
fix wrong upper indexes, cleanup
lfoppiano Dec 7, 2024
9c77194
Merge branch 'refs/heads/master' into bugfix/fix-dropped-misclassifie…
lfoppiano Dec 16, 2024
2f0661b
cosmetics
lfoppiano Dec 16, 2024
2f04ccd
add tests for labelling adjustment
lfoppiano Dec 16, 2024
f5eb758
tests and refactoring in smaller pieces
lfoppiano Dec 17, 2024
81a1691
fix typo
lfoppiano Dec 17, 2024
3778a6e
add test for table token consolidation
lfoppiano Dec 17, 2024
21f85c9
rename methods for better clarity, move utility methods in Kotlin
lfoppiano Dec 18, 2024
1fa792c
fix header sequence with delft to revert any labels that do not have …
lfoppiano Dec 18, 2024
cbbe460
renaming
lfoppiano Dec 19, 2024
f036e0a
allow a loose approach to gather table/figure starting token when the…
lfoppiano Dec 19, 2024
09c824d
improve the way the candidate identification for bad figures/tables i…
lfoppiano Dec 19, 2024
77cf7a2
Merge branch 'bugfix/fix-dropped-misclassified-text' into bugfix/fix-…
lfoppiano Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion grobid-core/src/main/java/org/grobid/core/data/Figure.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,12 @@ public String getTeiId() {
return "fig_" + this.id;
}

public boolean isCompleteForTEI() {
return (StringUtils.isNotBlank(header) || StringUtils.isNotBlank(caption) || CollectionUtils.isNotEmpty(graphicObjects));
}

public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter formatter, List<MarkerType> markerTypes) {
if (StringUtils.isEmpty(header) && StringUtils.isEmpty(caption) && CollectionUtils.isEmpty(graphicObjects)) {
if (!isCompleteForTEI()) {
return null;
}
Element figureElement = XmlBuilderUtils.teiElement("figure");
Expand Down Expand Up @@ -568,4 +572,5 @@ public void setLabel(StringBuilder label) {
public void setUri(URI uri) {
this.uri = uri;
}

}
27 changes: 19 additions & 8 deletions grobid-core/src/main/java/org/grobid/core/data/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import nu.xom.Attribute;
import nu.xom.Element;
import nu.xom.Node;
import nu.xom.Text;

import static org.grobid.core.document.xml.XmlBuilderUtils.teiElement;
import static org.grobid.core.document.xml.XmlBuilderUtils.addXmlId;
Expand All @@ -43,6 +42,7 @@
public class Table extends Figure {
private List<LayoutToken> contentTokens = new ArrayList<>();
private List<LayoutToken> fullDescriptionTokens = new ArrayList<>();

private boolean goodTable = true;

private StringBuilder note = null;
Expand All @@ -62,9 +62,13 @@ public Table() {
note = new StringBuilder();
}

public boolean isCompleteForTEI() {
return (StringUtils.isNotEmpty(header) && StringUtils.isNotEmpty(caption));
}

@Override
public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter formatter, List<MarkerType> markerTypes) {
if (StringUtils.isEmpty(header) && StringUtils.isEmpty(caption)) {
if (!isCompleteForTEI()) {
return null;
}

Expand Down Expand Up @@ -104,7 +108,7 @@ public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter form
addXmlId(desc, "_" + divID);
}

if ( (labeledCaption != null) && (labeledCaption.length() > 0) ) {
if (StringUtils.isNotBlank(labeledCaption)) {
TaggingTokenClusteror clusteror = new TaggingTokenClusteror(GrobidModels.FULLTEXT, labeledCaption, captionLayoutTokens);
List<TaggingTokenCluster> clusters = clusteror.cluster();
for (TaggingTokenCluster cluster : clusters) {
Expand Down Expand Up @@ -169,15 +173,15 @@ public String toTEI(GrobidAnalysisConfig config, Document doc, TEIFormatter form
}

Element noteNode = null;
if (note != null && note.toString().trim().length()>0) {
if (StringUtils.isNotBlank(note)) {

noteNode = XmlBuilderUtils.teiElement("note");
if (config.isGenerateTeiIds()) {
String divID = KeyGen.getKey().substring(0, 7);
addXmlId(noteNode, "_" + divID);
}

if ( (labeledNote != null) && (labeledNote.length() > 0) ) {
if (StringUtils.isNotBlank(labeledNote)) {
TaggingTokenClusteror clusteror = new TaggingTokenClusteror(GrobidModels.FULLTEXT, labeledNote, noteLayoutTokens);
List<TaggingTokenCluster> clusters = clusteror.cluster();
for (TaggingTokenCluster cluster : clusters) {
Expand Down Expand Up @@ -346,9 +350,14 @@ public String getLabeledNote() {
return this.labeledNote;
}

private boolean validateTable() {
/** Check if the table:
* - has label, header and content
* - header starts with "tab"
* - label can be parsed
*/
public boolean validateTable() {
CntManager cnt = Engine.getCntManager();
if (StringUtils.isEmpty(label) || StringUtils.isEmpty(header) || StringUtils.isEmpty(content)) {
if (StringUtils.isAnyBlank(label, header, content)) {
cnt.i(TableRejectionCounters.EMPTY_LABEL_OR_HEADER_OR_CONTENT);
return false;
}
Expand All @@ -359,7 +368,8 @@ private boolean validateTable() {
cnt.i(TableRejectionCounters.CANNOT_PARSE_LABEL_TO_INT);
return false;
}
if (!getHeader().toLowerCase().startsWith("table")) {
// tab covers: table, tabelle, tableu, tabella, etc.
if (!StringUtils.startsWithIgnoreCase(getHeader(), "tab")) {
cnt.i(TableRejectionCounters.HEADER_NOT_STARTS_WITH_TABLE_WORD);
return false;
}
Expand Down Expand Up @@ -423,4 +433,5 @@ public boolean isGoodTable() {
public String getTeiId() {
return "tab_" + this.id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ public static List<GraphicObject> getConnectedGraphics(Block block, Document doc
public void postProcessTables() {
for (Table table : tables) {
if (!table.firstCheck()) {
table.setGoodTable(false);
continue;
}

Expand Down Expand Up @@ -919,7 +920,7 @@ public void postProcessTables() {
table.getContentTokens().clear();
table.getContentTokens().addAll(contentResult);

table.secondCheck();
table.setGoodTable(table.secondCheck());
}
}

Expand Down
Loading
Loading