Skip to content

Commit

Permalink
Merge pull request #4420 from inception-project/feature/4399-Allow-Op…
Browse files Browse the repository at this point in the history
…enNLP-Multi-Token-Sequence-Classifier-to-work-for-cross-sentence-layers

#4399 - Allow OpenNLP Multi-Token Sequence Classifier to work for cross-sentence layers
  • Loading branch information
reckart authored Jan 2, 2024
2 parents 1379f3a + e2e1522 commit 1ef2fee
Show file tree
Hide file tree
Showing 24 changed files with 600 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Obje
var value = (String) v;
var tag = schemaService.getTag(value, aFeature.getTagset());

if (aFeature.getTagset() != null && !tag.isEmpty()) {
if (isNotBlank(value) && aFeature.getTagset() != null && tag.isEmpty()) {
results.addDetail(new VLazyDetail(value, "Tag not in tagset"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Obje
if (aValue instanceof String) {
var value = (String) aValue;
var tag = schemaService.getTag(value, aFeature.getTagset());
if (aFeature.getTagset() != null && !tag.isEmpty()) {
if (isNotBlank(value) && aFeature.getTagset() != null && tag.isEmpty()) {
return asList(new VLazyDetailGroup(new VLazyDetail(value, "Tag not in tagset")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void thatPredictionWorks() throws Exception
casStorageSession.add("cas", EXCLUSIVE_WRITE_ACCESS, cas);

sut.train(context, Collections.singletonList(cas));
RecommenderTestHelper.addScoreFeature(cas, NamedEntity.class, "value");
RecommenderTestHelper.addPredictionFeatures(cas, NamedEntity.class, "value");

sut.predict(new PredictionContext(context), cas);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package de.tudarmstadt.ukp.inception.recommendation.imls.datamajority;

import static de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.EXCLUSIVE_WRITE_ACCESS;
import static de.tudarmstadt.ukp.inception.support.test.recommendation.RecommenderTestHelper.addScoreFeature;
import static de.tudarmstadt.ukp.inception.support.test.recommendation.RecommenderTestHelper.addPredictionFeatures;
import static de.tudarmstadt.ukp.inception.support.test.recommendation.RecommenderTestHelper.getPredictions;
import static java.util.Arrays.asList;
import static org.apache.uima.fit.factory.CollectionReaderFactory.createReader;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void thatPredictionWorks() throws Exception
CAS cas = casList.get(0);
try (CasStorageSession session = CasStorageSession.open()) {
session.add("testCas", EXCLUSIVE_WRITE_ACCESS, cas);
addScoreFeature(cas, NamedEntity.class.getName(), "value");
addPredictionFeatures(cas, NamedEntity.class.getName(), "value");
}

sut.train(context, asList(cas));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void thatPredictingWorks() throws Exception
sut.train(context, casses);

var cas = casses.get(0);
RecommenderTestHelper.addScoreFeature(cas, NamedEntity.class, "value");
RecommenderTestHelper.addPredictionFeatures(cas, NamedEntity.class, "value");
sut.predict(new PredictionContext(context), cas);

var predictions = getPredictions(cas, NamedEntity.class);
Expand Down Expand Up @@ -180,7 +180,7 @@ public void thatPredictingSendsCorrectRequest() throws Exception
sut.train(context, casses);

var cas = casses.get(0);
RecommenderTestHelper.addScoreFeature(cas, NamedEntity.class, "value");
RecommenderTestHelper.addPredictionFeatures(cas, NamedEntity.class, "value");
sut.predict(new PredictionContext(context), cas);

var request = fromJsonString(PredictionRequest.class, requestBodies.get(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private CAS loadData() throws IOException, UIMAException
CAS cas = loadData(path.toFile());
casStorageSession.add("test", EXCLUSIVE_WRITE_ACCESS, cas);

RecommenderTestHelper.addScoreFeature(cas, NamedEntity.class, "value");
RecommenderTestHelper.addPredictionFeatures(cas, NamedEntity.class, "value");

return cas;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import opennlp.tools.namefind.NameSample;
import opennlp.tools.util.ObjectStream;

public class NameSampleStream
class NameSampleStream
implements ObjectStream<NameSample>, AutoCloseable
{
private List<NameSample> samples;
Expand All @@ -41,6 +41,7 @@ public NameSample read()
if (iterator != null && iterator.hasNext()) {
return iterator.next();
}

return null;
}

Expand All @@ -56,5 +57,4 @@ public void close()
samples = null;
iterator = null;
}

}
Loading

0 comments on commit 1ef2fee

Please sign in to comment.