Search in sources :

Example 16 with TriplePattern

use of org.apache.jena.reasoner.TriplePattern in project jena by apache.

the class Drop method headAction.

/**
     * This method is invoked when the builtin is called in a rule head.
     * Such a use is only valid in a forward rule.
     * @param args the array of argument values for the builtin, this is an array 
     * of Nodes.
     * @param length the length of the argument list, may be less than the length of the args array
     * for some rule engines
     * @param context an execution context giving access to other relevant data
     */
@Override
public void headAction(Node[] args, int length, RuleContext context) {
    InfGraph inf = context.getGraph();
    Graph raw = inf.getRawGraph();
    Graph deductions = inf.getDeductionsGraph();
    for (int i = 0; i < length; i++) {
        Node clauseN = getArg(i, args, context);
        if (Util.isNumeric(clauseN)) {
            int clauseIndex = Util.getIntValue(clauseN);
            Object clause = context.getRule().getBodyElement(clauseIndex);
            if (clause instanceof TriplePattern) {
                Triple t = context.getEnv().instantiate((TriplePattern) clause);
                raw.delete(t);
                deductions.delete(t);
            } else {
                throw new BuiltinException(this, context, "illegal triple to remove non-triple clause");
            }
        } else {
            throw new BuiltinException(this, context, "illegal arg to remove (" + clauseN + "), must be an integer");
        }
    }
}
Also used : Triple(org.apache.jena.graph.Triple) BuiltinException(org.apache.jena.reasoner.rulesys.BuiltinException) InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) TriplePattern(org.apache.jena.reasoner.TriplePattern)

Aggregations

TriplePattern (org.apache.jena.reasoner.TriplePattern)16 Triple (org.apache.jena.graph.Triple)13 TransitiveGraphCache (org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)9 Graph (org.apache.jena.graph.Graph)2 InfGraph (org.apache.jena.reasoner.InfGraph)2 Node (org.apache.jena.graph.Node)1 ReasonerException (org.apache.jena.reasoner.ReasonerException)1 BuiltinException (org.apache.jena.reasoner.rulesys.BuiltinException)1 Node_RuleVariable (org.apache.jena.reasoner.rulesys.Node_RuleVariable)1 BindingVector (org.apache.jena.reasoner.rulesys.impl.BindingVector)1 JenaException (org.apache.jena.shared.JenaException)1