"[(a,r,0) <- (a,p,?x), (a,q,?y), lessThan(?x,?y)]" + "[(a,r,1) <- (a,p,?x), (a,q,?y), ge(?x, ?y)]", Util.makeIntNode(2),Util.makeIntNode(3), Util.makeIntNode(0) ); doBuiltinTest( "[(a,r,0) <- (a,p,?x), (a,q,?y), lessThan(?x,?y)]" + "[(a,r,1) <- (a,p,?x), (a,q,?y), ge(?x, ?y)]", Util.makeIntNode(3),Util.makeIntNode(3), Util.makeIntNode(1) ); doBuiltinTest( "[(a,r,0) <- (a,p,?x), (a,q,?y), le(?x,?y)]" + "[(a,r,1) <- (a,p,?x), (a,q,?y), greaterThan(?x, ?y)]", Util.makeIntNode(3),Util.makeIntNode(3), Util.makeIntNode(0) ); doBuiltinTest( "[(a,r,?z) <- (a,p,?x), (a,q,?y), min(?x,?y,?z)]", Util.makeIntNode(2),Util.makeIntNode(3), Util.makeIntNode(2) ); doBuiltinTest( "[(a,r,?z) <- (a,p,?x), (a,q,?y), min(?x,?y,?z)]", Util.makeIntNode(4),Util.makeIntNode(3), Util.makeIntNode(3) ); doBuiltinTest( "[(a,r,?z) <- (a,p,?x), (a,q,?y), max(?x,?y,?z)]", Util.makeIntNode(2),Util.makeIntNode(3), Util.makeIntNode(3) ); doBuiltinTest( "[(a,r,?z) <- (a,p,?x), (a,q,?y), max(?x,?y,?z)]", Util.makeIntNode(4),Util.makeIntNode(3), Util.makeIntNode(4)
private void compare(Number num1, Number num2, int outcome) { int z1 = Util.compareNumbers(num1, num2); assertEquals("compare(num1,num2)", outcome, z1); // reverse int z2 = Util.compareNumbers(num2, num1); assertEquals("compare(num2,num1)", outcome, -1 * z2); }
/** * This method is invoked when the builtin is called in a rule body. * @param args the array of argument values for the builtin, this is an array * of Nodes, some of which may be Node_RuleVariables. * @param context an execution context giving access to other relevant data * @return return true if the buildin predicate is deemed to have succeeded in * the current environment */ @Override public boolean bodyCall(Node[] args, int length, RuleContext context) { checkArgs(length, context); Node n1 = getArg(0, args, context); Node n2 = getArg(1, args, context); if (Util.comparable(n1, n2)) { return Util.compareTypedLiterals(n1, n2) <= 0; } else { return false; } }
/** * Convert an (assumed well formed) RDF list to a java list of Nodes */ private static List<Node> convertList( Node node, RuleContext context, List<Node> sofar ) { if (node == null || node.equals(RDF.nil.asNode())) return sofar; Node next = getPropValue(node, RDF.first.asNode(), context); if (next != null) { sofar.add(next); return convertList(getPropValue(node, RDF.rest.asNode(), context), context, sofar); } else { return sofar; } }
/** * This method is invoked when the builtin is called in a rule body. * @param args the array of argument values for the builtin, this is an array * of Nodes, some of which may be Node_RuleVariables. * @param context an execution context giving access to other relevant data * @param length the length of the argument list, may be less than the length of the args array * for some rule engines * @return return true if the buildin predicate is deemed to have succeeded in * the current environment */ @Override public boolean bodyCall(Node[] args, int length, RuleContext context) { checkArgs(length, context); BindingEnvironment env = context.getEnv(); boolean ok = false; Node a0 = getArg(0, args, context); Node a1 = getArg(1, args, context); if (Util.isNumeric(a0)) { Node newVal = Util.makeIntNode( Util.getIntValue(a0) + 1 ); ok = env.bind(args[1], newVal); } else if (Util.isNumeric(a1)) { Node newVal = Util.makeIntNode( Util.getIntValue(a1) - 1 ); ok = env.bind(args[0], newVal); } return ok; }
if (v1 instanceof Float || v1 instanceof Double || v2 instanceof Float || v2 instanceof Double) { sum = Util.makeDoubleNode(nv1.doubleValue() / nv2.doubleValue()); } else { sum = Util.makeLongNode(nv1.longValue() / nv2.longValue());
List<Rule> rules = Rule.parseRules(ruleSrc); Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, Util.makeList(new Node[]{C1,C2,C3},data))); InfGraph infgraph = makeInfGraph(rules, data); TestUtil.assertIteratorValues(this, infgraph.find(new Triple(a, r, Node.ANY)), new Triple[] { new Triple(a, r, Util.makeIntNode(3)) }); TestUtil.assertIteratorValues(this, data = Factory.createGraphMem(); data.add(new Triple(a, p, Util.makeList( new Node[]{C1, Util.makeIntNode(3), C3}, data) )); data.add(new Triple(a, q, Util.makeList( new Node[]{C3, C1, Util.makeLongNode(3)}, data) )); data.add(new Triple(a, r, Util.makeList( new Node[]{C3, C1, Util.makeLongNode(2)}, data) )); infgraph = makeInfGraph(rules, data); TestUtil.assertIteratorValues(this, data = Factory.createGraphMem(); data.add(new Triple(a, p, Util.makeList( new Node[]{C1, Util.makeIntNode(3), C3}, data) )); data.add(new Triple(a, q, C1)); data.add(new Triple(a, q, Util.makeLongNode(3))); data.add(new Triple(a, q, C2)); infgraph = makeInfGraph(rules, data);
""; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, q, Util.makeIntNode(2)) ); data.add(new Triple(n2, q, Util.makeIntNode(2)) ); data.add(new Triple(n3, q, Util.makeIntNode(3)) ); InfGraph infgraph = createInfGraph(rules, data); data.add(new Triple(n1, q, Util.makeIntNode(2)) ); data.add(new Triple(n2, q, Util.makeDoubleNode(2.2)) ); data.add(new Triple(n3, q, Util.makeDoubleNode(2.3)) ); infgraph = createInfGraph(rules, data); ""; data = Factory.createGraphMem(); data.add(new Triple(n1, p, Util.makeIntNode(3)) ); data.add(new Triple(n1, q, Util.makeIntNode(5)) ); infgraph = createInfGraph(rules, data); new Triple(n1, p, Util.makeIntNode(3)), new Triple(n1, q, Util.makeIntNode(5)), new Triple(n1, s, Util.makeIntNode(8)), new Triple(n1, t, Util.makeIntNode(15)), new Triple(n1, u, Util.makeIntNode(2)), new Triple(n1, v, Util.makeIntNode(1)), new Triple(n1, r, Util.makeIntNode(3)), new Triple(n1, x, Util.makeIntNode(5)), }); "";
/** * Convert an (assumed well formed) RDF list to a java list of Nodes * @param root the root node of the list * @param context the graph containing the list assertions */ public static List<Node> convertList(Node root, RuleContext context) { return convertList(root, context, new LinkedList<Node>()); }
/** Answer the list of rules loaded from the given filename. May throw a ReasonerException wrapping an IOException. */ public static List<Rule> loadRules( String fileName ) { try { return Rule.parseRules(Util.loadRuleParserFromResourceFile( fileName ) ); } catch (WrappedIOException e) { throw new ReasonerException("Can't load rules file: " + fileName, e.getCause() ); } }
public void doTestComparator(Node nLow, Node nHigh) { assertEquals(0, Util.compareTypedLiterals(nLow, nLow)); assertEquals(-1, Util.compareTypedLiterals(nLow, nHigh)); assertEquals(1, Util.compareTypedLiterals(nHigh, nLow)); }
/** * Constructor method that builds an instance of the associated Reasoner * @param configuration a set of arbitrary configuration information to be * passed the reasoner encoded within an RDF graph */ @Override public Reasoner create(Resource configuration) { OWLMiniReasoner reasoner = new OWLMiniReasoner(this); if (configuration != null) { Boolean doLog = Util.checkBinaryPredicate(ReasonerVocabulary.PROPderivationLogging, configuration); if (doLog != null) { reasoner.setDerivationLogging(doLog.booleanValue()); } Boolean doTrace = Util.checkBinaryPredicate(ReasonerVocabulary.PROPtraceOn, configuration); if (doTrace != null) { reasoner.setTraceOn( doTrace ); } } return reasoner; }
if (v1 instanceof Float || v1 instanceof Double || v2 instanceof Float || v2 instanceof Double) { sum = Util.makeDoubleNode(nv1.doubleValue() - nv2.doubleValue()); } else { sum = Util.makeLongNode(nv1.longValue() - nv2.longValue());
List<Rule> rules = Rule.parseRules(ruleSrc); Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, Util.makeList(new Node[]{C1,C2,C3},data))); InfGraph infgraph = makeInfGraph(rules, data); TestUtil.assertIteratorValues(this, infgraph.find(new Triple(a, r, Node.ANY)), new Triple[] { new Triple(a, r, Util.makeIntNode(3)) }); TestUtil.assertIteratorValues(this, data = Factory.createGraphMem(); data.add(new Triple(a, p, Util.makeList( new Node[]{C1, Util.makeIntNode(3), C3}, data) )); data.add(new Triple(a, q, Util.makeList( new Node[]{C3, C1, Util.makeLongNode(3)}, data) )); data.add(new Triple(a, r, Util.makeList( new Node[]{C3, C1, Util.makeLongNode(2)}, data) )); infgraph = makeInfGraph(rules, data); TestUtil.assertIteratorValues(this, data = Factory.createGraphMem(); data.add(new Triple(a, p, Util.makeList( new Node[]{C1, Util.makeIntNode(3), C3}, data) )); data.add(new Triple(a, q, C1)); data.add(new Triple(a, q, Util.makeLongNode(3))); data.add(new Triple(a, q, C2)); infgraph = makeInfGraph(rules, data);
""; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, q, Util.makeIntNode(2)) ); data.add(new Triple(n2, q, Util.makeIntNode(2)) ); data.add(new Triple(n3, q, Util.makeIntNode(3)) ); InfGraph infgraph = createInfGraph(rules, data); data.add(new Triple(n1, q, Util.makeIntNode(2)) ); data.add(new Triple(n2, q, Util.makeDoubleNode(2.2)) ); data.add(new Triple(n3, q, Util.makeDoubleNode(2.3)) ); infgraph = createInfGraph(rules, data); ""; data = Factory.createGraphMem(); data.add(new Triple(n1, p, Util.makeIntNode(3)) ); data.add(new Triple(n1, q, Util.makeIntNode(5)) ); infgraph = createInfGraph(rules, data); new Triple(n1, p, Util.makeIntNode(3)), new Triple(n1, q, Util.makeIntNode(5)), new Triple(n1, s, Util.makeIntNode(8)), new Triple(n1, t, Util.makeIntNode(15)), new Triple(n1, u, Util.makeIntNode(2)), new Triple(n1, v, Util.makeIntNode(1)), new Triple(n1, r, Util.makeIntNode(3)), new Triple(n1, x, Util.makeIntNode(5)), }); "";
/** * This method is invoked when the builtin is called in a rule body. * @param args the array of argument values for the builtin, this is an array * of Nodes, some of which may be Node_RuleVariables. * @param context an execution context giving access to other relevant data * @param length the length of the argument list, may be less than the length of the args array * for some rule engines * @return return true if the buildin predicate is deemed to have succeeded in * the current environment */ @Override public boolean bodyCall(Node[] args, int length, RuleContext context) { checkArgs(length, context); BindingEnvironment env = context.getEnv(); boolean ok = false; Node a0 = getArg(0, args, context); Node a1 = getArg(1, args, context); if (Util.isNumeric(a0)) { Node newVal = Util.makeIntNode( Util.getIntValue(a0) + 1 ); ok = env.bind(args[1], newVal); } else if (Util.isNumeric(a1)) { Node newVal = Util.makeIntNode( Util.getIntValue(a1) - 1 ); ok = env.bind(args[0], newVal); } return ok; }
/** * Convert an (assumed well formed) RDF list to a java list of Nodes * @param root the root node of the list * @param context the graph containing the list assertions */ public static List<Node> convertList(Node root, RuleContext context) { return convertList(root, context, new LinkedList<Node>()); }
/** Answer the list of rules loaded from the given filename. May throw a ReasonerException wrapping an IOException. */ public static List<Rule> loadRules( String fileName ) { try { return Rule.parseRules(Util.loadRuleParserFromResourceFile( fileName ) ); } catch (WrappedIOException e) { throw new ReasonerException("Can't load rules file: " + fileName, e.getCause() ); } }
/** * Convert an (assumed well formed) RDF list to a java list of Nodes */ private static List<Node> convertList( Node node, RuleContext context, List<Node> sofar ) { if (node == null || node.equals(RDF.nil.asNode())) return sofar; Node next = getPropValue(node, RDF.first.asNode(), context); if (next != null) { sofar.add(next); return convertList(getPropValue(node, RDF.rest.asNode(), context), context, sofar); } else { return sofar; } }
public void doTestComparator(Node nLow, Node nHigh) { assertEquals(0, Util.compareTypedLiterals(nLow, nLow)); assertEquals(-1, Util.compareTypedLiterals(nLow, nHigh)); assertEquals(1, Util.compareTypedLiterals(nHigh, nLow)); }