Search in sources :

Example 21 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class SingleResultPanel method getIds.

private MinMax getIds(SDocumentGraph graph) {
    List<SToken> sTokens = graph.getTokens();
    MinMax minMax = new MinMax();
    minMax.min = Long.MAX_VALUE;
    minMax.max = Long.MIN_VALUE;
    if (segmentationName == null) {
        minMax.segName = "tokens";
        if (sTokens != null) {
            for (SToken t : sTokens) {
                SFeature feature = t.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE);
                if (feature != null && feature.getValue() instanceof RelannisNodeFeature) {
                    RelannisNodeFeature f = (RelannisNodeFeature) feature.getValue();
                    if (minMax.min > f.getTokenIndex()) {
                        minMax.min = f.getTokenIndex();
                    }
                    if (minMax.max < f.getTokenIndex()) {
                        minMax.max = f.getTokenIndex();
                    }
                }
            }
        }
    } else {
        minMax.segName = segmentationName;
        List<SNode> nodes = CommonHelper.getSortedSegmentationNodes(segmentationName, graph);
        for (SNode n : nodes) {
            RelannisNodeFeature f = RelannisNodeFeature.extract(n);
            if (minMax.min > f.getSegIndex()) {
                minMax.min = f.getSegIndex();
            }
            if (minMax.max < f.getSegIndex()) {
                minMax.max = f.getSegIndex();
            }
        }
    }
    minMax.min++;
    minMax.max++;
    return minMax;
}
Also used : SToken(org.corpus_tools.salt.common.SToken) RelannisNodeFeature(annis.model.RelannisNodeFeature) SNode(org.corpus_tools.salt.core.SNode) SFeature(org.corpus_tools.salt.core.SFeature)

Example 22 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class TimelineReconstructor method createTokenFromSOrder.

private void createTokenFromSOrder() {
    nodesToDelete.add(graph.getTextualDSs().get(0));
    Map<String, SSpan> rootNodes = new HashMap<>();
    // also add nodes that are are marked as start by ANNIS even if they don't have an outgoing order rel
    for (SSpan n : graph.getSpans()) {
        SFeature feat = n.getFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_FIRST_NODE_SEGMENTATION_CHAIN);
        if (feat != null && feat.getValue_STEXT() != null) {
            rootNodes.put(feat.getValue_STEXT(), n);
        } else {
            // check if there is no incoming SOrderRelation but an outgoing
            boolean isRoot = true;
            for (SRelation<?, ?> inRel : n.getInRelations()) {
                if (inRel instanceof SOrderRelation) {
                    isRoot = false;
                    break;
                }
            }
            if (isRoot) {
                for (SRelation<?, ?> outRel : n.getOutRelations()) {
                    if (outRel instanceof SOrderRelation) {
                        rootNodes.put(((SOrderRelation) outRel).getType(), n);
                        break;
                    }
                }
            }
        }
    }
    // convert all root nodes to spans
    for (Map.Entry<String, SSpan> rootEntry : rootNodes.entrySet()) {
        SNode root = rootEntry.getValue();
        String orderName = rootEntry.getKey();
        convertSpanToToken((SSpan) root, orderName);
    }
    // traverse through all SOrderRelations in order
    graph.traverse(new LinkedList<SNode>(rootNodes.values()), GRAPH_TRAVERSE_TYPE.TOP_DOWN_DEPTH_FIRST, "TimeReconstructSOrderRelations", new GraphTraverseHandler() {

        @Override
        public void nodeReached(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order) {
            if (relation instanceof SOrderRelation && currNode instanceof SSpan) {
                String orderName = ((SOrderRelation) relation).getType();
                if (fromNode != null) {
                    // add a space to the text
                    StringBuilder t = textDataByName.get(orderName);
                    if (t != null) {
                        t.append(" ");
                    }
                }
                convertSpanToToken((SSpan) currNode, orderName);
            }
        }

        @Override
        public void nodeLeft(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order) {
        }

        @Override
        public boolean checkConstraint(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SRelation relation, SNode currNode, long order) {
            if (relation == null || relation instanceof SOrderRelation) {
                return true;
            } else {
                return false;
            }
        }
    });
    // update the text of the TextualDSs
    for (Map.Entry<String, StringBuilder> textDataEntry : textDataByName.entrySet()) {
        STextualDS textDS = textsByName.get(textDataEntry.getKey());
        if (textDS != null) {
            textDS.setText(textDataEntry.getValue().toString());
        }
    }
}
Also used : SNode(org.corpus_tools.salt.core.SNode) SSpan(org.corpus_tools.salt.common.SSpan) HashMap(java.util.HashMap) GRAPH_TRAVERSE_TYPE(org.corpus_tools.salt.core.SGraph.GRAPH_TRAVERSE_TYPE) GraphTraverseHandler(org.corpus_tools.salt.core.GraphTraverseHandler) SRelation(org.corpus_tools.salt.core.SRelation) STextualDS(org.corpus_tools.salt.common.STextualDS) SOrderRelation(org.corpus_tools.salt.common.SOrderRelation) HashMap(java.util.HashMap) Map(java.util.Map) SFeature(org.corpus_tools.salt.core.SFeature)

Example 23 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class SaltProjectProvider method writeTo.

@Override
public void writeTo(SaltProject project, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    SaltXML10Writer writer = new SaltXML10Writer();
    try {
        XMLStreamWriter xml = outFactory.createXMLStreamWriter(entityStream, "UTF-8");
        xml.writeStartDocument("1.1");
        xml.writeCharacters("\n");
        long startTime = System.currentTimeMillis();
        // output XMI root element
        writer.writeXMIRootElement(xml);
        for (SCorpusGraph corpusGraph : project.getCorpusGraphs()) {
            for (SDocument doc : corpusGraph.getDocuments()) {
                // make sure that any ANNIS feature on the document is copied to the document graph
                SDocumentGraph docGraph = doc.getDocumentGraph();
                for (SFeature feat : doc.getFeatures()) {
                    if (AnnisConstants.ANNIS_NS.equals(feat.getNamespace())) {
                        SFeature newFeat = SaltFactory.createSFeature();
                        feat.copy(newFeat);
                        docGraph.addFeature(newFeat);
                    }
                }
                writer.writeObjects(xml, docGraph);
            }
        }
        xml.writeEndDocument();
        long endTime = System.currentTimeMillis();
        log.debug("Saving XMI (" + mediaType.toString() + ") needed {} ms", endTime - startTime);
    } catch (XMLStreamException ex) {
        log.error("exception when serializing SDocumentGraph", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SaltXML10Writer(org.corpus_tools.salt.util.internal.persistence.SaltXML10Writer) SDocument(org.corpus_tools.salt.common.SDocument) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) SFeature(org.corpus_tools.salt.core.SFeature)

Example 24 with SFeature

use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.

the class RelannisEdgeFeature method extract.

public static RelannisEdgeFeature extract(SRelation rel) {
    RelannisEdgeFeature featRelation = null;
    SFeature sfeatRelation = rel.getFeature(ANNIS_NS + "::" + FEAT_RELANNIS_EDGE);
    if (sfeatRelation != null) {
        featRelation = (RelannisEdgeFeature) sfeatRelation.getValue();
    }
    return featRelation;
}
Also used : SFeature(org.corpus_tools.salt.core.SFeature)

Aggregations

SFeature (org.corpus_tools.salt.core.SFeature)24 SNode (org.corpus_tools.salt.core.SNode)12 RelannisNodeFeature (annis.model.RelannisNodeFeature)8 SToken (org.corpus_tools.salt.common.SToken)8 HashMap (java.util.HashMap)6 SRelation (org.corpus_tools.salt.core.SRelation)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 SAnnotation (org.corpus_tools.salt.core.SAnnotation)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 TreeMap (java.util.TreeMap)3 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)3 SOrderRelation (org.corpus_tools.salt.common.SOrderRelation)3 STextualDS (org.corpus_tools.salt.common.STextualDS)3 AnnotationGraph (annis.model.AnnotationGraph)2 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)2 LinkedHashSet (java.util.LinkedHashSet)2 SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)2