Search in sources :

Example 1 with STextualRelation

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());
}
Also used : RelannisNodeFeature(annis.model.RelannisNodeFeature) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SToken(org.corpus_tools.salt.common.SToken) STextualDS(org.corpus_tools.salt.common.STextualDS) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) SFeature(org.corpus_tools.salt.core.SFeature)

Example 2 with STextualRelation

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 "";
}
Also used : SRelation(org.corpus_tools.salt.core.SRelation) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SGraph(org.corpus_tools.salt.core.SGraph)

Example 3 with STextualRelation

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);
            }
        }
    }
}
Also used : SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SaltProject(org.corpus_tools.salt.common.SaltProject) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) Test(org.junit.Test)

Aggregations

STextualRelation (org.corpus_tools.salt.common.STextualRelation)3 RelannisNodeFeature (annis.model.RelannisNodeFeature)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)1 SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)1 SPointingRelation (org.corpus_tools.salt.common.SPointingRelation)1 SSpanningRelation (org.corpus_tools.salt.common.SSpanningRelation)1 STextualDS (org.corpus_tools.salt.common.STextualDS)1 SToken (org.corpus_tools.salt.common.SToken)1 SaltProject (org.corpus_tools.salt.common.SaltProject)1 SFeature (org.corpus_tools.salt.core.SFeature)1 SGraph (org.corpus_tools.salt.core.SGraph)1 SRelation (org.corpus_tools.salt.core.SRelation)1 Test (org.junit.Test)1