class MyHandler implements StreamRDF { ... public void triple(Triple triple) { if (triple.predicateMatches(DBpediaOWL.abstract)) { ... process ... } } ... } StreamRDF myHandler = new MyHandler(); RDFDataMgr.parse(myHandler, "dbpedia-file.nt");
/** * Returns all triple patterns in given SPARQL query that contain the * given predicate. * @param query the SPARQL query. * @param predicate the predicate * @return */ public Set<Triple> extractTriplePatternsWithPredicate(Query query, Node predicate){ // get all triple patterns Set<Triple> triplePatterns = extractTriplePattern(query); // filter by predicate triplePatterns.removeIf(tp -> !tp.predicateMatches(predicate)); return triplePatterns; }
@Override public int compare(Triple o1, Triple o2) { boolean same = o1.subjectMatches(o2.getSubject()) && o2.predicateMatches(o2.getPredicate()) && o1.getObject().isVariable() && o2.getObject().isVariable(); // && !var2OutgoingTPs.containsKey(o1.getObject()); if (same) return 0; return comp.compare(o1, o2); } });
@Override public int compare(Triple o1, Triple o2) { boolean same = o1.subjectMatches(o2.getSubject()) && o2.predicateMatches(o2.getPredicate()) && o1.getObject().isVariable() && o2.getObject().isVariable(); // && !var2IncomingTPs.containsKey(o1.getObject()); if (same) return 0; return comp.compare(o1, o2); } });
@Override public int compare(Triple o1, Triple o2) { boolean same = o1.objectMatches(o2.getObject()) && o2.predicateMatches(o2.getPredicate()) && o1.getSubject().isVariable() && o2.getSubject().isVariable(); // && !var2IncomingTPs.containsKey(o1.getObject()); if (same) return 0; return comp.compare(o1, o2); } });
public void testElementMatches() { assertTrue( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "S" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "P" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "O" ) ) ); /* */ assertFalse( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "Z" ) ) ); assertFalse( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "Q" ) ) ); assertFalse( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "I" ) ) ); /* */ assertTrue( NodeCreateUtils.createTriple( "?? P O" ).subjectMatches( node( "SUB" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S ?? O" ).predicateMatches( node( "PRED" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S P ??" ).objectMatches( node( "OBJ" ) ) ); }
public void testElementMatches() { assertTrue( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "S" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "P" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "O" ) ) ); /* */ assertFalse( NodeCreateUtils.createTriple( "S P O" ).subjectMatches( node( "Z" ) ) ); assertFalse( NodeCreateUtils.createTriple( "S P O" ).predicateMatches( node( "Q" ) ) ); assertFalse( NodeCreateUtils.createTriple( "S P O" ).objectMatches( node( "I" ) ) ); /* */ assertTrue( NodeCreateUtils.createTriple( "?? P O" ).subjectMatches( node( "SUB" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S ?? O" ).predicateMatches( node( "PRED" ) ) ); assertTrue( NodeCreateUtils.createTriple( "S P ??" ).objectMatches( node( "OBJ" ) ) ); }