use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.
the class SpanHTMLOutputter method outputAnnotation.
private void outputAnnotation(SNode span, String matchedQName, SortedMap<Long, List<OutputItem>> outputStartTags, SortedMap<Long, List<OutputItem>> outputEndTags, int priority) {
long left;
long right;
RelannisNodeFeature feat = (RelannisNodeFeature) span.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
left = feat.getLeftToken();
right = feat.getRightToken();
SAnnotation matchedAnnotation;
if (type == Type.META_NAME) {
// constant property is used to store metadata names, see VisParser.java
matchedAnnotation = span.getAnnotation("meta::" + constant);
} else {
matchedAnnotation = span.getAnnotation(matchedQName);
}
String value;
// output to an inner text node
switch(type) {
case CONSTANT:
value = constant;
break;
case HTML_TEMPLATE:
String original = constant;
String innerValue = matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT();
String innerAnno = matchedAnnotation == null ? "NULL" : matchedAnnotation.getName();
value = original.replaceAll("%%value%%", innerValue);
value = value.replaceAll("%%anno%%", innerAnno);
break;
case VALUE:
value = matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT();
break;
case ESCAPED_VALUE:
value = htmlEscaper.escape(matchedAnnotation == null ? "NULL" : matchedAnnotation.getValue_STEXT());
break;
case ANNO_NAME:
value = matchedAnnotation == null ? "NULL" : matchedAnnotation.getName();
break;
case META_NAME:
value = matchedAnnotation.getValue() == null ? "NULL" : matchedAnnotation.getValue().toString();
matchedQName = "meta::" + metaname;
break;
default:
value = "";
break;
}
outputAny(left, right, matchedQName, value, outputStartTags, outputEndTags, priority);
}
use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.
the class VisJsComponent method includeObject.
private static boolean includeObject(Set<SAnnotation> objectAnnotations, Map<String, Set<String>> displayedAnnotationsMap) {
for (SAnnotation objectAnnotation : objectAnnotations) {
String annotation = objectAnnotation.getName();
String namespace = objectAnnotation.getNamespace();
if (displayedAnnotationsMap.containsKey(annotation)) {
// namespace has not to be considered
if (displayedAnnotationsMap.get(annotation).isEmpty()) {
return true;
} else if (displayedAnnotationsMap.get(annotation).contains(namespace)) {
return true;
}
}
}
return false;
}
use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.
the class SaltAnnotateExtractor method createOrFindNewNode.
private SNode createOrFindNewNode(ResultSet resultSet, SDocumentGraph graph, TreeSet<Long> allTextIDs, TreeMap<Long, String> tokenTexts, TreeMap<Long, SToken> tokenByIndex, TreeMap<String, TreeMap<Long, String>> nodeBySegmentationPath, SolutionKey<?> key, FastInverseMap<Long, SNode> nodeByRankID) throws SQLException {
String name = stringValue(resultSet, NODE_TABLE, "node_name");
String saltID = stringValue(resultSet, NODE_TABLE, "salt_id");
if (saltID == null) {
// fallback to the name
saltID = name;
}
long internalID = longValue(resultSet, "node", "id");
String relationType = stringValue(resultSet, COMPONENT_TABLE, "type");
long tokenIndex = longValue(resultSet, NODE_TABLE, "token_index");
boolean isToken = !resultSet.wasNull();
org.eclipse.emf.common.util.URI nodeURI = graph.getDocument().getPath();
nodeURI = nodeURI.appendFragment(saltID);
SStructuredNode node = (SStructuredNode) graph.getNode(nodeURI.toString());
if (node == null) {
// create new node
if (isToken) {
node = createSToken(tokenIndex, resultSet, tokenTexts, tokenByIndex);
} else {
node = createOtherSNode(resultSet);
}
node.setName(name);
node.setId(nodeURI.toString());
setFeaturesForNode(node, internalID, resultSet);
Object nodeId = key.getNodeId(resultSet, outerQueryTableAccessStrategy);
graph.addNode(node);
Integer matchedNode = key.getMatchedNodeIndex(nodeId);
if (matchedNode != null) {
addLongSFeature(node, FEAT_MATCHEDNODE, matchedNode);
}
mapLayer(node, graph, resultSet);
long textRef = longValue(resultSet, NODE_TABLE, "text_ref");
allTextIDs.add(textRef);
} else if ("c".equals(relationType) && isToken == false) {
node = testAndFixNonSpan(node, nodeByRankID);
}
String nodeAnnoValue = stringValue(resultSet, NODE_ANNOTATION_TABLE, "value");
String nodeAnnoNameSpace = stringValue(resultSet, NODE_ANNOTATION_TABLE, "namespace");
String nodeAnnoName = stringValue(resultSet, NODE_ANNOTATION_TABLE, "name");
if (!resultSet.wasNull()) {
String fullName = (nodeAnnoNameSpace == null || nodeAnnoNameSpace.isEmpty() ? "" : (nodeAnnoNameSpace + "::")) + nodeAnnoName;
SAnnotation anno = node.getAnnotation(fullName);
if (anno == null) {
anno = SaltFactory.createSAnnotation();
anno.setNamespace(nodeAnnoNameSpace);
anno.setName(nodeAnnoName);
anno.setValue(nodeAnnoValue);
node.addAnnotation(anno);
}
}
// prepare SOrderingRelation if the node is part of a segmentation path
String segName = stringValue(resultSet, "node", "seg_name");
if (segName != null) {
long left = longValue(resultSet, "node", "seg_index");
// last ones
if (!nodeBySegmentationPath.containsKey(segName)) {
nodeBySegmentationPath.put(segName, new TreeMap<Long, String>());
}
nodeBySegmentationPath.get(segName).put(left, node.getId());
}
return node;
}
use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.
the class SaltAnnotateExtractor method moveNodeProperties.
private void moveNodeProperties(SStructuredNode oldNode, SStructuredNode newNode, SGraph graph) {
Validate.notNull(oldNode);
Validate.notNull(newNode);
// step 1: collect every information that is need in a separate variable
String id = oldNode.getId();
String name = oldNode.getName();
Set<SAnnotation> annotations = new LinkedHashSet<>(oldNode.getAnnotations());
Set<SFeature> features = new LinkedHashSet<>(oldNode.getFeatures());
Set<SProcessingAnnotation> processingAnnotations = new LinkedHashSet<>(oldNode.getProcessingAnnotations());
Set<SMetaAnnotation> metaAnnotations = new LinkedHashSet<>(oldNode.getMetaAnnotations());
Set<SLayer> nodeLayers = new LinkedHashSet<>(oldNode.getLayers());
Multimap<SRelation, SLayer> layerOfRelation = ArrayListMultimap.create();
List<SRelation<SNode, SNode>> inRelations = new LinkedList<>(graph.getInRelations(oldNode.getId()));
List<SRelation<SNode, SNode>> outRelations = new LinkedList<>(graph.getOutRelations(oldNode.getId()));
// step 2: remove the old node from everything it is connected to
for (SRelation<SNode, SNode> rel : inRelations) {
if (rel.getLayers() != null) {
layerOfRelation.putAll(rel, rel.getLayers());
}
graph.removeRelation(rel);
}
for (SRelation<SNode, SNode> rel : outRelations) {
if (rel.getLayers() != null) {
layerOfRelation.putAll(rel, rel.getLayers());
}
graph.removeRelation(rel);
}
graph.removeNode(oldNode);
// step 3: add the new node to everything it should be connected to
newNode.setName(name);
newNode.setId(id);
graph.addNode(newNode);
for (SAnnotation anno : annotations) {
newNode.addAnnotation(anno);
}
for (SFeature feat : features) {
// filter the features, do not include salt::SNAME
if (!(SaltUtil.SALT_NAMESPACE.equals(feat.getNamespace()) && SaltUtil.FEAT_NAME.equals(feat.getName()))) {
newNode.addFeature(feat);
}
}
for (SProcessingAnnotation proc : processingAnnotations) {
newNode.addProcessingAnnotation(proc);
}
for (SMetaAnnotation meta : metaAnnotations) {
newNode.addMetaAnnotation(meta);
}
for (SLayer l : nodeLayers) {
l.addNode(newNode);
}
for (SRelation rel : inRelations) {
rel.setTarget(newNode);
graph.addRelation(rel);
if (layerOfRelation.containsKey(rel)) {
for (SLayer l : layerOfRelation.get(rel)) {
l.addRelation(rel);
}
}
}
for (SRelation rel : outRelations) {
rel.setSource(newNode);
graph.addRelation(rel);
if (layerOfRelation.containsKey(rel)) {
for (SLayer l : layerOfRelation.get(rel)) {
l.addRelation(rel);
}
}
}
}
use of org.corpus_tools.salt.core.SAnnotation in project ANNIS by korpling.
the class SaltAnnotateExtractor method addRelationAnnotations.
private void addRelationAnnotations(ResultSet resultSet, SRelation rel) throws SQLException {
String relationAnnoValue = stringValue(resultSet, EDGE_ANNOTATION_TABLE, "value");
String relationAnnoNameSpace = stringValue(resultSet, EDGE_ANNOTATION_TABLE, "namespace");
String relationAnnoName = stringValue(resultSet, EDGE_ANNOTATION_TABLE, "name");
if (!resultSet.wasNull()) {
String fullName = relationAnnoNameSpace == null ? "" : relationAnnoNameSpace + "::" + relationAnnoName;
SAnnotation anno = rel.getAnnotation(fullName);
if (anno == null) {
anno = SaltFactory.createSAnnotation();
anno.setNamespace(relationAnnoNameSpace == null ? "" : relationAnnoNameSpace);
anno.setName(relationAnnoName);
anno.setValue(relationAnnoValue);
rel.addAnnotation(anno);
}
}
// end if relationAnnoName exists
}
Aggregations