1 10 package com.hp.hpl.jena.reasoner.rulesys.impl.oldCode; 11 12 import com.hp.hpl.jena.reasoner.*; 13 14 import java.util.*; 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 18 27 public class GoalTable { 28 29 30 protected Map table = new HashMap(); 31 32 33 protected BRuleEngine ruleEngine; 34 35 static Log logger = LogFactory.getLog(GoalTable.class); 36 37 43 public GoalTable(BRuleEngine ruleEngine) { 44 this.ruleEngine = ruleEngine; 45 } 46 47 54 public GoalState findGoal(TriplePattern goal) { 55 GoalResults results = (GoalResults) table.get(goal); 59 if (results == null || !goal.variantOf(results.goal)) { 60 results = new GoalResults(goal, ruleEngine); 61 table.put(goal, results); 62 } 63 return new GoalState(ruleEngine.getInfGraph().findDataMatches(goal), results); 64 } 65 66 69 public void reset() { 70 table = new HashMap(); 71 } 72 73 77 public void removePartialGoals() { 78 for (Iterator i= table.entrySet().iterator(); i.hasNext(); ) { 79 Map.Entry entry = (Map.Entry)i.next(); 80 TriplePattern goal = (TriplePattern)entry.getKey(); 81 GoalResults result = (GoalResults)entry.getValue(); 82 if ( ! result.isComplete()) { 83 for (Iterator d = result.dependents.iterator(); d.hasNext(); ) { 85 RuleState rs = (RuleState)d.next(); 86 if (rs.goalState != null) rs.goalState.close(); 87 } 88 i.remove(); 89 } 90 } 91 } 92 93 96 public void setAllComplete() { 97 for (Iterator i = table.values().iterator(); i.hasNext(); ) { 98 ((GoalResults)i.next()).setAllComplete(); 99 } 100 } 101 102 106 public void dump() { 107 System.out.println("Final goal table"); 108 for (Iterator i = table.values().iterator(); i.hasNext(); ) { 109 GoalResults gr = (GoalResults)i.next(); 110 System.out.println(gr.toString() ); 111 for (int j = 0; j < gr.numResults(); j++) { 112 System.out.println(" - " + gr.getResult(j)); 113 } 114 } 115 } 116 117 } 118 119 120 121 | Popular Tags |