@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); }
/** * Constructor for EntityGraphFactory * * @param monitor to report * @param options to be used during creation of graphs */ public EntityGraphFactory(final UimaMonitor monitor, EntityGraphOptions options) { this.monitor = monitor; this.options = options; DocumentGraphOptions documentOptions = new DocumentGraphOptions.Builder() .withDocument(false) .withRelationsAsLinks(true) .withContentHashAsId(options.isContentHashAsId()) .withEvents(options.isOutputEvents()) .withStopFeatures(options.getStopFeatures()) .withTypeClasses(options.getTypeClasses()) .build(); factory = new DocumentGraphFactory(monitor, documentOptions); }
@Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { super.doInitialize(aContext); Set<Class<? extends Entity>> typeClasses = TypeUtils.getTypeClasses(Entity.class, typeNames); DocumentGraphOptions.Builder builder = DocumentGraphOptions.builder() .withContentHashAsId(contentHashAsId) .withContent(outputContent) .withMeta(outputMeta) .withReferenceTargets(outputReferents) .withRelations(outputRelations) .withRelationsAsLinks(outputRelationsAsLinks) .withEvents(outputEvents) .withDocument(outputDocument) .withStopFeatures(filterFeatures) .withValueCoercer(valueCoercer) .withTypeClasses(typeClasses); addOptions(builder); factory = new DocumentGraphFactory(getMonitor(), builder.build()); }
@Override public void doInitialize(UimaContext aContext) throws ResourceInitializationException { super.doInitialize(aContext); Set<Class<? extends Entity>> typeClasses = TypeUtils.getTypeClasses(Entity.class, typeNames); DocumentGraphOptions.Builder builder = DocumentGraphOptions.builder() .withContentHashAsId(contentHashAsId) .withContent(outputContent) .withMeta(outputMeta) .withReferenceTargets(outputReferents) .withRelations(outputRelations) .withRelationsAsLinks(outputRelationsAsLinks) .withEvents(outputEvents) .withDocument(outputDocument) .withStopFeatures(filterFeatures) .withValueCoercer(valueCoercer) .withTypeClasses(typeClasses); addOptions(builder); factory = new DocumentGraphFactory(getMonitor(), builder.build()); }
/** * Constructor for EntityGraphFactory * * @param monitor to report * @param options to be used during creation of graphs */ public EntityGraphFactory(final UimaMonitor monitor, EntityGraphOptions options) { this.monitor = monitor; this.options = options; DocumentGraphOptions documentOptions = new DocumentGraphOptions.Builder() .withDocument(false) .withRelationsAsLinks(true) .withContentHashAsId(options.isContentHashAsId()) .withEvents(options.isOutputEvents()) .withStopFeatures(options.getStopFeatures()) .withTypeClasses(options.getTypeClasses()) .build(); factory = new DocumentGraphFactory(monitor, documentOptions); }