1 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 26 public class OWLExptRuleTranslationHook implements RulePreprocessHook { 27 28 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 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 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 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 75 protected static void translateIntersectionList(Node node, Finder dataFind, List elements) { 76 if (node.equals(RDF.nil.asNode())) { 77 return; } 79 Node description = Util.getPropValue(node, RDF.first.asNode(), dataFind); 80 elements.add(description); 81 Node next = Util.getPropValue(node, RDF.rest.asNode(), dataFind); 83 translateIntersectionList(next, dataFind, elements); 84 } 85 86 } 87 88 89 | Popular Tags |