Search in sources :

Example 6 with SPointingRelation

use of org.corpus_tools.salt.common.SPointingRelation 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)

Example 7 with SPointingRelation

use of org.corpus_tools.salt.common.SPointingRelation in project ANNIS by korpling.

the class TimelineReconstructor method moveRelations.

private void moveRelations(SStructuredNode oldSpan, SToken newToken, Set<String> validSpanAnnos, String orderName) {
    final List<SRelation> inRels = new LinkedList<>(oldSpan.getInRelations());
    final List<SRelation> outRels = new LinkedList<>(oldSpan.getOutRelations());
    final List<SToken> coveredByOldSpan = new LinkedList<>();
    for (SRelation rel : outRels) {
        if (rel instanceof SPointingRelation || rel instanceof SDominanceRelation) {
            rel.setSource(newToken);
        } else if (rel instanceof SSpanningRelation) {
            coveredByOldSpan.add(((SSpanningRelation) rel).getTarget());
        }
    }
    for (SRelation rel : inRels) {
        if (rel instanceof SPointingRelation || rel instanceof SDominanceRelation) {
            rel.setTarget(newToken);
        }
    }
    // find the connected spans and connect them with the new token instead
    for (SToken tok : coveredByOldSpan) {
        if (tok.getInRelations() != null) {
            for (SRelation<?, ?> rel : tok.getInRelations()) {
                if (rel instanceof SSpanningRelation) {
                    boolean valid = false;
                    SSpan spanToMap = ((SSpanningRelation) rel).getSource();
                    if (virtualTokenizationFromNamespace) {
                        for (SAnnotation anno : spanToMap.getAnnotations()) {
                            if (anno.getNamespace() != null && anno.getNamespace().equals(orderName)) {
                                valid = true;
                                break;
                            }
                        }
                    } else {
                        for (String validAnno : validSpanAnnos) {
                            if (spanToMap.getAnnotation(validAnno) != null) {
                                valid = true;
                                break;
                            }
                        }
                    }
                    if (valid) {
                        graph.createRelation(spanToMap, newToken, SALT_TYPE.SSPANNING_RELATION, null);
                    }
                }
            }
        }
    }
}
Also used : SPointingRelation(org.corpus_tools.salt.common.SPointingRelation) SSpan(org.corpus_tools.salt.common.SSpan) SAnnotation(org.corpus_tools.salt.core.SAnnotation) LinkedList(java.util.LinkedList) SToken(org.corpus_tools.salt.common.SToken) SRelation(org.corpus_tools.salt.core.SRelation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation)

Aggregations

SPointingRelation (org.corpus_tools.salt.common.SPointingRelation)7 SRelation (org.corpus_tools.salt.core.SRelation)6 LinkedList (java.util.LinkedList)4 SToken (org.corpus_tools.salt.common.SToken)4 HashMap (java.util.HashMap)3 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)3 SDominanceRelation (org.corpus_tools.salt.common.SDominanceRelation)3 SSpanningRelation (org.corpus_tools.salt.common.SSpanningRelation)3 SAnnotation (org.corpus_tools.salt.core.SAnnotation)3 SNode (org.corpus_tools.salt.core.SNode)3 IOException (java.io.IOException)2 RelannisEdgeFeature (annis.model.RelannisEdgeFeature)1 RelannisNodeFeature (annis.model.RelannisNodeFeature)1 Node (com.hp.gagawa.java.Node)1 Body (com.hp.gagawa.java.elements.Body)1 Doctype (com.hp.gagawa.java.elements.Doctype)1 Head (com.hp.gagawa.java.elements.Head)1 Html (com.hp.gagawa.java.elements.Html)1 Link (com.hp.gagawa.java.elements.Link)1 Script (com.hp.gagawa.java.elements.Script)1