KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > builtins > Table


1 /******************************************************************
2  * File: table.java
3  * Created by: Dave Reynolds
4  * Created on: 08-Aug-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: Table.java,v 1.8 2005/02/21 12:17:33 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.builtins;
11
12 import com.hp.hpl.jena.reasoner.*;
13 import com.hp.hpl.jena.reasoner.rulesys.*;
14 import com.hp.hpl.jena.graph.*;
15
16 /**
17  * Arrange that the given predicate is tabled by the backchaining engine.
18  *
19  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
20  * @version $Revision: 1.8 $ on $Date: 2005/02/21 12:17:33 $
21  */

22 public class Table extends BaseBuiltin {
23
24     /**
25      * Return a name for this builtin, normally this will be the name of the
26      * functor that will be used to invoke it.
27      */

28     public String JavaDoc getName() {
29         return "table";
30     }
31
32     /**
33      * This method is invoked when the builtin is called in a rule body.
34      * @param args the array of argument values for the builtin, this is an array
35      * of Nodes, some of which may be Node_RuleVariables.
36      * @param length the length of the argument list, may be less than the length of the args array
37      * for some rule engines
38      * @param context an execution context giving access to other relevant data
39      */

40     public void headAction(Node[] args, int length, RuleContext context) {
41         InfGraph infgraph = context.getGraph();
42         if (infgraph instanceof FBRuleInfGraph) {
43             for (int i = 0; i < length; i++) {
44                 ((FBRuleInfGraph)infgraph).setTabled(args[i]);
45             }
46         } else if (infgraph instanceof LPBackwardRuleInfGraph) {
47             for (int i = 0; i < length; i++) {
48                 ((LPBackwardRuleInfGraph)infgraph).setTabled(args[i]);
49             }
50         } else {
51             // Quietly ignore as an irrelevant directive
52
// Could log or throw exception but currently I want to be able to use
53
// the same rule base from different contexts which do and do not need
54
// to know about this.
55
}
56     }
57  
58 }
59
60 /*
61     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
62     All rights reserved.
63
64     Redistribution and use in source and binary forms, with or without
65     modification, are permitted provided that the following conditions
66     are met:
67
68     1. Redistributions of source code must retain the above copyright
69        notice, this list of conditions and the following disclaimer.
70
71     2. Redistributions in binary form must reproduce the above copyright
72        notice, this list of conditions and the following disclaimer in the
73        documentation and/or other materials provided with the distribution.
74
75     3. The name of the author may not be used to endorse or promote products
76        derived from this software without specific prior written permission.
77
78     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
79     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
80     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
81     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
82     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
83     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
87     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88 */
Popular Tags