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