use of org.corpus_tools.salt.common.STextualRelation 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.common.STextualRelation in project ANNIS by korpling.
the class CommonHelper method getSpannedText.
/**
* Gets the spannend/covered text for a token. This will get all
* {@link STextualRelation} edges for a {@link SToken} from the
* {@link SDocumentGraph} and calculates the appropiate substring from the
* {@link STextualDS}.
*
* @param tok The {@link SToken} which is overlapping the text sequence.
* @return An empty {@link String} object, if there is no
* {@link STextualRelation}
*/
public static String getSpannedText(SToken tok) {
SGraph graph = tok.getGraph();
List<SRelation<SNode, SNode>> edges = graph.getOutRelations(tok.getId());
for (SRelation<? extends SNode, ? extends SNode> e : edges) {
if (e instanceof STextualRelation) {
STextualRelation textRel = (STextualRelation) e;
return textRel.getTarget().getText().substring(textRel.getStart(), textRel.getEnd());
}
}
return "";
}
use of org.corpus_tools.salt.common.STextualRelation in project ANNIS by korpling.
the class SaltAnnotateExtractorTest method testRelationType.
@Test
public void testRelationType() throws SQLException {
SaltProject project = instance.extractData(resultSetProviderSingleText.getResultSet());
assertNotNull(project);
SDocumentGraph g = project.getCorpusGraphs().get(0).getDocuments().get(0).getDocumentGraph();
for (SRelation<? extends SNode, ? extends SNode> r : g.getRelations()) {
if (!(r instanceof STextualRelation)) {
assertEquals(1, r.getLayers().size());
String layerName = r.getLayers().iterator().next().getName();
if ("exmaralda".equals(layerName) || "urml".equals(layerName) || "mmax".equals(layerName)) {
assertTrue("instance of SSpanningRelation", r instanceof SSpanningRelation);
} else if ("dep".equals(layerName)) {
assertTrue("instance of SPointingRelation", r instanceof SPointingRelation);
} else if ("tiger".equals(layerName)) {
assertTrue("instance of SDominanceRelation", r instanceof SDominanceRelation);
}
}
}
}
Aggregations