use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class NLPManager method init.
public void init(GraphDatabaseService database, DynamicConfiguration configuration) {
if (initialized) {
return;
}
this.configuration = configuration;
this.languageManager = new LanguageManager();
this.database = database;
this.persistenceRegistry = new PersistenceRegistry(database);
this.enrichmentRegistry = buildAndRegisterEnrichers();
this.eventDispatcher = new EventDispatcher();
loadExtensions();
if (textProcessorsManager == null) {
this.textProcessorsManager = new TextProcessorsManager(configuration);
}
this.textProcessorsManager.registerPipelinesFromConfig();
loadVectorComputationProcesses();
loadSummarizers();
registerWord2VecModelFromConfig();
initialized = true;
}
use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class ConceptNet5EnricherIntegrationTest method testConceptWorksAfterImmediateRemoval.
@Test
public void testConceptWorksAfterImmediateRemoval() {
PersistenceRegistry registry = new PersistenceRegistry(getDatabase());
ConceptNet5Enricher enricher = new ConceptNet5Enricher(getDatabase(), registry, new TextProcessorsManager(new DynamicConfiguration(getDatabase())));
clearDb();
executeInTransaction("CALL ga.nlp.annotate({text: 'tension mounted as eclipse time approached.', id: 'test-proc', pipeline: 'tokenizer'})", (result -> {
//
}));
executeInTransaction("MATCH (n:Tag) CALL ga.nlp.enrich.concept({tag: n, depth: 2, language: 'en', admittedRelationships:['IsA','PartOf']}) YIELD result return result", (result -> {
assertTrue(result.hasNext());
}));
executeInTransaction("MATCH (n)-[r:IS_RELATED_TO]->(x) DELETE r", (result -> {
}));
executeInTransaction("MATCH (n:Tag) WHERE size((n)--()) = 0 DELETE n", (result -> {
}));
executeInTransaction("MATCH (n:Tag) CALL ga.nlp.enrich.concept({tag: n, depth: 2, language: 'en', admittedRelationships:['IsA','PartOf']}) YIELD result return result", (result -> {
assertTrue(result.hasNext());
}));
executeInTransaction("MATCH (n)-[r:IS_RELATED_TO]->(x) RETURN r", (result -> {
assertTrue(result.hasNext());
}));
}
use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class ConceptNet5EnricherIntegrationTest method testTagsCanBeEnrichedWithConceptNet5.
@Test
public void testTagsCanBeEnrichedWithConceptNet5() {
PersistenceRegistry registry = new PersistenceRegistry(getDatabase());
ConceptNet5Enricher enricher = new ConceptNet5Enricher(getDatabase(), registry, new TextProcessorsManager(new DynamicConfiguration(getDatabase())));
clearDb();
executeInTransaction("CALL ga.nlp.config.set('SETTING_fallbackLanguage','en')", emptyConsumer());
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.setDepth(1);
request.setProcessor(StubTextProcessor.class.getName());
request.setAdmittedRelationships(Arrays.asList("RelatedTo", "IsA"));
request.setFilterByLanguage(true);
request.setSplitTag(false);
request.setRelDirection("both");
request.setOutputLanguages(Arrays.asList("en"));
enricher.importConcept(request);
tx.success();
});
}
debugTagsRelations();
TestNLPGraph tester = new TestNLPGraph(getDatabase());
tester.assertTagWithValueExist("cats");
// tester.assertTagHasRelatedTag("cats", "cat");
tester.assertTagHasRelatedTag("kill", "death");
}
use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class ConceptNet5EnricherIntegrationTest method testRequestWithRelationshipsConstraintDoNotGetThem.
@Test
public void testRequestWithRelationshipsConstraintDoNotGetThem() {
PersistenceRegistry registry = new PersistenceRegistry(getDatabase());
ConceptNet5Enricher enricher = new ConceptNet5Enricher(getDatabase(), registry, new TextProcessorsManager(new DynamicConfiguration(getDatabase())));
clearDb();
executeInTransaction("CALL ga.nlp.annotate({text: 'tension mounted as the eclipse time approached.', id: 'test-proc', pipeline: 'tokenizer'})", (result -> {
//
}));
try (Transaction tx = getDatabase().beginTx()) {
getDatabase().findNodes(Label.label("Tag")).stream().forEach(node -> {
ConceptRequest request = new ConceptRequest();
request.setTag(node);
// request.setLanguage("en");
request.setDepth(2);
request.setProcessor(StubTextProcessor.class.getName());
request.setAdmittedRelationships(Arrays.asList("IsA", "PartOf"));
request.setFilterByLanguage(true);
request.setSplitTag(false);
enricher.importConcept(request);
tx.success();
});
}
executeInTransaction("MATCH (n)-[r:IS_RELATED_TO]->() WHERE r.type = 'AtLocation' RETURN n, r", (result -> {
assertFalse(result.hasNext());
}));
debugTagsRelations();
}
use of com.graphaware.nlp.processor.TextProcessorsManager in project neo4j-nlp by graphaware.
the class ConceptNet5EnricherIntegrationTest method testConceptEnrichmentWithRelConstraintViaProcedure.
@Test
public void testConceptEnrichmentWithRelConstraintViaProcedure() {
PersistenceRegistry registry = new PersistenceRegistry(getDatabase());
ConceptNet5Enricher enricher = new ConceptNet5Enricher(getDatabase(), registry, new TextProcessorsManager(new DynamicConfiguration(getDatabase())));
clearDb();
executeInTransaction("CALL ga.nlp.annotate({text: 'tension mounted as eclipse time approached.', id: 'test-proc', pipeline: 'tokenizer'})", (result -> {
//
}));
executeInTransaction("MATCH (n:Tag) CALL ga.nlp.enrich.concept({tag: n, depth: 2, language: 'en', admittedRelationships:['IsA','PartOf']}) YIELD result return result", (result -> {
assertTrue(result.hasNext());
}));
executeInTransaction("MATCH (n)-[r:IS_RELATED_TO]->() WHERE r.type = 'AtLocation' RETURN n, r", (result -> {
assertFalse(result.hasNext());
}));
debugTagsRelations();
}
Aggregations