本文整理了Java中org.apache.jena.graph.Factory.createGraphMem()
方法的一些代码示例,展示了Factory.createGraphMem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Factory.createGraphMem()
方法的具体详情如下:
包路径:org.apache.jena.graph.Factory
类名称:Factory
方法名:createGraphMem
暂无
代码示例来源:origin: apache/jena
private static Graph make(int N) {
Graph graph = Factory.createGraphMem();
for ( int i = 0 ; i < N ; i++ ) {
Triple t = GraphTestBase.triple("a P 'x"+i+"'");
graph.add(t);
}
return graph ;
}
代码示例来源:origin: apache/jena
/**
* Assemble a test infGraph from a rule source and empty data
*/
public InfGraph createInfGraph(String rules) {
return createReasoner( Rule.parseRules(rules) ).bind(Factory.createGraphMem());
}
代码示例来源:origin: apache/jena
/**
* Test basic rule operations - simple AND rule
*/
public void testBaseRules1() {
List<Rule> rules = Rule.parseRules("[r1: (?a r ?c) <- (?a p ?b),(?b p ?c)]");
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(b, p, c));
data.add(new Triple(b, p, d));
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(null, r, null),
new Object[] {
new Triple(a, r, c),
new Triple(a, r, d)
} );
}
代码示例来源:origin: apache/jena
/**
* Test example hybrid rule.
*/
public void testHybrid1() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(p, ty, s));
String rules =
"[r1: (?p rdf:type s) -> [r1b: (?x ?p ?y) <- (?y ?p ?x)]]";
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this,
infgraph.find(null, p, null), new Object[] {
new Triple(a, p, b),
new Triple(b, p, a)
} );
}
代码示例来源:origin: apache/jena
/**
* Test basic builtin usage.
*/
public void testBuiltin3() {
Graph data = Factory.createGraphMem();
List<Rule> rules = Rule.parseRules(
"[r1: (a p b ) <- unbound(?x) ]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, null, null),
new Object[] {
new Triple(a, p, b)
} );
}
代码示例来源:origin: apache/jena
/**
* Generic test operation.
* @param ruleSrc the source of the rules
* @param triples a set of triples to insert in the graph before the query
* @param query the Triple to search for
* @param results the array of expected results
*/
private void doTest(String ruleSrc, Triple[] triples, Triple query, Object[] results) {
List<Rule> rules = Rule.parseRules(ruleSrc);
Graph data = Factory.createGraphMem();
for ( Triple triple : triples )
{
data.add( triple );
}
InfGraph infgraph = makeInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(query), results);
}
代码示例来源:origin: org.apache.jena/jena-core
/**
* Test basic rule operations - simple AND rule
*/
public void testBaseRules1() {
List<Rule> rules = Rule.parseRules("[r1: (?a r ?c) <- (?a p ?b),(?b p ?c)]");
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(b, p, c));
data.add(new Triple(b, p, d));
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(null, r, null),
new Object[] {
new Triple(a, r, c),
new Triple(a, r, d)
} );
}
代码示例来源:origin: org.apache.jena/jena-core
/**
* Test example hybrid rule.
*/
public void testHybrid1() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(p, ty, s));
String rules =
"[r1: (?p rdf:type s) -> [r1b: (?x ?p ?y) <- (?y ?p ?x)]]";
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this,
infgraph.find(null, p, null), new Object[] {
new Triple(a, p, b),
new Triple(b, p, a)
} );
}
代码示例来源:origin: org.apache.jena/jena-core
/**
* Test basic builtin usage.
*/
public void testBuiltin3() {
Graph data = Factory.createGraphMem();
List<Rule> rules = Rule.parseRules(
"[r1: (a p b ) <- unbound(?x) ]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, null, null),
new Object[] {
new Triple(a, p, b)
} );
}
代码示例来源:origin: org.apache.jena/jena-core
/**
* Generic test operation.
* @param ruleSrc the source of the rules
* @param triples a set of triples to insert in the graph before the query
* @param query the Triple to search for
* @param results the array of expected results
*/
private void doTest(String ruleSrc, Triple[] triples, Triple query, Object[] results) {
List<Rule> rules = Rule.parseRules(ruleSrc);
Graph data = Factory.createGraphMem();
for ( Triple triple : triples )
{
data.add( triple );
}
InfGraph infgraph = makeInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(query), results);
}
代码示例来源:origin: org.apache.jena/jena-core
private static Graph make(int N) {
Graph graph = Factory.createGraphMem();
for ( int i = 0 ; i < N ; i++ ) {
Triple t = GraphTestBase.triple("a P 'x"+i+"'");
graph.add(t);
}
return graph ;
}
代码示例来源:origin: org.apache.jena/jena-core
/**
* Assemble a test infGraph from a rule source and empty data
*/
public InfGraph createInfGraph(String rules) {
return createReasoner( Rule.parseRules(rules) ).bind(Factory.createGraphMem());
}
代码示例来源:origin: apache/jena
/**
* Test size bug, used to blow up if size was called before any queries.
*/
public void testSize() {
String rules = "[rule1: (?x p ?y) -> (?x q ?y)]";
List<Rule> ruleList = Rule.parseRules(rules);
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, p, n2));
InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(data);
assertEquals(infgraph.size(), 2);
}
代码示例来源:origin: org.apache.jena/jena-core
private Node getSkolem(Node x, Node y) {
String rules = "[r1: (?n p ?x) (?n q ?y) makeSkolem(?s ?x ?y) -> (?n s ?s)]";
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, p, x));
data.add(new Triple(n1, q, y));
InfGraph infgraph = createInfGraph(rules, data);
return infgraph.find(n1, s, Node.ANY).next().getObject();
}
代码示例来源:origin: org.apache.jena/jena-core
/**
* Test basic builtin usage.
*/
public void testBuiltin1() {
Graph data = Factory.createGraphMem();
List<Rule> rules = Rule.parseRules(
"[a1: -> (a p 2) ]" +
"[a2: -> (a q 3) ]" +
"[r1: (?x r ?s) <- (?x p ?y), (?x q ?z), sum(?y, ?z, ?s)]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, r, null),
new Object[] {
new Triple(a, r, Util.makeIntNode(5))
} );
}
代码示例来源:origin: apache/jena
/**
* Generic test operation.
* @param ruleSrc the source of the rules
* @param tabled the predicates that should be tabled
* @param triples a set of triples to insert in the graph before the query
* @param query the Triple to search for
* @param results the array of expected results
*/
private void doTest(String ruleSrc, Node[] tabled, Triple[] triples, Triple query, Object[] results) {
List<Rule> rules = Rule.parseRules(ruleSrc);
Graph data = Factory.createGraphMem();
for ( Triple triple : triples )
{
data.add( triple );
}
InfGraph infgraph = makeInfGraph(rules, data, tabled);
TestUtil.assertIteratorValues(this, infgraph.find(query), results);
}
代码示例来源:origin: apache/jena
/**
* Perform a rule test on the raw RETE engine. This requires some fiddling
* with dummy parent graphs.
*/
private void doRuleTest(String rules, Triple[] adds, Triple[] expected) {
List<Rule> ruleList = Rule.parseRules(rules);
BasicForwardRuleInfGraph infgraph = new BasicForwardRuleInfGraph(null, new ArrayList<Rule>(), null, Factory.createGraphMem());
// infgraph.setTraceOn(true);
RETEEngine engine = new RETEEngine(infgraph, ruleList);
infgraph.prepare();
engine.init(true, new FGraph(Factory.createGraphMem()));
for ( Triple add : adds )
{
engine.addTriple( add, true );
}
engine.runAll();
TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), expected);
}
代码示例来源:origin: apache/jena
/**
* Test basic rule operations - simple AND/OR with tabling.
*/
public void testBaseRules4() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, r, b));
data.add(new Triple(b, r, c));
data.add(new Triple(b, r, b));
data.add(new Triple(b, r, d));
List<Rule> rules = Rule.parseRules(
"[r1: (?x p ?y) <- (?x r ?y)]" +
"[r2: (?x p ?z) <- (?x p ?y), (?y r ?z)]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, p, null),
new Object[] {
new Triple(a, p, b),
new Triple(a, p, d),
new Triple(a, p, c)
} );
}
代码示例来源:origin: apache/jena
private Node getSkolem(Node x, Node y) {
String rules = "[r1: (?n p ?x) (?n q ?y) makeSkolem(?s ?x ?y) -> (?n s ?s)]";
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, p, x));
data.add(new Triple(n1, q, y));
InfGraph infgraph = createInfGraph(rules, data);
return infgraph.find(n1, s, Node.ANY).next().getObject();
}
代码示例来源:origin: apache/jena
/**
* Test basic builtin usage.
*/
public void testBuiltin1() {
Graph data = Factory.createGraphMem();
List<Rule> rules = Rule.parseRules(
"[a1: -> (a p 2) ]" +
"[a2: -> (a q 3) ]" +
"[r1: (?x r ?s) <- (?x p ?y), (?x q ?z), sum(?y, ?z, ?s)]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, r, null),
new Object[] {
new Triple(a, r, Util.makeIntNode(5))
} );
}
内容来源于网络,如有侵权,请联系作者删除!