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. |
From: <ku...@us...> - 2008-04-17 06:24:14
|
Revision: 796 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=796&view=rev Author: kurzum Date: 2008-04-16 23:24:07 -0700 (Wed, 16 Apr 2008) Log Message: ----------- small fix changed: new OWLXMLOntologyFormat() to new RDFXMLOntologyFormat() submitted bug to owlapi: http://sourceforge.net/tracker/index.php?func=detail&aid=1944634&group_id=90989&atid=595534 Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/utilities/CloseOntology.java trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java Modified: trunk/src/dl-learner/org/dllearner/utilities/CloseOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/CloseOntology.java 2008-04-17 06:19:33 UTC (rev 795) +++ trunk/src/dl-learner/org/dllearner/utilities/CloseOntology.java 2008-04-17 06:24:07 UTC (rev 796) @@ -25,9 +25,10 @@ * simply the path to the owl ontology "examples/test.owl" */ public static void main(String[] args) { - // String ontopath="examples/krkworking/test.owl"; + String ontopath=""; + //ontopath="examples/carcinogenesis/carcinogenesis.owl"; // inputURI - String ontopath = args[0]; + //ontopath = args[0]; File file = new File(ontopath); URI inputURI = file.toURI(); Modified: trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java 2008-04-17 06:19:33 UTC (rev 795) +++ trunk/src/dl-learner/org/dllearner/utilities/OntologyCloserOWLAPI.java 2008-04-17 06:24:07 UTC (rev 796) @@ -16,6 +16,7 @@ import org.dllearner.reasoning.OWLAPIReasoner; import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.io.OWLXMLOntologyFormat; +import org.semanticweb.owl.io.RDFXMLOntologyFormat; import org.semanticweb.owl.model.AddAxiom; import org.semanticweb.owl.model.OWLAxiom; import org.semanticweb.owl.model.OWLDataFactory; @@ -210,7 +211,7 @@ public void writeOWLFile(URI filename) { try { - manager.saveOntology(this.onto, new OWLXMLOntologyFormat(), + manager.saveOntology(this.onto, new RDFXMLOntologyFormat(), filename); } catch (Exception e) { e.printStackTrace(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-05-26 10:37:58
|
Revision: 927 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=927&view=rev Author: kurzum Date: 2008-05-26 03:37:56 -0700 (Mon, 26 May 2008) Log Message: ----------- fixed all immanent warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java trunk/src/dl-learner/org/dllearner/utilities/examples/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticExampleFinderRolesSPARQL.java Deleted: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticExampleFinderRolesSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticExampleFinderRolesSPARQL.java 2008-05-26 09:49:09 UTC (rev 926) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticExampleFinderRolesSPARQL.java 2008-05-26 10:37:56 UTC (rev 927) @@ -1,113 +0,0 @@ -package org.dllearner.utilities.examples; - -// keep this class it still needs to be worked in -public class AutomaticExampleFinderRolesSPARQL { - -// private static Logger logger = Logger -// .getLogger(ComponentManager.class); -// -// private Cache c; -// private SparqlEndpoint se; -// private SortedSet<String> posExamples; -// private SortedSet<String> negExamples; -// private int roleLimit=1000; - - /* - public AutomaticExampleFinderRolesSPARQL(SparqlEndpoint se){ - this.c=new Cache("cachetemp"); - this.se=se; - posExamples = new TreeSet<String>(); - negExamples = new TreeSet<String>(); - } - - public void initDomainRange(String role, int poslimit, int neglimit) { - makePositiveExamplesAsDomain( role); - SortedSet<String> keepForClean = new TreeSet<String>(); - keepForClean.addAll(this.posExamples); - this.posExamples = SetManipulation.fuzzyShrink(this.posExamples, poslimit); - logger.trace("shrinking: pos Example size: "+posExamples.size()); - - makeNegativeExamplesAsRange( role); - - - //clean - negExamples.removeAll(keepForClean); - logger.trace("neg Example size after cleaning: "+negExamples.size()); - this.negExamples = SetManipulation.fuzzyShrink(negExamples, neglimit); - logger.debug("pos Example size after shrinking: "+posExamples.size()); - logger.debug("neg Example size after shrinking: "+negExamples.size()); - logger.debug("Finished examples for role: "+role); - } - - - - - private void makePositiveExamplesAsDomain(String role){ - logger.debug("making Positive Examples from Role as Domain: "+role); - this.posExamples.addAll(getDomain( role, roleLimit)); - logger.debug(" pos Example size: "+posExamples.size()); - } - - private void makeNegativeExamplesAsRange(String role){ - logger.debug("making Negative Examples from Role as Range: "+role); - this.negExamples.addAll(getRange( role, roleLimit)); - logger.debug(" neg Example size: "+negExamples.size()); - } - - private SortedSet<String> getDomain(String role,int limit){ - - String query = "" + - "SELECT DISTINCT ?domain " + - "WHERE { \n" + - "?domain <" + role + "> " + " ?o. \n" + - "?domain a []\n." + - "FILTER (!isLiteral(?domain))." + - "}\n" + - "LIMIT "+limit; - - - String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se))); - ResultSet rs =SparqlQuery.JSONtoResultSet(JSON); - JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs); - return rsc.getStringListForVariable("domain"); - - } - - private SortedSet<String> getRange(String role,int limit){ - - String query = "" + - "SELECT DISTINCT ?range " + - "WHERE { \n" + - "?s <" + role + "> " + " ?range. \n" + - "?range a [].\n" + - "FILTER (!isLiteral(?range))." + - "}\n" + - "LIMIT "+limit; - - - String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se))); - ResultSet rs =SparqlQuery.JSONtoResultSet(JSON); - JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs); - return rsc.getStringListForVariable("range"); - - } - - - - - - - public SortedSet<String> getPosExamples() { - return posExamples; - } - - public SortedSet<String> getNegExamples() { - return negExamples; - } - - - - */ - - -} Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-05-26 09:49:09 UTC (rev 926) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-05-26 10:37:56 UTC (rev 927) @@ -5,13 +5,8 @@ import org.apache.log4j.Logger; import org.dllearner.core.ComponentManager; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.utilities.datastructures.SetManipulation; -import com.hp.hpl.jena.query.ResultSet; - public class AutomaticNegativeExampleFinderSPARQL { // CHECK @@ -21,25 +16,20 @@ private SortedSet<String> fullPositiveSet; - //static boolean useRelated = false; - private SortedSet<String> fromRelated; - //static boolean useSuperClasses = false; - private SortedSet<String> fromSuperclasses; - //static boolean useParallelClasses = true; - private SortedSet<String> fromParallelClasses; + private SortedSet<String> fromRelated = new TreeSet<String>(); + private SortedSet<String> fromSuperclasses = new TreeSet<String>();; + private SortedSet<String> fromParallelClasses = new TreeSet<String>();; + private SortedSet<String> fromDomain = new TreeSet<String>();; + private SortedSet<String> fromRange = new TreeSet<String>();; static int poslimit = 10; static int neglimit = 20; - // CHECK all vars needed + // CHECK separate posexamples and fullposset public AutomaticNegativeExampleFinderSPARQL( SortedSet<String> fullPositiveSet, SPARQLTasks st) { super(); - this.fromParallelClasses = new TreeSet<String>(); - this.fromRelated = new TreeSet<String>(); - this.fromSuperclasses = new TreeSet<String>(); - this.fullPositiveSet = fullPositiveSet; this.sparqltasks = st; @@ -80,8 +70,8 @@ } - // QUALITY: weird function, best removed - public void dbpediaMakeNegativeExamplesFromRelatedInstances(String subject) { + // QUALITY: keep a while may still be needed + /*public void dbpediaMakeNegativeExamplesFromRelatedInstances(String subject) { // SortedSet<String> result = new TreeSet<String>(); String SPARQLquery = "SELECT * WHERE { \n" + "<" + subject + "> " + "?p ?o. \n" @@ -90,7 +80,7 @@ this.fromRelated.addAll(sparqltasks.queryAsSet(SPARQLquery, "o")); - } + }*/ public void makeNegativeExamplesFromParallelClasses(SortedSet<String> positiveSet, int resultLimit){ makeNegativeExamplesFromClassesOfInstances(positiveSet, resultLimit); @@ -141,5 +131,22 @@ this.fromSuperclasses.removeAll(this.fullPositiveSet); logger.debug("|-neg Example from superclass: " + fromSuperclasses.size()); } + + @SuppressWarnings("unused") + private void makeNegativeExamplesFromDomain(String role, int resultLimit){ + logger.debug("making Negative Examples from Domain of : "+role); + this.fromDomain.addAll(sparqltasks.getDomain(role, resultLimit)); + this.fromDomain.removeAll(this.fullPositiveSet); + logger.debug("|-neg Example size from Domain: "+this.fromDomain.size()); + } + + @SuppressWarnings("unused") + private void makeNegativeExamplesFromRange(String role, int resultLimit){ + logger.debug("making Negative Examples from Range of : "+role); + this.fromRange.addAll(sparqltasks.getRange(role, resultLimit)); + this.fromRange.removeAll(this.fullPositiveSet); + logger.debug("|-neg Example size from Range: "+this.fromRange.size()); + } + } Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java 2008-05-26 09:49:09 UTC (rev 926) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java 2008-05-26 10:37:56 UTC (rev 927) @@ -5,8 +5,6 @@ import org.apache.log4j.Logger; import org.dllearner.core.ComponentManager; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SparqlEndpoint; public class AutomaticPositiveExampleFinderSPARQL { @@ -47,7 +45,22 @@ this.posExamples = sparqltasks.retrieveInstancesForSKOSConcept(SKOSConcept, 0); logger.debug("pos Example size: "+posExamples.size()); } - + + @SuppressWarnings("unused") + public void makePositiveExamplesFromDomain(String role, int resultLimit){ + logger.debug("making Positive Examples from Domain of : "+role); + this.posExamples.addAll(sparqltasks.getDomain(role, resultLimit)); + logger.debug("pos Example size: "+posExamples.size()); + } + + @SuppressWarnings("unused") + public void makePositiveExamplesFromRange(String role, int resultLimit){ + logger.debug("making Positive Examples from Range of : "+role); + this.posExamples.addAll(sparqltasks.getRange(role, resultLimit)); + logger.debug("pos Example size: "+posExamples.size()); + } + + public SortedSet<String> getPosExamples() { return posExamples; } Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/SPARQLTasks.java 2008-05-26 09:49:09 UTC (rev 926) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/SPARQLTasks.java 2008-05-26 10:37:56 UTC (rev 927) @@ -17,6 +17,7 @@ public class SPARQLTasks { //CHECK + @SuppressWarnings("unused") private static Logger logger = Logger .getLogger(SPARQLTasks.class); private Cache c; @@ -163,6 +164,38 @@ + public SortedSet<String> getDomain(String role,int resultLimit){ + + String SPARQLquery = "" + + "SELECT DISTINCT ?domain " + + "WHERE { \n" + + "?domain <" + role + "> " + " ?o. \n" + + "?domain a []\n." + + "FILTER (!isLiteral(?domain))." + + "}\n" + limit(resultLimit); + + return queryAsSet(SPARQLquery, "domain"); + + + } + + + public SortedSet<String> getRange(String role,int resultLimit){ + + String SPARQLquery = "" + + "SELECT DISTINCT ?range " + + "WHERE { \n" + + "?s <" + role + "> " + " ?range. \n" + + "?range a [].\n" + + "FILTER (!isLiteral(?range))." + + "}\n" + limit(resultLimit); + + return queryAsSet(SPARQLquery, "range"); + + } + + + /** * query a pattern with a standard SPARQL query * usage (?subject, ?predicate, <http:something> , subject ) @@ -225,11 +258,12 @@ return ""; } - @SuppressWarnings("unchecked") + public static SortedSet<String> getStringListForVariable(ResultSet rs, String var){ SortedSet<String> result = new TreeSet<String>(); //String s=ResultSetFormatter.asXMLString(this.rs); + @SuppressWarnings("unchecked") List<ResultBinding> l = ResultSetFormatter.toList(rs); for (ResultBinding resultBinding : l) { Modified: trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java 2008-05-26 09:49:09 UTC (rev 926) +++ trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java 2008-05-26 10:37:56 UTC (rev 927) @@ -1,8 +1,6 @@ package org.dllearner.utilities.learn; import java.util.HashSet; -import java.util.Iterator; -import java.util.List; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -14,7 +12,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; -import org.dllearner.core.owl.Description; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegLP; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |