Search in sources :

Example 21 with Triple

use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.

the class ClerezzaRDFParser method parse.

@Override
public RDFDataset parse(Object input) throws JsonLdError {
    count = 0;
    Map<BlankNode, String> bNodeMap = new HashMap<BlankNode, String>(1024);
    final RDFDataset result = new RDFDataset();
    if (input instanceof Graph) {
        for (Triple t : ((Graph) input)) {
            handleStatement(result, t, bNodeMap);
        }
    }
    //help gc
    bNodeMap.clear();
    return result;
}
Also used : RDFDataset(com.github.jsonldjava.core.RDFDataset) Triple(org.apache.clerezza.commons.rdf.Triple) Graph(org.apache.clerezza.commons.rdf.Graph) HashMap(java.util.HashMap) BlankNode(org.apache.clerezza.commons.rdf.BlankNode)

Example 22 with Triple

use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.

the class IndexedGraphTest method remove.

@Test(expected = ConcurrentModificationException.class)
public void remove() {
    Graph itc = new IndexedGraph();
    itc.add(triple1);
    itc.add(triple2);
    itc.add(triple3);
    itc.add(triple4);
    itc.add(triple5);
    Iterator<Triple> iter = itc.filter(uriRef1, null, null);
    while (iter.hasNext()) {
        Triple triple = iter.next();
        itc.remove(triple);
    }
    Assert.assertEquals(3, itc.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 23 with Triple

use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.

the class IndexedGraphTest method filterIteratorRemove.

@Test
public void filterIteratorRemove() {
    Graph itc = new IndexedGraph();
    itc.add(triple1);
    itc.add(triple2);
    itc.add(triple3);
    itc.add(triple4);
    itc.add(triple5);
    Iterator<Triple> iter = itc.filter(uriRef1, null, null);
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
    }
    Assert.assertEquals(3, itc.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 24 with Triple

use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.

the class IndexedGraphTest method iteratorRemove.

@Test
public void iteratorRemove() {
    Graph itc = new IndexedGraph();
    itc.add(triple1);
    itc.add(triple2);
    itc.add(triple3);
    itc.add(triple4);
    itc.add(triple5);
    Iterator<Triple> iter = itc.iterator();
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
    }
    Assert.assertEquals(0, itc.size());
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 25 with Triple

use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.

the class TripleMatcherGroupImpl method getMatchingSubjects.

@Override
public Set<IRI> getMatchingSubjects(ImmutableGraph g) {
    if (matchers.isEmpty()) {
        return new HashSet<IRI>();
    }
    // For all matchers, find the set of subjects that match
    // and compute the intersection of those sets
    Set<IRI> intersection = null;
    for (TripleMatcher m : matchers) {
        final Set<IRI> s = new HashSet<IRI>();
        final Iterator<Triple> it = g.iterator();
        while (it.hasNext()) {
            final Triple t = it.next();
            if (m.matches(t)) {
                final BlankNodeOrIRI n = t.getSubject();
                if (n instanceof IRI) {
                    s.add((IRI) n);
                } else {
                // TODO do we need to handle non-IRI subjects?
                }
            }
        }
        if (intersection == null) {
            intersection = s;
        } else {
            intersection.retainAll(s);
        }
    }
    return intersection;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) IRI(org.apache.clerezza.commons.rdf.IRI) TripleMatcher(org.apache.stanbol.enhancer.benchmark.TripleMatcher) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) HashSet(java.util.HashSet)

Aggregations

Triple (org.apache.clerezza.commons.rdf.Triple)151 IRI (org.apache.clerezza.commons.rdf.IRI)88 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)84 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)70 Graph (org.apache.clerezza.commons.rdf.Graph)45 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)41 HashSet (java.util.HashSet)34 Literal (org.apache.clerezza.commons.rdf.Literal)30 ArrayList (java.util.ArrayList)27 Lock (java.util.concurrent.locks.Lock)21 HashMap (java.util.HashMap)20 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)19 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)19 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)15 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)12 Test (org.junit.Test)12 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)10 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)9 GraphNode (org.apache.clerezza.rdf.utils.GraphNode)8 IOException (java.io.IOException)7