Search in sources :

Example 6 with SFeature

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

the class SaltAnnotateExtractor method setFeaturesForNode.

private void setFeaturesForNode(SStructuredNode node, long internalID, ResultSet resultSet) throws SQLException {
    SFeature feat = SaltFactory.createSFeature();
    feat.setNamespace(ANNIS_NS);
    feat.setName(FEAT_RELANNIS_NODE);
    RelannisNodeFeature val = new RelannisNodeFeature();
    val.setInternalID(longValue(resultSet, "node", "id"));
    val.setCorpusRef(longValue(resultSet, "node", "corpus_ref"));
    val.setTextRef(longValue(resultSet, "node", "text_ref"));
    val.setLeft(longValue(resultSet, "node", "left"));
    val.setLeftToken(longValue(resultSet, "node", "left_token"));
    val.setRight(longValue(resultSet, "node", "right"));
    val.setRightToken(longValue(resultSet, "node", "right_token"));
    val.setTokenIndex(longValue(resultSet, "node", "token_index"));
    val.setSegIndex(longValue(resultSet, "node", "seg_index"));
    val.setSegName(stringValue(resultSet, "node", "seg_name"));
    feat.setValue(val);
    node.addFeature(feat);
}
Also used : RelannisNodeFeature(annis.model.RelannisNodeFeature) SFeature(org.corpus_tools.salt.core.SFeature)

Example 7 with SFeature

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

the class SaltAnnotateExtractor method setMatchedIDs.

private static void setMatchedIDs(SDocumentGraph docGraph, Match match) {
    List<String> allUrisAsString = new LinkedList<>();
    for (URI u : match.getSaltIDs()) {
        allUrisAsString.add(u.toASCIIString());
    }
    // set the matched keys
    SFeature featIDs = SaltFactory.createSFeature();
    featIDs.setNamespace(ANNIS_NS);
    featIDs.setName(FEAT_MATCHEDIDS);
    featIDs.setValue(Joiner.on(",").join(allUrisAsString));
    docGraph.addFeature(featIDs);
    SFeature featAnnos = SaltFactory.createSFeature();
    featAnnos.setNamespace(ANNIS_NS);
    featAnnos.setName(FEAT_MATCHEDANNOS);
    featAnnos.setValue(Joiner.on(",").join(match.getAnnos()));
    docGraph.addFeature(featAnnos);
}
Also used : URI(java.net.URI) LinkedList(java.util.LinkedList) SFeature(org.corpus_tools.salt.core.SFeature)

Example 8 with SFeature

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

the class SaltAnnotateExtractor method addLongSFeature.

private void addLongSFeature(SNode node, String name, long value) throws SQLException {
    SFeature feat = SaltFactory.createSFeature();
    feat.setNamespace(ANNIS_NS);
    feat.setName(name);
    feat.setValue(value);
    node.addFeature(feat);
}
Also used : SFeature(org.corpus_tools.salt.core.SFeature)

Example 9 with SFeature

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

the class CommonHelper method getSortedSegmentationNodes.

/**
 * Calculates a {@link SOrderRelation} node chain of a {@link SDocumentGraph}.
 *
 * <p>
 * If no segmentation name is set, a list of sorted {@link SToken} will be
 * returned.<p>
 *
 * @param segName The segmentation name, for which the chain is computed.
 * @param graph The salt document graph, which is traversed for the
 * segmentation.
 *
 * @return Returns a List of {@link SNode}, which is sorted by the
 * {@link SOrderRelation}.
 */
public static List<SNode> getSortedSegmentationNodes(String segName, SDocumentGraph graph) {
    List<SNode> token = new ArrayList<SNode>();
    if (segName == null) {
        // if no segmentation is given just return the sorted token list
        List<SToken> unsortedToken = graph.getSortedTokenByText();
        if (unsortedToken != null) {
            token.addAll(unsortedToken);
        }
    } else {
        // get the very first node of the order relation chain
        Set<SNode> startNodes = new LinkedHashSet<SNode>();
        for (SNode n : graph.getNodes()) {
            SFeature feat = n.getFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_FIRST_NODE_SEGMENTATION_CHAIN);
            if (feat != null && segName.equalsIgnoreCase(feat.getValue_STEXT())) {
                startNodes.add(n);
            }
        }
        Set<String> alreadyAdded = new HashSet<String>();
        // add all nodes on the order relation chain beginning from the start node
        for (SNode s : startNodes) {
            SNode current = s;
            while (current != null) {
                token.add(current);
                List<SRelation<SNode, SNode>> out = graph.getOutRelations(current.getId());
                current = null;
                if (out != null) {
                    for (SRelation<? extends SNode, ? extends SNode> e : out) {
                        if (e instanceof SOrderRelation) {
                            current = ((SOrderRelation) e).getTarget();
                            if (alreadyAdded.contains(current.getId())) {
                                // abort if cycle detected
                                current = null;
                            } else {
                                alreadyAdded.add(current.getId());
                            }
                            break;
                        }
                    }
                }
            }
        }
    }
    return token;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SNode(org.corpus_tools.salt.core.SNode) ArrayList(java.util.ArrayList) SToken(org.corpus_tools.salt.common.SToken) SRelation(org.corpus_tools.salt.core.SRelation) SOrderRelation(org.corpus_tools.salt.common.SOrderRelation) SFeature(org.corpus_tools.salt.core.SFeature) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 10 with SFeature

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

the class TimelineReconstructor method cleanup.

private void cleanup() {
    for (SNode node : nodesToDelete) {
        graph.removeNode(node);
    }
    // update the feature matchedIDs
    SFeature matchids = graph.getFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_MATCHEDIDS);
    if (matchids != null) {
        String[] ids = matchids.getValue_STEXT().split(",");
        for (int i = 0; i < ids.length; i++) {
            if (this.oldID2newID.containsKey(ids[i]))
                ids[i] = this.oldID2newID.get(ids[i]);
        }
        matchids.setValue(Joiner.on(',').join(ids));
    }
}
Also used : SNode(org.corpus_tools.salt.core.SNode) 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