Skip to content
Merged
Changes from all commits
Commits
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
42 changes: 28 additions & 14 deletions src/main/java/org/grobid/core/engines/DatasetParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public class DatasetParser extends AbstractParser {
private static final java.util.concurrent.atomic.AtomicBoolean gluttonWarningLogged =
new java.util.concurrent.atomic.AtomicBoolean(false);

// guard to warn only once about the disambiguator not being available
private static final java.util.concurrent.atomic.AtomicBoolean disambiguatorWarningLogged =
new java.util.concurrent.atomic.AtomicBoolean(false);

private EngineParsers parsers;
private DatastetServiceConfiguration datastetConfiguration;
private DataTypeClassifier dataTypeClassifier;
Expand All @@ -91,6 +95,12 @@ private static void warnGluttonNotConfiguredOnce() {
}
}

private static void warnDisambiguatorNotAvailableOnce() {
if (disambiguatorWarningLogged.compareAndSet(false, true)) {
LOGGER.warn("Dataset disambiguator is not available, dataset disambiguation will be skipped");
}
}

public static DatasetParser getInstance(
DatastetServiceConfiguration configuration,
DataTypeClassifier dataTypeClassifier,
Expand Down Expand Up @@ -122,7 +132,7 @@ private DatasetParser(DatastetServiceConfiguration configuration) {
DatastetLexicon.getInstance();
this.parsers = new EngineParsers();
this.datastetConfiguration = configuration;
this.disambiguator = disambiguator;
this.disambiguator = DatasetDisambiguator.getInstance(configuration.getDatastetConfiguration());
this.datasetContextClassifier = datasetContextClassifier;
}

Expand Down Expand Up @@ -273,22 +283,26 @@ public List<List<Dataset>> processing(List<DatasetDocumentSequence> datasetDocum

// disambiguation
if (disambiguate) {
localDatasets = disambiguator.disambiguate(localDatasets, tokens);

// apply existing filtering
indexToBeFiltered = new ArrayList<>();
k = 0;
for (Dataset entity : localDatasets) {
if (entity.isFiltered()) {
indexToBeFiltered.add(Integer.valueOf(k));
if (disambiguator != null) {
localDatasets = disambiguator.disambiguate(localDatasets, tokens);

// apply existing filtering
indexToBeFiltered = new ArrayList<>();
k = 0;
for (Dataset entity : localDatasets) {
if (entity.isFiltered()) {
indexToBeFiltered.add(Integer.valueOf(k));
}
k++;
}
k++;
}

if (indexToBeFiltered.size() > 0) {
for (int j = indexToBeFiltered.size() - 1; j >= 0; j--) {
localDatasets.remove(indexToBeFiltered.get(j).intValue());
if (indexToBeFiltered.size() > 0) {
for (int j = indexToBeFiltered.size() - 1; j >= 0; j--) {
localDatasets.remove(indexToBeFiltered.get(j).intValue());
}
}
} else {
warnDisambiguatorNotAvailableOnce();
}
}

Expand Down
Loading