01: /******************************************************************
02: * File: table.java
03: * Created by: Dave Reynolds
04: * Created on: 08-Aug-2003
05: *
06: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
07: * [See end of file]
08: * $Id: Table.java,v 1.11 2008/01/02 12:06:20 andy_seaborne Exp $
09: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.builtins;
10:
11: import com.hp.hpl.jena.reasoner.*;
12: import com.hp.hpl.jena.reasoner.rulesys.*;
13: import com.hp.hpl.jena.graph.*;
14:
15: /**
16: * Arrange that the given predicate is tabled by the backchaining engine.
17: *
18: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
19: * @version $Revision: 1.11 $ on $Date: 2008/01/02 12:06:20 $
20: */
21: public class Table extends BaseBuiltin {
22:
23: /**
24: * Return a name for this builtin, normally this will be the name of the
25: * functor that will be used to invoke it.
26: */
27: public String getName() {
28: return "table";
29: }
30:
31: /**
32: * This method is invoked when the builtin is called in a rule body.
33: * @param args the array of argument values for the builtin, this is an array
34: * of Nodes, some of which may be Node_RuleVariables.
35: * @param length the length of the argument list, may be less than the length of the args array
36: * for some rule engines
37: * @param context an execution context giving access to other relevant data
38: */
39: public void headAction(Node[] args, int length, RuleContext context) {
40: InfGraph infgraph = context.getGraph();
41: if (infgraph instanceof FBRuleInfGraph) {
42: for (int i = 0; i < length; i++) {
43: ((FBRuleInfGraph) infgraph).setTabled(args[i]);
44: }
45: } else if (infgraph instanceof LPBackwardRuleInfGraph) {
46: for (int i = 0; i < length; i++) {
47: ((LPBackwardRuleInfGraph) infgraph).setTabled(args[i]);
48: }
49: } else {
50: // Quietly ignore as an irrelevant directive
51: // Could log or throw exception but currently I want to be able to use
52: // the same rule base from different contexts which do and do not need
53: // to know about this.
54: }
55: }
56:
57: }
58:
59: /*
60: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
61: All rights reserved.
62:
63: Redistribution and use in source and binary forms, with or without
64: modification, are permitted provided that the following conditions
65: are met:
66:
67: 1. Redistributions of source code must retain the above copyright
68: notice, this list of conditions and the following disclaimer.
69:
70: 2. Redistributions in binary form must reproduce the above copyright
71: notice, this list of conditions and the following disclaimer in the
72: documentation and/or other materials provided with the distribution.
73:
74: 3. The name of the author may not be used to endorse or promote products
75: derived from this software without specific prior written permission.
76:
77: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
78: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
79: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
80: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
81: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
82: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
83: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
84: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
85: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
86: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87: */
|