Search in sources :

Example 1 with TripleMatcher

use of org.apache.stanbol.enhancer.benchmark.TripleMatcher 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

HashSet (java.util.HashSet)1 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 Triple (org.apache.clerezza.commons.rdf.Triple)1 TripleMatcher (org.apache.stanbol.enhancer.benchmark.TripleMatcher)1