From: <lor...@us...> - 2013-06-11 13:06:16
|
Revision: 3987 http://sourceforge.net/p/dl-learner/code/3987 Author: lorenz_b Date: 2013-06-11 13:06:13 +0000 (Tue, 11 Jun 2013) Log Message: ----------- Improved enrichment script. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-10 10:07:42 UTC (rev 3986) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-11 13:06:13 UTC (rev 3987) @@ -52,6 +52,11 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.Set; import java.util.SortedSet; @@ -61,6 +66,7 @@ import joptsimple.OptionSpec; import org.aksw.commons.jena_owlapi.Conversion; +import org.aksw.jena_sparql_api.core.QueryExecutionFactory; import org.apache.jena.riot.checker.CheckerLiterals; import org.apache.jena.riot.system.ErrorHandlerFactory; import org.apache.log4j.ConsoleAppender; @@ -123,10 +129,10 @@ import org.dllearner.learningproblems.Heuristics.HeuristicType; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.EnrichmentVocabulary; import org.dllearner.utilities.Helper; import org.dllearner.utilities.PrefixCCMap; -import org.dllearner.utilities.datastructures.SetManipulation; import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; @@ -151,13 +157,17 @@ import com.clarkparsia.owlapiv3.XSD; import com.google.common.collect.Sets; +import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Statement; +import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; @@ -225,6 +235,8 @@ private int chunksize = 1000; private boolean omitExistingAxioms; private List<String> allowedNamespaces = new ArrayList<String>(); + private int maxNrOfPositiveExamples = 20; + private int maxNrOfNegativeExamples = 20; private boolean useInference; private SPARQLReasoner reasoner; @@ -333,7 +345,7 @@ // loop over all entities and call appropriate algorithms Set<NamedClass> classes = reasoner.getTypes();//st.getAllClasses(); - filterByNamespaces(classes); + filterByNamespaces(classes);//classes = Sets.newHashSet(new NamedClass("http://dbpedia.org/ontology/GrandPrix")); int entities = 0; for(NamedClass nc : classes) { try { @@ -406,6 +418,39 @@ } } + private void filterByNamespaces(Model model){ + if(allowedNamespaces != null && !allowedNamespaces.isEmpty()){ + for (StmtIterator iterator = model.listStatements(); iterator.hasNext();) { + Statement st = iterator.next(); + Property predicate = st.getPredicate(); + RDFNode object = st.getObject(); + boolean startsWithAllowedNamespace = false; + if(predicate.equals(RDF.type)){ + if(object.isURIResource()){ + for (String ns : allowedNamespaces) { + if(object.asResource().getURI().startsWith(ns)){ + startsWithAllowedNamespace = true; + break; + } + } + } else { + startsWithAllowedNamespace = true; + } + } else { + for (String ns : allowedNamespaces) { + if(predicate.getURI().startsWith(ns)){ + startsWithAllowedNamespace = true; + break; + } + } + } + if(!startsWithAllowedNamespace){ + iterator.remove(); + } + } + } + } + @SuppressWarnings("unchecked") private void runClassLearningAlgorithms(SparqlEndpointKS ks, NamedClass nc) throws ComponentInitException { System.out.println("Running algorithms for class " + nc); @@ -435,12 +480,10 @@ } private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, NamedClass nc, boolean equivalence, boolean reuseKnowledgeSource) throws ComponentInitException { - // get instances of class as positive examples - SPARQLReasoner sr = new SPARQLReasoner(ks); System.out.print("finding positives ... "); long startTime = System.currentTimeMillis(); - SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); + SortedSet<Individual> posExamples = reasoner.getIndividuals(nc, maxNrOfPositiveExamples); long runTime = System.currentTimeMillis() - startTime; if(posExamples.isEmpty()){ System.out.println("Skipping CELOE because class " + nc.toString() + " is empty."); @@ -452,13 +495,11 @@ // use own implementation of negative example finder System.out.print("finding negatives ... "); startTime = System.currentTimeMillis(); - AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); - negExStr = SetManipulation.stableShrink(negExStr, 20); - SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); + AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(reasoner, "http://dbpedia.org/ontology"); + SortedSet<Individual> negExamples = finder.getNegativeExamples(nc, posExamples, maxNrOfNegativeExamples); SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); runTime = System.currentTimeMillis() - startTime; - System.out.println("done (" + negExStr.size()+ " examples found in " + runTime + " ms)"); + System.out.println("done (" + negExamples.size()+ " examples found in " + runTime + " ms)"); AbstractReasonerComponent rc; KnowledgeSource ksFragment; @@ -468,14 +509,11 @@ } else { System.out.print("extracting fragment ... ");//com.hp.hpl.jena.shared.impl.JenaParameters.enableEagerLiteralValidation = true; startTime = System.currentTimeMillis(); - ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getEndpoint(), cache, 2); - Model model = ModelFactory.createDefaultModel(); - for(Individual example : Sets.union(posExamples, negExamples)){ - Model cbd = cbdGen.getConciseBoundedDescription(example.getName()); - model.add(cbd); - } + Model model = getFragmentMultithreaded(ks, Sets.union(posExamples, negExamples)); filter(model); + filterByNamespaces(model); OWLEntityTypeAdder.addEntityTypes(model); + runTime = System.currentTimeMillis() - startTime; System.out.println("done (" + model.size()+ " triples found in " + runTime + " ms)"); OWLOntology ontology = asOWLOntology(model); @@ -483,8 +521,12 @@ // ksFragment.init(); rc = new FastInstanceChecker(ksFragment); rc.init(); + rc.setSubsumptionHierarchy(reasoner.getClassHierarchy()); ksCached = ksFragment; rcCached = rc; +// for (Individual ind : posExamples) { +// System.out.println(ResultSetFormatter.asText(com.hp.hpl.jena.query.QueryExecutionFactory.create("SELECT * WHERE {<" + ind.getName() + "> ?p ?o. OPTIONAL{?o a ?o_type}}",model).execSelect())); +// } } /*//old way to get SPARQL fragment @@ -516,7 +558,7 @@ ksCached = ks2; rcCached = rc; }*/ - + ClassLearningProblem lp = new ClassLearningProblem(rc); lp.setClassToDescribe(nc); lp.setEquivalence(equivalence); @@ -528,7 +570,9 @@ CELOE la = new CELOE(lp, rc); la.setMaxExecutionTimeInSeconds(10); la.setNoisePercentage(25); + la.setMaxNrOfResults(100); la.init(); + ((RhoDRDown)la.getOperator()).setUseNegation(false); startTime = System.currentTimeMillis(); System.out.print("running CELOE (for " + (equivalence ? "equivalent classes" : "sub classes") + ") ... "); la.start(); @@ -554,6 +598,42 @@ return learnedAxioms; } + private Model getFragment(SparqlEndpointKS ks, Set<Individual> individuals){ + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getEndpoint(), cache, 2); + Model model = ModelFactory.createDefaultModel(); + for(Individual ind : individuals){ + Model cbd = cbdGen.getConciseBoundedDescription(ind.getName()); + model.add(cbd); + } + return model; + } + + private Model getFragmentMultithreaded(final SparqlEndpointKS ks, Set<Individual> individuals){ + Model model = ModelFactory.createDefaultModel(); + ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + List<Future<Model>> futures = new ArrayList<Future<Model>>(); + for (final Individual ind : individuals) { + futures.add(threadPool.submit(new Callable<Model>() { + @Override + public Model call() throws Exception { + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getEndpoint(), cache, 2); + return cbdGen.getConciseBoundedDescription(ind.getName()); + } + })); + } + for (Future<Model> future : futures) { + try { + model.add(future.get()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + } + threadPool.shutdown(); + return model; + } + private List<EvaluatedAxiom> applyLearningAlgorithm(Class<? extends AxiomLearningAlgorithm> algorithmClass, SparqlEndpointKS ks, Entity entity) throws ComponentInitException { AxiomLearningAlgorithm learner = null; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-06-12 09:00:02
|
Revision: 3990 http://sourceforge.net/p/dl-learner/code/3990 Author: lorenz_b Date: 2013-06-12 08:59:59 +0000 (Wed, 12 Jun 2013) Log Message: ----------- Improved equivalence learning in enrichment script. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-12 07:34:30 UTC (rev 3989) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-12 08:59:59 UTC (rev 3990) @@ -226,7 +226,7 @@ // restrict tested number of entities per type (only for testing purposes); // should be set to -1 in production mode - int maxEntitiesPerType = 5; + int maxEntitiesPerType = -1; // number of axioms which will be learned/considered (only applies to // some learners) @@ -345,7 +345,7 @@ // loop over all entities and call appropriate algorithms Set<NamedClass> classes = reasoner.getTypes();//st.getAllClasses(); - filterByNamespaces(classes);//classes = Sets.newHashSet(new NamedClass("http://dbpedia.org/ontology/GrandPrix")); + filterByNamespaces(classes);//classes = Sets.newHashSet(new NamedClass("http://dbpedia.org/ontology/AdministrativeRegion")); int entities = 0; for(NamedClass nc : classes) { try { @@ -425,7 +425,7 @@ Property predicate = st.getPredicate(); RDFNode object = st.getObject(); boolean startsWithAllowedNamespace = false; - if(predicate.equals(RDF.type)){ + if(predicate.equals(RDF.type) || predicate.equals(OWL.equivalentClass)){ if(object.isURIResource()){ for (String ns : allowedNamespaces) { if(object.asResource().getURI().startsWith(ns)){ @@ -517,11 +517,14 @@ runTime = System.currentTimeMillis() - startTime; System.out.println("done (" + model.size()+ " triples found in " + runTime + " ms)"); OWLOntology ontology = asOWLOntology(model); + if(reasoner.getClassHierarchy() != null){ + ontology.getOWLOntologyManager().addAxioms(ontology, reasoner.getClassHierarchy().toOWLAPIAxioms()); + } ksFragment = new OWLAPIOntology(ontology); // ksFragment.init(); rc = new FastInstanceChecker(ksFragment); rc.init(); - rc.setSubsumptionHierarchy(reasoner.getClassHierarchy()); +// rc.setSubsumptionHierarchy(reasoner.getClassHierarchy()); ksCached = ksFragment; rcCached = rc; // for (Individual ind : posExamples) { @@ -616,7 +619,7 @@ futures.add(threadPool.submit(new Callable<Model>() { @Override public Model call() throws Exception { - ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getEndpoint(), cache, 2); + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getEndpoint(), "enrichment-cache", 2); return cbdGen.getConciseBoundedDescription(ind.getName()); } })); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-06-27 18:31:02
|
Revision: 4005 http://sourceforge.net/p/dl-learner/code/4005 Author: lorenz_b Date: 2013-06-27 18:31:00 +0000 (Thu, 27 Jun 2013) Log Message: ----------- Updated enrichment script. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-21 13:36:20 UTC (rev 4004) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-27 18:31:00 UTC (rev 4005) @@ -52,13 +52,13 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.Set; -import java.util.SortedSet; import joptsimple.OptionException; import joptsimple.OptionParser; @@ -66,8 +66,6 @@ import joptsimple.OptionSpec; import org.aksw.commons.jena_owlapi.Conversion; -import org.aksw.jena_sparql_api.core.QueryExecutionFactory; -import org.apache.jena.riot.Lang; import org.apache.jena.riot.checker.CheckerLiterals; import org.apache.jena.riot.system.ErrorHandlerFactory; import org.apache.log4j.ConsoleAppender; @@ -75,7 +73,7 @@ import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat; -import org.coode.owlapi.turtle.TurtleOntologyFormat; +import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.properties.AsymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; @@ -158,9 +156,7 @@ import com.clarkparsia.owlapiv3.XSD; import com.google.common.collect.Sets; -import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -306,7 +302,7 @@ dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); -// classAlgorithms.add(DisjointClassesLearner.class); + classAlgorithms.add(DisjointClassesLearner.class); // classAlgorithms.add(SimpleSubclassLearner.class); classAlgorithms.add(CELOE.class); @@ -359,26 +355,26 @@ break; } } -// entities = 0; -// Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); -// filterByNamespaces(objectProperties); -// for(ObjectProperty property : objectProperties) { -// runObjectPropertyAlgorithms(ks, property); -// entities++; -// if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { -// break; -// } -// } -// entities = 0; -// Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); -// filterByNamespaces(dataProperties); -// for(DatatypeProperty property : dataProperties) { -// runDataPropertyAlgorithms(ks, property); -// entities++; -// if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { -// break; -// } -// } + entities = 0; + Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); + filterByNamespaces(objectProperties); + for(ObjectProperty property : objectProperties) { + runObjectPropertyAlgorithms(ks, property); + entities++; + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { + break; + } + } + entities = 0; + Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); + filterByNamespaces(dataProperties); + for(DatatypeProperty property : dataProperties) { + runDataPropertyAlgorithms(ks, property); + entities++; + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { + break; + } + } } else { if(resource instanceof ObjectProperty) { System.out.println(resource + " appears to be an object property. Running appropriate algorithms.\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-06-27 18:47:39
|
Revision: 4006 http://sourceforge.net/p/dl-learner/code/4006 Author: lorenz_b Date: 2013-06-27 18:47:37 +0000 (Thu, 27 Jun 2013) Log Message: ----------- Updated enrichment script. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-27 18:31:00 UTC (rev 4005) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-06-27 18:47:37 UTC (rev 4006) @@ -341,7 +341,7 @@ // loop over all entities and call appropriate algorithms - Set<NamedClass> classes = reasoner.getTypes();//st.getAllClasses(); + Set<NamedClass> classes = allowedNamespaces.isEmpty() ? reasoner.getOWLClasses() : reasoner.getOWLClasses(allowedNamespaces.iterator().next());//st.getAllClasses(); filterByNamespaces(classes);//classes = Sets.newHashSet(new NamedClass("http://dbpedia.org/ontology/Arachnid")); int entities = 0; for(NamedClass nc : classes) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-07-11 12:24:25
|
Revision: 4017 http://sourceforge.net/p/dl-learner/code/4017 Author: lorenz_b Date: 2013-07-11 12:24:23 +0000 (Thu, 11 Jul 2013) Log Message: ----------- Added CLI paramters for entity type filtering when doing a batch processing. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-07-11 12:23:36 UTC (rev 4016) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-07-11 12:24:23 UTC (rev 4017) @@ -256,7 +256,13 @@ private Set<OWLAxiom> learnedOWLAxioms; private Set<EvaluatedAxiom> learnedEvaluatedAxioms; + private boolean processPropertiesTypeInferred = false; + private boolean iterativeMode = false; + private boolean processObjectProperties; + private boolean processDataProperties; + private boolean processClasses; + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, boolean useInference, boolean verbose, int chunksize, int maxExecutionTimeInSeconds, boolean omitExistingAxioms) { @@ -302,7 +308,7 @@ dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); - classAlgorithms.add(DisjointClassesLearner.class); +// classAlgorithms.add(DisjointClassesLearner.class); // classAlgorithms.add(SimpleSubclassLearner.class); classAlgorithms.add(CELOE.class); @@ -316,11 +322,19 @@ this.allowedNamespaces = allowedNamespaces; } + /** + * @param iterativeMode the iterativeMode to set + */ + public void setIterativeMode(boolean iterativeMode) { + this.iterativeMode = iterativeMode; + } + public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException, MalformedURLException { // instantiate SPARQL endpoint wrapper component SparqlEndpointKS ks = new SparqlEndpointKS(se); ks.init(); + ks.setSupportsSPARQL_1_1(!iterativeMode); // common helper objects SPARQLTasks st = new SPARQLTasks(se); @@ -340,41 +354,70 @@ if(resource == null) { // loop over all entities and call appropriate algorithms - - Set<NamedClass> classes = allowedNamespaces.isEmpty() ? reasoner.getOWLClasses() : reasoner.getOWLClasses(allowedNamespaces.iterator().next());//st.getAllClasses(); - filterByNamespaces(classes);//classes = Sets.newHashSet(new NamedClass("http://dbpedia.org/ontology/Arachnid")); int entities = 0; - for(NamedClass nc : classes) { - try { - runClassLearningAlgorithms(ks, nc); - } catch (Exception e) { - e.printStackTrace(); - } - entities++; - if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { - break; - } + Set<org.dllearner.core.owl.Property> processedProperties = new HashSet<org.dllearner.core.owl.Property>(); + if(processClasses){ + Set<NamedClass> classes = allowedNamespaces.isEmpty() ? reasoner.getOWLClasses() : reasoner.getOWLClasses(allowedNamespaces.iterator().next());//st.getAllClasses(); + filterByNamespaces(classes);//classes = Sets.newHashSet(new NamedClass("http://dbpedia.org/ontology/Arachnid")); + for(NamedClass nc : classes) { + try { + runClassLearningAlgorithms(ks, nc); + } catch (Exception e) { + e.printStackTrace(); + } + entities++; + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { + break; + } + } } entities = 0; - Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); - filterByNamespaces(objectProperties); - for(ObjectProperty property : objectProperties) { - runObjectPropertyAlgorithms(ks, property); - entities++; - if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { - break; - } + if(processObjectProperties){ + Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); + filterByNamespaces(objectProperties); + for(ObjectProperty property : objectProperties) { + runObjectPropertyAlgorithms(ks, property); + entities++; + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { + break; + } + } + processedProperties.addAll(objectProperties); } entities = 0; - Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); - filterByNamespaces(dataProperties); - for(DatatypeProperty property : dataProperties) { - runDataPropertyAlgorithms(ks, property); - entities++; - if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { - break; - } + if(processDataProperties){ + Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); + filterByNamespaces(dataProperties); + for(DatatypeProperty property : dataProperties) { + runDataPropertyAlgorithms(ks, property); + entities++; + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { + break; + } + } + processedProperties.addAll(dataProperties); } + + //optionally, get all properties and infer its type + if(processPropertiesTypeInferred ){ + reasoner.precomputePopularity(); + Set<org.dllearner.core.owl.Property> properties = allowedNamespaces.isEmpty() ? reasoner.getProperties(true) : reasoner.getProperties(true, allowedNamespaces.iterator().next()); + properties.removeAll(processedProperties); + filterByNamespaces(properties); + for(org.dllearner.core.owl.Property property : properties) { + if(property instanceof ObjectProperty){ + runObjectPropertyAlgorithms(ks, (ObjectProperty) property); + entities++; + } else if(property instanceof DatatypeProperty){ + runDataPropertyAlgorithms(ks, (DatatypeProperty) property); + entities++; + } + + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { + break; + } + } + } } else { if(resource instanceof ObjectProperty) { System.out.println(resource + " appears to be an object property. Running appropriate algorithms.\n"); @@ -529,36 +572,6 @@ // } } - /*//old way to get SPARQL fragment - SparqlKnowledgeSource ks2; - AbstractReasonerComponent rc; - if(reuseKnowledgeSource) { - ks2 = ksCached; - rc = rcCached; - System.out.println("re-using previously generated knowledge base fragment"); - } else { - ks2 = new SparqlKnowledgeSource(); - ks2.setInstances(Datastructures.individualSetToStringSet(examples.getCompleteSet())); - ks2.setUrl(ks.getEndpoint().getURL()); - ks2.setDefaultGraphURIs(new TreeSet<String>(ks.getEndpoint().getDefaultGraphURIs())); - ks2.setUseLits(false); - ks2.setUseCacheDatabase(true); - ks2.setCacheDir(cacheDir); - ks2.setRecursionDepth(2); - ks2.setCloseAfterRecursion(true); - ks2.setDissolveBlankNodes(false); - ks2.setSaveExtractedFragment(true); - startTime = System.currentTimeMillis(); - System.out.print("getting knowledge base fragment ... "); - ks2.init(); - runTime = System.currentTimeMillis() - startTime; - System.out.println("done in " + runTime + " ms"); - rc = new FastInstanceChecker(ks2); - rc.init(); - ksCached = ks2; - rcCached = rc; - }*/ - ClassLearningProblem lp = new ClassLearningProblem(rc); lp.setClassToDescribe(nc); lp.setEquivalence(equivalence); @@ -572,7 +585,7 @@ la.setNoisePercentage(25); la.setMaxNrOfResults(100); la.init(); - ((RhoDRDown)la.getOperator()).setUseNegation(false); +// ((RhoDRDown)la.getOperator()).setUseNegation(false); startTime = System.currentTimeMillis(); System.out.print("running CELOE (for " + (equivalence ? "equivalent classes" : "sub classes") + ") ... "); la.start(); @@ -1005,6 +1018,34 @@ public List<AlgorithmRun> getAlgorithmRuns() { return algorithmRuns; } + + /** + * @param processClasses the processClasses to set + */ + public void setProcessClasses(boolean processClasses) { + this.processClasses = processClasses; + } + + /** + * @param processDataProperties the processDataProperties to set + */ + public void setProcessDataProperties(boolean processDataProperties) { + this.processDataProperties = processDataProperties; + } + + /** + * @param processObjectProperties the processObjectProperties to set + */ + public void setProcessObjectProperties(boolean processObjectProperties) { + this.processObjectProperties = processObjectProperties; + } + + /** + * @param processPropertiesTypeInferred the processPropertiesTypeInferred to set + */ + public void setProcessPropertiesTypeInferred(boolean processPropertiesTypeInferred) { + this.processPropertiesTypeInferred = processPropertiesTypeInferred; + } public static void main(String[] args) throws IOException, ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException { @@ -1039,6 +1080,8 @@ .ofType(Integer.class).defaultsTo(10); parser.acceptsAll(asList("i", "inference"), "Specifies whether to use inference. If yes, the schema will be loaded into a reasoner and used for computing the scores.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); + parser.acceptsAll(asList("iterative"), + "Specifies whether to use local fragments or single query mode.").withOptionalArg().ofType(Boolean.class).defaultsTo(false); parser.acceptsAll(asList("s", "serialize"), "Specify a file where the ontology with all axioms can be written.") .withRequiredArg().ofType(File.class); parser.acceptsAll(asList("a", "annotations"), @@ -1052,7 +1095,14 @@ OptionSpec<String> allowedNamespacesOption = parser.accepts( "ns" ).withRequiredArg().ofType( String.class ) .withValuesSeparatedBy( ',' ); + parser.acceptsAll(asList("op"), + "Specifies whether to compute axiom for object properties.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); + parser.acceptsAll(asList("dp"), + "Specifies whether to compute axiom for data properties.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); + parser.acceptsAll(asList("cls"), + "Specifies whether compute axiom for classes.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); + //username and password if endpoint is protected parser.acceptsAll(asList("u", "username"), "Specify the username.") .withOptionalArg().ofType(String.class); @@ -1150,6 +1200,7 @@ } boolean useInference = (Boolean) options.valueOf("i"); + boolean iterativeMode = (Boolean) options.valueOf("iterative"); // boolean verbose = (Boolean) options.valueOf("v"); double threshold = (Double) options.valueOf("t"); int maxNrOfResults = (Integer) options.valueOf("l"); @@ -1173,8 +1224,17 @@ //extract namespaces to which the analyzed entities will be restricted List<String> allowedNamespaces = options.valuesOf(allowedNamespacesOption); + //check which entity types we have to process + boolean processObjectProperties = (Boolean) options.valueOf("op"); + boolean processDataProperties = (Boolean) options.valueOf("dp"); + boolean processClasses = (Boolean) options.valueOf("cls"); + Enrichment e = new Enrichment(se, resource, threshold, maxNrOfResults, useInference, false, chunksize, maxExecutionTimeInSeconds, omitExistingAxioms); e.setAllowedNamespaces(allowedNamespaces); + e.setIterativeMode(iterativeMode); + e.setProcessObjectProperties(processObjectProperties); + e.setProcessDataProperties(processDataProperties); + e.setProcessClasses(processClasses); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |