use of de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext in project inception by inception-project.
the class LappsGridRecommender method predict.
@Override
public void predict(RecommenderContext aContext, CAS aCas) throws RecommendationException {
try {
Container container = new Container();
new DKPro2Lif().convert(aCas.getJCas(), container);
String request = new Data<>(Discriminators.Uri.LIF, container).asJson();
String response = client.execute(request);
DataContainer result = Serializer.parse(response, DataContainer.class);
aCas.reset();
new Lif2DKPro().convert(result.getPayload(), aCas.getJCas());
Feature isPredictionFeature = getIsPredictionFeature(aCas);
for (AnnotationFS predictedAnnotation : select(aCas, getPredictedType(aCas))) {
predictedAnnotation.setBooleanValue(isPredictionFeature, true);
}
// Drop the tokens we got from the remote service since their boundaries might not
// match ours.
select(aCas, getType(aCas, Token.class)).forEach(aCas::removeFsFromIndexes);
// If the remote service did not return tokens (or if we didn't find them...), then
// let's just re-add the tokens that we originally sent. We need the tokens later
// when extracting the predicted annotations
Type tokenType = getType(aCas, Token.class);
if (select(aCas, getType(aCas, Token.class)).isEmpty()) {
container.getView(0).getAnnotations().stream().filter(a -> Discriminators.Uri.TOKEN.equals(a.getAtType())).forEach(token -> {
AnnotationFS t = aCas.createAnnotation(tokenType, token.getStart().intValue(), token.getEnd().intValue());
aCas.addFsToIndexes(t);
});
}
} catch (Exception e) {
throw new RecommendationException("Cannot predict", e);
}
}
use of de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext in project inception by inception-project.
the class LappsRecommenderIntegrationTest method thatPredictingPosWorks.
@Test
@Disabled
public void thatPredictingPosWorks() throws Exception {
RecommenderContext context = new RecommenderContext();
CAS cas = loadData();
sut.predict(context, cas);
Collection<POS> predictions = JCasUtil.select(cas.getJCas(), POS.class);
assertThat(predictions).as("There should be some predictions").isNotEmpty();
}
use of de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext in project inception by inception-project.
the class OpenNlpDoccatRecommenderTest method setUp.
@BeforeEach
public void setUp() {
context = new RecommenderContext();
recommender = buildRecommender();
traits = new OpenNlpDoccatRecommenderTraits();
traits.setNumThreads(2);
traits.setTrainingSetSizeLimit(250);
traits.setPredictionLimit(250);
}
use of de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext in project inception by inception-project.
the class StringMatchingRecommenderTest method setUp.
@BeforeEach
public void setUp() {
casStorageSession = CasStorageSession.open();
context = new RecommenderContext();
recommender = buildRecommender();
traits = new StringMatchingRecommenderTraits();
}
use of de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext in project inception by inception-project.
the class DL4JSequenceRecommenderTest method setUp.
@BeforeEach
public void setUp() {
// By default, ND4J will use a value equal to the number of physical CPU cores (not logical
// cores) as this will give optimal performance
// Nd4jBlas nd4jBlas = (Nd4jBlas) Nd4j.factory().blas();
// nd4jBlas.setMaxThreads(2);
// NativeOpsHolder instance = NativeOpsHolder.getInstance();
// NativeOps deviceNativeOps = instance.getDeviceNativeOps();
// deviceNativeOps.setOmpNumThreads(2);
context = new RecommenderContext();
traits = new DL4JSequenceRecommenderTraits();
traits.setTrainingSetSizeLimit(250);
traits.setPredictionLimit(250);
traits.setBatchSize(50);
casSession = CasStorageSession.open();
}
Aggregations