KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > impl > OWLExptRuleTranslationHook


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

10 package com.hp.hpl.jena.reasoner.rulesys.impl;
11
12 import com.hp.hpl.jena.reasoner.rulesys.*;
13 import com.hp.hpl.jena.reasoner.*;
14 import com.hp.hpl.jena.graph.*;
15 import com.hp.hpl.jena.vocabulary.*;
16
17 import java.util.*;
18
19 /**
20  * Experimental change to OWL translation hook that doesn't handle translation
21  * of restrictions to functors.
22  *
23  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
24  * @version $Revision: 1.4 $ on $Date: 2005/02/21 12:17:57 $
25  */

26 public class OWLExptRuleTranslationHook implements RulePreprocessHook {
27
28     /**
29      * Invoke the preprocessing hook. This will be called during the
30      * preparation time of the hybrid reasoner.
31      * @param infGraph the inference graph which is being prepared,
32      * the hook code can use this to addDeductions or add additional
33      * rules (using addRuleDuringPrepare).
34      * @param dataFind the finder which packages up the raw data (both
35      * schema and data bind) and any cached transitive closures.
36      * @param inserts a temporary graph into which the hook should insert
37      * all new deductions that should be seen by the rules.
38      */

39     public void run(FBRuleInfGraph infGraph, Finder dataFind, Graph inserts) {
40         Iterator it = dataFind.find(new TriplePattern(null, OWL.intersectionOf.asNode(), null));
41         while (it.hasNext()) {
42             Triple decl = (Triple)it.next();
43             Node className = decl.getSubject();
44             List elements = new ArrayList();
45             translateIntersectionList(decl.getObject(), dataFind, elements);
46             // Generate the corresponding ruleset
47
List recognitionBody = new ArrayList();
48             Node var = new Node_RuleVariable("?x", 0);
49             for (Iterator i = elements.iterator(); i.hasNext(); ) {
50                 Node description = (Node)i.next();
51                 // Implication rule
52
Rule ir = new Rule("intersectionImplication", new ClauseEntry[] {
53                                     new TriplePattern(className, RDFS.subClassOf.asNode(), description)
54                                     }, new ClauseEntry[0]);
55                 ir.setBackward(false);
56                 infGraph.addRuleDuringPrepare(ir);
57                // Recognition rule elements
58
recognitionBody.add(new TriplePattern(var, RDF.type.asNode(), description));
59             }
60             List recognitionHead = new ArrayList(1);
61             recognitionHead.add(new TriplePattern(var, RDF.type.asNode(), className));
62             Rule rr = new Rule("intersectionRecognition", recognitionHead, recognitionBody);
63             rr.setBackward(true);
64             infGraph.addRuleDuringPrepare(rr);
65         }
66     }
67     
68     /**
69      * Translation code to translate a list of intersection elements into a
70      * Java list of corresponding class names or restriction functors.
71      * @param node the list node currently being processed
72      * @param data the source data to use as a context for this processing
73      * @param elements the list of elements found so far
74      */

75     protected static void translateIntersectionList(Node node, Finder dataFind, List elements) {
76         if (node.equals(RDF.nil.asNode())) {
77             return; // end of list
78
}
79         Node description = Util.getPropValue(node, RDF.first.asNode(), dataFind);
80         elements.add(description);
81         // Process the list tail
82
Node next = Util.getPropValue(node, RDF.rest.asNode(), dataFind);
83         translateIntersectionList(next, dataFind, elements);
84     }
85
86 }
87
88
89 /*
90     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
91     All rights reserved.
92
93     Redistribution and use in source and binary forms, with or without
94     modification, are permitted provided that the following conditions
95     are met:
96
97     1. Redistributions of source code must retain the above copyright
98        notice, this list of conditions and the following disclaimer.
99
100     2. Redistributions in binary form must reproduce the above copyright
101        notice, this list of conditions and the following disclaimer in the
102        documentation and/or other materials provided with the distribution.
103
104     3. The name of the author may not be used to endorse or promote products
105        derived from this software without specific prior written permission.
106
107     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
108     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
109     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
110     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
111     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
112     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
113     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
114     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
115     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
116     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
117 */
Popular Tags