KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > test > DebugRules


1 /******************************************************************
2  * File: DebugRules.java
3  * Created by: Dave Reynolds
4  * Created on: 15-Apr-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: DebugRules.java,v 1.6 2005/04/08 16:36:04 der Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.test;
11
12 import com.hp.hpl.jena.reasoner.rulesys.*;
13 import com.hp.hpl.jena.mem.GraphMem;
14 import com.hp.hpl.jena.reasoner.*;
15 import com.hp.hpl.jena.graph.*;
16 import com.hp.hpl.jena.util.PrintUtil;
17
18 import java.util.*;
19 import java.io.*;
20
21 /** * Using during debuging of the rule systems.
22  * Runs a named set of rules (can contain axioms and rules) and
23  * lists all the resulting entailments.
24  * * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a> * @version $Revision: 1.6 $ on $Date: 2005/04/08 16:36:04 $ */

25 public class DebugRules {
26
27     /** The name of the rule set to load */
28     public static final String JavaDoc ruleFile = "etc/temp.rules";
29     
30     /** The parsed set of rules */
31     public List ruleset;
32     
33     /** Constructor - loads the rules */
34     public DebugRules(String JavaDoc rulefileName) throws IOException {
35         ruleset = Rule.parseRules(Util.loadRuleParserFromResourceFile(rulefileName));
36     }
37     
38     /** Run a single test */
39     public void run() {
40         
41         BasicForwardRuleReasoner reasoner = new BasicForwardRuleReasoner(ruleset);
42         InfGraph result = reasoner.bind(new GraphMem());
43         System.out.println("Final graph state");
44         for (Iterator i = result.find(null, null, null); i.hasNext(); ) {
45             System.out.println(PrintUtil.print((Triple)i.next()));
46         }
47         
48     }
49     
50     public static void main(String JavaDoc[] args) {
51         try {
52             DebugRules tester = new DebugRules(ruleFile);
53             tester.run();
54         } catch (Exception JavaDoc e) {
55             System.out.println("Problem: " + e);
56         }
57     }
58     
59 }
60
61 /*
62  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
63  * All rights reserved.
64  *
65  * Redistribution and use in source and binary forms, with or without
66  * modification, are permitted provided that the following conditions
67  * are met:
68  * 1. Redistributions of source code must retain the above copyright
69  * notice, this list of conditions and the following disclaimer.
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  * 3. The name of the author may not be used to endorse or promote products
74  * derived from this software without specific prior written permission.
75  *
76  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
77  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
78  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
79  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
80  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
81  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
82  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
83  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
85  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86  */

87
Popular Tags