use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.
the class SingleResultPanel method getIds.
private MinMax getIds(SDocumentGraph graph) {
List<SToken> sTokens = graph.getTokens();
MinMax minMax = new MinMax();
minMax.min = Long.MAX_VALUE;
minMax.max = Long.MIN_VALUE;
if (segmentationName == null) {
minMax.segName = "tokens";
if (sTokens != null) {
for (SToken t : sTokens) {
SFeature feature = t.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE);
if (feature != null && feature.getValue() instanceof RelannisNodeFeature) {
RelannisNodeFeature f = (RelannisNodeFeature) feature.getValue();
if (minMax.min > f.getTokenIndex()) {
minMax.min = f.getTokenIndex();
}
if (minMax.max < f.getTokenIndex()) {
minMax.max = f.getTokenIndex();
}
}
}
}
} else {
minMax.segName = segmentationName;
List<SNode> nodes = CommonHelper.getSortedSegmentationNodes(segmentationName, graph);
for (SNode n : nodes) {
RelannisNodeFeature f = RelannisNodeFeature.extract(n);
if (minMax.min > f.getSegIndex()) {
minMax.min = f.getSegIndex();
}
if (minMax.max < f.getSegIndex()) {
minMax.max = f.getSegIndex();
}
}
}
minMax.min++;
minMax.max++;
return minMax;
}
use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.
the class TimelineReconstructor method createTokenFromSOrder.
private void createTokenFromSOrder() {
nodesToDelete.add(graph.getTextualDSs().get(0));
Map<String, SSpan> rootNodes = new HashMap<>();
// also add nodes that are are marked as start by ANNIS even if they don't have an outgoing order rel
for (SSpan n : graph.getSpans()) {
SFeature feat = n.getFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_FIRST_NODE_SEGMENTATION_CHAIN);
if (feat != null && feat.getValue_STEXT() != null) {
rootNodes.put(feat.getValue_STEXT(), n);
} else {
// check if there is no incoming SOrderRelation but an outgoing
boolean isRoot = true;
for (SRelation<?, ?> inRel : n.getInRelations()) {
if (inRel instanceof SOrderRelation) {
isRoot = false;
break;
}
}
if (isRoot) {
for (SRelation<?, ?> outRel : n.getOutRelations()) {
if (outRel instanceof SOrderRelation) {
rootNodes.put(((SOrderRelation) outRel).getType(), n);
break;
}
}
}
}
}
// convert all root nodes to spans
for (Map.Entry<String, SSpan> rootEntry : rootNodes.entrySet()) {
SNode root = rootEntry.getValue();
String orderName = rootEntry.getKey();
convertSpanToToken((SSpan) root, orderName);
}
// traverse through all SOrderRelations in order
graph.traverse(new LinkedList<SNode>(rootNodes.values()), GRAPH_TRAVERSE_TYPE.TOP_DOWN_DEPTH_FIRST, "TimeReconstructSOrderRelations", new GraphTraverseHandler() {
@Override
public void nodeReached(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order) {
if (relation instanceof SOrderRelation && currNode instanceof SSpan) {
String orderName = ((SOrderRelation) relation).getType();
if (fromNode != null) {
// add a space to the text
StringBuilder t = textDataByName.get(orderName);
if (t != null) {
t.append(" ");
}
}
convertSpanToToken((SSpan) currNode, orderName);
}
}
@Override
public void nodeLeft(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order) {
}
@Override
public boolean checkConstraint(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SRelation relation, SNode currNode, long order) {
if (relation == null || relation instanceof SOrderRelation) {
return true;
} else {
return false;
}
}
});
// update the text of the TextualDSs
for (Map.Entry<String, StringBuilder> textDataEntry : textDataByName.entrySet()) {
STextualDS textDS = textsByName.get(textDataEntry.getKey());
if (textDS != null) {
textDS.setText(textDataEntry.getValue().toString());
}
}
}
use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.
the class SaltProjectProvider method writeTo.
@Override
public void writeTo(SaltProject project, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
SaltXML10Writer writer = new SaltXML10Writer();
try {
XMLStreamWriter xml = outFactory.createXMLStreamWriter(entityStream, "UTF-8");
xml.writeStartDocument("1.1");
xml.writeCharacters("\n");
long startTime = System.currentTimeMillis();
// output XMI root element
writer.writeXMIRootElement(xml);
for (SCorpusGraph corpusGraph : project.getCorpusGraphs()) {
for (SDocument doc : corpusGraph.getDocuments()) {
// make sure that any ANNIS feature on the document is copied to the document graph
SDocumentGraph docGraph = doc.getDocumentGraph();
for (SFeature feat : doc.getFeatures()) {
if (AnnisConstants.ANNIS_NS.equals(feat.getNamespace())) {
SFeature newFeat = SaltFactory.createSFeature();
feat.copy(newFeat);
docGraph.addFeature(newFeat);
}
}
writer.writeObjects(xml, docGraph);
}
}
xml.writeEndDocument();
long endTime = System.currentTimeMillis();
log.debug("Saving XMI (" + mediaType.toString() + ") needed {} ms", endTime - startTime);
} catch (XMLStreamException ex) {
log.error("exception when serializing SDocumentGraph", ex);
}
}
use of org.corpus_tools.salt.core.SFeature in project ANNIS by korpling.
the class RelannisEdgeFeature method extract.
public static RelannisEdgeFeature extract(SRelation rel) {
RelannisEdgeFeature featRelation = null;
SFeature sfeatRelation = rel.getFeature(ANNIS_NS + "::" + FEAT_RELANNIS_EDGE);
if (sfeatRelation != null) {
featRelation = (RelannisEdgeFeature) sfeatRelation.getValue();
}
return featRelation;
}
Aggregations