use of org.apache.jena.graph.Triple in project jena by apache.
the class NodeTransformLib method transform.
/** Do a node->node conversion of a BGP - return original BGP for "no change" */
public static BasicPattern transform(NodeTransform nodeTransform, BasicPattern pattern) {
BasicPattern bgp2 = new BasicPattern();
boolean changed = false;
for (Triple triple : pattern) {
Triple t2 = transform(nodeTransform, triple);
bgp2.add(t2);
if (t2 != triple)
changed = true;
}
if (!changed)
return pattern;
return bgp2;
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class ElementTransformSubst method transform.
@Override
public Element transform(ElementTriplesBlock el) {
ElementTriplesBlock etb = new ElementTriplesBlock();
boolean changed = false;
for (Triple t : el.getPattern()) {
Triple t2 = transform(t);
changed = changed || t != t2;
etb.addTriple(t2);
}
if (changed)
return etb;
return el;
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class FmtUtils method formatPattern.
public static void formatPattern(IndentedWriter out, BasicPattern pattern, SerializationContext sCxt) {
StringBuilder buffer = new StringBuilder();
boolean first = true;
for (Triple triple : pattern) {
if (!first)
buffer.append("\n");
stringForTriple(buffer, triple, sCxt);
buffer.append(" .");
out.print(buffer.toString());
buffer.setLength(0);
first = false;
}
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class IsoMatcher method tuplesTriples.
private static List<Tuple<Node>> tuplesTriples(Iterator<Triple> iter) {
List<Tuple<Node>> tuples = new ArrayList<>();
for (; iter.hasNext(); ) {
Triple t = iter.next();
Tuple<Node> tuple = tuple(t.getSubject(), t.getPredicate(), t.getObject());
tuples.add(tuple);
}
return tuples;
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class TestAPI method testARQConstructQuad_a_1.
// // Execute a test both with and without regex optimization enabled
// // Check the number of results
// private void XexecRegexTest(int expected, String queryString)
// {
// Object b = ARQ.getContext().get(ARQ.enableRegexConstraintsOpt) ;
// try {
// ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, "false") ;
// int count1 = queryAndCount(queryString) ;
// ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, "true") ;
// int count2 = queryAndCount(queryString) ;
// assertEquals("Different number of results", count1, count2) ;
// if ( expected >= 0 )
// assertEquals("Unexpected number of results", expected, count1) ;
// } finally {
// ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, b) ;
// }
// }
// ARQ Construct Quad Tests:
// Two types of query strings: a) construct triple string; b) construct quad string;
// Two kinds of query methods: 1) execTriples(); 2) execQuads();
// Test a)+1)
@Test
public void testARQConstructQuad_a_1() {
String queryString = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?g { ?s ?p ?o } }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Iterator<Triple> ts = qExec.execConstructTriples();
Model result = ModelFactory.createDefaultModel();
while (ts.hasNext()) {
Triple t = ts.next();
Statement stmt = ModelUtils.tripleToStatement(result, t);
if (stmt != null)
result.add(stmt);
}
assertEquals(3, result.size());
assertTrue(m.isIsomorphicWith(result));
}
Aggregations