Search in sources :

Example 1 with SFeature

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

the class VisJsComponent method setHighlightingColor.

/**
 * Implements the getHighlightingColor method of the org.corpus_tools.salt.util.StyleImporter interface.
 */
@Override
public String setHighlightingColor(SNode node) {
    String color = null;
    SFeature featMatched = node.getFeature(ANNIS_NS, FEAT_MATCHEDNODE);
    Long matchRaw = featMatched == null ? null : featMatched.getValue_SNUMERIC();
    // token is matched
    if (matchRaw != null) {
        color = MatchedNodeColors.getHTMLColorByMatch(matchRaw);
        return color;
    }
    return color;
}
Also used : SFeature(org.corpus_tools.salt.core.SFeature)

Example 2 with SFeature

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

the class Helper method addMatchToDocumentGraph.

public static void addMatchToDocumentGraph(Match match, SDocument document) {
    List<String> allUrisAsString = new LinkedList<>();
    long i = 1;
    for (URI u : match.getSaltIDs()) {
        allUrisAsString.add(u.toASCIIString());
        SNode matchedNode = document.getDocumentGraph().getNode(u.toASCIIString());
        // set the feature for this specific node
        if (matchedNode != null) {
            SFeature existing = matchedNode.getFeature(ANNIS_NS, FEAT_MATCHEDNODE);
            if (existing == null) {
                SFeature featMatchedNode = SaltFactory.createSFeature();
                featMatchedNode.setNamespace(ANNIS_NS);
                featMatchedNode.setName(FEAT_MATCHEDNODE);
                featMatchedNode.setValue(i);
                matchedNode.addFeature(featMatchedNode);
            }
        }
        i++;
    }
    SFeature featIDs = SaltFactory.createSFeature();
    featIDs.setNamespace(ANNIS_NS);
    featIDs.setName(FEAT_MATCHEDIDS);
    featIDs.setValue(Joiner.on(",").join(allUrisAsString));
    document.addFeature(featIDs);
    SFeature featAnnos = SaltFactory.createSFeature();
    featAnnos.setNamespace(ANNIS_NS);
    featAnnos.setName(FEAT_MATCHEDANNOS);
    featAnnos.setValue(Joiner.on(",").join(match.getAnnos()));
    document.addFeature(featAnnos);
}
Also used : SNode(org.corpus_tools.salt.core.SNode) URI(java.net.URI) LinkedList(java.util.LinkedList) SFeature(org.corpus_tools.salt.core.SFeature)

Example 3 with SFeature

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

the class Helper method calculateColorsForMarkedExact.

public static Map<String, String> calculateColorsForMarkedExact(SDocument result) {
    Map<String, String> markedExactMap = new HashMap<>();
    if (result != null) {
        SDocumentGraph g = result.getDocumentGraph();
        if (g != null) {
            for (SNode n : result.getDocumentGraph().getNodes()) {
                SFeature featMatched = n.getFeature(ANNIS_NS, FEAT_MATCHEDNODE);
                Long matchNum = featMatched == null ? null : featMatched.getValue_SNUMERIC();
                if (matchNum != null) {
                    int color = Math.max(0, Math.min((int) matchNum.longValue() - 1, MatchedNodeColors.values().length - 1));
                    RelannisNodeFeature feat = RelannisNodeFeature.extract(n);
                    if (feat != null) {
                        markedExactMap.put("" + feat.getInternalID(), MatchedNodeColors.values()[color].name());
                    }
                }
            }
        }
    // end if g not null
    }
    // end if result not null
    return markedExactMap;
}
Also used : RelannisNodeFeature(annis.model.RelannisNodeFeature) SNode(org.corpus_tools.salt.core.SNode) HashMap(java.util.HashMap) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SFeature(org.corpus_tools.salt.core.SFeature)

Example 4 with SFeature

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

the class SaltAnnotateExtractor method createSinglePrimaryText.

private void createSinglePrimaryText(SDocumentGraph graph, long textID, TreeMap<Long, String> tokenTexts, TreeMap<Long, SToken> tokenByIndex) {
    STextualDS textDataSource = SaltFactory.createSTextualDS();
    textDataSource.setName("sText" + textID);
    graph.addNode(textDataSource);
    StringBuilder sbText = new StringBuilder();
    Iterator<Map.Entry<Long, String>> itToken = tokenTexts.entrySet().iterator();
    long index = 0;
    while (itToken.hasNext()) {
        Map.Entry<Long, String> e = itToken.next();
        SToken tok = tokenByIndex.get(e.getKey());
        SFeature rawFeature = tok.getFeature(SaltUtil.createQName(ANNIS_NS, FEAT_RELANNIS_NODE));
        if (rawFeature != null) {
            RelannisNodeFeature feat = (RelannisNodeFeature) rawFeature.getValue();
            if (feat.getTextRef() == textID) {
                STextualRelation textRel = SaltFactory.createSTextualRelation();
                textRel.setSource(tok);
                textRel.setTarget(textDataSource);
                textRel.setStart(sbText.length());
                textRel.setEnd(sbText.length() + e.getValue().length());
                textRel.setName("sTextRel" + textID + "_" + (index++));
                textRel.setTarget(textDataSource);
                graph.addRelation(textRel);
                sbText.append(e.getValue());
                if (itToken.hasNext()) {
                    sbText.append(" ");
                }
            }
        }
    }
    textDataSource.setText(sbText.toString());
}
Also used : RelannisNodeFeature(annis.model.RelannisNodeFeature) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SToken(org.corpus_tools.salt.common.SToken) STextualDS(org.corpus_tools.salt.common.STextualDS) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) SFeature(org.corpus_tools.salt.core.SFeature)

Example 5 with SFeature

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

the class SaltAnnotateExtractor method createNewRelation.

private SRelation createNewRelation(SDocumentGraph graph, SStructuredNode sourceNode, SNode targetNode, String relationName, String type, long componentID, SLayer layer, long pre, FastInverseMap<Long, SNode> nodeByRankID, AtomicInteger numberOfRelations) {
    SRelation rel = null;
    if (null != type) // create new relation
    {
        switch(type) {
            case "d":
                SDominanceRelation domrel = SaltFactory.createSDominanceRelation();
                // always set a name by ourself since the SDocumentGraph#basicAddRelation()
                // functions otherwise real slow
                domrel.setName("sDomRel" + numberOfRelations.incrementAndGet());
                rel = domrel;
                if (sourceNode != null && !(sourceNode instanceof SStructure)) {
                    log.debug("Mismatched source type: should be SStructure");
                    SNode oldNode = sourceNode;
                    sourceNode = recreateNode(SStructure.class, sourceNode);
                    updateMapAfterRecreatingNode(oldNode, sourceNode, nodeByRankID);
                }
                if (relationName == null || relationName.isEmpty()) {
                    // layer but has a non-empty relation name
                    if (handleArtificialDominanceRelation(graph, sourceNode, targetNode, rel, layer, componentID, pre)) {
                        // don't include this relation
                        rel = null;
                    }
                }
                break;
            case "c":
                SSpanningRelation spanrel = SaltFactory.createSSpanningRelation();
                // always set a name by ourself since the SDocumentGraph#basicAddRelation()
                // functions is real slow otherwise
                spanrel.setName("sSpanRel" + numberOfRelations.incrementAndGet());
                rel = spanrel;
                sourceNode = testAndFixNonSpan(sourceNode, nodeByRankID);
                break;
            case "p":
                SPointingRelation pointingrel = SaltFactory.createSPointingRelation();
                pointingrel.setName("sPointingRel" + numberOfRelations.incrementAndGet());
                rel = pointingrel;
                break;
            default:
                throw new IllegalArgumentException("Invalid type " + type + " for new Relation");
        }
        try {
            if (rel != null) {
                rel.setType(relationName);
                RelannisEdgeFeature featRelation = new RelannisEdgeFeature();
                featRelation.setPre(pre);
                featRelation.setComponentID(componentID);
                SFeature sfeatRelation = SaltFactory.createSFeature();
                sfeatRelation.setNamespace(ANNIS_NS);
                sfeatRelation.setName(FEAT_RELANNIS_EDGE);
                sfeatRelation.setValue(featRelation);
                rel.addFeature(sfeatRelation);
                rel.setSource(sourceNode);
                if ("c".equals(type) && !(targetNode instanceof SToken)) {
                    log.warn("invalid relation detected: target node ({}) " + "of a coverage relation (from: {}, internal id {}) was not a token", new Object[] { targetNode.getName(), sourceNode == null ? "null" : sourceNode.getName(), "" + pre });
                } else {
                    rel.setTarget(targetNode);
                    graph.addRelation(rel);
                    layer.addRelation(rel);
                }
            }
        } catch (SaltException ex) {
            log.warn("invalid relation detected", ex);
        }
    }
    return rel;
}
Also used : SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SToken(org.corpus_tools.salt.common.SToken) SRelation(org.corpus_tools.salt.core.SRelation) SNode(org.corpus_tools.salt.core.SNode) SaltException(org.corpus_tools.salt.exceptions.SaltException) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) RelannisEdgeFeature(annis.model.RelannisEdgeFeature) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) SStructure(org.corpus_tools.salt.common.SStructure) 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