Search in sources :

Example 26 with TextAnnotation

use of com.google.cloud.vision.v1p4beta1.TextAnnotation in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallNode.

protected void marshallNode(FlowNode node, Map<String, Object> properties, String stencil, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
    if (properties == null) {
        properties = new LinkedHashMap<String, Object>();
    }
    putDocumentationProperty(node, properties);
    if (node.getName() != null) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(node.getName()));
    } else {
        if (node instanceof TextAnnotation) {
            if (((TextAnnotation) node).getText() != null) {
                properties.put(NAME, ((TextAnnotation) node).getText());
            } else {
                properties.put(NAME, "");
            }
        } else {
            properties.put(NAME, "");
        }
    }
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(node.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put("name", elementName);
    }
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", stencil);
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    for (SequenceFlow outgoing : node.getOutgoing()) {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", outgoing.getId());
        generator.writeEndObject();
    }
    // we need to also add associations as outgoing elements
    Process process = (Process) plane.getBpmnElement();
    writeAssociations(process, node.getId(), generator);
    // and boundary events for activities
    List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
    findBoundaryEvents(process, boundaryEvents);
    for (BoundaryEvent be : boundaryEvents) {
        if (be.getAttachedToRef().getId().equals(node.getId())) {
            generator.writeStartObject();
            generator.writeObjectField("resourceId", be.getId());
            generator.writeEndObject();
        }
    }
    generator.writeEndArray();
    // boundary events have a docker
    if (node instanceof BoundaryEvent) {
        Iterator<FeatureMap.Entry> iter = node.getAnyAttribute().iterator();
        boolean foundDockerInfo = false;
        while (iter.hasNext()) {
            FeatureMap.Entry entry = iter.next();
            if (entry.getEStructuralFeature().getName().equals("dockerinfo")) {
                foundDockerInfo = true;
                String dockerInfoStr = String.valueOf(entry.getValue());
                if (dockerInfoStr != null && dockerInfoStr.length() > 0) {
                    if (dockerInfoStr.endsWith("|")) {
                        dockerInfoStr = dockerInfoStr.substring(0, dockerInfoStr.length() - 1);
                        String[] dockerInfoParts = dockerInfoStr.split("\\|");
                        String infoPartsToUse = dockerInfoParts[0];
                        String[] infoPartsToUseParts = infoPartsToUse.split("\\^");
                        if (infoPartsToUseParts != null && infoPartsToUseParts.length > 0) {
                            generator.writeArrayFieldStart("dockers");
                            generator.writeStartObject();
                            generator.writeObjectField("x", Double.valueOf(infoPartsToUseParts[0]));
                            generator.writeObjectField("y", Double.valueOf(infoPartsToUseParts[1]));
                            generator.writeEndObject();
                            generator.writeEndArray();
                        }
                    }
                }
            }
        }
        // backwards compatibility to older versions -- BZ 1196259
        if (!foundDockerInfo) {
            // find the edge associated with this boundary event
            for (DiagramElement element : plane.getPlaneElement()) {
                if (element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == node) {
                    List<Point> waypoints = ((BPMNEdge) element).getWaypoint();
                    if (waypoints != null && waypoints.size() > 0) {
                        // one per boundary event
                        Point p = waypoints.get(0);
                        if (p != null) {
                            generator.writeArrayFieldStart("dockers");
                            generator.writeStartObject();
                            generator.writeObjectField("x", p.getX());
                            generator.writeObjectField("y", p.getY());
                            generator.writeEndObject();
                            generator.writeEndArray();
                        }
                    }
                }
            }
        }
    }
    BPMNShape shape = (BPMNShape) findDiagramElement(plane, node);
    Bounds bounds = shape.getBounds();
    correctEventNodeSize(shape);
    generator.writeObjectFieldStart("bounds");
    generator.writeObjectFieldStart("lowerRight");
    generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
    generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
    generator.writeEndObject();
    generator.writeObjectFieldStart("upperLeft");
    generator.writeObjectField("x", bounds.getX() - xOffset);
    generator.writeObjectField("y", bounds.getY() - yOffset);
    generator.writeEndObject();
    generator.writeEndObject();
}
Also used : BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) Bounds(org.eclipse.dd.dc.Bounds) ArrayList(java.util.ArrayList) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) DiagramElement(org.eclipse.dd.di.DiagramElement) Entry(java.util.Map.Entry) DataObject(org.eclipse.bpmn2.DataObject) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 27 with TextAnnotation

use of com.google.cloud.vision.v1p4beta1.TextAnnotation in project kie-wb-common by kiegroup.

the class TextAnnotationConverter method dmnFromNode.

@Override
public org.kie.dmn.model.v1_1.TextAnnotation dmnFromNode(final Node<View<TextAnnotation>, ?> node) {
    TextAnnotation source = node.getContent().getDefinition();
    org.kie.dmn.model.v1_1.TextAnnotation result = new org.kie.dmn.model.v1_1.TextAnnotation();
    result.setId(source.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    result.setText(source.getText().getValue());
    result.setTextFormat(source.getTextFormat().getValue());
    return result;
}
Also used : TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)

Example 28 with TextAnnotation

use of com.google.cloud.vision.v1p4beta1.TextAnnotation in project kie-wb-common by kiegroup.

the class TextAnnotationConverter method nodeFromDMN.

@Override
public Node<View<TextAnnotation>, ?> nodeFromDMN(final org.kie.dmn.model.v1_1.TextAnnotation dmn) {
    @SuppressWarnings("unchecked") Node<View<TextAnnotation>, ?> node = (Node<View<TextAnnotation>, ?>) factoryManager.newElement(dmn.getId(), TextAnnotation.class).asNode();
    Id id = new Id(dmn.getId());
    Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    Text text = new Text(dmn.getText());
    TextFormat textFormat = new TextFormat(dmn.getTextFormat());
    TextAnnotation textAnnotation = new TextAnnotation(id, description, text, textFormat, new BackgroundSet(), new FontSet(), new RectangleDimensionsSet());
    node.getContent().setDefinition(textAnnotation);
    return node;
}
Also used : FontSet(org.kie.workbench.common.dmn.api.property.font.FontSet) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) BackgroundSet(org.kie.workbench.common.dmn.api.property.background.BackgroundSet) Node(org.kie.workbench.common.stunner.core.graph.Node) TextFormat(org.kie.workbench.common.dmn.api.property.dmn.TextFormat) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 29 with TextAnnotation

use of com.google.cloud.vision.v1p4beta1.TextAnnotation in project kie-wb-common by kiegroup.

the class DMNMarshaller method marshall.

@Override
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
    Graph<?, Node<View, ?>> g = diagram.getGraph();
    Map<String, org.kie.dmn.model.v1_1.DRGElement> nodes = new HashMap<>();
    Map<String, org.kie.dmn.model.v1_1.TextAnnotation> textAnnotations = new HashMap<>();
    @SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) findDMNDiagramRoot(g);
    Definitions definitionsStunnerPojo = dmnDiagramRoot.getContent().getDefinition().getDefinitions();
    org.kie.dmn.model.v1_1.Definitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo);
    if (definitions.getExtensionElements() == null) {
        definitions.setExtensionElements(new org.kie.dmn.model.v1_1.Definitions.ExtensionElements());
    }
    org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram dmnDDDMNDiagram = new org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram();
    definitions.getExtensionElements().getAny().add(dmnDDDMNDiagram);
    for (Node<?, ?> node : g.nodes()) {
        if (node.getContent() instanceof View<?>) {
            View<?> view = (View<?>) node.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                DRGElement n = (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) view.getDefinition();
                nodes.put(n.getId().getValue(), stunnerToDMN(node));
                dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
            } else if (view.getDefinition() instanceof TextAnnotation) {
                TextAnnotation textAnnotation = (TextAnnotation) view.getDefinition();
                textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node));
                dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
                List<org.kie.dmn.model.v1_1.Association> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
                definitions.getArtifact().addAll(associations);
            }
        }
    }
    nodes.values().forEach(definitions.getDrgElement()::add);
    textAnnotations.values().forEach(definitions.getArtifact()::add);
    String marshalled = marshaller.marshal(definitions);
    return marshalled;
}
Also used : HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNElement(org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement) List(java.util.List) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)

Example 30 with TextAnnotation

use of com.google.cloud.vision.v1p4beta1.TextAnnotation in project spring-cloud-gcp by spring-cloud.

the class DocumentOcrTemplateIntegrationTests method testDocumentOcrTemplate.

@Test
public void testDocumentOcrTemplate() throws ExecutionException, InterruptedException, InvalidProtocolBufferException, TimeoutException {
    GoogleStorageLocation document = GoogleStorageLocation.forFile("vision-integration-test-bucket", "test.pdf");
    GoogleStorageLocation outputLocationPrefix = GoogleStorageLocation.forFile("vision-integration-test-bucket", "it_output/test-");
    ListenableFuture<DocumentOcrResultSet> result = this.documentOcrTemplate.runOcrForDocument(document, outputLocationPrefix);
    DocumentOcrResultSet ocrPages = result.get(5, TimeUnit.MINUTES);
    String page1Text = ocrPages.getPage(1).getText();
    assertThat(page1Text).contains("Hello World. Is mayonnaise an instrument?");
    String page2Text = ocrPages.getPage(2).getText();
    assertThat(page2Text).contains("Page 2 stuff");
    ArrayList<String> pageContent = new ArrayList<>();
    Iterator<TextAnnotation> pageIterator = ocrPages.getAllPages();
    while (pageIterator.hasNext()) {
        pageContent.add(pageIterator.next().getText());
    }
    assertThat(pageContent).containsExactly("Hello World. Is mayonnaise an instrument?\n", "Page 2 stuff\n", "Page 3 stuff\n", "Page 4 stuff\n");
}
Also used : DocumentOcrResultSet(org.springframework.cloud.gcp.vision.DocumentOcrResultSet) ArrayList(java.util.ArrayList) GoogleStorageLocation(org.springframework.cloud.gcp.storage.GoogleStorageLocation) TextAnnotation(com.google.cloud.vision.v1.TextAnnotation) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)15 TextAnnotation (com.google.cloud.vision.v1.TextAnnotation)12 Test (org.junit.Test)11 ByteString (com.google.protobuf.ByteString)9 TextAnnotation (com.google.cloud.videointelligence.v1.TextAnnotation)8 VideoAnnotationResults (com.google.cloud.videointelligence.v1.VideoAnnotationResults)8 List (java.util.List)7 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)7 FreeTextAnnotation (org.opencastproject.metadata.mpeg7.FreeTextAnnotation)7 TextAnnotation (org.opencastproject.metadata.mpeg7.TextAnnotation)7 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)6 Duration (com.google.protobuf.Duration)6 AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)4 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)4 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)4 NormalizedVertex (com.google.cloud.videointelligence.v1.NormalizedVertex)4 TextFrame (com.google.cloud.videointelligence.v1.TextFrame)4 TextSegment (com.google.cloud.videointelligence.v1.TextSegment)4 VideoIntelligenceServiceClient (com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient)4 VideoSegment (com.google.cloud.videointelligence.v1.VideoSegment)4