Hi, I agree that generic-general purpose RuleEngines can not hold this computation. The problem is that you have dublication of Facts, which kill memory-space. For instance, if you execute the Example with 4 Triples under Drools you get: <0> <subClassOf> <1> <1> <subClassOf> <2> <2> <subClassOf> <3> <3> <subClassOf> <4> <0> <subClassOf> <2> <2> <subClassOf> <4> <1> <subClassOf> <3> <0> <subClassOf> <3> <1> <subClassOf> <4> <0> <subClassOf> <4> <0> <subClassOf> <3> <1> <subClassOf> <4> <0> <subClassOf> <4> <0> <subClassOf> <4> <0> <subClassOf> <4> <0> <subClassOf> <4> The marked Triples are dublicates. With a growing number of Triples the dublicates grow exponentialy. Each of the Triple is represented by a TripleObject (see Triple Class in first email). Theoreticly, Drools does a correct Job. In Practice, this behaviour is not always desired. Suppose the very common usecase, where you like to calculate all Transitiv relations of a Hierarchie, like in a Tree (with countless specific usecases). In most cases, you simply dont need dublicated Facts, because they dont offer any more information.....If you look at the Drools output from before, you Know that 0 is a subClass of 4....you dont need to be told 6 times (!) One RuleEngine which does solve this problem very efficiently is Jena. You can execute the example @ appendix. There I create a Class Hierachie, with a specific depth. You can also see the output of the inferencing as a proof (at the end of the class) Try to set a dept of 1000, it only takes 500 ms (my pc: Intel Celeron 2 Ghz, 512 mb ram) Jena is a general purpose RuleEngine as well and you can specify rules in a Prolog-like Syntax. Jena does not include dublicated Triples and this is why it is so fast. >From my point of view, it would be a very very nice if Drools could also support such an optimization in Future releases. It could be implemented as an optional feature, for people who dont need dublicated Facts. best regards, Andreas Peter Van Weert schrieb: Hi, |
import java.util.ArrayList; import java.util.List; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.util.iterator.ExtendedIterator; public class Main2 { /** * @param args */ public static void main(String[] args) { //Create Model WITHOUT Inferencing OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM); //set the number of linear connected Triples (here a Classes hierachie, with subClassOf Properties) int depth = 1000; //create the Classes List<OntClass> classList = new ArrayList<OntClass>(); for(int i=0; i<=depth; i++){ OntClass clazz = model.createClass("Class"+i); classList.add(clazz); } //create subClassOf relations. Constructs the hierarchie with the specified depth Object[] classArr = classList.toArray(); for(int i=1; i<classArr.length; i++){ OntClass current = (OntClass)classArr[i-1]; OntClass next = (OntClass)classArr[i]; current.addSuperClass(next); } long time = System.currentTimeMillis(); //Apply RDFS Rules on the model. RDFS Rules define transitivity of the subClassOf Property //The rdfsModel contains the predefined Facts + inferenced ones OntModel rdfsModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, model); long time2 = (System.currentTimeMillis()-time); System.out.println("RDFSModel creation Time: "+time2+" ms\n"); //Proof - display Results //displayConnectionsPerClass(rdfsModel, classList); displayAllTriples(rdfsModel, classList); }//end main private static void displayAllTriples(OntModel model, List classList){ Object[] classArr2 = classList.toArray(); for(int i=0; i<classArr2.length; i++){ OntClass current = model.getOntClass("Class"+i); ExtendedIterator iterator = current.listSuperClasses(); while (iterator.hasNext()) { OntClass element = (OntClass) iterator.next(); System.out.println(current.getURI()+" subClassOf "+element.getURI()); } System.out.println(); } } private static void displayConnectionsPerClass(OntModel model, List classList){ Object[] classArr2 = classList.toArray(); for(int i=0; i<classArr2.length; i++){ OntClass current = model.getOntClass("Class"+i); ExtendedIterator iterator = current.listSuperClasses(); System.out.println(current); int count = 0; while (iterator.hasNext()) { iterator.next(); count++; } System.out.println(count+"\n"); } } }//end class