use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class MicrosoftEnricherTest method testCanGetConceptsFromMicrosoft.
@Test
public void testCanGetConceptsFromMicrosoft() {
PersistenceRegistry registry = new PersistenceRegistry(getDatabase());
MicrosoftConceptEnricher enricher = new MicrosoftConceptEnricher(getDatabase(), registry, new TextProcessorsManager(new DynamicConfiguration(getDatabase())));
clearDb();
executeInTransaction("CALL ga.nlp.annotate({text: 'kill cats', id: 'test-proc', pipeline: 'tokenizer'})", emptyConsumer());
try (Transaction tx = getDatabase().beginTx()) {
getDatabase().findNodes(Label.label("AnnotatedText")).stream().forEach(node -> {
ConceptRequest request = new ConceptRequest();
request.setAnnotatedNode(node);
// request.setLanguage("en");
request.setDepth(1);
request.setProcessor(StubTextProcessor.class.getName());
enricher.importConcept(request);
tx.success();
});
}
debugTagsRelations();
TestNLPGraph tester = new TestNLPGraph(getDatabase());
tester.assertTagWithValueExist("pet");
tester.assertTagWithValueExist("specie");
tester.assertTagHasRelatedTag("cats", "animal");
tester.assertTagHasRelatedTag("cats", "pet");
}
use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class MicrosoftEnricherTest method testEnricherNameIsSetAsRelationshipProperty.
@Test
public void testEnricherNameIsSetAsRelationshipProperty() {
DynamicConfiguration configuration = new DynamicConfiguration(getDatabase());
PersistenceRegistry registry = new PersistenceRegistry(getDatabase());
MicrosoftConceptEnricher enricher = new MicrosoftConceptEnricher(getDatabase(), registry, new TextProcessorsManager(new DynamicConfiguration(getDatabase())));
clearDb();
executeInTransaction("CALL ga.nlp.annotate({text: 'kill cats', id: 'test-proc', pipeline: 'tokenizer'})", emptyConsumer());
try (Transaction tx = getDatabase().beginTx()) {
getDatabase().findNodes(Label.label("AnnotatedText")).stream().forEach(node -> {
ConceptRequest request = new ConceptRequest();
request.setAnnotatedNode(node);
// request.setLanguage("en");
request.setDepth(1);
request.setProcessor(StubTextProcessor.class.getName());
enricher.importConcept(request);
tx.success();
});
}
try (Transaction tx = getDatabase().beginTx()) {
getDatabase().getAllRelationships().stream().forEach(r -> {
if (r.isType(RelationshipType.withName("IS_RELATED_TO"))) {
assertTrue(r.hasProperty("source"));
assertEquals(MicrosoftConceptEnricher.ENRICHER_NAME, r.getProperty("source").toString());
}
});
tx.success();
}
}
use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class NLPManager method init.
public void init(GraphDatabaseService database, NLPConfiguration nlpConfiguration, DynamicConfiguration configuration) {
if (initialized) {
return;
}
this.nlpConfiguration = nlpConfiguration;
this.textProcessorsManager = new TextProcessorsManager();
this.configuration = configuration;
this.database = database;
this.persistenceRegistry = new PersistenceRegistry(database);
this.enrichmentRegistry = buildAndRegisterEnrichers();
this.eventDispatcher = new EventDispatcher();
this.vectorComputation = new QueryBasedVectorComputation(database);
loadExtensions();
registerEventListeners();
initialized = true;
registerPipelinesFromConfig();
}
use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class ConceptNet5EnricherIntegrationTest method testConceptNetUrlIsConfigurable.
@Test
public void testConceptNetUrlIsConfigurable() {
PersistenceRegistry registry = new PersistenceRegistry(getDatabase());
ConceptNet5Enricher enricher = new ConceptNet5Enricher(getDatabase(), registry, new TextProcessorsManager(new DynamicConfiguration(getDatabase())));
assertEquals("http://api.conceptnet.io", enricher.getConceptNetUrl());
getNLPManager().getConfiguration().updateInternalSetting("CONCEPT_NET_5_URL", "http://localhost:8001");
assertEquals("http://localhost:8001", enricher.getConceptNetUrl());
}
Aggregations