From: <ku...@us...> - 2008-04-07 10:07:48
|
Revision: 772 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=772&view=rev Author: kurzum Date: 2008-04-07 03:07:41 -0700 (Mon, 07 Apr 2008) Log Message: ----------- more comments Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/utilities/OntologyCloser.java trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java Modified: trunk/src/dl-learner/org/dllearner/utilities/OntologyCloser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/OntologyCloser.java 2008-04-07 09:22:24 UTC (rev 771) +++ trunk/src/dl-learner/org/dllearner/utilities/OntologyCloser.java 2008-04-07 10:07:41 UTC (rev 772) @@ -52,6 +52,22 @@ this.rs = new ReasoningService(owlapi); } + + public void updateReasoner() { + SimpleClock sc = new SimpleClock(); + sc.printAndSet(); + this.kbFile = new KBFile(this.kb); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); + ks.add(this.kbFile); + + sc.printAndSet("updating reasoner"); + OWLAPIReasoner owlapi = new OWLAPIReasoner(ks); + sc.printAndSet("init"); + owlapi.init(); + sc.printAndSet(); + this.rs = new ReasoningService(owlapi); + + } /** * counts the number of roles used by each individual and assigns @@ -156,7 +172,7 @@ // indToRestr.put(oneInd,) //make Description Description d = new NamedClass(oneRole+"Exact"+fillers.size()+"gen"); - d.addChild(oecr); + //d.addChild(oecr); kb.addTBoxAxiom(new EquivalentClassesAxiom(d,oecr)); //System.out.println(d.toManchesterSyntaxString("", new HashMap<String, String>())); kb.addABoxAxiom(new ClassAssertionAxiom(d,oneInd)); Modified: trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java 2008-04-07 09:22:24 UTC (rev 771) +++ trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java 2008-04-07 10:07:41 UTC (rev 772) @@ -28,194 +28,161 @@ import uk.ac.manchester.cs.owl.OWLObjectIntersectionOfImpl; public class OntologyCloserOWLAPI { - + OWLOntology onto; OWLAPIReasoner reasoner; - //Set<KnowledgeSource> ks; ReasoningService rs; - HashMap<Individual,Set<OWLObjectExactCardinalityRestrictionImpl>> indToRestr; + HashMap<Individual, Set<OWLObjectExactCardinalityRestrictionImpl>> indToRestr; OWLDataFactory factory; - OWLOntologyManager manager; + OWLOntologyManager manager; public int numberOfStatementsChanged = 0; - + public OntologyCloserOWLAPI(OWLAPIReasoner reasoner) { - //this.onto = reasoner.getOWLAPIOntologies().get(0); this.reasoner = reasoner; - this.indToRestr = new HashMap<Individual,Set<OWLObjectExactCardinalityRestrictionImpl>> (); + this.indToRestr = new HashMap<Individual, Set<OWLObjectExactCardinalityRestrictionImpl>>(); this.rs = new ReasoningService(reasoner); this.manager = OWLManager.createOWLOntologyManager(); this.factory = manager.getOWLDataFactory(); - this.onto = reasoner.getOWLAPIOntologies().get(0); - //URI ontologyURI = URI.create(reasoner.getBaseURI()); - //URI physicalURI = URI.create(owlFile); - //SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); - //manager.addURIMapper(mapper); - /*try{ - this.onto = manager.loadOntologyFromPhysicalURI(physicalURI); - }catch (Exception e) {e.printStackTrace();} - //manager.getOntologies().add(this.onto); - System.out.println(manager.getOntologies()); - System.out.println(this.onto);*/ - //reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); - //System.out.println(this.rs.getAtomicConcepts()); - } - /** * counts the number of roles used by each individual and assigns - * ExactCardinalityRestriction + * ExactCardinalityRestriction to Individuals */ public void applyNumberRestrictions() { - System.out.println("applyNRES"); + System.out.println("apply ExactCardinalityRestriction to Individuals"); Set<ObjectProperty> allRoles = this.rs.getAtomicRoles(); - System.out.println("found: "+allRoles.size()+" roles"); - // Set<Individual> allind = this.rs.getIndividuals(); - //testForTransitiveProperties(true); + System.out.println("found: " + allRoles.size() + " roles"); + testForTransitiveProperties(true); - - for (ObjectProperty oneRole : allRoles) { - // System.out.println(oneRole.getClass()); Map<Individual, SortedSet<Individual>> allRoleMembers = this.rs .getRoleMembers(oneRole); for (Individual oneInd : allRoleMembers.keySet()) { SortedSet<Individual> fillers = allRoleMembers.get(oneInd); + // only where roles exist if (fillers.size() > 0) { - OWLObjectExactCardinalityRestrictionImpl oecr = - new OWLObjectExactCardinalityRestrictionImpl( - factory, - factory.getOWLObjectProperty(URI.create(oneRole.getName())), - fillers.size(), - factory.getOWLThing() - ); - //System.out.println(oneRole.getName()+"||"+fillers.size()+"||"+oneInd); - /*ObjectExactCardinalityRestriction oecr = new ObjectExactCardinalityRestriction( - fillers.size(), oneRole, new Thing());*/ - //kb.addABoxAxiom(new ClassAssertionAxiom(oecr, oneInd)); - OWLAxiom axiom = factory.getOWLClassAssertionAxiom( - factory.getOWLIndividual(URI.create(oneInd.getName())) - , oecr); + OWLObjectExactCardinalityRestrictionImpl oecr = new OWLObjectExactCardinalityRestrictionImpl( + factory, factory.getOWLObjectProperty(URI + .create(oneRole.getName())), + fillers.size(), factory.getOWLThing()); + + OWLAxiom axiom = factory.getOWLClassAssertionAxiom(factory + .getOWLIndividual(URI.create(oneInd.getName())), + oecr); AddAxiom addAxiom = new AddAxiom(this.onto, axiom); - try{ - manager.applyChange(addAxiom); - }catch (Exception e) {e.printStackTrace();} + try { + // add change + manager.applyChange(addAxiom); + } catch (Exception e) { + e.printStackTrace(); + } } } } - // System.out.println("good ontology? " + rs.isSatisfiable()); } - + /** * counts the number of roles used by each individual and assigns - * ExactCardinalityRestriction + * ExactCardinalityRestriction, but uses only one Intersection: role1 + * exactly 1 and role2 exactly 2 and .... + * */ public void applyNumberRestrictionsConcise() { - + Set<ObjectProperty> allRoles = this.rs.getAtomicRoles(); - // Set<Individual> allind = this.rs.getIndividuals(); - // testForTransitiveProperties(true); + testForTransitiveProperties(true); + // collect info for roles and individuals for (ObjectProperty oneRole : allRoles) { - - // System.out.println(oneRole.getClass()); Map<Individual, SortedSet<Individual>> allRoleMembers = this.rs .getRoleMembers(oneRole); for (Individual oneInd : allRoleMembers.keySet()) { SortedSet<Individual> fillers = allRoleMembers.get(oneInd); if (fillers.size() > 0) { - OWLObjectExactCardinalityRestrictionImpl oecr = - new OWLObjectExactCardinalityRestrictionImpl( - factory, - factory.getOWLObjectProperty(URI.create(oneRole.getName())), - fillers.size(), - factory.getOWLThing() - ); - //indToRestr.put(oneInd,) - + OWLObjectExactCardinalityRestrictionImpl oecr = new OWLObjectExactCardinalityRestrictionImpl( + factory, factory.getOWLObjectProperty(URI + .create(oneRole.getName())), + fillers.size(), factory.getOWLThing()); collectExObjRestrForInd(oneInd, oecr); } } - - // + }// end for - }//end for - - //Intersection intersection = null; Set<OWLDescription> target = new HashSet<OWLDescription>(); Set<OWLObjectExactCardinalityRestrictionImpl> s = null; - + for (Individual oneInd : indToRestr.keySet()) { s = indToRestr.get(oneInd); for (OWLObjectExactCardinalityRestrictionImpl oecr : s) { target.add(oecr); } - OWLObjectIntersectionOfImpl intersection = - new OWLObjectIntersectionOfImpl(this.factory,target); - //kb.addABoxAxiom(new ClassAssertionAxiom(new OWLIntersection(ll), oneInd)); - - + // collect everything in an intersection + OWLObjectIntersectionOfImpl intersection = new OWLObjectIntersectionOfImpl( + this.factory, target); s = null; - target = new HashSet<OWLDescription>(); - - OWLAxiom axiom = factory.getOWLClassAssertionAxiom( - factory.getOWLIndividual(URI.create(oneInd.getName())) - , intersection); + target = new HashSet<OWLDescription>(); + + OWLAxiom axiom = factory.getOWLClassAssertionAxiom(factory + .getOWLIndividual(URI.create(oneInd.getName())), + intersection); AddAxiom addAxiom = new AddAxiom(this.onto, axiom); - try{ - manager.applyChange(addAxiom); - numberOfStatementsChanged++; - }catch (Exception e) {e.printStackTrace();} - - }//end for - - - - // - - // System.out.println("good ontology? " + rs.isSatisfiable()); + try { + manager.applyChange(addAxiom); + numberOfStatementsChanged++; + } catch (Exception e) { + e.printStackTrace(); + } + }// end for } - - + + /** + * @param printflag + * boolean for some output + * @return true if some roles are transitive + */ public boolean testForTransitiveProperties(boolean printflag) { - + boolean retval = false; - + Set<OWLPropertyAxiom> ax = onto.getObjectPropertyAxioms(); for (OWLPropertyAxiom propertyAxiom : ax) { - //System.out.println(propertyAxiom.getClass().getSimpleName()); if (propertyAxiom.getClass().getSimpleName().equals( "OWLTransitiveObjectPropertyAxiomImpl")) { retval = true; - if(printflag) { - System.out.println( - "WARNING transitive object property can't be used in cardinality restriction\n" - + propertyAxiom.toString()+"but I'm ignoring it"); + if (printflag) { + System.out + .println("WARNING transitive object property can't be used in cardinality restriction\n" + + propertyAxiom.toString() + + "but I'm ignoring it"); } } } - if(printflag) { - System.out.println( - "No transitive Properties found"); + if (printflag) { + System.out.println("No transitive Properties found"); } return retval; } -/* - public static void closeKB(KB kb) { - new OntologyCloserOWLAPI(kb).applyNumberRestrictions(); - } -*/ - + /* + * public static void closeKB(KB kb) { new + * OntologyCloserOWLAPI(kb).applyNumberRestrictions(); } + */ + + /** + * makes some retrieval queries + * @param conceptStr + * @return + */ public SortedSet<Individual> verifyConcept(String conceptStr) { - + Description d; - SimpleClock sc=new SimpleClock(); + SimpleClock sc = new SimpleClock(); StringBuffer sb = new StringBuffer(); sb.append(conceptStr); conceptStr = sb.toString(); @@ -223,39 +190,41 @@ try { d = KBParser.parseConcept(conceptStr); System.out.println("\n*******************\nStarting retrieval"); - System.out.println(d.toManchesterSyntaxString("", new HashMap<String,String>())); - //System.out.println(d.toString()); + System.out.println(d.toManchesterSyntaxString("", + new HashMap<String, String>())); + // System.out.println(d.toString()); sc.setTime(); this.rs.retrieval(d); - + System.out.println("retrieved: " + ind.size() + " instances"); sc.printAndSet(); for (Individual individual : ind) { System.out.print(individual + "|"); } - - } catch (Exception e) { e.printStackTrace(); } return ind; - } - - public void writeOWLFile(URI filename){ - try{ - manager.saveOntology(this.onto, new OWLXMLOntologyFormat(), - filename); - }catch (Exception e) {e.printStackTrace();} } - - - private boolean collectExObjRestrForInd(Individual ind, OWLObjectExactCardinalityRestrictionImpl oecr){ + + public void writeOWLFile(URI filename) { + try { + manager.saveOntology(this.onto, new OWLXMLOntologyFormat(), + filename); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private boolean collectExObjRestrForInd(Individual ind, + OWLObjectExactCardinalityRestrictionImpl oecr) { Set<OWLObjectExactCardinalityRestrictionImpl> s = indToRestr.get(ind); - - if(s==null){ - - indToRestr.put(ind, new HashSet<OWLObjectExactCardinalityRestrictionImpl>()); + + if (s == null) { + + indToRestr.put(ind, + new HashSet<OWLObjectExactCardinalityRestrictionImpl>()); s = indToRestr.get(ind); } return s.add(oecr); Modified: trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java 2008-04-07 09:22:24 UTC (rev 771) +++ trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java 2008-04-07 10:07:41 UTC (rev 772) @@ -1,5 +1,9 @@ package org.dllearner.utilities; +/** + * class for counting time and output it + * + */ public class SimpleClock { private long time; @@ -7,12 +11,28 @@ time=System.currentTimeMillis(); } + /** + * prints time needed + * and resets the clock + */ public void printAndSet() { long now=System.currentTimeMillis(); System.out.println("needed "+(now-time)+" ms"); time=now; } + + /** + * prints time needed + * and resets the clock + * @param s String for printing + */ + public void printAndSet(String s) { + long now=System.currentTimeMillis(); + System.out.println(s+" needed "+(now-time)+" ms"); + time=now; + } + public void setTime() { time=System.currentTimeMillis(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |