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);
}
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);
}
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);
}
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;
}
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));
}
}
Aggregations