use of org.corpus_tools.salt.core.SProcessingAnnotation in project ANNIS by korpling.
the class RSTImpl method createJsonEntry.
private JSONObject createJsonEntry(SNode currNode) {
JSONObject jsonData = new JSONObject();
StringBuilder sb = new StringBuilder();
// use a hash set so we don't get any duplicate entries
LinkedHashSet<SToken> token = new LinkedHashSet<>();
List<SRelation<SNode, SNode>> edges;
if (currNode instanceof SStructure) {
edges = currNode.getGraph().getOutRelations(currNode.getId());
// get all tokens directly dominated tokens and build a string
for (SRelation<SNode, SNode> sedge : edges) {
if (sedge.getTarget() instanceof SToken) {
token.add((SToken) sedge.getTarget());
}
}
// build strings
Iterator<SToken> tokIterator = token.iterator();
while (tokIterator.hasNext()) {
SToken tok = tokIterator.next();
String text = getText(tok);
String color = getHTMLColor(tok);
if (color != null) {
sb.append("<span style=\"color : ").append(color).append(";\">");
} else {
sb.append("<span>");
}
if (tokIterator.hasNext()) {
sb.append(text).append(" ");
} else {
sb.append(text);
}
sb.append("</span>");
}
}
try {
// build unique id, cause is used for an unique html element id.
jsonData.put("id", getUniStrId(currNode));
jsonData.put("name", currNode.getName());
/**
* additional data oject for edge labels and rendering sentences
*/
JSONObject data = new JSONObject();
JSONArray edgesJSON = getOutGoingEdgeTypeAnnotation(currNode);
// since we have found some tokens, it must be a sentence in RST.
if (token.size() > 0) {
data.put("sentence", sb.toString());
}
if (edgesJSON != null) {
data.put("edges", edgesJSON);
}
if (currNode instanceof SStructure && isSegment(currNode)) {
SProcessingAnnotation sentence_idx = currNode.getProcessingAnnotation(SENTENCE_INDEX + "::" + SENTENCE_INDEX);
int index = sentence_idx == null ? -1 : Integer.parseInt(sentence_idx.getValue_STEXT());
data.put(SENTENCE_LEFT, index);
data.put(SENTENCE_RIGHT, index);
}
jsonData.put("data", data);
} catch (JSONException ex) {
log.error("problems create entry for {}", currNode, ex);
}
return jsonData;
}
use of org.corpus_tools.salt.core.SProcessingAnnotation 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);
}
}
}
}
Aggregations