use of org.apache.jena.graph.Triple in project jena by apache.
the class AbstractDatasetGraphFind method find_union_01.
@Test
public void find_union_01() {
List<Quad> x = toList(dsg.find(Quad.unionGraph, null, null, null));
assertEquals(3, x.size());
x.stream().allMatch(q -> q.getGraph().equals(Quad.unionGraph));
List<Triple> z = x.stream().map(Quad::asTriple).collect(Collectors.toList());
assertTrue(z.contains(q4.asTriple()));
assertTrue(z.contains(q5.asTriple()));
Quad qx = Quad.create(Quad.unionGraph, q4.asTriple());
assertTrue(x.contains(qx));
Quad qz = Quad.create(Quad.unionGraph, q2.asTriple());
assertFalse(x.contains(qz));
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class RETEConflictSet method execute.
/**
* Execute a single rule firing.
*/
public static void execute(RETERuleContext context, boolean isAdd) {
Rule rule = context.getRule();
BindingEnvironment env = context.getEnv();
ForwardRuleInfGraphI infGraph = (ForwardRuleInfGraphI) context.getGraph();
if (infGraph.shouldTrace()) {
logger.info("Fired rule: " + rule.toShortString());
}
RETEEngine engine = context.getEngine();
engine.incRuleCount();
List<Triple> matchList = null;
if (infGraph.shouldLogDerivations() && isAdd) {
// Create derivation record
matchList = new ArrayList<>(rule.bodyLength());
for (int i = 0; i < rule.bodyLength(); i++) {
Object clause = rule.getBodyElement(i);
if (clause instanceof TriplePattern) {
matchList.add(env.instantiate((TriplePattern) clause));
}
}
}
for (int i = 0; i < rule.headLength(); i++) {
Object hClause = rule.getHeadElement(i);
if (hClause instanceof TriplePattern) {
Triple t = env.instantiate((TriplePattern) hClause);
// that we can't record in RDF
if (isAdd) {
if (!context.contains(t)) {
engine.addTriple(t, true);
if (infGraph.shouldLogDerivations()) {
infGraph.logDerivation(t, new RuleDerivation(rule, t, matchList, infGraph));
}
}
} else {
if (context.contains(t)) {
// Remove the generated triple
engine.deleteTriple(t, true);
}
}
// }
} else if (hClause instanceof Functor && isAdd) {
Functor f = (Functor) hClause;
Builtin imp = f.getImplementor();
if (imp != null) {
imp.headAction(f.getBoundArgs(env), f.getArgLength(), context);
} else {
throw new ReasonerException("Invoking undefined Functor " + f.getName() + " in " + rule.toShortString());
}
} else if (hClause instanceof Rule) {
Rule r = (Rule) hClause;
if (r.isBackward()) {
if (isAdd) {
infGraph.addBRule(r.instantiate(env));
} else {
infGraph.deleteBRule(r.instantiate(env));
}
} else {
throw new ReasonerException("Found non-backward subrule : " + r);
}
}
}
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class MonitorModel method snapshot.
/**
* Compute the differences between the current monitored graph and the last
* snapshot. The changes will also be forwarded to any listeners.
* Then take a new snapshot.
* @param additions a place in which the set of newly added statements should be noted, can be null
* @param deletions a place in which the set of newly deleted statements should be noted, can be null
*/
public void snapshot(List<Statement> additions, List<Statement> deletions) {
List<Triple> additionsTemp = (additions != null) ? new ArrayList<>() : null;
List<Triple> deletionsTemp = (deletions != null) ? new ArrayList<>() : null;
((MonitorGraph) getGraph()).snapshot(additionsTemp, deletionsTemp);
if (additions != null) {
for (Triple anAdditionsTemp : additionsTemp) {
additions.add(this.asStatement(anAdditionsTemp));
}
}
if (deletions != null) {
for (Triple aDeletionsTemp : deletionsTemp) {
deletions.add(this.asStatement(aDeletionsTemp));
}
}
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class AbstractTripleBlankNodeTests method writeTuples.
@Override
protected void writeTuples(File f, List<Triple> tuples) throws FileNotFoundException {
Graph g = GraphFactory.createGraphMem();
for (Triple t : tuples) {
g.add(t);
}
RDFDataMgr.write(new FileOutputStream(f), g, getLanguage());
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class AbstractTripleOutputFormatTests method generateTuples.
@Override
protected Iterator<TripleWritable> generateTuples(int num) {
List<TripleWritable> ts = new ArrayList<TripleWritable>();
for (int i = 0; i < num; i++) {
Triple t = new Triple(NodeFactory.createURI("http://example.org/subjects/" + i), NodeFactory.createURI("http://example.org/predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
ts.add(new TripleWritable(t));
}
return ts.iterator();
}
Aggregations