Search in sources :

Example 1 with ConceptRequest

use of com.graphaware.nlp.dsl.request.ConceptRequest 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");
}
Also used : PersistenceRegistry(com.graphaware.nlp.persistence.PersistenceRegistry) DynamicConfiguration(com.graphaware.nlp.configuration.DynamicConfiguration) Transaction(org.neo4j.graphdb.Transaction) TextProcessorsManager(com.graphaware.nlp.processor.TextProcessorsManager) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) ConceptRequest(com.graphaware.nlp.dsl.request.ConceptRequest) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EnricherAbstractTest(com.graphaware.nlp.enrich.EnricherAbstractTest) Test(org.junit.Test)

Example 2 with ConceptRequest

use of com.graphaware.nlp.dsl.request.ConceptRequest 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();
}
Also used : Arrays(java.util.Arrays) DynamicConfiguration(com.graphaware.nlp.configuration.DynamicConfiguration) PersistenceRegistry(com.graphaware.nlp.persistence.PersistenceRegistry) Label(org.neo4j.graphdb.Label) EnricherAbstractTest(com.graphaware.nlp.enrich.EnricherAbstractTest) TextProcessor(com.graphaware.nlp.processor.TextProcessor) ConceptRequest(com.graphaware.nlp.dsl.request.ConceptRequest) Test(org.junit.Test) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) TextProcessorsManager(com.graphaware.nlp.processor.TextProcessorsManager) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) Ignore(org.junit.Ignore) Transaction(org.neo4j.graphdb.Transaction) Assert(org.junit.Assert) Collections(java.util.Collections) Before(org.junit.Before) PersistenceRegistry(com.graphaware.nlp.persistence.PersistenceRegistry) DynamicConfiguration(com.graphaware.nlp.configuration.DynamicConfiguration) Transaction(org.neo4j.graphdb.Transaction) TextProcessorsManager(com.graphaware.nlp.processor.TextProcessorsManager) ConceptRequest(com.graphaware.nlp.dsl.request.ConceptRequest) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EnricherAbstractTest(com.graphaware.nlp.enrich.EnricherAbstractTest) Test(org.junit.Test)

Example 3 with ConceptRequest

use of com.graphaware.nlp.dsl.request.ConceptRequest 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");
}
Also used : PersistenceRegistry(com.graphaware.nlp.persistence.PersistenceRegistry) DynamicConfiguration(com.graphaware.nlp.configuration.DynamicConfiguration) Transaction(org.neo4j.graphdb.Transaction) TextProcessorsManager(com.graphaware.nlp.processor.TextProcessorsManager) TestNLPGraph(com.graphaware.nlp.util.TestNLPGraph) ConceptRequest(com.graphaware.nlp.dsl.request.ConceptRequest) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EnricherAbstractTest(com.graphaware.nlp.enrich.EnricherAbstractTest) Test(org.junit.Test)

Example 4 with ConceptRequest

use of com.graphaware.nlp.dsl.request.ConceptRequest 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();
    }
}
Also used : PersistenceRegistry(com.graphaware.nlp.persistence.PersistenceRegistry) DynamicConfiguration(com.graphaware.nlp.configuration.DynamicConfiguration) Transaction(org.neo4j.graphdb.Transaction) TextProcessorsManager(com.graphaware.nlp.processor.TextProcessorsManager) ConceptRequest(com.graphaware.nlp.dsl.request.ConceptRequest) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) EnricherAbstractTest(com.graphaware.nlp.enrich.EnricherAbstractTest) Test(org.junit.Test)

Example 5 with ConceptRequest

use of com.graphaware.nlp.dsl.request.ConceptRequest in project neo4j-nlp by graphaware.

the class ConceptRequestUnitTest method testRequestThrowsFriendlyMessageWithAlmostGoodConfigKey.

@Test(expected = RuntimeException.class)
public void testRequestThrowsFriendlyMessageWithAlmostGoodConfigKey() {
    Map<String, Object> map = new HashMap<>();
    map.put("node", new NodeProxy());
    map.put("language", "en");
    map.put("admittedRelationship", new ArrayList<>());
    ConceptRequest request = ConceptRequest.fromMap(map);
}
Also used : HashMap(java.util.HashMap) ConceptRequest(com.graphaware.nlp.dsl.request.ConceptRequest) NodeProxy(com.graphaware.nlp.util.NodeProxy) Test(org.junit.Test)

Aggregations

ConceptRequest (com.graphaware.nlp.dsl.request.ConceptRequest)8 Test (org.junit.Test)7 DynamicConfiguration (com.graphaware.nlp.configuration.DynamicConfiguration)4 EnricherAbstractTest (com.graphaware.nlp.enrich.EnricherAbstractTest)4 PersistenceRegistry (com.graphaware.nlp.persistence.PersistenceRegistry)4 TextProcessorsManager (com.graphaware.nlp.processor.TextProcessorsManager)4 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)4 Transaction (org.neo4j.graphdb.Transaction)4 NodeProxy (com.graphaware.nlp.util.NodeProxy)3 TestNLPGraph (com.graphaware.nlp.util.TestNLPGraph)3 HashMap (java.util.HashMap)3 NodeResult (com.graphaware.nlp.dsl.result.NodeResult)1 Enricher (com.graphaware.nlp.enrich.Enricher)1 TextProcessor (com.graphaware.nlp.processor.TextProcessor)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Label (org.neo4j.graphdb.Label)1