@Test public void testDocumentGraphCreatesMetadataFromJCas() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withMeta(true).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertMetadata(jCas, graph.variables().asMap()); }
@Test public void testDocumentGraphCreatesVerticiesAndEdgesFromJCas() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertEquals(3, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue()); assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue()); assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue()); assertEquals(2, graph.traversal().V().hasLabel(RELATION).count().next().intValue()); assertEquals(4, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue()); assertNoDocumentNode(graph); assertNoRelationEdges(graph); assertEquals(10, IteratorUtils.count(graph.vertices())); assertEquals(10, IteratorUtils.count(graph.edges())); }
@Test public void testDocumentGraphWithRelationsAsLinks() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withRelationsAsLinks(true).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertEquals(3, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue()); assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue()); assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue()); assertEquals(4, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(RELATION).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue()); assertNoDocumentNode(graph); assertRelationsNotRerified(graph); assertEquals(8, IteratorUtils.count(graph.vertices())); assertEquals(8, IteratorUtils.count(graph.edges())); } }
@Test public void testDocumentGraphWithoutReferents() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withReferenceTargets(false).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertEquals(0, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue()); assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue()); assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue()); assertEquals(2, graph.traversal().V().hasLabel(RELATION).count().next().intValue()); assertEquals(0, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue()); assertNoDocumentNode(graph); assertEquals(7, IteratorUtils.count(graph.vertices())); assertEquals(6, IteratorUtils.count(graph.edges())); }
@Test public void testDocumentGraphMetadataHasContentFromJCas() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withContent(true).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); Variables variables = graph.variables(); assertEquals(JCasTestGraphUtil.CONTENT, variables.get(FIELD_CONTENT).orElse("")); }
@Test public void testDocumentGraphWithoutEvents() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withEvents(false).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertEquals(3, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue()); assertEquals(0, graph.traversal().V().hasLabel(EVENT).count().next().intValue()); assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue()); assertEquals(2, graph.traversal().V().hasLabel(RELATION).count().next().intValue()); assertEquals(4, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue()); assertEquals(0, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue()); assertNoDocumentNode(graph); assertNoRelationEdges(graph); assertEquals(9, IteratorUtils.count(graph.vertices())); assertEquals(8, IteratorUtils.count(graph.edges())); }
@Test public void testDocumentGraphWithoutRelations() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withRelations(false).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertEquals(3, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue()); assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue()); assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue()); assertEquals(4, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue()); assertEquals(0, graph.traversal().E().hasLabel(RELATION).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue()); assertNoDocumentNode(graph); assertRelationsNotRerified(graph); assertEquals(8, IteratorUtils.count(graph.vertices())); assertEquals(6, IteratorUtils.count(graph.edges())); }
DocumentGraphFactory factory = createfactory(options);
@Test public void testDocumentGraphWithTypeFiltering() throws UIMAException { Set<Class<? extends Entity>> typeClasses = TypeUtils.getTypeClasses(Entity.class, Person.class.getSimpleName()); DocumentGraphOptions options = DocumentGraphOptions.builder().withTypeClasses(typeClasses).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertEquals(2, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue()); assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue()); assertEquals(3, graph.traversal().V().hasLabel(MENTION).count().next().intValue()); assertEquals(1, graph.traversal().V().hasLabel(RELATION).count().next().intValue()); assertEquals(3, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue()); assertNoDocumentNode(graph); assertNoRelationEdges(graph); assertEquals(7, IteratorUtils.count(graph.vertices())); assertEquals(7, IteratorUtils.count(graph.edges())); }
@Test public void testDocumentGraphWithDocument() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withDocument(true).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); assertEquals(1, graph.traversal().V().hasLabel(DOCUMENT).count().next().intValue()); assertEquals(10, graph.traversal().E().hasLabel(MENTION_IN).count().next().intValue()); assertEquals(2, graph.traversal().V().hasLabel(RELATION).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(SOURCE).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(TARGET).count().next().intValue()); assertEquals(3, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue()); assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue()); assertEquals(4, graph.traversal().V().hasLabel(MENTION).count().next().intValue()); assertEquals(4, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue()); assertEquals(0, graph.traversal().E().hasLabel(RELATION).count().next().intValue()); assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue()); assertEquals(11, IteratorUtils.count(graph.vertices())); assertEquals(20, IteratorUtils.count(graph.edges())); DocumentAnnotation da = UimaSupport.getDocumentAnnotation(jCas); String documentId = ConsumerUtils.getExternalId(da, false); Vertex documentVert = graph.traversal().V(documentId).next(); Map<String, Object> properties = new HashMap<>(); documentVert.properties().forEachRemaining(vp -> properties.put(vp.key(), vp.value())); assertMetadata(jCas, properties); }