You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <lor...@us...> - 2011-12-01 11:01:58
|
Revision: 3457 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3457&view=rev Author: lorenz_b Date: 2011-12-01 11:01:47 +0000 (Thu, 01 Dec 2011) Log Message: ----------- Added algorithm for inverse object property axioms. Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java 2011-12-01 11:01:47 UTC (rev 3457) @@ -0,0 +1,166 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.dllearner.algorithms.properties; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; + +import org.aksw.commons.collections.multimaps.BiHashMultimap; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.InverseObjectPropertyAxiom; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.reasoning.SPARQLReasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +@ComponentAnn(name="inverse objectproperty domain axiom learner", shortName="oplinv", version=0.1) +public class InverseObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(InverseObjectPropertyAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + + public InverseObjectPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + if(reasoner.isPrepared()){ + //get existing inverse object property axioms + SortedSet<ObjectProperty> existingInverseObjectProperties = reasoner.getInverseObjectProperties(propertyToDescribe); + for(ObjectProperty invProp : existingInverseObjectProperties){ + existingAxioms.add(new InverseObjectPropertyAxiom(invProp, propertyToDescribe)); + } + } + + if(ks.supportsSPARQL_1_1()){ + runSPARQL1_1_Mode(); + } else { + runSPARQL1_0_Mode(); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + private void runSPARQL1_0_Mode(){ + Map<ObjectProperty, Integer> prop2CountMap = new HashMap<ObjectProperty, Integer>(); + boolean repeat = true; + int limit = 1000; + int total = 0; + while(!terminationCriteriaSatisfied() && repeat){ + String query = String.format("SELECT ?s ?p WHERE {?s <%s> ?o. OPTIONAL{?o ?p ?s.}} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, fetchedRows); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + ObjectProperty p; + int cnt = 0; + while(rs.hasNext()){ + qs = rs.next(); + if(qs.getResource("p") != null){ + p = new ObjectProperty(qs.getResource("p").getURI()); + Integer oldCnt = prop2CountMap.get(p); + if(oldCnt == null){ + oldCnt = Integer.valueOf(0); + } + prop2CountMap.put(p, Integer.valueOf(oldCnt + 1)); + } + cnt++; + } + total += cnt; + for(Entry<ObjectProperty, Integer> entry : prop2CountMap.entrySet()){ + currentlyBestAxioms = Collections.singletonList(new EvaluatedAxiom(new InverseObjectPropertyAxiom(entry.getKey(), propertyToDescribe), + computeScore(total, entry.getValue()))); + } + fetchedRows += limit; + repeat = (cnt == limit); + } + } + + private void runSPARQL1_1_Mode(){ + String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + int total = 0; + while(rs.hasNext()){ + qs = rs.next(); + total = qs.getLiteral("total").getInt(); + } + + query = String.format("SELECT ?p (COUNT(?s) AS ?cnt) WHERE {?s <%s> ?o. ?o ?p ?s.} GROUP BY ?p", propertyToDescribe.getName()); + rs = executeSelectQuery(query); + while(rs.hasNext()){ + qs = rs.next(); + currentlyBestAxioms.add(new EvaluatedAxiom( + new InverseObjectPropertyAxiom(new ObjectProperty(qs.getResource("p").getURI()), propertyToDescribe), + computeScore(total, qs.getLiteral("cnt").getInt()))); + } + + } + + public static void main(String[] args) throws Exception{ + SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql")));//.getEndpointDBpediaLiveAKSW())); + + SPARQLReasoner reasoner = new SPARQLReasoner(ks); + reasoner.prepareSubsumptionHierarchy(); + + + InverseObjectPropertyAxiomLearner l = new InverseObjectPropertyAxiomLearner(ks); + l.setReasoner(reasoner); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/officialLanguage")); + l.setMaxExecutionTimeInSeconds(10); +// l.setReturnOnlyNewAxioms(true); + l.init(); + l.start(); + + System.out.println(l.getCurrentlyBestEvaluatedAxioms(10, 0.2)); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-01 09:48:53
|
Revision: 3456 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3456&view=rev Author: lorenz_b Date: 2011-12-01 09:48:47 +0000 (Thu, 01 Dec 2011) Log Message: ----------- Added learning algorithm for asymmetric objectproperty axioms. Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java Added: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2011-12-01 09:48:47 UTC (rev 3456) @@ -0,0 +1,159 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.dllearner.algorithms.properties; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; + +import org.aksw.commons.collections.multimaps.BiHashMultimap; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.owl.AsymmetricObjectPropertyAxiom; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.vocabulary.OWL2; + +@ComponentAnn(name="asymmetric objectproperty axiom learner", shortName="oplasymm", version=0.1) +public class AsymmetricObjectPropertyAxiomLearner extends AbstractAxiomLearningAlgorithm { + + private static final Logger logger = LoggerFactory.getLogger(AsymmetricObjectPropertyAxiomLearner.class); + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) + private ObjectProperty propertyToDescribe; + + public AsymmetricObjectPropertyAxiomLearner(SparqlEndpointKS ks){ + this.ks = ks; + } + + public ObjectProperty getPropertyToDescribe() { + return propertyToDescribe; + } + + public void setPropertyToDescribe(ObjectProperty propertyToDescribe) { + this.propertyToDescribe = propertyToDescribe; + } + + @Override + public void start() { + logger.info("Start learning..."); + startTime = System.currentTimeMillis(); + fetchedRows = 0; + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); + + //check if property is already declared as asymmetric in knowledge base + String query = String.format("ASK {<%s> a <%s>}", propertyToDescribe, OWL2.AsymmetricProperty.getURI()); + boolean declaredAsymmetric = executeAskQuery(query); + if(declaredAsymmetric) { + existingAxioms.add(new AsymmetricObjectPropertyAxiom(propertyToDescribe)); + logger.info("Property is already declared as symmetric in knowledge base."); + } + + if(ks.supportsSPARQL_1_1()){ + runSPARQL1_1_Mode(); + } else { + runSPARQL1_0_Mode(); + } + + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); + } + + private void runSPARQL1_0_Mode(){ + BiHashMultimap<Individual, Individual> individualsMap = new BiHashMultimap<Individual, Individual>(); + boolean repeat = true; + int limit = 1000; + while(!terminationCriteriaSatisfied() && repeat){ + String query = String.format("SELECT DISTINCT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d", propertyToDescribe.getURI().toString(), limit, fetchedRows); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + Individual s; + Individual o; + int cnt = 0; + while(rs.hasNext()){ + qs = rs.next(); + s = new Individual(qs.getResource("s").getURI()); + o = new Individual(qs.getResource("o").getURI()); + individualsMap.put(s, o); + cnt++; + } + int total = individualsMap.size(); + int asymmetric = 0; + + for(java.util.Map.Entry<Individual, Individual> e : individualsMap.entries()){ + if(!individualsMap.getInverse().containsEntry(e.getKey(), e.getValue())){ + asymmetric++; + } + } + + currentlyBestAxioms = Collections.singletonList(new EvaluatedAxiom(new AsymmetricObjectPropertyAxiom(propertyToDescribe), + computeScore(total, asymmetric))); + fetchedRows += limit; + repeat = (cnt == limit); + } + } + + private void runSPARQL1_1_Mode(){ + String query = "SELECT (COUNT(?s) AS ?total) WHERE {?s <%s> ?o.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + int total = 0; + while(rs.hasNext()){ + qs = rs.next(); + total = qs.getLiteral("total").getInt(); + } + query = "SELECT (COUNT(?s) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + rs = executeSelectQuery(query); + int symmetric = 0; + while(rs.hasNext()){ + qs = rs.next(); + symmetric = qs.getLiteral("symmetric").getInt(); + } + int asymmetric = total - symmetric; + + if(total > 0){ + currentlyBestAxioms.add(new EvaluatedAxiom(new AsymmetricObjectPropertyAxiom(propertyToDescribe), + computeScore(total, asymmetric))); + } + + } + + public static void main(String[] args) throws Exception{ + AsymmetricObjectPropertyAxiomLearner l = new AsymmetricObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://factforge.net/sparql"))));//.getEndpointDBpediaLiveAKSW())); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/country")); + l.setMaxExecutionTimeInSeconds(10); + l.init(); + l.start(); + System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-30 22:12:14
|
Revision: 3455 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3455&view=rev Author: lorenz_b Date: 2011-11-30 22:12:07 +0000 (Wed, 30 Nov 2011) Log Message: ----------- Continued bug fixing of example confs. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/QuickStart.java trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-30 22:11:54 UTC (rev 3454) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-30 22:12:07 UTC (rev 3455) @@ -41,6 +41,7 @@ import org.dllearner.confparser3.ParseException; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.learningproblems.PosNegLP; @@ -65,6 +66,9 @@ private IConfiguration configuration; private File confFile; + private LearningAlgorithm algorithm; + private KnowledgeSource knowledgeSource; + // some CLI options private boolean writeSpringConfiguration = false; private boolean performCrossValidation = false; @@ -119,7 +123,8 @@ AbstractCELA la = context.getBean(AbstractCELA.class); new CrossValidation(la,lp,rs,nrOfFolds,false); } else { - LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); + knowledgeSource = context.getBean(KnowledgeSource.class); + algorithm = context.getBean(LearningAlgorithm.class); algorithm.start(); } @@ -221,5 +226,13 @@ public void setNrOfFolds(int nrOfFolds) { this.nrOfFolds = nrOfFolds; } + + public LearningAlgorithm getLearningAlgorithm() { + return algorithm; + } + + public KnowledgeSource getKnowledgeSource() { + return knowledgeSource; + } } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/QuickStart.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/QuickStart.java 2011-11-30 22:11:54 UTC (rev 3454) +++ trunk/interfaces/src/main/java/org/dllearner/cli/QuickStart.java 2011-11-30 22:12:07 UTC (rev 3455) @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; /** * A tool to quickly start a learning example. It detects all conf files in the @@ -173,7 +174,7 @@ // System.out.println(f.isDirectory()+f.getAbsolutePath()); } - public static void getAllConfs(File f, String path, HashMap<String, ArrayList<String>> confs) { + public static void getAllConfs(File f, String path, Map<String, ArrayList<String>> confs) { path = path + File.separator; // System.out.println(path); String[] act = f.list(); Modified: trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2011-11-30 22:11:54 UTC (rev 3454) +++ trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2011-11-30 22:12:07 UTC (rev 3455) @@ -30,6 +30,8 @@ import java.util.Map; import java.util.Random; import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.TreeSet; import org.apache.log4j.ConsoleAppender; @@ -72,7 +74,7 @@ // if true, then examples are executed in random order (avoids the problem // that the same examples are tested first on several runs); otherwise // it runs the examples in alphabetical order - boolean randomize = true; + boolean randomize = false; // GPs can be excluded temporarily (because those tests are very time-consuming) boolean testGP = false; @@ -90,7 +92,7 @@ logger.setLevel(Level.WARN); // map containing a list of conf files for each path - HashMap<String, ArrayList<String>> confFiles = new HashMap<String, ArrayList<String>>(); + Map<String, ArrayList<String>> confFiles = new TreeMap<String, ArrayList<String>>(); String exampleDir = ".." + File.separator + "examples"; File f = new File(exampleDir); QuickStart.getAllConfs(f, exampleDir, confFiles); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-30 22:12:00
|
Revision: 3454 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3454&view=rev Author: lorenz_b Date: 2011-11-30 22:11:54 +0000 (Wed, 30 Nov 2011) Log Message: ----------- Continued bug fixing of example confs. Modified Paths: -------------- trunk/examples/datatypes/double.conf trunk/examples/family/father_oe.conf Modified: trunk/examples/datatypes/double.conf =================================================================== --- trunk/examples/datatypes/double.conf 2011-11-30 17:01:10 UTC (rev 3453) +++ trunk/examples/datatypes/double.conf 2011-11-30 22:11:54 UTC (rev 3454) @@ -29,4 +29,4 @@ alg.type = "ocel" alg.searchTreeFile = "log/doubleTree.txt" -//alg.writeSearchTree = true; \ No newline at end of file +//alg.writeSearchTree = true Modified: trunk/examples/family/father_oe.conf =================================================================== --- trunk/examples/family/father_oe.conf 2011-11-30 17:01:10 UTC (rev 3453) +++ trunk/examples/family/father_oe.conf 2011-11-30 22:11:54 UTC (rev 3454) @@ -1,7 +1,17 @@ +// declare some prefixes to use as abbreviations +prefixes = [ ("ex","http://example.com/father#") ] -import("father_oe.owl"); +// knowledge source definition +ks.type = "OWL File" +ks.fileName = "father_oe.owl" -problem = classLearning; -classLearning.classToDescribe = "http://example.com/father#father"; +// reasoner +reasoner.type = "fast instance checker" +reasoner.sources = { ks } -algorithm = celoe; +// learning problem +lp.type = "clp" +lp.classToDescribe = "ex:father" + +// create learning algorithm to run +alg.type = "ocel" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-30 17:01:18
|
Revision: 3453 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3453&view=rev Author: jenslehmann Date: 2011-11-30 17:01:10 +0000 (Wed, 30 Nov 2011) Log Message: ----------- updated manual Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/examples/datatypes/stringtyped.conf trunk/interfaces/doc/manual/bibliography.bib trunk/interfaces/doc/manual/manual.tex Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-30 16:09:23 UTC (rev 3452) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-30 17:01:10 UTC (rev 3453) @@ -353,7 +353,7 @@ valueFrequency = null; dataValueFrequency = null; - System.out.println("freqDataValues: " + frequentDataValues); +// System.out.println("freqDataValues: " + frequentDataValues); // compute splits for double datatype properties for(DatatypeProperty dp : reasoner.getDoubleDatatypeProperties()) { Modified: trunk/examples/datatypes/stringtyped.conf =================================================================== --- trunk/examples/datatypes/stringtyped.conf 2011-11-30 16:09:23 UTC (rev 3452) +++ trunk/examples/datatypes/stringtyped.conf 2011-11-30 17:01:10 UTC (rev 3453) @@ -29,8 +29,9 @@ op.type = "rho" op.useDataHasValueConstructor=true +op.useStringDatatypes = true alg.type = "ocel" alg.searchTreeFile = "log/stringTypedTree.txt" -alg.writeSearchTree = true +// alg.writeSearchTree = true Modified: trunk/interfaces/doc/manual/bibliography.bib =================================================================== --- trunk/interfaces/doc/manual/bibliography.bib 2011-11-30 16:09:23 UTC (rev 3452) +++ trunk/interfaces/doc/manual/bibliography.bib 2011-11-30 17:01:10 UTC (rev 3453) @@ -107,3 +107,69 @@ volume = "4894", pages = "161--174" } + +@ARTICLE{auer-swj-2010, + author = {Sören Auer and Jens Lehmann}, + title = {Making the Web a Data Washing Machine - Creating Knowledge out of + Interlinked Data}, + journal = {Semantic Web Journal}, + year = {2010}, + keywords = {2010 group_aksw auer lehmann mole event_swj sys:relevantFor:infai + sys:relevantFor:bis seebiproject_OntoWiki peer-reviewed ontowiki_eu}, + timestamp = {2010.01.17}, + url = {http://www.jens-lehmann.org/files/2010/washing_machine_swj.pdf} +} + +@INCOLLECTION{sh_scalability_2011, + author = {Sebastian Hellmann and Jens Lehmann and Sören Auer}, + title = {Learning of OWL Class Expressions on Very Large Knowledge Bases and + its Applications.}, + booktitle = {Learning of OWL Class Expressions on Very Large Knowledge Bases and + its Applications}, + publisher = {IGI Global}, + year = {2011}, + editor = {Semantic Services, Interoperability and Web Applications: Emerging + Concepts}, + chapter = {5}, + pages = {104-130}, + doi = {doi:10.4018/978-1-60960-593-3}, + keywords = {peer-reviewed 2011 hellmann lehmann auer group_aksw mole sys:relevantFor:infai + sys:relevantFor:bis}, + owner = {sebastian}, + timestamp = {2011.06.27} +} + +@INPROCEEDINGS{hanne, + author = {Sebastian Hellmann and Jörg Unbehauen and Jens Lehmann}, + title = {HANNE - A Holistic Application for Navigational Knowledge Engineering}, + booktitle = {Posters and Demos of ISWC 2010}, + year = {2010}, + keywords = {2010 group_aksw event_iswc hellmann unbehauen lehmann mole sys:relevantFor:infai + sys:relevantFor:bis dllearner}, + url = {http://iswc2010.semanticweb.org/pdf/522.pdf} +} + +@INPROCEEDINGS{fuzzy, + author = {Josué Iglesias and Jens Lehmann}, + title = {Towards Integrating Fuzzy Logic Capabilities into an Ontology-based + Inductive Logic Programming Framework}, + booktitle = {Proc. of the 11th International Conference on Intelligent Systems + Design and Applications (ISDA)}, + year = {2011}, + keywords = {2011 group_aksw lehmann mole sys:relevantFor:infai sys:relevantFor:bis + sys:relevantFor:lod2 lod2page dllearner}, + owner = {jl}, + timestamp = {2011.08.23} +} + +@INPROCEEDINGS{autosparql, + author = {Jens Lehmann and Lorenz Bühmann}, + title = {AutoSPARQL: Let Users Query Your Knowledge Base}, + booktitle = {Proceedings of ESWC 2011}, + year = {2011}, + keywords = {2011 group_aksw mole event_eswc lehmann buehmann sys:relevantFor:infai + dllearner sys:relevantFor:bis sys:relevantFor:lod2 lod2page peer-reviewed}, + owner = {jl}, + timestamp = {2011.03.22}, + url = {http://jens-lehmann.org/files/2011/autosparql_eswc.pdf} +} \ No newline at end of file Modified: trunk/interfaces/doc/manual/manual.tex =================================================================== --- trunk/interfaces/doc/manual/manual.tex 2011-11-30 16:09:23 UTC (rev 3452) +++ trunk/interfaces/doc/manual/manual.tex 2011-11-30 17:01:10 UTC (rev 3453) @@ -38,9 +38,23 @@ \maketitle \begin{abstract} +\vspace{-15pt} DL-Learner is a machine learning framework for OWL and description logics. It includes several learning algorithms and is easy to extend. DL-Learner widens the scope of Inductive Logic Programming to description logics and the Semantic Web. This manual provides the entry point to using DL-Learner and explains its basic concepts. + +Please refer to the following publication (BibTeX) when citing DL-Learner: +\begin{verbatim} + @Article{dllearner_jmlr, + author = "Jens Lehmann", + title = "{DL-Learner:} Learning Concepts in Description Logics", + journal = "Journal of Machine Learning Research (JMLR)", + year = "2009", + volume = "10", + pages = "2639--2642" +} +\end{verbatim} \end{abstract} +\vspace{-25pt} \tableofcontents \clearpage @@ -56,44 +70,43 @@ In the most common scenario we consider, we have a background knowledge base in OWL/DLs and additionally, we are given positive and negative examples. Each example is an individual in our knowledge base. The goal is to find an OWL \emph{class expression}\footnote{\owlce} such that all/many of the positive examples are \emph{instances} of this expression and none/few of the negative examples are instances of it. The primary purpose of learning is to find a class expression, which can classify unseen individuals (i.e.~not belonging to the examples) correctly. It is also important that the obtained class expression is easy to understand for a domain expert. We call these criteria \emph{accuracy} and \emph{readability}. -As an example, consider the problem to find out whether a chemical compound can cause cancer\footnote{see \carc{} for a more detailed description}. In this case, the background knowledge contains information about chemical compounds in general and certain concrete compounds we are interested in. The positive examples are those compounds causing cancer, whereas the negative examples are those compounds not causing cancer. The prediction for the examples has been obtained from experiments and long-term research trials in this case. Of course, all examples have to be described in the considered background knowledge. A learning algorithm can now derive a class expression from examples and background knowledge, e.g.~such a class expression in natural language could be ``chemical compounds containing a phosphorus atom''. (Of course, in practice the expression will be more complex to obtain a reasonable accuracy.) Using this class expression, we can not classify unseen chemical compounds. +As an example, consider the problem to find out whether a chemical compound can cause cancer\footnote{see \carc{} for a more detailed description}. In this case, the background knowledge contains information about chemical compounds in general and certain concrete compounds we are interested in. The positive examples are those compounds causing cancer, whereas the negative examples are those compounds not causing cancer. The prediction for the examples has been obtained from experiments and long-term research trials in this case. Of course, all examples have to be described in the considered background knowledge. A learning algorithm can now derive a class expression from examples and background knowledge, e.g.~such a class expression in natural language could be ``chemical compounds containing a phosphorus atom''. (Of course, in practice the expression will be more complex to obtain a reasonable accuracy.) Using this class expression, we can now classify unseen chemical compounds. +Please note that the latest versions of DL-Learner are not limited to OWL class expressions anymore. There is also preliminary support for learning simple SPARQL queries~\cite{autosparql}. Preliminary support for fuzzy OWL class expressions~\cite{fuzzy} is also included, but requires setting up a fuzzy OWL reasoner. Please contact us via the DL-Learner discussion list if you plan to do this. + \section{Getting Started} \label{sec:start} -DL-Learner is written in Java, i.e.~it can be used on almost all platforms. Currently, Java 6 or higher is required. To install the latest release, please visit the download page\footnote{\dldownload} and extract the file on your harddisk. In the top level directory, you will notice several executables. Those files ending with \verb|bat| are Windows executables, whereas the corresponding files without file extension are the Non-Windows (e.g.~Linux, Mac) executables. To test whether DL-Learner works, please run the following on the command line depending on your operating system: +DL-Learner is written in Java, i.e.~it can be used on almost all platforms. Currently, Java 6 or higher is required. To install the latest release, please visit the download page\footnote{\dldownload} and extract the file on your harddisk. In the \verb|bin| directory, you will notice several executables. Those files ending with \verb|bat| are Windows executables, whereas the corresponding files without file extension are the Non-Windows (e.g.~Linux, Mac) executables. To test whether DL-Learner works, please run the following on the command line depending on your operating system: \begin{verbatim} -dllearner examples/father.conf (Non-Windows Operating System) -dllearner.bat examples/father.conf (Windows Operating System) +./dllearner ../examples/father.conf (Non-Windows Operating System) +dllearner.bat ..\examples\father.conf (Windows Operating System) \end{verbatim} -\emph{Conf files}, e.g. \verb|examples/father.conf| in this case, describe the learning problem and specify which algorithm you want to use to solve it. In the simplest case they just say where to find the background knowledge to use (in the OWL file \verb|examples/father.owl| in this case) and the positive and negative examples (marked by ``+'' and ``-'', respectively). When running the above command, you should get something similar to the following: +\emph{Conf files}, e.g. \verb|examples/father.conf| in this case, describe the learning problem and specify which algorithm you want to use to solve it. In the simplest case they just say where to find the background knowledge to use (in the OWL file \verb|examples/father.owl| in this case) and the positive and negative examples. When running the above command, you should get something similar to the following: \begin{verbatim} -DL-Learner 2010-08-07 command line interface -starting component manager ... OK (157ms) -initialising component "OWL file" ... OK (0ms) -initialising component "fast instance checker" ... OK (842ms) -initialising component "pos neg learning problem" ... OK (0ms) -initialising component "refinement operator based - learning algorithm II" ... OK (14ms) +DL-Learner command line interface +Initializing Component "OWL File"... OK (0ms) +Initializing Component "fast instance checker"... OK (835ms) +Initializing Component "PosNegLPStandard"... OK (0ms) +Initializing Component "OWL Class Expression Learner"... OK (21ms) starting top down refinement with: Thing (50% accuracy) more accurate (83,33%) class expression found: male solutions (at most 20 are shown): 1: (male and hasChild some Thing) (accuracy 100%, length 5, depth 3) -Algorithm terminated successfully. +Algorithm terminated successfully (2236 descriptions tested). number of retrievals: 4 -retrieval reasoning time: 0ms (0ms per retrieval) -number of instance checks: 93 (0 multiple) -instance check reasoning time: 1ms ( 0ms per instance check) -overall reasoning time: 1ms (11,016% of overall runtime) -overall algorithm runtime: 17ms +retrieval reasoning time: 0ms ( 0ms per retrieval) +number of instance checks: 7455 (0 multiple) +instance check reasoning time: 54ms ( 0ms per instance check) +overall reasoning time: 54ms \end{verbatim} -The first part of the output tells you which components are used (more on this in Section \ref{sec:components}). In the second part you see output coming from the used learning algorithm, i.e.~it can print information while running (``more accurate (83,33\%) class description found'') and the final solutions, it computed. The results are displayed in Manchester OWL Syntax\footnote{\mos}. There can be several solutions, in which case they are ordered with the most promising one in the first position. In this case the only solution is \verb|male and hasChild some Thing| defining the class father. The last part of the output contains some runtime statistics. +The first part of the output tells you which components are used (more on this in Section \ref{sec:components}). In the second part you see output coming from the used learning algorithm, i.e.~it can print information while running (``more accurate (83,33\%) class expression found'') and the final solutions, it computed. The results are displayed in Manchester OWL Syntax\footnote{\mos}. There can be several solutions, in which case they are ordered with the most promising one in the first position. In this case the only solution is \verb|male and hasChild some Thing| defining the class father. The last part of the output contains some runtime statistics. \section{DL-Learner Architecture} @@ -105,9 +118,9 @@ \label{fig:structure} \end{figure} -To be flexible in integrating new learning algorithms, new kinds of learning problems, new knowledge bases, and new reasoner implementations, DL-Learner uses a component based model. Adding a component can be done by subclassing the appropriate class and adding the name of the new class to the “components.ini” file (more on that in Section \ref{sec:developing}). +To be flexible in integrating new learning algorithms, new kinds of learning problems, new knowledge bases, and new reasoner implementations, DL-Learner uses a component based model. Adding a component can be done by implementing the appropriate Java interface and adding appropriate annotations (more on that in Section \ref{sec:developing}). -There are four types of components (knowledge source, reasoning service, learning problem, learning algorithm). For each type, there are several implemented components and each component can have its own configuration options as illustrated in Figure \ref{fig:components}. Configuration options can be used to change parameters/settings of a component. In Section \ref{sec:components}, we describe the components in DL-Learner and their configuration options. +There are four common types of components (knowledge source, reasoning service, learning problem, learning algorithm). DL-Learner is not restricted to those types, i.e.~others can easily be added, but we limit ourselves to those four to make this manual easier to read. For each type, there are several implemented components and each component can have its own configuration options as illustrated in Figure \ref{fig:components}. Configuration options can be used to change parameters/settings of a component. In Section \ref{sec:components}, we describe the components in DL-Learner and their configuration options. \begin{figure} \includegraphics[width=\textwidth]{components_print} @@ -118,21 +131,27 @@ \section{DL-Learner Components} \label{sec:components} -In this part, we describe concrete components currently implemented in DL-Learner. Each of the subsections contains a list of components according to the type specified in the subsection heading. Note that this does not constitute a full description, i.e.~we omit some components and many configuration options. The purpose of the manual is to obtain a general understanding of the implemented components. A full list, which is generated automatically from the source code, can be found in \verb|doc/configOptions.txt| including the default values for all options and their usage in conf files. +In this part, we describe concrete components currently implemented in DL-Learner. Each of the subsections contains a list of components according to the type specified in the subsection heading. Note that this does not constitute a full description, i.e.~we omit some components and many configuration options. The purpose of the manual is to obtain a general understanding of the implemented components. A full list, which is generated automatically from the source code, can be found in \verb|doc/configOptions.html| including the default values for all options and their usage in conf files. The file is also available online at \url{http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/interfaces/doc/configOptions.html}. \subsection{Knowledge Sources} -Knowledge sources have a URI and can be included in conf files using \verb|import("$url");|, e.g.~\verb|import("ontology.owl")|. Depending on the file ending, DL-Learner will guess the correct type of knowledge source. If you want to overwrite this, you can use a second parameter with value \verb|OWL|, \verb|KB|, or \verb|SPARQL|, e.g.~\verb|import("ontology.owl","OWL")|. +%Knowledge sources have a URI and can be included in conf files using \verb|import("$url");|, e.g.~\verb|import("ontology.owl")|. Depending on the file ending, DL-Learner will guess the correct type of knowledge source. If you want to overwrite this, you can use a second parameter with value \verb|OWL|, \verb|KB|, or \verb|SPARQL|, e.g.~\verb|import("ontology.owl","OWL")|. +The following contains some knowledge sources implemented in DL-Learner. To give an example, this is how a local OWL file can be declared as knowlege source in a conf file: +\begin{verbatim} +ks.type = "OWL File" +ks.fileName = "father.owl" +\end{verbatim} \begin{description} \item[OWL File] DL-Learner supports OWL files in different formats, e.g. RDF/XML or N-Triples. If there is a standard OWL format, you want to use, but is not supported by DL-Learner please let us know. We use the OWL API for parsing, so all formats supported by it can be used\footnote{ for a list see \owlapi}. - \item[KB File] KB files are an internal non-standardised knowledge representation format, which corresponds to description logic syntax except that the special symbols have been replaced by ASCII strings, e.g.~\verb|AND| instead of $\sqcap$. You can find several KB files in the examples folder. The \verb|doc/kbFileSyntax.txt| contains an EBNF description of the language. + \item[KB File] KB files are an internal non-standardised knowledge representation format, which corresponds to description logic syntax except that the special symbols have been replaced by ASCII strings, e.g.~\verb|AND| instead of $\sqcap$. You can find several KB files in the examples folder. A description of the syntax is available online\footnote{\url{http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/interfaces/doc/kbFileSyntax.txt}}. If in doubt, please use the standard OWL syntax formats. +%The \verb|doc/kbFileSyntax.txt| contains an EBNF description of the language. \item[SPARQL Endpoint] DL-Learner allows to use SPARQL endpoints as background knowledge source, which enables the incorporation of very large knowledge bases, e.g. DBpedia\cite{2008_dbpedia}, in DL-Learner. This works by using a set of start instances, which usually correspond to the examples in a learning problem, and then retrieving knowledge about these instances via SPARQL queries. The obtained knowledge base fragment can be converted to OWL and consumed by a reasoner later since it is now sufficiently small to be processed in reasonable time. Please see \cite{2009_ijswis} for details about the knowledge fragment extraction algorithm. Some options of the SPARQL component are: \begin{itemize} \item instances: Set of individuals to use for starting the knowledge fragment extraction. Example use in conf file: \begin{verbatim}sparql.instances = {"http://dbpedia.org/resource/Matt_Stone", - "http://dbpedia.org/resource/Sarah_Silverman"};\end{verbatim} - \item recursionDepth: Maximum distance of an extracted individual from a start individual. This influences the size of the extracted fragment and depends on the maximum property depth you want the learned class expression to have. Example use in conf file: \verb|sparql.recursionDepth = 2;|. -\item saveExtractedFragment: Specifies whether the extracted ontology is written to a file or not. If set to true, then the OWL file is written to the cache dir. Example usage: \verb|sparql.saveExtractedFragment = true;| + "http://dbpedia.org/resource/Sarah_Silverman"}\end{verbatim} + \item recursionDepth: Maximum distance of an extracted individual from a start individual. This influences the size of the extracted fragment and depends on the maximum property depth you want the learned class expression to have. Example use in conf file: \verb|sparql.recursionDepth = 2|. +\item saveExtractedFragment: Specifies whether the extracted ontology is written to a file or not. If set to true, then the OWL file is written to the cache dir. Example usage: \verb|sparql.saveExtractedFragment = true| \end{itemize} Many further options allow to modify the extracted fragment on the fly or fine-tune the extraction process. The extraction can be started separately by running and modifying \verb|org.dllearner.test.SparqlExtractionTest|. The collected ontology will be saved in the DL-Learner directory. @@ -140,30 +159,34 @@ \subsection{Reasoner Components} -Several reasoner components are implemented, which can be interfaces to concrete reasoner implementations. To select a component in a conf file, use \verb|reasoner=$value;|, where \verb|$value| is one of \verb|digReasoner|, \verb|fastInstanceChecker|, or \verb|owlAPIReasoner|, which are explained below. Note that OWLlink reasoners can be attached via the OWL API interface. +Several reasoner components are implemented, which can be interfaces to concrete reasoner implementations. +%To select a component in a conf file, use \verb|reasoner=$value;|, where \verb|$value| is one of \verb|digReasoner|, \verb|fastInstanceChecker|, or \verb|owlAPIReasoner|, which are explained below. +Note that OWLlink reasoners can be attached via the OWL API interface. \begin{description} \item[OWL API] The OWL API reasoner interface can be used in conjunction with the Pellet, FaCT++, HermiT and OWLlink reasoners. The only option allows to switch between them: \begin{itemize} - \item reasonerType: Selects the desired reasoner. By default, Pellet is used. Usage: \verb|owlAPIReasoner.reasonerType = fact;|. Pellet, FaCT++ and HermiT are already included in DL-Learner. Note that for FaCT++, you need to add -Djava.library.path=lib/fact/64bit (or 32bit) to the Java command. You can also use an external OWLlink reasoner by setting the reasoner type to \verb|owllink|. You can then use the option \verb|owlLinkURL| to specify the URL of the OWLlink reasoner (http://localhost:8080/ by default). + \item reasonerType: Selects the desired reasoner. By default, Pellet is used. Usage: \verb|owlAPIReasoner.reasonerType = fact|. Pellet, FaCT++ and HermiT are already included in DL-Learner. Note that for FaCT++, you need to add -Djava.library.path=lib/fact/64bit (or 32bit) to the Java command. You can also use an external OWLlink reasoner by setting the reasoner type to \verb|owllink|. You can then use the option \verb|owlLinkURL| to specify the URL of the OWLlink reasoner (http://localhost:8080/ by default). \end{itemize} - \item[DIG] DIG 1.1\footnote{\dig} is an interface to description logic reasoners and supported by a large variety of reasoners including Pellet, FaCT++, KAON2, and Racer Pro. The major drawback is that the current version DIG 1.1 is not aligned with the OWL specification and therefore lacks several features, which are crucial to the more recent learning algorithms in DL-Learner. If you still want to use the DIG interface, you have to download a DIG capable reasoner and start the DIG server there. DL-Learner communicates with the reasoner using the XML based protocol over HTTP. + \item[DIG] DIG 1.1\footnote{\dig} is an interface to description logic reasoners and supported by a large variety of reasoners including Pellet, FaCT++, KAON2, and Racer Pro. The major drawback is that the current version DIG 1.1 is not aligned with the OWL specification and therefore lacks several features, which are crucial to the more recent learning algorithms in DL-Learner. If you still want to use the DIG interface, you have to download a DIG capable reasoner and start the DIG server there. DL-Learner communicates with the reasoner using the XML based protocol over HTTP. In the latest versions of DL-Learner, DIG support is considered unsupported. You can use it at your own risk, but we will not maintain this part of the code and may remove it in the future. \item[Fast Instance Checker] Instance checks, i.e.~testing whether an individual is instance of a class, is the major reasoner task in many learning algorithms. This reasoner is a self-development of the DL-Learner project. It remedies some problems related to Machine Learning and the Open World Assumption in OWL and therefore is not correct w.r.t.~OWL semantics. (See \cite{cheng00} Section 4 for an explanation.) Furthermore, it provides an improved performance for instance checks by precomputing some inferences and keeping them in memory. The fast instance checker is build on top of Pellet and the default reasoner component in DL-Learner. \end{description} \subsection{Learning Problems} -In the introductory Sections \ref{sec:whatis} and \ref{sec:start}, we described a specific learning problem where positive and negative examples are given. In practice different variations of similar problems occur. You can switch between the different problems using \verb|problem=$value;|, where \verb|$value| is one of \verb|posNegLPStandard|, \verb|posOnlyLP|, \verb|classLearning|. The default is \verb|posNegLPStandard|. +In the introductory Sections \ref{sec:whatis} and \ref{sec:start}, we described a specific learning problem where positive and negative examples are given. In practice different variations of similar problems occur. +%You can switch between the different problems using \verb|problem=$value;|, where \verb|$value| is one of \verb|posNegLPStandard|, \verb|posOnlyLP|, \verb|classLearning|. The default is \verb|posNegLPStandard|. \begin{description} - \item[Positive and Negative Examples] Let the name of the background ontology be $\mathcal{O}$. The goal in this learning problem is to find an OWL class expression $C$ such that all/many positive examples are instances of $C$ w.r.t.~$\mathcal{O}$ and none/few negative examples are instances of $C$ w.r.t.~$\mathcal{O}$. As explained previously, $C$ should be learned such that it generalises to unseen individuals and is readable. The important configuration options of this component are obviously the positive and negative examples, which are often indicated with \verb|+| and \verb|-| signs in conf files as an optional shortcut to using e.g.~\verb|posNegLPStandard.positiveExamples = {...}|. + \item[Positive and Negative Examples] Let the name of the background ontology be $\mathcal{O}$. The goal in this learning problem is to find an OWL class expression $C$ such that all/many positive examples are instances of $C$ w.r.t.~$\mathcal{O}$ and none/few negative examples are instances of $C$ w.r.t.~$\mathcal{O}$. As explained previously, $C$ should be learned such that it generalises to unseen individuals and is readable. The important configuration options of this component are obviously the positive and negative examples, which you can specify via, e.g.~\verb|posNegLPStandard.positiveExamples = {...}|. \item[Positive Examples] This learning problem is similar to the one before, but without negative examples. In this case, it is desirable to find a class expression which closely fits the positive examples while still generalising sufficiently well. For instance, you usually do not want to have \verb|owl:Thing| as a solution for this problem, but neither do you want to have an enumeration of all examples. \item[Class Learning] In class learning, you are given an existing class $A$ within your ontology $\mathcal{O}$ and want to describe it. It is similar to the previous problem in that you can use the instances of the class as positive examples. However, there are some differences, e.g.~you do not want to have $A$ itself as a proposed solution of the problem, and since this is an ontology engineering task, the focus on short and readable class expressions is stronger than for the two problems mentioned before. The learner can also take advantage of existing knowledge about the class to describe. \end{description} \subsection{Learning Algorithms} -The implemented algorithms vary from very simple (and usually inappropriate) algorithms to sophisticated ones. You can switch between the different algorithms using \verb|algorithm=$value;|, where \verb|$value| is one of \verb|bruteForce|, \verb|random|, \verb|gp|, \verb|refinement|, \verb|refexamples|, \verb|celoe|, \verb|el| and \verb|disjunctiveEL|. The default is \verb|refexamples|. +The implemented algorithms vary from very simple (and usually inappropriate) algorithms to sophisticated ones. +%You can switch between the different algorithms using \verb|algorithm=$value;|, where \verb|$value| is one of \verb|bruteForce|, \verb|random|, \verb|gp|, \verb|refinement|, \verb|refexamples|, \verb|celoe|, \verb|el| and \verb|disjunctiveEL|. The default is \verb|refexamples|. \begin{description} \item[Brute Force]: This algorithm tests all class expressions up to a specified length, which you can set using e.g.~\verb|bruteForce.maxlength = 7|. @@ -173,10 +196,10 @@ \item number of individuals: The individual count is the size of each generation in a GP algorithm. It is one of the most crucial parameters. Setting it to a higher value usually means investing more computational resource for increasing the likelihood that a solution will be found. Usage: \verb|gp.numberOfIndividuals = 100|. \item refinement probability: This is used to specify how likely the usage of the genetic refinement operator should be, e.g.~\verb|gp.refinementProbability = 0.6| means that it will be selected 60\% of the time. \end{itemize} - The GP algorithm has 15 more options documented in \verb|doc/configOptions.txt|. + The GP algorithm has 15 more options documented in \verb|doc/configOptions.html|. \item[Refinement] This is a top down refinement operator approach, which is described in \cite{alc_learning_algorithm} and based on insights in \cite{property_analysis}. Some options include: \begin{itemize} - \item target language: The standard target language of this algorithm is $\mathcal{ALCN(D)}$. However, you can change the language, i.e.~you can exclude the $\forall$ constructor by using \verb|refinement.useAllConstructor = false;|. Similar options exist for $\exists$, $\neg$, cardinality restrictions, and boolean datatypes. + \item target language: The standard target language of this algorithm is $\mathcal{ALCN(D)}$. However, you can change the language, i.e.~you can exclude the $\forall$ constructor by using \verb|refinement.useAllConstructor = false|. Similar options exist for $\exists$, $\neg$, cardinality restrictions, and boolean datatypes. \item maximum execution time: If there is no perfect solution of a given problem, the algorithm can potentially run forever (in practice it will run out of memory). It is therefore often interesting to limit the execution time. You can use e.g.~\verb|refinement.maxExecutionTimeInSeconds = 100| to say that the algorithm should run for at most 100 seconds. Often, it will run slightly longer than the maximum execution time since it waits for the next internal loop of the algorithm to stop gracefully. \end{itemize} The algorithm supports a range of further options. For instance, one can specify which classes and properties must not occur in resulting class expressions. @@ -201,23 +224,27 @@ \section{DL-Learner Interfaces} -\subsection{Command Line Interface} +% \subsection{Command Line Interface} -\todo{Description of Conf File Syntax; special cases: empty set of beans is denoted by ``-''; the name of a bean must not be ``true'' or ``false'' or start with a number; config options must not have the name ``type''; these conentions are introduced in order to be a able to provide a very compact syntax} +%\todo{Description of Conf File Syntax; special cases: empty set of beans is denoted by ``-''; the name of a bean must not be ``true'' or ``false'' or start with a number; config options must not have the name ``type''; these conentions are introduced in order to be a able to provide a very compact syntax} -One interface you have already used in Section \ref{sec:start} is the command line. There are two executables, which can be used for starting DL-Learner on the commandline: \verb|dl-learner| and \verb|quickstart|. The first one takes a conf file as argument, whereas the latter one lists all conf files in the examples folder and allows you to select one of those. +One interface you have already used in Section \ref{sec:start} is the command line. There are two executables, which can be used for starting DL-Learner on the commandline: \verb|dl-learner| and \verb|quickstart|. The first one takes a conf file as argument, whereas the latter one lists all conf files in the examples folder and allows you to select one of those. There are a lot of conf files available in the \verb|/examples| directory, which you can use a base for your own experiments. -\begin{figure} - \centering - \includegraphics[width=.8\textwidth]{screenshots/gui_algorithm} - \caption{GUI screenshot showing the learning algorithm tab. The UI allows you to set different options and then proceed to the next tab and execute the algorithm.} - \label{fig:gui} -\end{figure} +%\begin{figure} +% \centering +% \includegraphics[width=.8\textwidth]{screenshots/gui_algorithm} +% \caption{GUI screenshot showing the learning algorithm tab. The UI allows you to set different options and then proceed to the next tab and execute the algorithm.} +% \label{fig:gui} +%\end{figure} -Apart from the command line, there is also a prototypical graphical interface. You can use \verb|gui| (or \verb|gui.bat|) to start it. Optionally, a conf file can be passed as argument. The main GUI window has four tabs corresponding to the four different types of components and a run tab to execute the learning algorithm. Using the GUI, you can assemble the desired combination of components and options. The \verb|File| menu allows you to load a conf file or save the current configuration to a conf file. The GUI implementation is currently prototypical, so please report any bugs or feature requests you have (see Section \ref{sec:contact}). Since the GUI uses the component manager, it will automatically evolve when new components and options are added. +DL-Learner had a graphical user interface and a web service. In 2011, DL-Learner was generalised to be able to solve general learning problems and arbitrarily combine components, which was necessary for learning SPARQL queries and fuzzy OWL class expressions. The commandline interface has been adapted for this purpose, but the graphical user interface and web service are currently under construction and will be re-introduced at a later stage. -A third interface through which DL-Learner can be accessed programmatically is a web service. You can execute \verb|ws| (or \verb|ws.bat|) to start the web service. It is based on the Java API for XML Web Services (JAX-WS), which is included in Java 6 or higher. Executing the command will start a web server on port 8181 of your local machine. The WSDL can be accessed via \url{http://localhost:8181/services?wsdl}. You can use a WSDL viewer to see the supported operations or view the JavaDoc of the corresponding Java file\footnote{viewable online at \wsjavadoc}. Some examples for calling the web service from PHP can be found in the DL-Learner subversion repository\footnote{in the directory src/php-examples/:\\ \wsphpexamples}. +% Web Service and GUI "under construction" at the moment +%Apart from the command line, there is also a prototypical graphical interface. You can use \verb|gui| (or \verb|gui.bat|) to start it. Optionally, a conf file can be passed as argument. The main GUI window has four tabs corresponding to the four different types of components and a run tab to execute the learning algorithm. Using the GUI, you can assemble the desired combination of components and options. The \verb|File| menu allows you to load a conf file or save the current configuration to a conf file. The GUI implementation is currently prototypical, so please report any bugs or feature requests you have (see Section \ref{sec:contact}). Since the GUI uses the component manager, it will automatically evolve when new components and options are added. + +%A third interface through which DL-Learner can be accessed programmatically is a web service. You can execute \verb|ws| (or \verb|ws.bat|) to start the web service. It is based on the Java API for XML Web Services (JAX-WS), which is included in Java 6 or higher. Executing the command will start a web server on port 8181 of your local machine. The WSDL can be accessed via \url{http://localhost:8181/services?wsdl}. You can use a WSDL viewer to see the supported operations or view the JavaDoc of the corresponding Java file\footnote{viewable online at \wsjavadoc}. Some examples for calling the web service from PHP can be found in the DL-Learner subversion repository\footnote{in the directory src/php-examples/:\\ \wsphpexamples}. + Another means to access DL-Learner, in particular for ontology engineering, is to use the OntoWiki and Protégé plugins. The OntoWiki plugin is not officially released yet, but can be used in the SVN version of OntoWiki. The Protégé 4 plugin can be installed either by downloading it from the DL-Learner download page or directly within Protégé 4 by clicking on ``File'', ``Preferences'', ``Plugins'', ``Check for Downloads'' now and selecting the DL-Learner plugin. For more information and a screencast see the Protégé plugin wiki page \footnote{\wikiprotplugin}. \section{Extending DL-Learner} @@ -225,7 +252,7 @@ DL-Learner is open source and component based. If you want to develop a specific part or extension of a class expression learning algorithm for OWL, then you are invited to use DL-Learner as a base. This allows you to focus on the part you want to implement while being able to use DL-Learner as a library and access it through one of the interfaces. -If you want to create a new component, then you first have to decide on the type of your component. To implement a concrete component, you have to subclass one of the following classes and implement their abstract methods: +If you want to create a new component, then you first have to decide on the type of your component. To implement a concrete component, you can implement one of the following interfaces (list is incomplete): \begin{itemize} \item org.dllearner.core.KnowledgeSource @@ -234,9 +261,94 @@ \item org.dllearner.core.LearningAlgorithm \end{itemize} -You then have to add your component to \verb|lib/components.ini| such that it is registered in the component manager when DL-Learner starts up. If you want to use configuration options in your component, you need to create a static method as follows: +%You then have to add your component to \verb|lib/components.ini| such that it is registered in the component manager when DL-Learner starts up. If you want to use configuration options in your component, you need to create a static method as follows: +That is sufficient for using your component programmatically in combination with existing DL-Learner components. +If your class name is \verb|org.example.TestAlgorithm|, then you can instantiate your class in a conf file via: +\begin{verbatim} +c.type = "org.example.TestAlgorithm" +\end{verbatim} +As you have probably seen by now in various conf files, DL-Learner allows to configure components. This is done via standard Java Beans. If you want to create a conf option \verb|testOption|, you just need to create a variable with getters and setters in your code: + \begin{verbatim} +public class TestAlgorithm implements LearningAlgorithm { + + private double testOption = 0.0; + + [...] + + public double getTestOption() { + return testOption; + } + + public void setTestOption(double testOption) { + this.startNodeBonus = startNodeBonus; + } + +} +\end{verbatim} + +That would be sufficient to include your components in conf files: +\begin{verbatim} +c.type = "org.example.TestAlgorithm" +c.testOption = 0.3 +\end{verbatim} + +In your code, you should have an empty default constructor and an \verb|init()| method (as required by the Component interface). The default constructor will be called first, followed by setter methods and then the \verb|init()| method. This is a standard Java Beans approach. In summary, you need to the following: +\begin{itemize} + \item implement an appropriate DL-Learner interface for what you want to do + \item add variables for all config options as well as getters and setters for them + \item if you implement a constructor, please also add a default constructor with an empty set of arguments +\end{itemize} + +By only requiring those few steps, we want to make adding further components to DL-Learner as lightweight as possible. + +If you are familiar with the Spring framework\footnote{\url{http://www.springsource.org}}, then it is helpful to know that conf files are just an abbreviated syntax for Spring XML configurations. You can use all powerful features of Spring in your code, which we do not describe in full detail here. In fact, you can convert the conf files to Spring configuration files by adding those lines: + +\begin{verbatim} +cli.type = "org.dllearner.cli.CLI" +cli.writeSpringConfiguration = true +\end{verbatim} + +If you added this in \verb|test.conf|, then this generates a \verb|file.xml|, which is the Spring equivalent of conf file. + +If you are a DL-Learner developer and want to properly document your component\footnote{}, you should do some further steps: +\begin{itemize} + \item add your class to \verb|AnnComponentManager.componentClassNames| + \item add an annotation for your class + \item add annotations for all configuration options +\end{itemize} + +An example of an annotated class could look as follows: + +\begin{verbatim} +@ComponentAnn(name="Test Algorithm", shortName="ta", version=0.1, + description="My first experiment.") +public class TestAlgorithm implements LearningAlgorithm { ... + + @ConfigOption(name="testOption", defaultValue="0.0", + description="The option allows to control xyz.") + private double testOption = 0.0; + + [...] + + public double getTestOption() { + return testOption; + } + + public void setTestOption(double testOption) { + this.startNodeBonus = startNodeBonus; + } + +} +\end{verbatim} + +The \verb|@ComponentAnn| annotation allow to mark classes as DL-Learner components. Similarly, the \verb|@ConfigOption| annotations marks variables as configuration options. That should be those variables, which you want the user to be able to configure and play with. A benefit of adding the extra metadata provided by the annotations is that the component will appear in documentation pages such as \url{http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/interfaces/doc/configOptions.html}. In general, they provide users of your component with useful information. + +\begin{comment} +You can then add your class to + +\begin{verbatim} public static Collection<ConfigOption<?>> createConfigOptions() { List<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new IntegerConfigOption("maxDepth", @@ -260,6 +372,7 @@ \end{itemize} Restricting to these option types this gives us the possibility to build very flexible user interfaces. Whenever, a new component or a new configuration option for a component is added, the current user interfaces (GUI, web service, commandline) will automatically support it without any or only minimal code changes. +\end{comment} This quick introduction only serves as an entry point to get you started. For more detailed questions about how to extend DL-Learner, please drop us a message in the DL-Learner mailing list. @@ -276,6 +389,7 @@ \item Latest Release: \url{http://sourceforge.net/project/showfiles.php?group_id=203619} \end{itemize} +\nocite{*} \bibliographystyle{apalike} \bibliography{bibliography} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-30 16:09:30
|
Revision: 3452 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3452&view=rev Author: jenslehmann Date: 2011-11-30 16:09:23 +0000 (Wed, 30 Nov 2011) Log Message: ----------- fixed another bug Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-11-30 14:14:54 UTC (rev 3451) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-11-30 16:09:23 UTC (rev 3452) @@ -354,38 +354,17 @@ // create a refinement operator and pass all configuration // variables to it -// RhoDRDown if(operator == null) { // we use a default operator and inject the class hierarchy for now operator = new RhoDRDown(); ((RhoDRDown)operator).setReasoner(reasoner); - -// operator = new RhoDRDown( -// reasoner, -// classHierarchy, -//// configurator, -// applyAllFilter, -// applyExistsFilter, -//// useAllConstructor, -// true, -//// useExistsConstructor, -// true, -// useHasValueConstructor, -// valueFrequencyThreshold, -// useCardinalityRestrictions, -// useNegation, -// useBooleanDatatypes, -// useDoubleDatatypes, -// startClass, -// cardinalityLimit, -// useStringDatatypes, -// instanceBasedDisjoints -// ); + ((RhoDRDown)operator).init(); } + // TODO: find a better solution as this is quite difficult to debug ((RhoDRDown)operator).setSubHierarchy(classHierarchy); ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); - ((RhoDRDown)operator).init(); + // create an algorithm object and pass all configuration // options to it Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-11-30 14:14:54 UTC (rev 3451) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-11-30 16:09:23 UTC (rev 3452) @@ -344,5 +344,9 @@ */ public static double getVersion(Component component){ return getVersion(component.getClass()); + } + + public static boolean addComponentClassName(String e) { + return componentClassNames.add(e); } } Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-30 14:14:54 UTC (rev 3451) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-30 16:09:23 UTC (rev 3452) @@ -37,6 +37,7 @@ import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.Component; import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.options.CommonConfigOptions; @@ -224,47 +225,52 @@ // private Map<NamedClass,Map<NamedClass,Boolean>> notABDisjoint = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); // private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); + private boolean isInitialised = false; + public RhoDRDown() { } - public RhoDRDown(AbstractReasonerComponent reasoningService) { -// this(reasoningService, reasoningService.getClassHierarchy(), null, true, true, true, true, true, 3, true, true, true, true, null); - this.reasoner = reasoningService; - this.subHierarchy = reasoner.getClassHierarchy(); - init(); - } +// public RhoDRDown(AbstractReasonerComponent reasoningService) { +//// this(reasoningService, reasoningService.getClassHierarchy(), null, true, true, true, true, true, 3, true, true, true, true, null); +// this.reasoner = reasoningService; +// this.subHierarchy = reasoner.getClassHierarchy(); +// init(); +// } // TODO constructor which takes a RhoDRDownConfigurator object; // this should be an interface implemented e.g. by ExampleBasedROLComponentConfigurator; // the goal is to use the configurator system while still being flexible enough to // use one refinement operator in several learning algorithms - public RhoDRDown(AbstractReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, - boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass, - int cardinalityLimit, boolean useStringDatatypes, boolean instanceBasedDisjoints) { - this.reasoner = reasoningService; - this.subHierarchy = subHierarchy; - this.applyAllFilter = applyAllFilter; - this.applyExistsFilter = applyExistsFilter; - this.useAllConstructor = useAllConstructor; - this.useExistsConstructor = useExistsConstructor; - this.useHasValueConstructor = useHasValueConstructor; - this.frequencyThreshold = valueFrequencyThreshold; - this.useCardinalityRestrictions = useCardinalityRestrictions; - this.cardinalityLimit = cardinalityLimit; - this.useNegation = useNegation; - this.useBooleanDatatypes = useBooleanDatatypes; - this.useDoubleDatatypes = useDoubleDatatypes; - this.useStringDatatypes = useStringDatatypes; - this.instanceBasedDisjoints = instanceBasedDisjoints; - if(startClass != null) { - this.startClass = startClass; - } - init(); - } +// public RhoDRDown(AbstractReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, +// boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass, +// int cardinalityLimit, boolean useStringDatatypes, boolean instanceBasedDisjoints) { +// this.reasoner = reasoningService; +// this.subHierarchy = subHierarchy; +// this.applyAllFilter = applyAllFilter; +// this.applyExistsFilter = applyExistsFilter; +// this.useAllConstructor = useAllConstructor; +// this.useExistsConstructor = useExistsConstructor; +// this.useHasValueConstructor = useHasValueConstructor; +// this.frequencyThreshold = valueFrequencyThreshold; +// this.useCardinalityRestrictions = useCardinalityRestrictions; +// this.cardinalityLimit = cardinalityLimit; +// this.useNegation = useNegation; +// this.useBooleanDatatypes = useBooleanDatatypes; +// this.useDoubleDatatypes = useDoubleDatatypes; +// this.useStringDatatypes = useStringDatatypes; +// this.instanceBasedDisjoints = instanceBasedDisjoints; +// if(startClass != null) { +// this.startClass = startClass; +// } +// init(); +// } // subHierarchy = rs.getClassHierarchy(); - public void init() { + public void init() throws ComponentInitException { + if(isInitialised) { + throw new ComponentInitException("Refinement operator cannot be nitialised twice."); + } // System.out.println("subHierarchy: " + subHierarchy); // System.out.println("object properties: " + ); @@ -347,6 +353,8 @@ valueFrequency = null; dataValueFrequency = null; + System.out.println("freqDataValues: " + frequentDataValues); + // compute splits for double datatype properties for(DatatypeProperty dp : reasoner.getDoubleDatatypeProperties()) { computeSplits(dp); @@ -368,6 +376,9 @@ } maxNrOfFillers.put(op, maxFillers); } + + isInitialised = true; + } /* Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java 2011-11-30 14:14:54 UTC (rev 3451) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java 2011-11-30 16:09:23 UTC (rev 3452) @@ -88,7 +88,8 @@ // rs.prepareSubsumptionHierarchy(); // rs.prepareRoleHierarchy(); - RhoDRDown op = new RhoDRDown(rc); + RhoDRDown op = new RhoDRDown(); + op.setReasoner(rc); Description concept = KBParser.parseConcept(uri("Compound")); Set<Description> results = op.refine(concept, 4, null); @@ -113,7 +114,8 @@ AbstractReasonerComponent reasoner = TestOntologies.getTestOntology(TestOntology.EPC_OE); baseURI = reasoner.getBaseURI(); - RhoDRDown op = new RhoDRDown(reasoner); + RhoDRDown op = new RhoDRDown(); + op.setReasoner(reasoner); Description concept = KBParser.parseConcept("(\"http://localhost/aris/sap_model.owl#EPC\" AND EXISTS \"http://localhost/aris/sap_model.owl#hasModelElements\".\"http://localhost/aris/sap_model.owl#Object\")"); Set<Description> results = op.refine(concept,10); @@ -148,9 +150,8 @@ classHierarchy.thinOutSubsumptionHierarchy(); System.out.println(" UNIT TEST INCOMPLETE AFTER FRAMEWORK CHANGE, BECAUSE CLASS HIERARCHY IS NOT PASSED TO REFINEMENT OPERATOR "); - RhoDRDown op = new RhoDRDown( - reasoner // TODO: pass class hierarchy here - ); + RhoDRDown op = new RhoDRDown(); + op.setReasoner(reasoner); Description concept = KBParser.parseConcept("EXISTS \"http://www.test.de/test#hasPiece\".EXISTS \"http://www.test.de/test#hasLowerRankThan\".(\"http://www.test.de/test#WRook\" AND TOP)"); Set<Description> results = op.refine(concept,8); @@ -192,7 +193,8 @@ @Test public void rhoDRDownTest4() throws ParseException, LearningProblemUnsupportedException { AbstractReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.RHO1); - RefinementOperator operator = new RhoDRDown(rs); + RefinementOperator operator = new RhoDRDown(); + ((RhoDRDown)operator).setReasoner(rs); Description concept = KBParser.parseConcept("(car AND EXISTS hasOwner.person)"); // Description concept = Thing.instance; Set<Description> refinements = operator.refine(concept, 6); @@ -204,7 +206,8 @@ @Test public void rhoDRDownTest5() throws ParseException, LearningProblemUnsupportedException { AbstractReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SWORE); - RefinementOperator operator = new RhoDRDown(rs); + RefinementOperator operator = new RhoDRDown(); + ((RhoDRDown)operator).setReasoner(rs); // Description concept = KBParser.parseConcept("((NOT \"http://ns.softwiki.de/req/Requirement\") OR (ALL \"http://ns.softwiki.de/req/isCreatedBy\".(NOT \"http://ns.softwiki.de/req/Creditor\")))"); Description concept = KBParser.parseConcept("(NOT \"http://ns.softwiki.de/req/Requirement\" OR ALL \"http://ns.softwiki.de/req/isCreatedBy\".NOT \"http://ns.softwiki.de/req/Creditor\")"); System.out.println(concept); @@ -217,7 +220,8 @@ @Test public void invertedOperatorTest() throws ParseException { AbstractReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.RHO1); - RhoDRDown rho = new RhoDRDown(rs); + RhoDRDown rho = new RhoDRDown(); + rho.setReasoner(rs); rho.setDropDisjuncts(true); RefinementOperator operator = new OperatorInverter(rho); Description concept = KBParser.parseConcept("(limo AND EXISTS hasOwner.man)"); @@ -234,7 +238,8 @@ public void rhoDownTestPellet() { Logger.getRootLogger().setLevel(Level.TRACE); AbstractReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.FATHER); - RhoDRDown rho = new RhoDRDown(rs); + RhoDRDown rho = new RhoDRDown(); + rho.setReasoner(rs); NamedClass nc = new NamedClass("http://example.com/father#male"); Set<Description> refinements = rho.refine(nc, 5); for(Description refinement : refinements) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-30 14:15:00
|
Revision: 3451 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3451&view=rev Author: lorenz_b Date: 2011-11-30 14:14:54 +0000 (Wed, 30 Nov 2011) Log Message: ----------- Fixed Unit test. Modified Paths: -------------- trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java Modified: trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2011-11-30 11:50:32 UTC (rev 3450) +++ trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2011-11-30 14:14:54 UTC (rev 3451) @@ -37,10 +37,14 @@ import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.dllearner.algorithms.gp.GP; +import org.dllearner.cli.CLI; import org.dllearner.cli.QuickStart; import org.dllearner.cli.Start; +import org.dllearner.core.AbstractCELA; +import org.dllearner.core.ClassExpressionLearningAlgorithm; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.Helper; import org.junit.Test; @@ -87,7 +91,7 @@ // map containing a list of conf files for each path HashMap<String, ArrayList<String>> confFiles = new HashMap<String, ArrayList<String>>(); - String exampleDir = "." + File.separator + "examples"; + String exampleDir = ".." + File.separator + "examples"; File f = new File(exampleDir); QuickStart.getAllConfs(f, exampleDir, confFiles); @@ -155,16 +159,22 @@ boolean success = false, started = false; try { // start example - Start start = new Start(new File(conf)); + CLI start = new CLI(new File(conf)); + start.init(); + start.run(); // System.out.println("algorithm: " + start.getLearningAlgorithm()); - boolean isSparql = start.getSources().iterator().next() instanceof SparqlKnowledgeSource; - if((testGP || !(start.getLearningAlgorithm() instanceof GP)) && + boolean isSparql = start.getKnowledgeSource() instanceof SparqlKnowledgeSource; +// boolean isSparql = false; + LearningAlgorithm algorithm = start.getLearningAlgorithm(); + if((testGP || !(algorithm instanceof GP)) && (sparql == 0 || (sparql == 1 && isSparql) || (sparql == 2 && !isSparql) ) ) { started = true; - start.start(false); +// start.start(false); // test is successful if a concept was learned - assert (start.getLearningAlgorithm().getCurrentlyBestDescription() != null); - start.getReasonerComponent().releaseKB(); + if(algorithm instanceof AbstractCELA){ + assert (((AbstractCELA) algorithm).getCurrentlyBestDescription() != null); + } +// start.getReasonerComponent().releaseKB(); success = true; } else { System.out.println("Test skipped, because of GP or SPARQL settings."); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-30 11:50:40
|
Revision: 3450 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3450&view=rev Author: jenslehmann Date: 2011-11-30 11:50:32 +0000 (Wed, 30 Nov 2011) Log Message: ----------- annotated config options in CELOE Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/interfaces/doc/configOptions.html Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-29 18:15:18 UTC (rev 3449) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-30 11:50:32 UTC (rev 3450) @@ -30,8 +30,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import javax.sound.midi.SysexMessage; - import org.apache.log4j.Logger; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; @@ -39,18 +37,12 @@ import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.options.BooleanConfigOption; -import org.dllearner.core.options.CommonConfigOptions; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.DoubleConfigOption; -import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Restriction; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.ClassLearningProblem; @@ -94,6 +86,7 @@ private RefinementOperator operator; private DescriptionMinimizer minimizer; + @ConfigOption(name="useMinimizer", defaultValue="true", description="Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.") private boolean useMinimizer = true; // all nodes in the search tree (used for selecting most promising node) @@ -102,6 +95,7 @@ // root of search tree private OENode startNode; // the class with which we start the refinement process + @ConfigOption(name = "startClass", defaultValue="owl:Thing", description="You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.") private Description startClass; // all descriptions in the search tree plus those which were too weak (for fast redundancy check) @@ -111,6 +105,7 @@ // if true, then each solution is evaluated exactly instead of approximately // private boolean exactBestDescriptionEvaluation = false; + @ConfigOption(name = "singleSuggestionMode", defaultValue="false", description="Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.") private boolean singleSuggestionMode; private Description bestDescription; private double bestAccuracy = Double.MIN_VALUE; @@ -156,27 +151,37 @@ Set<NamedClass> allowedConcepts = null; Set<NamedClass> ignoredConcepts = null; + @ConfigOption(name = "writeSearchTree", defaultValue="false", description="specifies whether to write a search tree") private boolean writeSearchTree = false; + @ConfigOption(name = "searchTreeFile", defaultValue="log/searchTree.txt", description="file to use for the search tree") private String searchTreeFile = "log/searchTree.txt"; + @ConfigOption(name = "replaceSearchTree", defaultValue="false", description="specifies whether to replace the search tree in the log file after each run or append the new search tree") + private boolean replaceSearchTree = false; + + @ConfigOption(name = "maxNrOfResults", defaultValue="10", description="Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).") private int maxNrOfResults = 10; + @ConfigOption(name = "noisePercentage", defaultValue="0.0", description="the (approximated) percentage of noise within the examples") private double noisePercentage = 0.0; + @ConfigOption(name = "filterDescriptionsFollowingFromKB", defaultValue="false", description="If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.") private boolean filterDescriptionsFollowingFromKB = false; + @ConfigOption(name = "reuseExistingDescription", defaultValue="false", description="If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.") private boolean reuseExistingDescription = false; - private boolean replaceSearchTree = false; - + @ConfigOption(name = "maxClassDescriptionTests", defaultValue="0", description="The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)") private int maxClassDescriptionTests = 0; - @org.dllearner.core.config.ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") + @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name = "terminateOnNoiseReached", defaultValue="false", description="specifies whether to terminate when noise criterion is met") private boolean terminateOnNoiseReached = false; + @ConfigOption(name = "maxDepth", defaultValue="7", description="maximum depth of description") private double maxDepth = 7; // public CELOEConfigurator getConfigurator() { @@ -192,44 +197,12 @@ // configurator = new CELOEConfigurator(this); } - public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { - Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); - problems.add(AbstractLearningProblem.class); - return problems; - } +// public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { +// Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); +// problems.add(AbstractLearningProblem.class); +// return problems; +// } - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(CommonConfigOptions.useAllConstructor()); - options.add(CommonConfigOptions.useExistsConstructor()); - options.add(CommonConfigOptions.useHasValueConstructor()); - options.add(CommonConfigOptions.useDataHasValueConstructor()); - options.add(CommonConfigOptions.valueFreqencyThreshold()); - options.add(CommonConfigOptions.useCardinalityRestrictions()); - options.add(CommonConfigOptions.cardinalityLimit()); - // by default, we do not use negation (should be configurable in GUI) - options.add(CommonConfigOptions.useNegation(false)); - options.add(CommonConfigOptions.useBooleanDatatypes()); - options.add(CommonConfigOptions.useDoubleDatatypes()); - options.add(CommonConfigOptions.maxExecutionTimeInSeconds(10)); - options.add(CommonConfigOptions.getNoisePercentage()); - options.add(CommonConfigOptions.getTerminateOnNoiseReached(false)); - options.add(CommonConfigOptions.getMaxDepth(7)); - options.add(CommonConfigOptions.maxNrOfResults(10)); - options.add(CommonConfigOptions.maxClassDescriptionTests()); - options.add(new BooleanConfigOption("singleSuggestionMode", "Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.", false)); - options.add(CommonConfigOptions.getInstanceBasedDisjoints()); - options.add(new BooleanConfigOption("filterDescriptionsFollowingFromKB", "If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.", false)); - options.add(new BooleanConfigOption("reuseExistingDescription", "If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.", false)); - options.add(new BooleanConfigOption("writeSearchTree", "specifies whether to write a search tree", false)); - options.add(new StringConfigOption("searchTreeFile","file to use for the search tree", "log/searchTree.txt")); - options.add(new BooleanConfigOption("replaceSearchTree","specifies whether to replace the search tree in the log file after each run or append the new search tree", false)); - options.add(new DoubleConfigOption("expansionPenaltyFactor","heuristic penalty per syntactic construct used (lower = finds more complex expression, but might miss simple ones)", 0.1)); - options.add(CommonConfigOptions.allowedConcepts()); - options.add(CommonConfigOptions.ignoredConcepts()); - return options; - } - public static String getName() { return "CELOE"; } Modified: trunk/interfaces/doc/configOptions.html =================================================================== --- trunk/interfaces/doc/configOptions.html 2011-11-29 18:15:18 UTC (rev 3449) +++ trunk/interfaces/doc/configOptions.html 2011-11-30 11:50:32 UTC (rev 3450) @@ -21,7 +21,10 @@ <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.BruteForceLearner">Brute Force Learner</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.celoe.CELOE">CELOE</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.ClassLearningProblem">ClassLearningProblem</a></li></div> -<div class="KnowledgeSource"><li><a href="#org.dllearner.kb.KBFile">KB file</a></li></div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.fuzzydll.FuzzyCELOE">Fuzzy CELOE</a></li></div> +<div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.fuzzydll.FuzzyOWLAPIReasoner">Fuzzy OWL API Reasoner</a></li></div> +<div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.FuzzyPosNegLPStandard">FuzzyPosNegLPStandard</a></li></div> +<div class="KnowledgeSource"><li><a href="#org.dllearner.kb.KBFile">KB File</a></li></div> <div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.OWLAPIReasoner">OWL API Reasoner</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.ocel.OCEL">OWL Class Expression Learner</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.OWLFile">OWL File</a></li></div> @@ -46,6 +49,7 @@ <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner">objectproperty domain axiom learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner">objectproperty range learner</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.PosOnlyLP">positive only learning problem</a></li></div> +<div class="LearningAlgorithm"><li><a href="#org.dllearner.algorithm.qtl.QTL">query tree learner</a></li></div> <div class="RefinementOperator"><li><a href="#org.dllearner.refinementoperators.RhoDRDown">rho refinement operator</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.SimpleSubclassLearner">simple subclass learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner">symmetric objectproperty axiom learner</a></li></div> @@ -54,12 +58,35 @@ <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.BruteForceLearner"><h2>Brute Force Learner</h2></a> <p>short name: bruteForce<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.CELOE"><h2>CELOE</h2></a> -<p>short name: celoe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.<br /></p>This component does not have configuration options.</div> +<p>short name: celoe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>maxClassDescriptionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> +<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> +<tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> +<tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.ClassLearningProblem"><h2>ClassLearningProblem</h2></a> <p>short name: clp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> -<div class="KnowledgeSource"><a name="org.dllearner.kb.KBFile"><h2>KB file</h2></a> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.fuzzydll.FuzzyCELOE"><h2>Fuzzy CELOE</h2></a> +<p>short name: fceloe<br />version: 0.2<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: See Fuzzy DL-Learner paper published at ISDA 2011.<br /></p>This component does not have configuration options.</div> +<div class="ReasonerComponent"><a name="org.dllearner.reasoning.fuzzydll.FuzzyOWLAPIReasoner"><h2>Fuzzy OWL API Reasoner</h2></a> +<p>short name: foar<br />version: 0.2<br />implements: ReasonerComponent<br /></p>This component does not have configuration options.</div> +<div class="LearningProblem"><a name="org.dllearner.learningproblems.FuzzyPosNegLPStandard"><h2>FuzzyPosNegLPStandard</h2></a> +<p>short name: fuzzyPosNeg<br />version: 0.2<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> +<div class="KnowledgeSource"><a name="org.dllearner.kb.KBFile"><h2>KB File</h2></a> <p>short name: kbfile<br />version: 0.8<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>url</td><td>URL pointer to the KB file</td><td> String</td><td></td><td> false</td></tr> +<tr><td>fileName</td><td>relative or absolute path to KB file</td><td> String</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.OWLAPIReasoner"><h2>OWL API Reasoner</h2></a> @@ -75,17 +102,17 @@ <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStandard"><h2>PosNegLPStandard</h2></a> <p>short name: posNegStandard<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy.</td><td> String</td><td>predacc</td><td> false</td></tr> +<tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> -<tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.RandomGuesser"><h2>Random Guesser</h2></a> <p>short name: randomGuesser<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.SparqlEndpointKS"><h2>SPARQL endpoint</h2></a> <p>short name: sparql<br />version: 0.2<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>defaultGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>namedGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>url</td><td>no description available</td><td> URL</td><td></td><td> true</td></tr> -<tr><td>defaultGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> </tbody></table> </div> <div class="KnowledgeSource"><a name="org.dllearner.kb.sparql.SparqlKnowledgeSource"><h2>SPARQL endpoint fragment</h2></a> @@ -93,49 +120,41 @@ <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner"><h2>data subPropertyOf axiom learner</h2></a> <p>short name: dplsubprop<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner"><h2>dataproperty domain axiom learner</h2></a> <p>short name: dpldomain<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner"><h2>dataproperty range learner</h2></a> <p>short name: dblrange<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.DisjointClassesLearner"><h2>disjoint classes learner</h2></a> <p>short name: cldisjoint<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> <tr><td>classToDescribe</td><td></td><td> NamedClass</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner"><h2>disjoint dataproperty axiom learner</h2></a> <p>short name: dpldisjoint<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.DisjointObjectPropertyAxiomLearner"><h2>disjoint objectproperty axiom learner</h2></a> <p>short name: opldisjoint<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner"><h2>equivalent dataproperty axiom learner</h2></a> <p>short name: dplequiv<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.EquivalentObjectPropertyAxiomLearner"><h2>equivalent objectproperty axiom learner</h2></a> <p>short name: oplequiv<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.FastInstanceChecker"><h2>fast instance checker</h2></a> @@ -147,84 +166,77 @@ <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.FunctionalDataPropertyAxiomLearner"><h2>functional dataproperty axiom learner</h2></a> <p>short name: dplfunc<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.FunctionalObjectPropertyAxiomLearner"><h2>functional objectproperty axiom learner</h2></a> <p>short name: oplfunc<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.InverseFunctionalObjectPropertyAxiomLearner"><h2>inversefunctional objectproperty axiom learner</h2></a> <p>short name: oplinvfunc<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="OtherComponent"><a name="org.dllearner.algorithms.ocel.MultiHeuristic"><h2>multiple criteria heuristic</h2></a> <p>short name: multiheuristic<br />version: 0.7<br />implements: OtherComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>negationPenalty</td><td>no description available</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> <tr><td>negativeWeight</td><td>no description available</td><td> double</td><td>1.0</td><td> false</td></tr> <tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> +<tr><td>nodeChildPenalty</td><td>no description available</td><td> double</td><td>0.0001</td><td> false</td></tr> <tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> -<tr><td>negationPenalty</td><td>no description available</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>nodeChildPenalty</td><td>no description available</td><td> double</td><td>0.0001</td><td> false</td></tr> -<tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner"><h2>object subPropertyOf axiom learner</h2></a> <p>short name: oplsubprop<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner"><h2>objectproperty domain axiom learner</h2></a> <p>short name: opldomain<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner"><h2>objectproperty range learner</h2></a> <p>short name: oplrange<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosOnlyLP"><h2>positive only learning problem</h2></a> <p>short name: posonlylp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> +<div class="LearningAlgorithm"><a name="org.dllearner.algorithm.qtl.QTL"><h2>query tree learner</h2></a> +<p>short name: qtl<br />version: 0.8<br />implements: LearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="RefinementOperator"><a name="org.dllearner.refinementoperators.RhoDRDown"><h2>rho refinement operator</h2></a> <p>short name: rho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> -<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.SimpleSubclassLearner"><h2>simple subclass learner</h2></a> <p>short name: clsub<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>classToDescribe</td><td></td><td> NamedClass</td><td></td><td> true</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner"><h2>symmetric objectproperty axiom learner</h2></a> <p>short name: oplsymm<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner"><h2>transitive objectproperty axiom learner</h2></a> <p>short name: opltrans<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> -<tr><td>maxFetchedRows</td><td>The maximum number of rows fetched from the endpoint to approximate the result.</td><td> int</td><td></td><td> false</td></tr> </tbody></table> </div> </body></html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-29 18:15:25
|
Revision: 3449 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3449&view=rev Author: jenslehmann Date: 2011-11-29 18:15:18 +0000 (Tue, 29 Nov 2011) Log Message: ----------- - fixed bug which occurred when using OCEL with manual heuristics in conf file - improved efficiency of rho refinement operator Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/examples/family/grandfather.conf Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -276,12 +276,12 @@ if(operator == null) { operator = new RhoDRDown(); ((RhoDRDown)operator).setStartClass(startClass); - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); ((RhoDRDown)operator).setReasoner(reasoner); - ((RhoDRDown)operator).init(); - } else { - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); } + ((RhoDRDown)operator).setSubHierarchy(classHierarchy); + ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + ((RhoDRDown)operator).init(); // operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); baseURI = reasoner.getBaseURI(); prefixes = reasoner.getPrefixes(); @@ -1002,6 +1002,14 @@ public void setUseMinimizer(boolean useMinimizer) { this.useMinimizer = useMinimizer; + } + + public OEHeuristicRuntime getHeuristic() { + return heuristic; + } + + public void setHeuristic(OEHeuristicRuntime heuristic) { + this.heuristic = heuristic; } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -215,4 +215,20 @@ public void setExpansionPenaltyFactor(double expansionPenaltyFactor) { this.expansionPenaltyFactor = expansionPenaltyFactor; } + + public int getNrOfNegativeExamples() { + return nrOfNegativeExamples; + } + + public void setNrOfNegativeExamples(int nrOfNegativeExamples) { + this.nrOfNegativeExamples = nrOfNegativeExamples; + } + + public int getNrOfExamples() { + return nrOfExamples; + } + + public void setNrOfExamples(int nrOfExamples) { + this.nrOfExamples = nrOfExamples; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -104,7 +104,7 @@ private File searchTreeFile; private boolean replaceSearchTree = false; private static String defaultSearchTreeFile = "log/searchTree.txt"; - private String heuristicStr = "multi"; +// private String heuristicStr = "multi"; Set<NamedClass> allowedConcepts; Set<ObjectProperty> allowedRoles; Set<NamedClass> ignoredConcepts; @@ -239,84 +239,6 @@ } /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings({"unchecked"}) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); - if(name.equals("writeSearchTree")) - writeSearchTree = (Boolean) entry.getValue(); - else if(name.equals("searchTreeFile")) - searchTreeFile = new File((String)entry.getValue()); - else if(name.equals("replaceSearchTree")) - replaceSearchTree = (Boolean) entry.getValue(); - else if(name.equals("heuristic")) { - String value = (String) entry.getValue(); - if(value.equals("lexicographic")) - heuristicStr = "lexicographic"; - else - heuristicStr = "flexible"; - } else if(name.equals("allowedConcepts")) { - allowedConcepts = CommonConfigMappings.getAtomicConceptSet((Set<String>)entry.getValue()); - } else if(name.equals("allowedRoles")) { - allowedRoles = CommonConfigMappings.getAtomicRoleSet((Set<String>)entry.getValue()); - } else if(name.equals("ignoredConcepts")) { - ignoredConcepts = CommonConfigMappings.getAtomicConceptSet((Set<String>)entry.getValue()); - } else if(name.equals("ignoredRoles")) { - ignoredRoles = CommonConfigMappings.getAtomicRoleSet((Set<String>)entry.getValue()); - } else if(name.equals("applyAllFilter")) { -// applyAllFilter = (Boolean) entry.getValue(); - } else if(name.equals("applyExistsFilter")) { -// applyExistsFilter = (Boolean) entry.getValue(); - } else if(name.equals("useTooWeakList")) { - useTooWeakList = (Boolean) entry.getValue(); - } else if(name.equals("useOverlyGeneralList")) { - useOverlyGeneralList = (Boolean) entry.getValue(); - } else if(name.equals("useShortConceptConstruction")) { - useShortConceptConstruction = (Boolean) entry.getValue(); - } else if(name.equals("improveSubsumptionHierarchy")) { - improveSubsumptionHierarchy = (Boolean) entry.getValue(); - } else if(name.equals("useAllConstructor")) { -// useAllConstructor = (Boolean) entry.getValue(); - } else if(name.equals("useExistsConstructor")) { -// useExistsConstructor = (Boolean) entry.getValue(); - } else if(name.equals("useHasValueConstructor")) { -// useHasValueConstructor = (Boolean) entry.getValue(); - } else if(name.equals("valueFrequencyThreshold")) { -// valueFrequencyThreshold = (Integer) entry.getValue(); - } else if(name.equals("useCardinalityRestrictions")) { -// useCardinalityRestrictions = (Boolean) entry.getValue(); - } else if(name.equals("useNegation")) { -// useNegation = (Boolean) entry.getValue(); - } else if(name.equals("noisePercentage")) { - noisePercentage = (Double) entry.getValue(); - } else if(name.equals("useBooleanDatatypes")) { -// useBooleanDatatypes = (Boolean) entry.getValue(); - } else if(name.equals("useDoubleDatatypes")) { -// useDoubleDatatypes = (Boolean) entry.getValue(); - } else if(name.equals("usePropernessChecks")) { - usePropernessChecks = (Boolean) entry.getValue(); - } else if(name.equals("maxPosOnlyExpansion")) { - maxPosOnlyExpansion = (Integer) entry.getValue(); - } else if(name.equals("startClass")) { - startClass = new NamedClass((String)entry.getValue()); - }else if(name.equals("maxExecutionTimeInSeconds")) { - maxExecutionTimeInSeconds = (Integer) entry.getValue(); - }else if(name.equals("minExecutionTimeInSeconds")) { - minExecutionTimeInSeconds = (Integer) entry.getValue(); - }else if(name.equals("guaranteeXgoodDescriptions")) { - guaranteeXgoodDescriptions = (Integer) entry.getValue(); - } else if(name.equals("maxClassDescriptionTests")) { - maxClassDescriptionTests = (Integer) entry.getValue(); - } else if(name.equals("logLevel")) { - logLevel = ((String)entry.getValue()).toUpperCase(); - } else if(name.equals("forceRefinementLengthIncrease")) { - forceRefinementLengthIncrease = (Boolean) entry.getValue(); - } - } - - /* (non-Javadoc) * @see org.dllearner.core.Component#init() */ @Override @@ -340,22 +262,47 @@ // adjust heuristic if(heuristic == null) { - if(heuristicStr == "lexicographic") - heuristic = new LexicographicHeuristic(); - else if(heuristicStr == "flexible") { - if(learningProblem instanceof PosOnlyLP) { - throw new RuntimeException("does not work with positive examples only yet"); - } - heuristic = new FlexibleHeuristic(((PosNegLP) getLearningProblem()).getNegativeExamples().size(), ((PosNegLP) getLearningProblem()).getPercentPerLengthUnit()); - } else { if(getLearningProblem() instanceof PosOnlyLP) { throw new RuntimeException("does not work with positive examples only yet"); // heuristic = new MultiHeuristic(((PosOnlyLP) getLearningProblem()).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } else { heuristic = new MultiHeuristic(((PosNegLP) getLearningProblem()).getPositiveExamples().size(),((PosNegLP) getLearningProblem()).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); + } + + // OLD CODE below: in the new framework we assume that the + // heuristic is always injected as object (not as string) +// if(heuristicStr == "lexicographic") +// heuristic = new LexicographicHeuristic(); +// else if(heuristicStr == "flexible") { +// if(learningProblem instanceof PosOnlyLP) { +// throw new RuntimeException("does not work with positive examples only yet"); +// } +// heuristic = new FlexibleHeuristic(((PosNegLP) getLearningProblem()).getNegativeExamples().size(), ((PosNegLP) getLearningProblem()).getPercentPerLengthUnit()); +// } else { +// if(getLearningProblem() instanceof PosOnlyLP) { +// throw new RuntimeException("does not work with positive examples only yet"); +// // heuristic = new MultiHeuristic(((PosOnlyLP) getLearningProblem()).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); +// } else { +// heuristic = new MultiHeuristic(((PosNegLP) getLearningProblem()).getPositiveExamples().size(),((PosNegLP) getLearningProblem()).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); +// } +// } + } else { + // we need to set some variables to make the heuristic work + if(heuristic instanceof MultiHeuristic) { + MultiHeuristic mh = ((MultiHeuristic)heuristic); + if(mh.getNrOfNegativeExamples() == 0) { + mh.setNrOfNegativeExamples(((PosNegLP) getLearningProblem()).getNegativeExamples().size()); + } + int nrPosEx = ((PosNegLP) getLearningProblem()).getPositiveExamples().size(); + int nrNegEx = ((PosNegLP) getLearningProblem()).getNegativeExamples().size(); + if(mh.getNrOfExamples() == 0) { + mh.setNrOfExamples(nrPosEx + nrNegEx); + } + if(mh.getNrOfNegativeExamples() == 0) { + mh.setNrOfNegativeExamples(nrNegEx); + } } } - } // warn the user if he/she sets any non-standard heuristic, because it will just be ignored if(learningProblem instanceof PosNegLPStandard) { @@ -411,9 +358,7 @@ if(operator == null) { // we use a default operator and inject the class hierarchy for now operator = new RhoDRDown(); - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); ((RhoDRDown)operator).setReasoner(reasoner); - ((RhoDRDown)operator).init(); // operator = new RhoDRDown( // reasoner, @@ -436,10 +381,11 @@ // useStringDatatypes, // instanceBasedDisjoints // ); - } else { - // we still have to inject the class hierarchy even if the operator is configured - operator.setSubHierarchy(classHierarchy); } + ((RhoDRDown)operator).setSubHierarchy(classHierarchy); + ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + ((RhoDRDown)operator).init(); // create an algorithm object and pass all configuration // options to it @@ -572,14 +518,6 @@ this.replaceSearchTree = replaceSearchTree; } - public String getHeuristicStr() { - return heuristicStr; - } - - public void setHeuristicStr(String heuristic) { - this.heuristicStr = heuristic; - } - public Set<NamedClass> getAllowedConcepts() { return allowedConcepts; } Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-29 18:15:18 UTC (rev 3449) @@ -45,6 +45,7 @@ import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DoubleMaxValue; @@ -60,6 +61,7 @@ import org.dllearner.core.owl.ObjectMinCardinalityRestriction; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyExpression; +import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.ObjectValueRestriction; @@ -98,6 +100,8 @@ // hierarchies private ClassHierarchy subHierarchy; + private ObjectPropertyHierarchy objectPropertyHierarchy; + private DatatypePropertyHierarchy dataPropertyHierarchy; // domains and ranges private Map<ObjectProperty,Description> opDomains = new TreeMap<ObjectProperty,Description>(); @@ -262,6 +266,7 @@ // subHierarchy = rs.getClassHierarchy(); public void init() { // System.out.println("subHierarchy: " + subHierarchy); +// System.out.println("object properties: " + ); // query reasoner for domains and ranges // (because they are used often in the operator) @@ -560,7 +565,9 @@ // rule 2: EXISTS r.D => EXISTS s.D or EXISTS r^-1.D => EXISTS s^-1.D // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); + // remove reasoner calls +// Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) refinements.add(new ObjectSomeRestriction(moreSpecialRole, description.getChild(0))); @@ -604,7 +611,8 @@ // rule 3: ALL r.D => ALL s.D or ALL r^-1.D => ALL s^-1.D // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); +// Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = objectPropertyHierarchy.getMoreSpecialRoles(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) { refinements.add(new ObjectAllRestriction(moreSpecialRole, description.getChild(0))); } @@ -961,9 +969,9 @@ topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; // if(domain == null) { -// System.out.println("computed top refinements: " + topRefinementsCumulative.get(maxLength)); +// System.out.println("computed top refinements up to length " + topRefinementsLength + ": " + topRefinementsCumulative.get(maxLength)); // } else { -// System.out.println("computed top refinements: " + topARefinementsCumulative.get(domain).get(maxLength)); +// System.out.println("computed top refinements up to length " + topARefinementsLength + ": (domain: "+domain+"): " + topARefinementsCumulative.get(domain).get(maxLength)); // } } @@ -1002,6 +1010,7 @@ SortedSet<Description> m3 = new TreeSet<Description>(conceptComparator); if(useExistsConstructor) { // only uses most general roles +// System.out.println("EXISTS: " + reasoner.getMostGeneralProperties()); for(ObjectProperty r : reasoner.getMostGeneralProperties()) { m3.add(new ObjectSomeRestriction(r, new Thing())); } @@ -1674,4 +1683,20 @@ public void setCardinalityLimit(int cardinalityLimit) { this.cardinalityLimit = cardinalityLimit; } + + public ObjectPropertyHierarchy getObjectPropertyHierarchy() { + return objectPropertyHierarchy; + } + + public void setObjectPropertyHierarchy(ObjectPropertyHierarchy objectPropertyHierarchy) { + this.objectPropertyHierarchy = objectPropertyHierarchy; + } + + public DatatypePropertyHierarchy getDataPropertyHierarchy() { + return dataPropertyHierarchy; + } + + public void setDataPropertyHierarchy(DatatypePropertyHierarchy dataPropertyHierarchy) { + this.dataPropertyHierarchy = dataPropertyHierarchy; + } } \ No newline at end of file Modified: trunk/examples/family/grandfather.conf =================================================================== --- trunk/examples/family/grandfather.conf 2011-11-29 10:19:02 UTC (rev 3448) +++ trunk/examples/family/grandfather.conf 2011-11-29 18:15:18 UTC (rev 3449) @@ -40,12 +40,13 @@ op.reasoner = reasoner // create a heuristic and configure it -h.type = "multiheuristic" -h.expansionPenaltyFactor = 0.2 +// h.type = "multiheuristic" +// h.expansionPenaltyFactor = 0.2 // create learning algorithm to run alg.type = "ocel" alg.reasoner = reasoner alg.operator = op -alg.heuristic = h -alg.maxExecutionTimeInSeconds = 15 +// alg.heuristic = h +alg.maxExecutionTimeInSeconds = 5 + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-11-29 10:19:08
|
Revision: 3448 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3448&view=rev Author: sebastianwtr Date: 2011-11-29 10:19:02 +0000 (Tue, 29 Nov 2011) Log Message: ----------- [tbsl] fixed getRelatedNouns function Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-11-28 15:20:35 UTC (rev 3447) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/nlp/WordNet.java 2011-11-29 10:19:02 UTC (rev 3448) @@ -117,56 +117,67 @@ * @return List of Hypo and Hypernyms * @throws JWNLException */ - public List<String> getRelatedNouns(String s) throws JWNLException { + public List<String> getRelatedNouns(String s) { List<String> result = new ArrayList<String>(); - IndexWord word = dict.getIndexWord(POS.NOUN,s); - - Synset sense = word.getSense(1); - - PointerTargetNodeList relatedListHypernyms = null; - PointerTargetNodeList relatedListHyponyms = null; - try { - relatedListHypernyms = PointerUtils.getInstance().getDirectHypernyms(sense); - } catch (JWNLException e) { + IndexWord word = null; + Synset sense=null; + try{ + word=dict.getIndexWord(POS.NOUN,s); + if(word!=null){ + sense = word.getSense(1); + //Synset sense = word.getSense(1); + + PointerTargetNodeList relatedListHypernyms = null; + PointerTargetNodeList relatedListHyponyms = null; + try { + relatedListHypernyms = PointerUtils.getInstance().getDirectHypernyms(sense); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + relatedListHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Iterator i = relatedListHypernyms.iterator(); + while (i.hasNext()) { + PointerTargetNode related = (PointerTargetNode) i.next(); + Synset s1 = related.getSynset(); + String tmp=(s1.toString()).replace(s1.getGloss(), ""); + tmp=tmp.replace(" -- ()]",""); + tmp=tmp.replaceAll("[0-9]",""); + tmp=tmp.replace("[Synset: [Offset: ",""); + tmp=tmp.replace("] [POS: noun] Words: ",""); + //its possible, that there is more than one word in a line from wordnet + String[] array_tmp=tmp.split(","); + for(String z : array_tmp) result.add(z.replace(" ", "")); + } + + Iterator j = relatedListHyponyms.iterator(); + while (j.hasNext()) { + PointerTargetNode related = (PointerTargetNode) j.next(); + Synset s1 = related.getSynset(); + String tmp=(s1.toString()).replace(s1.getGloss(), ""); + tmp=tmp.replace(" -- ()]",""); + tmp=tmp.replaceAll("[0-9]",""); + tmp=tmp.replace("[Synset: [Offset: ",""); + tmp=tmp.replace("] [POS: noun] Words: ",""); + //its possible, that there is more than one word in a line from wordnet + String[] array_tmp=tmp.split(","); + for(String z : array_tmp) result.add(z.replace(" ", "")); + } + } + }catch (JWNLException e) { // TODO Auto-generated catch block e.printStackTrace(); } - try { - relatedListHyponyms = PointerUtils.getInstance().getDirectHyponyms(sense); - } catch (JWNLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Iterator i = relatedListHypernyms.iterator(); - while (i.hasNext()) { - PointerTargetNode related = (PointerTargetNode) i.next(); - Synset s1 = related.getSynset(); - String tmp=(s1.toString()).replace(s1.getGloss(), ""); - tmp=tmp.replace(" -- ()]",""); - tmp=tmp.replaceAll("[0-9]",""); - tmp=tmp.replace("[Synset: [Offset: ",""); - tmp=tmp.replace("] [POS: noun] Words: ",""); - //its possible, that there is more than one word in a line from wordnet - String[] array_tmp=tmp.split(","); - for(String z : array_tmp) result.add(z.replace(" ", "")); - } - Iterator j = relatedListHyponyms.iterator(); - while (j.hasNext()) { - PointerTargetNode related = (PointerTargetNode) j.next(); - Synset s1 = related.getSynset(); - String tmp=(s1.toString()).replace(s1.getGloss(), ""); - tmp=tmp.replace(" -- ()]",""); - tmp=tmp.replaceAll("[0-9]",""); - tmp=tmp.replace("[Synset: [Offset: ",""); - tmp=tmp.replace("] [POS: noun] Words: ",""); - //its possible, that there is more than one word in a line from wordnet - String[] array_tmp=tmp.split(","); - for(String z : array_tmp) result.add(z.replace(" ", "")); - } return result; } - + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2011-11-28 15:20:48
|
Revision: 3447 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3447&view=rev Author: kurzum Date: 2011-11-28 15:20:35 +0000 (Mon, 28 Nov 2011) Log Message: ----------- sparql yet another approach Modified Paths: -------------- trunk/examples/sparql/new_approach.conf Added Paths: ----------- trunk/examples/sparql/new_approach_data_include.conf Modified: trunk/examples/sparql/new_approach.conf =================================================================== --- trunk/examples/sparql/new_approach.conf 2011-11-28 14:44:48 UTC (rev 3446) +++ trunk/examples/sparql/new_approach.conf 2011-11-28 15:20:35 UTC (rev 3447) @@ -73,8 +73,6 @@ Filter ( ?class LIKE <http://dbpedia.org/ontology/%> ) . } " - - reasoner.type = "fast instance checker" reasoner.sources = {ks1, ks2, ks3, ks4 } @@ -92,3 +90,7 @@ // we use the OCEL algorithm alg.type = "ocel" alg.operator = op + +alg.maxExecutionTimeInSeconds = 20 +//alg.terminateOnNoiseReached = false +alg.noisePercentage = 5 Added: trunk/examples/sparql/new_approach_data_include.conf =================================================================== --- trunk/examples/sparql/new_approach_data_include.conf (rev 0) +++ trunk/examples/sparql/new_approach_data_include.conf 2011-11-28 15:20:35 UTC (rev 3447) @@ -0,0 +1,36 @@ + + +ks1.type = "OWL File" +ks1.url = "http://dbpedia.org/sparql" +ks1.defaultGraphURIs= {"http://dbpedia.org"} +ks1.sparql = " +Construct { +<http://dbpedia.org/resource/Berlin> a <http://dbpedia.org/ontology/City> , owl:Thing . +<http://dbpedia.org/resource/City> a owl:Class. +<http://dbpedia.org/resource/London> a <http://dbpedia.org/ontology/Town> , owl:Thing . +<http://dbpedia.org/resource/Town> a owl:Class . +} +{ +} " + +reasoner.type = "fast instance checker" +reasoner.sources = {ks1} + +lp.type = "posNegStandard" +lp.positiveExamples = {"http://dbpedia.org/resource/Berlin"} +lp.negativeExamples = {"http://dbpedia.org/resource/London"} + +// create a refinement operator and configure it +op.type = "rho" +op.useNegation = false +op.useAllConstructor = false +op.useCardinalityRestrictions = false +op.reasoner = reasoner + +// we use the OCEL algorithm +alg.type = "ocel" +alg.operator = op + +alg.maxExecutionTimeInSeconds = 20 +//alg.terminateOnNoiseReached = false +alg.noisePercentage = 5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-28 14:44:58
|
Revision: 3446 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3446&view=rev Author: lorenz_b Date: 2011-11-28 14:44:48 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Added preliminary support to use conf files via REST interface. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java trunk/interfaces/src/main/java/org/dllearner/server/Rest.java Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java 2011-11-28 14:43:45 UTC (rev 3445) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java 2011-11-28 14:44:48 UTC (rev 3446) @@ -6,6 +6,7 @@ import org.dllearner.configuration.IConfigurationProperty; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.Component; +import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import java.io.IOException; @@ -30,7 +31,11 @@ public ConfParserConfiguration(Resource source) { try { // baseDir = source.getFile().getAbsoluteFile().getParent(); - baseDir = source.getFile().getParentFile().toURI().toString(); + if(!(source instanceof InputStreamResource)){ + baseDir = source.getFile().getParentFile().toURI().toString(); + } else { + baseDir = null; + } parser = new ConfParser(source.getInputStream()); parser.Start(); } catch (ParseException e) { Modified: trunk/interfaces/src/main/java/org/dllearner/server/Rest.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/server/Rest.java 2011-11-28 14:43:45 UTC (rev 3445) +++ trunk/interfaces/src/main/java/org/dllearner/server/Rest.java 2011-11-28 14:44:48 UTC (rev 3446) @@ -1,23 +1,39 @@ package org.dllearner.server; -import org.apache.commons.httpclient.util.ExceptionUtil; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.commons.lang.exception.ExceptionUtils; +import org.dllearner.configuration.IConfiguration; +import org.dllearner.configuration.spring.ApplicationContextBuilder; +import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; +import org.dllearner.confparser3.ConfParserConfiguration; +import org.dllearner.core.ClassExpressionLearningAlgorithm; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.core.io.InputStreamResource; +import org.springframework.core.io.Resource; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.HashMap; -import java.util.Map; - public class Rest extends HttpServlet { private static Logger log = LoggerFactory.getLogger(Rest.class); @@ -51,7 +67,6 @@ conf = httpServletRequest.getParameter("conf"); } - /*todo learn*/ if (isSet("debug", httpServletRequest) && httpServletRequest.getParameter("debug").equalsIgnoreCase("true")) { @@ -118,7 +133,24 @@ * @return */ public EvaluatedDescriptionPosNeg learn(String conf) { + try { + Resource confFile = new InputStreamResource(new ByteArrayInputStream(conf.getBytes())); + + IConfiguration configuration = new ConfParserConfiguration(confFile); + ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); + ApplicationContext context = builder.buildApplicationContext(configuration, new ArrayList<Resource>()); + + LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); + algorithm.start(); + if(algorithm instanceof ClassExpressionLearningAlgorithm){ + return (EvaluatedDescriptionPosNeg)((ClassExpressionLearningAlgorithm) algorithm).getCurrentlyBestEvaluatedDescriptions(1).iterator().next(); + } + } catch (BeansException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } return null; } @@ -138,6 +170,28 @@ } return ret; } + + public static void main(String[] args) throws Exception{ + String filePath = "../examples/father.conf"; + byte[] buffer = new byte[(int) new File(filePath).length()]; + BufferedInputStream f = null; + try { + f = new BufferedInputStream(new FileInputStream(filePath)); + f.read(buffer); + } finally { + if (f != null) try { f.close(); } catch (IOException ignored) { } + } + String confString = new String(buffer); + + Resource confFile = new InputStreamResource(new ByteArrayInputStream(confString.getBytes())); + + IConfiguration configuration = new ConfParserConfiguration(confFile); + ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); + ApplicationContext context = builder.buildApplicationContext(configuration, new ArrayList<Resource>()); + + LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); + algorithm.start(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-28 14:43:55
|
Revision: 3445 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3445&view=rev Author: lorenz_b Date: 2011-11-28 14:43:45 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Fixed example syntax. Modified Paths: -------------- trunk/examples/sparql/new_approach.conf Modified: trunk/examples/sparql/new_approach.conf =================================================================== --- trunk/examples/sparql/new_approach.conf 2011-11-28 12:11:47 UTC (rev 3444) +++ trunk/examples/sparql/new_approach.conf 2011-11-28 14:43:45 UTC (rev 3445) @@ -81,7 +81,6 @@ lp.type = "posNegStandard" lp.positiveExamples = {"http://dbpedia.org/resource/Berlin"} lp.negativeExamples = {"http://dbpedia.org/resource/London"} -lp.reasoner = reasoner // create a refinement operator and configure it op.type = "rho" @@ -92,6 +91,4 @@ // we use the OCEL algorithm alg.type = "ocel" -alg.reasoner = reasoner -alg.learningProblem = lp alg.operator = op This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <km...@us...> - 2011-11-28 12:11:57
|
Revision: 3444 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3444&view=rev Author: kmpf Date: 2011-11-28 12:11:47 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Logger configuration changed. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/ProteinDataSet.java Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-11-28 11:22:01 UTC (rev 3443) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-11-28 12:11:47 UTC (rev 3444) @@ -84,6 +84,7 @@ resprint.put(TRP, new PrintStream(allConfFiles.get(TRP))); resprint.put(TYR, new PrintStream(allConfFiles.get(TYR))); resprint.put(SEL, new PrintStream(allConfFiles.get(SEL))); + resprint.put(HYT, new PrintStream(allConfFiles.get(HYT))); } catch (FileNotFoundException e) { e.printStackTrace(); } @@ -114,6 +115,7 @@ resourceString.put(TRP, new StringBuffer(init)); resourceString.put(TYR, new StringBuffer(init)); resourceString.put(SEL, new StringBuffer(init)); + resourceString.put(HYT, new StringBuffer(init)); return resourceString; } @@ -172,6 +174,14 @@ return resnum; } + /* + * +++ Amino acid properties +++ + * + * the following amino acid properties were gathered from + * http://www.russelllab.org/aas/ + * + */ + public static HashMap<String, String> getAminoAcidNumericArffAttributeMap(){ // Hydrophobicity hydrophilic = 0; Hydrophobic = 1; aromatic = 2; aliphatic = 3 // Polarity unpolar = 0; polar = 1; positive = 2; negative = 3; @@ -232,7 +242,6 @@ resdata.put(new String("X"), new String("?,?,?")); // unknown residue (e.g. modified amino acids) resdata.put(new String("Y"), new String("Aromatic,Polar,Large")); resdata.put(new String("U"), new String("?,?,?")); - return resdata; } } Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-11-28 11:22:01 UTC (rev 3443) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-11-28 12:11:47 UTC (rev 3444) @@ -53,7 +53,7 @@ // console, you have to set the threshold and log level to trace // (but we recommend just setting the log level to trace and observe // the log file) - consoleAppender.setThreshold(Level.DEBUG); + consoleAppender.setThreshold(Level.INFO); // logger 2 is writes to a file; it records all debug messages // (you can choose HTML or TXT) @@ -66,11 +66,12 @@ fileName = _dataDir + "log/log.html"; } else { // simple variant: layout2 = new SimpleLayout(); - layout2 = new PatternLayout("%r [%t] %-5p %c :\n%m%n\n"); + layout2 = new PatternLayout("%d [%t] %-5p %c : %m%n"); fileName = _dataDir + "log/log.txt"; } try { fileAppenderNormal = new FileAppender(layout2, fileName, false); + fileAppenderNormal.setThreshold(Level.INFO); } catch (IOException e) { e.printStackTrace(); } @@ -79,7 +80,7 @@ _rootLogger.removeAllAppenders(); _rootLogger.addAppender(consoleAppender); _rootLogger.addAppender(fileAppenderNormal); - _rootLogger.setLevel(Level.DEBUG); + _rootLogger.setLevel(Level.INFO); Boolean fasta = true; @@ -102,12 +103,12 @@ Boolean dlLearn = false; Boolean wekaLearn = false; - int dataSet = 5; + int dataSet = 1; /* * data for test purpose */ - PDBProtein testProtein = new PDBProtein("1XFF","A"); + PDBProtein testProtein = new PDBProtein("1EDM","B"); // PDBProtein testProtein = new PDBProtein("1LMB", "3"); // PDBProtein testProtein = new PDBProtein("8ABP"); @@ -146,6 +147,7 @@ if (rdfConf || arff) { PDBProtein protein = proteinSet.getProteinset().get(i); + _logger.info("Start with extracting data from: " + protein.getPdbID()); String pdbDir = _dataDir + protein.getPdbID() + "/"; File directory = new File(pdbDir); if(! directory.exists()) directory.mkdir(); @@ -153,7 +155,7 @@ //String arffFilePath = pdbDir + protein.getArffFileName(); _logger.info("PDB ID: " + protein.getPdbID()); - _logger.info("chain ID: " + protein.getChainID()); + _logger.info("Chain ID: " + protein.getChainID()); trainmodel = new PDBIdRdfModel(protein); @@ -189,6 +191,8 @@ trainmodel.removeStatementsWithObject(residue); Property isPartOf = ResourceFactory.createProperty("http://purl.org/dc/terms/", "isPartOf"); trainmodel.removeStatementsWithPoperty(isPartOf); + Property hasValue = ResourceFactory.createProperty("http://bio2rdf.org/pdb:", "hasValue"); + trainmodel.removeStatementsWithPoperty(hasValue); /* * we add the information which amino acid is the fourth predecessor of which other amino acid */ @@ -533,7 +537,7 @@ dataLine.append( "?" ); } - _logger.info(dataLine); + _logger.debug(dataLine); out.println(dataLine); } @@ -623,7 +627,7 @@ dataLine.append( "?" ); } - _logger.info(dataLine); + _logger.debug(dataLine); out.println(dataLine); } Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-11-28 11:22:01 UTC (rev 3443) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-11-28 12:11:47 UTC (rev 3444) @@ -34,7 +34,7 @@ public class PDBIdRdfModel { - private static Logger _logger = Logger.getRootLogger(); + private static Logger _logger = Logger.getLogger(HelixRDFCreator.class); private PdbRdfModel _pdbIdModel = new PdbRdfModel(); private PdbRdfModel _removedFromModel = new PdbRdfModel(); @@ -48,9 +48,9 @@ this._protein = protein; this._pdbIdModel = this.getPdbRdfModel(); this.getProtein().setSequence(extractSequence(_pdbIdModel)); - System.out.println("Sequence: " + this.getProtein().getSequence()); + _logger.info("Sequence: " + this.getProtein().getSequence()); this.getProtein().setSpecies(extractSpecies(_pdbIdModel)); - System.out.println("Species: " + this.getProtein().getSpecies()); + _logger.info("Species: " + this.getProtein().getSpecies()); createPositivesAndNegatives(); this._positionResource = createPositionResidueMap(); } @@ -122,7 +122,7 @@ " ?x1 pdb:isImmediatelyBefore ?x4 ." + " OPTIONAL { ?x5 rdfs:label ?species FILTER (str(?x5) = fn:concat(str(?x2), '/extraction/source/gene/organism')) . } . }"; - // System.out.println(queryString); + _logger.debug(queryString); PdbRdfModel construct = new PdbRdfModel(); Query query = QueryFactory.create(queryString); @@ -138,10 +138,7 @@ { RDFNode nextRes = niter.next(); species = nextRes.toString(); -/* QuerySolution soln = results.nextSolution() ; - Literal l = soln.getLiteral("species") ; // Get a result variable - must be a literal - species = l.getString();*/ - System.out.println(species); + _logger.debug(species); } } finally @@ -166,7 +163,7 @@ NodeIterator niter = model.listObjectsOfProperty(nextRes, hasValue); sequence = niter.next().toString(); - System.out.println("Sequence: " + sequence); + _logger.debug("Sequence: " + sequence); } } ; return sequence; @@ -219,9 +216,10 @@ " ?organism rdfs:label ?organismName ." + " ?seq rdf:type pdb:PolymerSequence ." + " ?seq pdb:hasValue ?sequence . } " + - "WHERE { ?x1 rdf:type pdb:Helix ." + + "WHERE { " + + " OPTIONAL { ?x1 rdf:type pdb:Helix ." + " ?x1 pdb:beginsAt ?x2 ." + - " ?x1 pdb:endsAt ?x3 ." + + " ?x1 pdb:endsAt ?x3 . } . " + " ?x3 dcterms:isPartOf ?x4 ." + " ?x4 rdf:type <http://bio2rdf.org/pdb:Polypeptide(L)> ." + " ?x5 dcterms:isPartOf ?x4 ." + @@ -245,7 +243,7 @@ " OPTIONAL { ?organism rdfs:label ?organismName " + "FILTER (str(?organism) = fn:concat(str(?x4), '/extraction/source/gene/organism')) . } . }"; - System.out.println(queryString); + _logger.debug(queryString); Query query = QueryFactory.create(queryString); QueryExecution qe = QueryExecutionFactory.create(query, model); construct.add(qe.execConstruct()); @@ -318,7 +316,6 @@ position = positionLabels.get(0); } else { position = new Integer(0); - _logger.error(""); } return position.intValue(); } @@ -347,7 +344,7 @@ "PREFIX x:<" + prop.getNameSpace() + "> " + "CONSTRUCT { ?x1 x:" + prop.getLocalName()+ " ?x2 . } " + "WHERE { ?x1 x:" + prop.getLocalName() + " ?x2 . }"; - //System.out.println(queryString); + _logger.debug(queryString); Query query = QueryFactory.create(queryString); QueryExecution qe = QueryExecutionFactory.create(query, _pdbIdModel); StmtIterator stmtiter = qe.execConstruct().listStatements(); @@ -365,7 +362,7 @@ "PREFIX x:<" + res.getNameSpace() + "> " + "CONSTRUCT { ?x1 ?x2 x:" + res.getLocalName() + " . } " + "WHERE { ?x1 ?x2 x:" + res.getLocalName() + " . }"; - // System.out.println(queryString); + _logger.debug(queryString); Query query = QueryFactory.create(queryString); QueryExecution qe = QueryExecutionFactory.create(query, _pdbIdModel); StmtIterator stmtiter = qe.execConstruct().listStatements(); @@ -392,7 +389,7 @@ while (riter.hasNext()) { // Initialization of variables needed Resource firstAA = riter.nextResource(); - System.out.println("First AA: " + firstAA.getLocalName()); + _logger.debug("First AA: " + firstAA.getLocalName()); Resource currentAA = firstAA; Resource nextAA = firstAA; boolean inHelix = false; @@ -427,15 +424,15 @@ } while (currentAA.hasProperty(iib)) ; } _positives = pos; - System.out.println("+++ Positive set +++"); + _logger.debug("+++ Positive set +++"); for (int i = 0; i < pos.size(); i++){ - System.out.println("Das " + i + "te Element: " + pos.get(i).getLocalName()); + _logger.debug("Das " + i + "te Element: " + pos.get(i).getLocalName()); } _negatives = neg; - System.out.println("+++ Negatvie set +++"); + _logger.debug("+++ Negatvie set +++"); for (int i = 0; i < neg.size(); i++){ - System.out.println("Das " + i + "te Element: " + neg.get(i).getLocalName()); + _logger.debug("Das " + i + "te Element: " + neg.get(i).getLocalName()); } } @@ -473,84 +470,4 @@ this.getProtein().setFastaFileName(fastaFileName); this.createFastaFile(dir); } - - - /* - * OLD STUFF - * - // every element in riter stands for a AA-chain start - // every first amino acid indicates a new AA-chain - while (riter.hasNext()) - { - // Initialization of variables needed - int i = 0; - Resource aaOne = riter.nextResource(); - Resource currentaa = aaOne; - Resource nextaa = aaOne; - boolean inHelix = false; - _logger.debug(currentaa.getURI()); - // look if there is a next AA - do { - ++i; - _logger.debug(i); - //looks weird, but is needed to enter loop even for the last AA which does not have a iib-Property - currentaa = nextaa; - NodeIterator resType = model.listObjectsOfProperty(currentaa,type); - - // die Guten ins Töpfchen ... - // if we get an non-empty iterator for pdb:beginsAt the next AAs are within a AA-helix - if(model.listResourcesWithProperty(ba, currentaa).hasNext() && !inHelix ) - { - inHelix = true; - } - // die Schlechten ins Kröpfchen - // if we get an non-empty iterator for pdb:endsAt and are already within a AA-helix - // the AAs AFTER the current ones aren't within a helix - if (model.listResourcesWithProperty(ea, currentaa).hasNext() && inHelix) - { - inHelix = false; - } - // get next AA if there is one - if (model.listObjectsOfProperty(currentaa, iib).hasNext()) - { - nextaa = model.getProperty(currentaa, iib).getResource(); - } - - // add current amino acid to positives or negatives set - while(resType.hasNext()) - { - Resource aaType = resType.next().asResource(); - _logger.info(aaType.getURI()); - if (resdata.get(aaType) != null) - { - if (inHelix) - { - data += i + "," + 1 + "," + resdata.get(aaType); - } - else - { - data += i + "," + 0 + "," + resdata.get(aaType); - } - } - } - - } while (currentaa.hasProperty(iib)) ; - } - - try - { - PrintStream out = new PrintStream (new File(arffFilePath)); - out.println(relation); - out.print(attribute); - out.print(data); - out.close(); - } - catch (FileNotFoundException e ) - { - System.err.println("Datei " + arffFilePath + " konnte nicht angelegt werden!"); - e.printStackTrace(); - } - - - */ } Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/ProteinDataSet.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/ProteinDataSet.java 2011-11-28 11:22:01 UTC (rev 3443) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/ProteinDataSet.java 2011-11-28 12:11:47 UTC (rev 3444) @@ -11,8 +11,12 @@ import java.util.HashMap; import java.util.Random; +import org.apache.log4j.Logger; + public class ProteinDataSet { + private static Logger _logger = Logger.getLogger(HelixRDFCreator.class); + private static String _dataDir = "../test/pdb/"; @@ -71,11 +75,11 @@ pdbproteins.close(); // get number of lines int linenr = lines.size(); - System.out.println("File "+ pdbIDlist.getCanonicalPath() + " has " + linenr + " lines."); + _logger.info("File "+ pdbIDlist.getCanonicalPath() + " has " + linenr + " lines."); this._proteinSet = new ArrayList<PDBProtein>(linenr); for (int i = 0; i < linenr; i++) { - System.out.println("LINES element " + i + " contains " + lines.get(i)); + _logger.info("LINES element " + i + " contains " + lines.get(i)); this._proteinSet.add( new PDBProtein( this.getPdbID(i, lines), @@ -85,7 +89,7 @@ } catch (IOException e) { - System.err.println("File " + pdbIDlist.getAbsolutePath() + " could not be read in!"); + _logger.error("File " + pdbIDlist.getAbsolutePath() + " could not be read in!"); // TODO Auto-generated catch block e.printStackTrace(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-28 11:22:09
|
Revision: 3443 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3443&view=rev Author: lorenz_b Date: 2011-11-28 11:22:01 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Continued script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-28 10:43:10 UTC (rev 3442) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-28 11:22:01 UTC (rev 3443) @@ -39,6 +39,7 @@ import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; @@ -48,6 +49,7 @@ import org.semanticweb.owlapi.model.OWLObjectProperty; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyFormat; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.reasoner.InferenceType; @@ -72,9 +74,9 @@ private SparqlEndpoint endpoint; private ExtractionDBCache cache = new ExtractionDBCache("cache"); - private int sampleSize = 100; + private int sampleSize = 10; private int depth = 4; - private int nrOfChunks = 100; + private int nrOfChunks = 1; private int maxNrOfExplanations = 20; private Logger logger = Logger.getLogger(SPARQLSampleDebugging.class); @@ -265,7 +267,7 @@ try { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - man.saveOntology(ontology, baos); + man.saveOntology(ontology, new RDFXMLOntologyFormat(), baos); bais = new ByteArrayInputStream(baos.toByteArray()); model.read(bais, null); } catch (OWLOntologyStorageException e) { @@ -476,7 +478,7 @@ SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); - new SPARQLSampleDebugging(endpoint).runPatternBasedDetection(); +// new SPARQLSampleDebugging(endpoint).runPatternBasedDetection(); new SPARQLSampleDebugging(endpoint).run3(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-28 10:43:16
|
Revision: 3442 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3442&view=rev Author: lorenz_b Date: 2011-11-28 10:43:10 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Changed database writing because OWLAxioms are not serializable. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-28 10:01:07 UTC (rev 3441) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-28 10:43:10 UTC (rev 3442) @@ -7,6 +7,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.ObjectOutputStream; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; @@ -47,6 +49,7 @@ import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.OWLReasoner; @@ -127,7 +130,22 @@ } else { ps.setInt(4, explanations.size()); ps.setString(5, explanations.toString()); - ps.setObject(6, explanations); + try { + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + OWLOntology ont = OWLManager.createOWLOntologyManager().createOntology(); + for(Set<OWLAxiom> axioms : explanations){ + man.addAxioms(ont, axioms); + } + Model model = convert(ont); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + model.write(baos, "N-TRIPLE"); + String modelStr = baos.toString("UTF-8"); + ps.setClob(6, new StringReader(modelStr)); + } catch (UnsupportedEncodingException e) { + logger.error("ERROR", e); + } catch (OWLOntologyCreationException e) { + logger.error("ERROR", e); + } } @@ -241,6 +259,29 @@ return retOnt; } + private Model convert(OWLOntology ontology) { + Model model = ModelFactory.createDefaultModel(); + ByteArrayInputStream bais = null; + try { + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + man.saveOntology(ontology, baos); + bais = new ByteArrayInputStream(baos.toByteArray()); + model.read(bais, null); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); + } finally { + try { + if(bais != null){ + bais.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return model; + } + public void run() throws OWLOntologyCreationException{ OWLOntology reference = loadReferenceOntology(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-28 10:01:18
|
Revision: 3441 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3441&view=rev Author: lorenz_b Date: 2011-11-28 10:01:07 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Added exec-maven-plugin. Modified Paths: -------------- trunk/scripts/pom.xml Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2011-11-28 09:58:31 UTC (rev 3440) +++ trunk/scripts/pom.xml 2011-11-28 10:01:07 UTC (rev 3441) @@ -1,61 +1,61 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <groupId>org.dllearner</groupId> - <artifactId>scripts</artifactId> - <packaging>jar</packaging> + <groupId>org.dllearner</groupId> + <artifactId>scripts</artifactId> + <packaging>jar</packaging> - <name>Executable scripts</name> - <url>http://aksw.org/Projects/DLLearner</url> + <name>Executable scripts</name> + <url>http://aksw.org/Projects/DLLearner</url> - <parent> - <groupId>org.dllearner</groupId> - <artifactId>dllearner-parent</artifactId> - <version>1.0-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.dllearner</groupId> + <artifactId>dllearner-parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> - <dependencies> - <dependency> - <groupId>org.dllearner</groupId> - <artifactId>components-core</artifactId> - </dependency> - <dependency> - <groupId>org.dllearner</groupId> - <artifactId>components-ext</artifactId> - </dependency> - <dependency> - <groupId>org.dllearner</groupId> - <artifactId>interfaces</artifactId> - </dependency> - <dependency> - <groupId>net.sourceforge.secondstring</groupId> - <artifactId>secondstring</artifactId> - </dependency> - <dependency> - <groupId>postgresql</groupId> - <artifactId>postgresql</artifactId> - </dependency> - <dependency> - <groupId>com.dumontierlab</groupId> - <artifactId>pdb2rdf-parser</artifactId> - <exclusions> - <exclusion> - <artifactId>slf4j-log4j12</artifactId> - <groupId>org.slf4j</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>com.dumontierlab</groupId> - <artifactId>pdb2rdf-cli</artifactId> - </dependency> - <dependency> - <groupId>org.aksw.commons</groupId> - <artifactId>sparql</artifactId> - </dependency> + <dependencies> <dependency> + <groupId>org.dllearner</groupId> + <artifactId>components-core</artifactId> + </dependency> + <dependency> + <groupId>org.dllearner</groupId> + <artifactId>components-ext</artifactId> + </dependency> + <dependency> + <groupId>org.dllearner</groupId> + <artifactId>interfaces</artifactId> + </dependency> + <dependency> + <groupId>net.sourceforge.secondstring</groupId> + <artifactId>secondstring</artifactId> + </dependency> + <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + </dependency> + <dependency> + <groupId>com.dumontierlab</groupId> + <artifactId>pdb2rdf-parser</artifactId> + <exclusions> + <exclusion> + <artifactId>slf4j-log4j12</artifactId> + <groupId>org.slf4j</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.dumontierlab</groupId> + <artifactId>pdb2rdf-cli</artifactId> + </dependency> + <dependency> + <groupId>org.aksw.commons</groupId> + <artifactId>sparql</artifactId> + </dependency> + <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> @@ -69,6 +69,32 @@ <artifactId>weka</artifactId> <version>3.6.5</version> </dependency> - - </dependencies> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.2</version> + <executions> + + <execution> + <goals> + <goal>exec</goal> + </goals> + </execution> + </executions> + <configuration> + <executable>java</executable> + <arguments> + <argument>-Xms512m</argument> + <argument>-Xmx4000m</argument> + </arguments> + </configuration> + </plugin> + </plugins> + + </build> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-28 09:58:42
|
Revision: 3440 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3440&view=rev Author: lorenz_b Date: 2011-11-28 09:58:31 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Extended script to write into database. Added methods to compute unsatisfiable object and data properties. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-28 08:24:14 UTC (rev 3439) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-28 09:58:31 UTC (rev 3440) @@ -2,14 +2,27 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.io.InputStream; +import java.io.ObjectOutputStream; import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Types; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.prefs.Preferences; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; @@ -21,13 +34,20 @@ import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; +import org.ini4j.IniPreferences; +import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLObjectProperty; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.OWLReasoner; import com.clarkparsia.owlapi.explanation.PelletExplanation; @@ -41,8 +61,8 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; -import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.RDFS; public class SPARQLSampleDebugging { @@ -56,12 +76,69 @@ private Logger logger = Logger.getLogger(SPARQLSampleDebugging.class); + private Connection conn; + private PreparedStatement ps; + static {PelletExplanation.setup();} public SPARQLSampleDebugging(SparqlEndpoint endpoint) { this.endpoint = endpoint; + initDBConnection(); } + private void initDBConnection() { + try { + String iniFile = "db_settings.ini"; + Preferences prefs = new IniPreferences(new FileReader(iniFile)); + String dbServer = prefs.node("database").get("server", null); + String dbName = prefs.node("database").get("name", null); + String dbUser = prefs.node("database").get("user", null); + String dbPass = prefs.node("database").get("pass", null); + + Class.forName("com.mysql.jdbc.Driver"); + String url = "jdbc:mysql://" + dbServer + "/" + dbName; + conn = DriverManager.getConnection(url, dbUser, dbPass); + + ps = conn.prepareStatement("INSERT INTO debugging_evaluation (" + + "resource, fragement_size , consistent, nr_of_justifications, justifications, justificationsObject) " + "VALUES(?,?,?,?,?,?)"); + + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (InvalidFileFormatException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void writeToDB(String resource, int fragementSize, boolean consistent, Set<Set<OWLAxiom>> explanations) { + try { + ps.setString(1, resource); + ps.setInt(2, fragementSize); + ps.setBoolean(3, consistent); + if(explanations == null){ + ps.setInt(4, 0); + ps.setNull(5, Types.NULL); + ps.setObject(6, Types.NULL); + } else { + ps.setInt(4, explanations.size()); + ps.setString(5, explanations.toString()); + ps.setObject(6, explanations); + } + + + ps.executeUpdate(); + } catch (SQLException e) { + logger.error("Error while writing to DB.", e); + e.printStackTrace(); + } + + } + private Set<String> extractSampleResourcesChunked(int size){ logger.info("Extracting " + sampleSize + " sample resources..."); long startTime = System.currentTimeMillis(); @@ -227,11 +304,49 @@ } + private Set<OWLObjectProperty> getUnsatisfiableObjectProperties(PelletReasoner reasoner){ + SortedSet<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(new Comparator<OWLObjectProperty>() { + @Override + public int compare(OWLObjectProperty o1, OWLObjectProperty o2) { + return o1.toString().compareTo(o2.toString()); + } + }); + OWLDataFactory f = OWLManager.createOWLOntologyManager().getOWLDataFactory(); + for(OWLObjectProperty p : reasoner.getRootOntology().getObjectPropertiesInSignature()){ + boolean satisfiable = reasoner.isSatisfiable(f.getOWLObjectExactCardinality(1, p)); + if(!satisfiable){ + properties.add(p); + } + } + return properties; + + } + + private Set<OWLDataProperty> getUnsatisfiableDataProperties(PelletReasoner reasoner){ + SortedSet<OWLDataProperty> properties = new TreeSet<OWLDataProperty>(); + OWLDataFactory f = OWLManager.createOWLOntologyManager().getOWLDataFactory(); + for(OWLDataProperty p : reasoner.getRootOntology().getDataPropertiesInSignature()){ + boolean satisfiable = reasoner.isSatisfiable(f.getOWLDataExactCardinality(1, p)); + if(!satisfiable){ + properties.add(p); + } + } + return properties; + + } + public void run3() throws OWLOntologyCreationException{ OWLOntology reference = loadReferenceOntology(); Set<OWLOntology> ontologies = new HashSet<OWLOntology>(); ontologies.add(reference); - PelletReasoner reasoner; + PelletReasoner reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(reference); + reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); + Set<OWLClass> unsatisfiableClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); + logger.info("Unsatisfiable classes(" + unsatisfiableClasses.size() + "): " + unsatisfiableClasses); + Set<OWLObjectProperty> unsatisfiableObjectProperties = getUnsatisfiableObjectProperties(reasoner); + logger.info("Unsatisfiable object properties(" + unsatisfiableObjectProperties.size() + "): " + unsatisfiableObjectProperties); + Set<OWLDataProperty> unsatisfiableDataProperties = getUnsatisfiableDataProperties(reasoner); + logger.info("Unsatisfiable data properties(" + unsatisfiableDataProperties.size() + "): " + unsatisfiableDataProperties); OWLOntology merged; OWLOntology module; @@ -244,8 +359,9 @@ reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(merged); boolean isConsistent = reasoner.isConsistent(); logger.info("Consistent: " + isConsistent); + Set<Set<OWLAxiom>> explanations = null; if(!isConsistent){ - Set<Set<OWLAxiom>> explanations = computeExplanations(reasoner); + explanations = computeExplanations(reasoner); logger.info("Found " + explanations.size() + " explanations."); Map<AxiomType, Integer> axiomType2CountMap = new HashMap<AxiomType, Integer>(); for(Set<OWLAxiom> explanation : explanations){ @@ -265,6 +381,7 @@ } ontologies.remove(module); reasoner.dispose(); + writeToDB(resource, module.getLogicalAxiomCount(), isConsistent, explanations); } @@ -283,6 +400,11 @@ //query for conflicts String queryString = "SELECT ?s WHERE {?type1 <" + OWL.disjointWith + "> ?type2. ?s a ?type1. ?s a ?type2.} LIMIT 1"; + queryString = "SELECT ?s ?p ?type1 ?type2 WHERE {" + + "?type1 <" + OWL.disjointWith + "> ?type2." + + "?p <" + RDFS.domain + "> ?type1. ?p <" + RDFS.domain + "> ?type2." + + " ?s ?p ?o1." + + " ?s ?p ?o2.} LIMIT 10"; Query query = QueryFactory.create(queryString) ; QueryExecution qexec = QueryExecutionFactory.create(query, model) ; try { @@ -290,8 +412,10 @@ for ( ; results.hasNext() ; ) { QuerySolution soln = results.nextSolution() ; - Resource r = soln.getResource("s") ; - System.out.println(r.getURI()); + for(String var : results.getResultVars()){ + System.out.print(soln.get(var) + "|"); + } + System.out.println(); } } finally { qexec.close() ; } } @@ -312,7 +436,7 @@ SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); new SPARQLSampleDebugging(endpoint).runPatternBasedDetection(); -// new SPARQLSampleDebugging(endpoint).run3(); + new SPARQLSampleDebugging(endpoint).run3(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-28 08:24:25
|
Revision: 3439 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3439&view=rev Author: lorenz_b Date: 2011-11-28 08:24:14 +0000 (Mon, 28 Nov 2011) Log Message: ----------- Added simple implementation for concise bounded description generator without resolving blank nodes and reification. Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGenerator.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SymmetricConciseBoundedDescriptionGeneratorImpl.java Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGenerator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGenerator.java 2011-11-28 08:24:14 UTC (rev 3439) @@ -0,0 +1,10 @@ +package org.dllearner.kb.sparql; + +import com.hp.hpl.jena.rdf.model.Model; + +public interface ConciseBoundedDescriptionGenerator { + + public Model getConciseBoundedDescription(String resourceURI); + + public Model getConciseBoundedDescription(String resourceURI, int depth); +} Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2011-11-28 08:24:14 UTC (rev 3439) @@ -0,0 +1,134 @@ +package org.dllearner.kb.sparql; + +import java.io.UnsupportedEncodingException; +import java.sql.SQLException; +import java.util.Set; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + +public class ConciseBoundedDescriptionGeneratorImpl implements ConciseBoundedDescriptionGenerator{ + + private static final Logger logger = Logger.getLogger(ConciseBoundedDescriptionGeneratorImpl.class); + + private static final int CHUNK_SIZE = 1000; + private static final int DEFAULT_DEPTH = 1; + + private ExtractionDBCache cache; + private SparqlEndpoint endpoint; + + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, ExtractionDBCache cache) { + this.endpoint = endpoint; + this.cache = cache; + } + + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint) { + this(endpoint, null); + } + + public Model getConciseBoundedDescription(String resourceURI){ + return getConciseBoundedDescription(resourceURI, DEFAULT_DEPTH); + } + + public Model getConciseBoundedDescription(String resourceURI, int depth){ + return getModelChunked(resourceURI, depth); + } + + private Model getModelChunked(String resource, int depth){ + String query = makeConstructQueryOptional(resource, CHUNK_SIZE, 0, depth); + Model all = ModelFactory.createDefaultModel(); + try { + Model model; + if(cache == null){ + model = getModel(query); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + all.add(model); + int i = 1; + while(model.size() != 0){ +// while(model.size() == CHUNK_SIZE){ + query = makeConstructQueryOptional(resource, CHUNK_SIZE, i * CHUNK_SIZE, depth); + if(cache == null){ + model = getModel(query); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + all.add(model); + i++; + } + } catch (UnsupportedEncodingException e) { + logger.error(e); + } catch (SQLException e) { + logger.error(e); + } + return all; + } + + /** + * A SPARQL CONSTRUCT query is created, to get a RDF graph for the given example with a specific recursion depth. + * @param example The example resource for which a CONSTRUCT query is created. + * @return The JENA ARQ Query object. + */ + private String makeConstructQueryOptional(String resource, int limit, int offset, int depth){ + StringBuilder sb = new StringBuilder(); + sb.append("CONSTRUCT {\n"); + sb.append("<").append(resource).append("> ").append("?p0 ").append("?o0").append(".\n"); + for(int i = 1; i < depth; i++){ + sb.append("?o").append(i-1).append(" ").append("?p").append(i).append(" ").append("?o").append(i).append(".\n"); + } + sb.append("}\n"); + sb.append("WHERE {\n"); + sb.append("<").append(resource).append("> ").append("?p0 ").append("?o0").append(".\n"); + for(int i = 1; i < depth; i++){ + sb.append("OPTIONAL{\n"); + sb.append("?o").append(i-1).append(" ").append("?p").append(i).append(" ").append("?o").append(i).append(".\n"); + } + for(int i = 1; i < depth; i++){ + sb.append("}"); + } + sb.append("}\n"); + sb.append("LIMIT ").append(limit).append("\n"); + sb.append("OFFSET ").append(offset); + + return sb.toString(); + } + + private Model getModel(String query) throws UnsupportedEncodingException, SQLException{ + if(logger.isDebugEnabled()){ + logger.debug("Sending SPARQL query ..."); + logger.debug("Query:\n" + query.toString()); + } + + Model model; + if(cache == null){ + QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); + for (String dgu : endpoint.getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : endpoint.getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + model = queryExecution.execConstruct(); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + if(logger.isDebugEnabled()){ + logger.debug("Got " + model.size() + " new triples in."); + } + return model; + } + + public static void main(String[] args) { + Logger.getRootLogger().setLevel(Level.DEBUG); + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpedia()); + cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 2); + } + +} Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SymmetricConciseBoundedDescriptionGeneratorImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SymmetricConciseBoundedDescriptionGeneratorImpl.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SymmetricConciseBoundedDescriptionGeneratorImpl.java 2011-11-28 08:24:14 UTC (rev 3439) @@ -0,0 +1,197 @@ +package org.dllearner.kb.sparql; + +import java.io.UnsupportedEncodingException; +import java.sql.SQLException; +import java.util.Set; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + +public class SymmetricConciseBoundedDescriptionGeneratorImpl implements ConciseBoundedDescriptionGenerator{ + + private static final Logger logger = Logger.getLogger(SymmetricConciseBoundedDescriptionGeneratorImpl.class); + + private static final int CHUNK_SIZE = 1000; + private static final int DEFAULT_DEPTH = 1; + + private ExtractionDBCache cache; + private SparqlEndpoint endpoint; + + public SymmetricConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, ExtractionDBCache cache) { + this.endpoint = endpoint; + this.cache = cache; + } + + public SymmetricConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint) { + this(endpoint, null); + } + + public Model getConciseBoundedDescription(String resourceURI){ + return getConciseBoundedDescription(resourceURI, DEFAULT_DEPTH); + } + + public Model getConciseBoundedDescription(String resourceURI, int depth){ + Model cbd = ModelFactory.createDefaultModel(); + cbd.add(getModelChunkedResourceIsObject(resourceURI, depth)); + cbd.add(getModelChunkedResourceIsSubject(resourceURI, depth)); + return cbd; + } + + private Model getModelChunkedResourceIsObject(String resource, int depth){ + String query = makeConstructQueryObject(resource, CHUNK_SIZE, 0, depth); + Model all = ModelFactory.createDefaultModel(); + try { + Model model; + if(cache == null){ + model = getModel(query); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + all.add(model); + int i = 1; + while(model.size() != 0){ +// while(model.size() == CHUNK_SIZE){ + query = makeConstructQueryObject(resource, CHUNK_SIZE, i * CHUNK_SIZE, depth); + if(cache == null){ + model = getModel(query); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + all.add(model); + i++; + } + } catch (UnsupportedEncodingException e) { + logger.error(e); + } catch (SQLException e) { + logger.error(e); + } + return all; + } + + private Model getModelChunkedResourceIsSubject(String resource, int depth){ + String query = makeConstructQuerySubject(resource, CHUNK_SIZE, 0, depth); + Model all = ModelFactory.createDefaultModel(); + try { + Model model; + if(cache == null){ + model = getModel(query); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + all.add(model); + int i = 1; + while(model.size() != 0){ +// while(model.size() == CHUNK_SIZE){ + query = makeConstructQuerySubject(resource, CHUNK_SIZE, i * CHUNK_SIZE, depth); + if(cache == null){ + model = getModel(query); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + all.add(model); + i++; + } + } catch (UnsupportedEncodingException e) { + logger.error(e); + } catch (SQLException e) { + logger.error(e); + } + return all; + } + + /** + * A SPARQL CONSTRUCT query is created, to get a RDF graph for the given resource and recursion depth. + * @param resource The resource for which a CONSTRUCT query is created. + * @return The CONSTRUCT query + */ + private String makeConstructQuerySubject(String resource, int limit, int offset, int depth){ + StringBuilder sb = new StringBuilder(); + sb.append("CONSTRUCT {\n"); + sb.append("<").append(resource).append("> ").append("?p0 ").append("?o0").append(".\n"); + for(int i = 1; i < depth; i++){ + sb.append("?o").append(i-1).append(" ").append("?p").append(i).append(" ").append("?o").append(i).append(".\n"); + } + sb.append("}\n"); + sb.append("WHERE {\n"); + sb.append("<").append(resource).append("> ").append("?p0 ").append("?o0").append(".\n"); + for(int i = 1; i < depth; i++){ + sb.append("OPTIONAL{\n"); + sb.append("?o").append(i-1).append(" ").append("?p").append(i).append(" ").append("?o").append(i).append(".\n"); + } + for(int i = 1; i < depth; i++){ + sb.append("}"); + } + sb.append("}\n"); + sb.append("LIMIT ").append(limit).append("\n"); + sb.append("OFFSET ").append(offset); + + return sb.toString(); + } + + /** + * A SPARQL CONSTRUCT query is created, to get a RDF graph for the given resource and recursion depth. + * @param resource The resource for which a CONSTRUCT query is created. + * @return The CONSTRUCT query + */ + private String makeConstructQueryObject(String resource, int limit, int offset, int depth){ + StringBuilder sb = new StringBuilder(); + sb.append("CONSTRUCT {\n"); + sb.append("?s0 ").append("?p0 ").append("<").append(resource).append(">").append(".\n"); + for(int i = 1; i < depth; i++){ + sb.append("?o").append(i).append(" ").append("?p").append(i).append(" ").append("?s").append(i-1).append(".\n"); + } + sb.append("}\n"); + sb.append("WHERE {\n"); + sb.append("?s0 ").append("?p0 ").append("<").append(resource).append(">").append(".\n"); + for(int i = 1; i < depth; i++){ + sb.append("OPTIONAL{\n"); + sb.append("?o").append(i).append(" ").append("?p").append(i).append(" ").append("?s").append(i-1).append(".\n"); + } + for(int i = 1; i < depth; i++){ + sb.append("}"); + } + sb.append("}\n"); + sb.append("LIMIT ").append(limit).append("\n"); + sb.append("OFFSET ").append(offset); + + return sb.toString(); + } + + private Model getModel(String query) throws UnsupportedEncodingException, SQLException{ + if(logger.isDebugEnabled()){ + logger.debug("Sending SPARQL query ..."); + logger.debug("Query:\n" + query.toString()); + } + + Model model; + if(cache == null){ + QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); + for (String dgu : endpoint.getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : endpoint.getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + model = queryExecution.execConstruct(); + } else { + model = cache.executeConstructQuery(endpoint, query); + } + if(logger.isDebugEnabled()){ + logger.debug("Got " + model.size() + " new triples in."); + } + return model; + } + + public static void main(String[] args) { + Logger.getRootLogger().setLevel(Level.DEBUG); + ConciseBoundedDescriptionGenerator cbdGen = new SymmetricConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpedia()); + cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 1); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-27 22:14:28
|
Revision: 3438 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3438&view=rev Author: lorenz_b Date: 2011-11-27 22:14:21 +0000 (Sun, 27 Nov 2011) Log Message: ----------- Added simple method which checks consistency with anti-pattern. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-24 18:11:01 UTC (rev 3437) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2011-11-27 22:14:21 UTC (rev 3438) @@ -2,10 +2,13 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.InputStream; import java.net.URL; import java.util.Collections; -import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.apache.log4j.ConsoleAppender; @@ -19,6 +22,7 @@ import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLOntology; @@ -29,19 +33,26 @@ import com.clarkparsia.owlapi.explanation.PelletExplanation; import com.clarkparsia.pellet.owlapiv3.PelletReasoner; import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.vocabulary.OWL; public class SPARQLSampleDebugging { private SparqlEndpoint endpoint; private ExtractionDBCache cache = new ExtractionDBCache("cache"); - private int sampleSize = 10; - private int depth = 5; - private int nrOfChunks = 10; - private int maxNrOfExplanations = 10; + private int sampleSize = 100; + private int depth = 4; + private int nrOfChunks = 100; + private int maxNrOfExplanations = 20; private Logger logger = Logger.getLogger(SPARQLSampleDebugging.class); @@ -235,9 +246,22 @@ logger.info("Consistent: " + isConsistent); if(!isConsistent){ Set<Set<OWLAxiom>> explanations = computeExplanations(reasoner); + logger.info("Found " + explanations.size() + " explanations."); + Map<AxiomType, Integer> axiomType2CountMap = new HashMap<AxiomType, Integer>(); for(Set<OWLAxiom> explanation : explanations){ logger.info(explanation); + for(OWLAxiom axiom : explanation){ + Integer cnt = axiomType2CountMap.get(axiom.getAxiomType()); + if(cnt == null){ + cnt = Integer.valueOf(0); + } + cnt = Integer.valueOf(cnt + 1); + axiomType2CountMap.put(axiom.getAxiomType(), cnt); + } } + for(Entry<AxiomType, Integer> entry : axiomType2CountMap.entrySet()){ + logger.info(entry.getKey() + "\t: " + entry.getValue()); + } } ontologies.remove(module); reasoner.dispose(); @@ -246,6 +270,32 @@ } + public void runPatternBasedDetection(){ + Model model = ModelFactory.createDefaultModel(); + + //read schema + InputStream in = getClass().getClassLoader().getResourceAsStream("dbpedia_0.75.owl"); + model.read(in, null); + + //read data + ModelGenerator modelGen = new ModelGenerator(endpoint, cache); + model.add(modelGen.createModel("http://dbpedia.org/resource/Leipzig", Strategy.CHUNKS, depth)); + + //query for conflicts + String queryString = "SELECT ?s WHERE {?type1 <" + OWL.disjointWith + "> ?type2. ?s a ?type1. ?s a ?type2.} LIMIT 1"; + Query query = QueryFactory.create(queryString) ; + QueryExecution qexec = QueryExecutionFactory.create(query, model) ; + try { + ResultSet results = qexec.execSelect() ; + for ( ; results.hasNext() ; ) + { + QuerySolution soln = results.nextSolution() ; + Resource r = soln.getResource("s") ; + System.out.println(r.getURI()); + } + } finally { qexec.close() ; } + } + /** * @param args * @throws Exception @@ -261,7 +311,8 @@ SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); - new SPARQLSampleDebugging(endpoint).run3(); + new SPARQLSampleDebugging(endpoint).runPatternBasedDetection(); +// new SPARQLSampleDebugging(endpoint).run3(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-11-24 18:11:08
|
Revision: 3437 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3437&view=rev Author: sebastianwtr Date: 2011-11-24 18:11:01 +0000 (Thu, 24 Nov 2011) Log Message: ----------- [tbsl.exploration] added sqlite function etc Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-11-24 12:19:01 UTC (rev 3436) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-11-24 18:11:01 UTC (rev 3437) @@ -1,5 +1,6 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; import java.io.BufferedReader; + import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -13,6 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import net.didion.jwnl.JWNLException; @@ -28,8 +30,15 @@ import org.dllearner.algorithm.tbsl.templator.BasicTemplator; import org.dllearner.algorithm.tbsl.templator.Templator; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + public class SparqlObject { //global Variable dict @@ -41,19 +50,25 @@ static WordNet wordnet; BasicTemplator btemplator; Templator templator; - private static HashMap<String, String> hm = new HashMap<String, String>(); +/* private static HashMap<String, String> hm = new HashMap<String, String>(); + private static HashMap<String, String> hm_new = new HashMap<String, String>();*/ + private static mySQLDictionary myindex; //Konstruktor - public SparqlObject() throws MalformedURLException{ + public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ wordnet = new WordNet(); //hm=hm_new; - hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity2",hm); - hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity1",hm); + /*hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity2",hm); + hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity1",hm);*/ System.out.println("Loading SPARQL Templator"); btemplator = new BasicTemplator(); templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); + System.out.println("Start Indexing Wikipedia URI's"); + myindex = new mySQLDictionary(); + + System.out.println("Done:Indexing Wikipedia URI's"); setExplorationdepthwordnet(1); //eigentlich immer mit 0 initialisieren setIterationdepth(1); @@ -103,7 +118,7 @@ * "Main" Method of this Class. * */ - public void create_Sparql_query(String question) throws JWNLException, IOException{ + public void create_Sparql_query(String question) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); @@ -215,7 +230,7 @@ //asking server String answer; answer=sendServerQuestionRequest(query); - + System.out.println(query); //if Emty answer, get properties an look up the right property with levensthein if(answer.contains("EmtyAnswer")){ //TODO: get all information from the query @@ -249,7 +264,8 @@ Boolean goOnAfterProperty = true; try { //using uri now, not the string - properties=property.getPropertys(hm.get(rescource.toLowerCase())); + //properties=property.getPropertys(hm.get(rescource.toLowerCase())); + properties=property.getPropertys(getUriFromIndex(rescource.toLowerCase(),0)); if (properties==null){ final_answer.add("Error in getting Properties\n"); goOnAfterProperty=false; @@ -276,7 +292,8 @@ //System.out.println(tmp); //alte property uri mit neuer ersetzen: String query_tmp=query; - query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(i-1)); + //query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(i-1)); + query_tmp=query_tmp.replace(getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties.get(i-1)); //System.out.println("hm.get(property_to_compare_with.toLowerCase(): " + hm.get(property_to_compare_with.toLowerCase())); new_queries.add(query_tmp); } @@ -328,7 +345,9 @@ //create new query result_SemanticsMatchProperties.add(properties.get(h)); String query_tmp=query; - query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(h-1)); + + //query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(h-1)); + query_tmp=query_tmp.replace(getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties.get(h-1)); //System.out.println("hm.get(property_to_compare_with.toLowerCase(): " + hm.get(property_to_compare_with.toLowerCase())); new_queries.add(query_tmp); } @@ -402,13 +421,16 @@ //create_Sparql_query_old(string); // } + + /** * Method gets a String and takes the information from the templator to creat a Sparql query. * @param question question in natural language * @return ArrayList of Sparql queries. + * @throws SQLException */ - private ArrayList<ArrayList<String>> getQuery(String question) { + private ArrayList<ArrayList<String>> getQuery(String question) throws SQLException { ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); for (BasicQueryTemplate temp : querytemps) { @@ -423,6 +445,7 @@ String query; String selTerms =""; for(SPARQL_Term terms :temp.getSelTerms()) selTerms=selTerms+(terms.toString())+" "; + System.out.println(selTerms); String conditions = ""; for(Path condition: temp.getConditions()) conditions=conditions+(condition.toString())+"."; @@ -474,7 +497,9 @@ //System.out.println("replace: " + replace); //hier dann den hm wert von array[1] eintragen - String hm_result=hm.get(array[1].toLowerCase()); + + //String hm_result=hm.get(array[1].toLowerCase()); + String hm_result=getUriFromIndex(array[1].toLowerCase(),0); try { if(hm_result.contains("Category:")) hm_result=hm_result.replace("Category:",""); @@ -515,78 +540,40 @@ - - - private void doIteration(String string1, String string2) throws JWNLException{ - long startTime = System.currentTimeMillis(); - - String string2_uri; - string2_uri=hm.get(string2); - string2_uri=string2_uri.replace("Category:", ""); - string2_uri=string2_uri.replace("category:", ""); - System.out.println("Get Propertys of "+string2); - - //contains uri AND string, every second is the string - ArrayList<String> properties = new ArrayList<String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); - try { - //using uri now, not the string - properties=property.getPropertys(hm.get(string2)); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + /** + * + * @param string + * @param fall 1 Property 0 no Property + * @return + * @throws SQLException + */ + private String getUriFromIndex(String string, int fall) throws SQLException{ + String result=null; + if(fall==0){ + //result=hm.get(string.toLowerCase()); + //if(result==null)result=myindex.getURI(string); + result=myindex.getResourceURI(string.toLowerCase()); + if(result==null)result=myindex.getPropertyURI(string.toLowerCase()); } - - System.out.println("Start Iterating Wordnet with "+string1+" and deept of "+explorationdepthwordnet); - ArrayList<String> semantics=new ArrayList<String>(); - ArrayList<String> tmp_semantics=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - semantics.add(string1); - tmp_semantics=semantics; - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semantics=getSemantics(tmp_semantics); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - + if(fall==1){ + /*result=hm.get(string.toLowerCase()); + if(result==null)result=myindex.getURI(string); + if(result==null)result="http://dbpedia.org/property/"+string.toLowerCase();*/ + //should be alway property an not resource + //result=result.replace("resource", "property"); + result=myindex.getPropertyURI(string.toLowerCase()); + if(result==null){ + result=myindex.getResourceURI(string.toLowerCase()); + result=result.replace("resource", "property"); } - //each word only one time - for(String k : tmp_semantics){ - if(!semantics.contains(k)) semantics.add(k); - } - - } - long endTime = System.currentTimeMillis(); - System.out.println("Getting Properties and Semantics took "+(endTime-startTime) +" ms\n"); - - //TODO: Try, if it works, if you use only one loop: (b.lowerCase).contains(properties.get(h)) - for(int h=1;h<properties.size()-2;h=h+2){ - for(String b : semantics){ - //System.out.println(properties.get(h)); - //System.out.println(b); - if(properties.get(h).contains(b.toLowerCase())){ - if(!result_SemanticsMatchProperties.contains(properties.get(h))) - result_SemanticsMatchProperties.add(properties.get(h)); - } - } + } - for(String b : result_SemanticsMatchProperties){ - string1=b.toLowerCase(); - String anfrage; - String string1_uri; - string1_uri=hm.get(string1); - if(string1_uri!=null){ - anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+string2_uri+"> <"+string1_uri+"> ?x.}"; - System.out.println("Answer with the property \" " + b + "\" :\n"+sendServerQuestionRequest(anfrage)); - } - } - long endTime2 = System.currentTimeMillis(); - System.out.println("Getting Properties, Semantics and Answer from server took "+(endTime2-startTime) +" ms"); + + if(result==null) return "http://dbpedia.org/property/"+string.toLowerCase(); + else return result; } - + private static ArrayList<String> getSemantics (ArrayList<String> semantics) throws IOException, JWNLException { @@ -612,6 +599,7 @@ private String sendServerQuestionRequest(String query){ //SPARQL-Endpoint of Semantic Computing Group String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + System.out.println(tmp); URL url; InputStream is; InputStreamReader isr; @@ -711,8 +699,14 @@ return query; } + + + + } + + /** * Cluster function */ Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 2011-11-24 18:11:01 UTC (rev 3437) @@ -0,0 +1,309 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +public class mySQLDictionary { + private Connection conn; + + public mySQLDictionary() throws ClassNotFoundException, SQLException { + // TODO Auto-generated constructor stub + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:"); + createIndexPropertys(); + createIndexResource(); + + //optional!! + //createIndexWikipedia(); + + } + +private String createSimpleHashKey(String string){ + string = string.replace("!",""); + string = string.replace(":",""); + string = string.replace("/",""); + string = string.replace("\\",""); + string = string.replace("?",""); + string = string.replace(":",""); + + string = string.replace("a","1"); + string = string.replace("b","2"); + string = string.replace("c","3"); + string = string.replace("d","4"); + string = string.replace("e","5"); + string = string.replace("f","6"); + string = string.replace("g","7"); + string = string.replace("h","8"); + string = string.replace("i","9"); + string = string.replace("j","10"); + string = string.replace("k","11"); + string = string.replace("l","12"); + string = string.replace("m","13"); + string = string.replace("n","14"); + string = string.replace("o","15"); + string = string.replace("p","16"); + string = string.replace("q","17"); + string = string.replace("r","18"); + string = string.replace("s","19"); + string = string.replace("t","20"); + string = string.replace("u","21"); + string = string.replace("v","22"); + string = string.replace("w","23"); + string = string.replace("x","24"); + string = string.replace("y","25"); + string = string.replace("z","26"); + string = string.replace("ä","0"); + string = string.replace("ö","0"); + string = string.replace("ü","0"); + string = string.replace("?","0"); + string = string.replace(" ","0"); + return string; + + +} + + public String getResourceURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from resource where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + } + + public String getPropertyURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from property where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + public String getWikipediaURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from wikiindex where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + + private void createIndexWikipedia() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test"); + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:");*/ + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists wikiindex;"); + stat.executeUpdate("create table wikiindex (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into wikiindex values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/URIsFromWikipedia" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split("::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + //if(zaehler%100000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + System.out.println("done"); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Done"); + //Statement stat = conn.createStatement(); + /* long start = System.currentTimeMillis(); + // zu messender Code + + ResultSet rs = stat.executeQuery("select * from people where name='kornyval';"); + while (rs.next()) + { + System.out.println("name = " + rs.getString("name")); + System.out.println("job = " + rs.getString("occupation")); + } + System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); + + start = System.currentTimeMillis(); + // zu messender Code + + rs = stat.executeQuery("select * from people where name='barack obama';"); + while (rs.next()) + { + System.out.println("name = " + rs.getString("name")); + System.out.println("job = " + rs.getString("occupation")); + } + System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); + + rs = stat.executeQuery("select * from people where name='kornyval';"); + while (rs.next()) + { + System.out.println("name = " + rs.getString("name")); + System.out.println("job = " + rs.getString("occupation")); + } + System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); + + + rs.close();*/ + // conn.close(); + } +private void createIndexPropertys() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test"); + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:");*/ + System.out.println("start indexing Properties"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists property;"); + stat.executeUpdate("create table property (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into property values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/property" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[1]); + prep.setString(2, tmp_array[0]); + prep.addBatch(); + zaehler=zaehler+1; + //if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + System.out.println("done"); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Done"); + + } +private void createIndexResource() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test");*/ + System.out.println("start indexing Resources"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists resource;"); + stat.executeUpdate("create table resource (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into resource values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/resource" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[1]); + prep.setString(2, tmp_array[0]); + prep.addBatch(); + zaehler=zaehler+1; + // if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + System.out.println("done"); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Done"); + + } + +} \ No newline at end of file Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2011-11-24 12:19:01 UTC (rev 3436) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2011-11-24 18:11:01 UTC (rev 3437) @@ -13,7 +13,11 @@ import net.didion.jwnl.JWNLException; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; -import org.dllearner.algorithm.tbsl.exploration.sax.ParseXmlHtml; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; /* * @@ -21,6 +25,18 @@ * in Eclipse Run -> RunConfigurations -> Arguments -> VM Arguments -> -Xmx1024m */ +/* + * + * + * for pom.xml file + * <dependencies> + <dependency> + <groupId>org.xerial</groupId> + <artifactId>sqlite-jdbc</artifactId> + <version>3.6.16</version> + </dependency> + </dependencies> + */ // Sax example from http://www.bennyn.de/programmierung/java/java-xml-sax-parser.html /* @@ -39,14 +55,15 @@ * @throws IOException * @throws JWNLException * @throws InterruptedException + * @throws ClassNotFoundException + * @throws SQLException */ - public static void main(String[] args) throws IOException, JWNLException, InterruptedException { + public static void main(String[] args) throws IOException, JWNLException, InterruptedException, ClassNotFoundException, SQLException { /** * Do the starting initializing stuff */ long startInitTime = System.currentTimeMillis(); - System.out.println("Start Indexing"); //For testing! @@ -168,5 +185,7 @@ return name; } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-24 12:19:11
|
Revision: 3436 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3436&view=rev Author: lorenz_b Date: 2011-11-24 12:19:01 +0000 (Thu, 24 Nov 2011) Log Message: ----------- Changes to be able to load conf files under. Windows . Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-11-24 12:17:25 UTC (rev 3435) +++ trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-11-24 12:19:01 UTC (rev 3436) @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.net.URI; +import java.net.URISyntaxException; import java.util.Collection; import java.util.LinkedList; @@ -100,7 +101,7 @@ /** Leave it as is */ kb = KBParser.parseKBFile(getUrl()); } else { - File f = new File(baseDir, getUrl()); + File f = new File(new URI(baseDir + File.separator + getUrl())); setUrl(f.toURI().toString()); kb = KBParser.parseKBFile(f); } @@ -114,7 +115,9 @@ throw new ComponentInitException("KB file " + getUrl() + " could not be parsed correctly.", e); }catch (FileNotFoundException e) { throw new ComponentInitException("KB file " + getUrl() + " could not be found.", e); - } + } catch (URISyntaxException e) { + throw new ComponentInitException("KB file " + getUrl() + " could not be found.", e); + } } /* Modified: trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2011-11-24 12:17:25 UTC (rev 3435) +++ trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2011-11-24 12:19:01 UTC (rev 3436) @@ -127,7 +127,8 @@ } else if (url == null) { try { - url = new URL("file://" + baseDir + "/" + fileName); +// url = new URL("file://" + baseDir + "/" + fileName); + url = new URL(baseDir + "/" + fileName); } catch (MalformedURLException e) { throw new RuntimeException(e); } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java 2011-11-24 12:17:25 UTC (rev 3435) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java 2011-11-24 12:19:01 UTC (rev 3436) @@ -29,7 +29,8 @@ public ConfParserConfiguration(Resource source) { try { - baseDir = source.getFile().getAbsoluteFile().getParent(); +// baseDir = source.getFile().getAbsoluteFile().getParent(); + baseDir = source.getFile().getParentFile().toURI().toString(); parser = new ConfParser(source.getInputStream()); parser.Start(); } catch (ParseException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-24 12:17:36
|
Revision: 3435 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3435&view=rev Author: lorenz_b Date: 2011-11-24 12:17:25 +0000 (Thu, 24 Nov 2011) Log Message: ----------- Updated syntax. Modified Paths: -------------- trunk/examples/family/daughter.conf trunk/examples/family/father.conf trunk/examples/family/grandfather.conf trunk/examples/family/uncle.conf Modified: trunk/examples/family/daughter.conf =================================================================== --- trunk/examples/family/daughter.conf 2011-11-24 09:45:15 UTC (rev 3434) +++ trunk/examples/family/daughter.conf 2011-11-24 12:17:25 UTC (rev 3435) @@ -1,22 +1,39 @@ -/** - * Example "grandfather with daughter" - * - * possible solution: - * male AND EXISTS hasDaughter.EXISTS hasChild.TOP - * male AND EXISTS hasChild.(female AND EXISTS hasChild.TOP) - * - * Copyright (C) 2007, Jens Lehmann - */ +// declare some prefixes to use as abbreviations +prefixes = [ ("kb","http://localhost/foo#") ] -/** background knowledge ***/ -import("daughter.kb"); +// knowledge source definition +ks.type = "KB File" +ks.url = "daughter.kb" +// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. -/** examples **/ --stefan -+markus -+bernd --heinz --anna --gabi --michelle --franz +// reasoner +reasoner.type = "fast instance checker" +reasoner.reasonerComponent = embeddedReasoner + +embeddedReasoner.type = "OWL API Reasoner" +embeddedReasoner.sources = { ks } + +// learning problem +lp.type = "posNegStandard" +lp.positiveExamples = {"kb:markus","kb:bernd"} +lp.negativeExamples = {"kb:heinz","kb:anna","kb:gabi","kb:michelle","kb:stefan","kb:franz"} + +// plug a reasoner into the learning problem +lp.reasoner = reasoner +//lp.reasoner = reasoner - try to remove the component:part in the parser + +// create a refinement operator and configure it +op.type = "rho" +op.useCardinalityRestrictions = true +op.reasoner = reasoner + +// create a heuristic and configure it +h.type = "multiheuristic" +h.expansionPenaltyFactor = 0.2 + +// create learning algorithm to run +alg.type = "ocel" +alg.reasoner = reasoner +alg.operator = op +alg.heuristic = h +alg.maxExecutionTimeInSeconds = 15 Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-11-24 09:45:15 UTC (rev 3434) +++ trunk/examples/family/father.conf 2011-11-24 12:17:25 UTC (rev 3435) @@ -44,7 +44,6 @@ alg.type = "ocel" alg.reasoner = reasoner alg.operator = op -alg.learningProblem = lp alg.heuristic = h alg.maxExecutionTimeInSeconds = 15 Modified: trunk/examples/family/grandfather.conf =================================================================== --- trunk/examples/family/grandfather.conf 2011-11-24 09:45:15 UTC (rev 3434) +++ trunk/examples/family/grandfather.conf 2011-11-24 12:17:25 UTC (rev 3435) @@ -10,21 +10,42 @@ * Copyright (C) 2007, Jens Lehmann */ -/** background knowledge ***/ +// declare some prefixes to use as abbreviations +prefixes = [ ("kb","http://localhost/foo#") ] -import("grandfather.kb"); +// knowledge source definition +ks.type = "KB File" +ks.url = "grandfather.kb" +// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. -/** examples **/ -+m1 --m2 --m3 --m4 -+m5 --m6 -+m7 --f1 --f2 --f3 --f4 --f5 --f6 +// reasoner +reasoner.type = "fast instance checker" +reasoner.reasonerComponent = embeddedReasoner + +embeddedReasoner.type = "OWL API Reasoner" +embeddedReasoner.sources = { ks } + +// learning problem +lp.type = "posNegStandard" +lp.positiveExamples = {"kb:m1","kb:m5", "kb:m7"} +lp.negativeExamples = {"kb:m2","kb:m3", "kb:m4","kb:m6","kb:f1", "kb:f2","kb:f3", "kb:f4","kb:f5", "kb:f6"} + +// plug a reasoner into the learning problem +lp.reasoner = reasoner +//lp.reasoner = reasoner - try to remove the component:part in the parser + +// create a refinement operator and configure it +op.type = "rho" +op.useCardinalityRestrictions = true +op.reasoner = reasoner + +// create a heuristic and configure it +h.type = "multiheuristic" +h.expansionPenaltyFactor = 0.2 + +// create learning algorithm to run +alg.type = "ocel" +alg.reasoner = reasoner +alg.operator = op +alg.heuristic = h +alg.maxExecutionTimeInSeconds = 15 Modified: trunk/examples/family/uncle.conf =================================================================== --- trunk/examples/family/uncle.conf 2011-11-24 09:45:15 UTC (rev 3434) +++ trunk/examples/family/uncle.conf 2011-11-24 12:17:25 UTC (rev 3435) @@ -13,23 +13,42 @@ * * Copyright (C) 2007, Jens Lehmann */ +// declare some prefixes to use as abbreviations +prefixes = [ ("kb","http://localhost/foo#") ] -/** background knowledge ***/ -import("uncle.kb"); +// knowledge source definition +ks.type = "KB File" +ks.url = "uncle.kb" +// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. -/** examples **/ -+heinrich -+alfred -+heinz -+hans -+alex --jan --markus --susi --anna --maria --katrin --johanna --mandy --miriam --hanna +// reasoner +reasoner.type = "fast instance checker" +reasoner.reasonerComponent = embeddedReasoner + +embeddedReasoner.type = "OWL API Reasoner" +embeddedReasoner.sources = { ks } + +// learning problem +lp.type = "posNegStandard" +lp.positiveExamples = {"kb:heinrich","kb:alfred","kb:heinz","kb:hans","kb:alex"} +lp.negativeExamples = {"kb:jan","kb:markus","kb:susi","kb:anna","kb:maria","kb:katrin","kb:johanna","kb:mandy","kb:miriam","kb:hanna"} + +// plug a reasoner into the learning problem +lp.reasoner = reasoner +//lp.reasoner = reasoner - try to remove the component:part in the parser + +// create a refinement operator and configure it +op.type = "rho" +op.useCardinalityRestrictions = true +op.reasoner = reasoner + +// create a heuristic and configure it +h.type = "multiheuristic" +h.expansionPenaltyFactor = 0.2 + +// create learning algorithm to run +alg.type = "ocel" +alg.reasoner = reasoner +alg.operator = op +alg.heuristic = h +alg.maxExecutionTimeInSeconds = 15 \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-24 09:45:26
|
Revision: 3434 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3434&view=rev Author: lorenz_b Date: 2011-11-24 09:45:15 +0000 (Thu, 24 Nov 2011) Log Message: ----------- MAde Template comparable. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java 2011-11-23 18:49:11 UTC (rev 3433) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java 2011-11-24 09:45:15 UTC (rev 3434) @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; -public class Template implements Serializable{ +public class Template implements Serializable, Comparable<Template>{ private static final long serialVersionUID = -3925093269596915997L; @@ -52,5 +52,10 @@ } return null; } + + @Override + public int compareTo(Template o) { + return getQuery().toString().compareTo(o.getQuery().toString()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <km...@us...> - 2011-11-23 18:49:18
|
Revision: 3433 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3433&view=rev Author: kmpf Date: 2011-11-23 18:49:11 +0000 (Wed, 23 Nov 2011) Log Message: ----------- Amino Acid Properties changed Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-11-23 14:24:16 UTC (rev 3432) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-11-23 18:49:11 UTC (rev 3433) @@ -117,32 +117,122 @@ return resourceString; } - public static HashMap<String, String> getAminoAcidArffAttributeMap(){ +/* + ++++ Amino acid names and numbers ++++ +Every line starts with the one-letter-code, followed by their numeric representation for .arff files, +followed by their three-letter-code and finally their name. + A = 1 Ala Alanin + C = 3 Cys Cystein + D = 4 Asp Aspartat + E = 5 Glu Glutamat + F = 6 Phe Phenylalanin + G = 7 Gly Glycin + H = 8 His Histidin + I = 9 Ile Isoleucin + K = 11 Lys Lysin + L = 12 Leu Leucin + M = 13 Met Methionin + N = 14 Asn Asparagin + O = 15 Pyl Pyrrolysin + P = 16 Pro Prolin + Q = 17 Gln Glutamin + R = 18 Arg Arginin + S = 19 Ser Serin + T = 20 Thr Threonin + U = 21 Sec Selenocystein + V = 22 Val Valin + W = 23 Trp Tryptophan + Y = 25 Tyr Tyrosin +*/ + public static HashMap<String, String> getAminoAcidNumber(){ + HashMap<String,String> resnum = new HashMap<String, String>(30); + resnum.put(new String("A"), new String("1")); + resnum.put(new String("C"), new String("3")); + resnum.put(new String("D"), new String("4")); + resnum.put(new String("E"), new String("5")); + resnum.put(new String("F"), new String("6")); + resnum.put(new String("G"), new String("7")); + resnum.put(new String("H"), new String("8")); + resnum.put(new String("I"), new String("9")); + resnum.put(new String("K"), new String("11")); + resnum.put(new String("L"), new String("12")); + resnum.put(new String("M"), new String("13")); + resnum.put(new String("N"), new String("14")); + resnum.put(new String("O"), new String("15")); + resnum.put(new String("P"), new String("16")); + resnum.put(new String("Q"), new String("17")); + resnum.put(new String("R"), new String("18")); + resnum.put(new String("S"), new String("19")); + resnum.put(new String("T"), new String("20")); + resnum.put(new String("U"), new String("21")); + resnum.put(new String("V"), new String("22")); + resnum.put(new String("W"), new String("23")); + resnum.put(new String("Y"), new String("25")); + + return resnum; + } + + public static HashMap<String, String> getAminoAcidNumericArffAttributeMap(){ + // Hydrophobicity hydrophilic = 0; Hydrophobic = 1; aromatic = 2; aliphatic = 3 + // Polarity unpolar = 0; polar = 1; positive = 2; negative = 3; + // Size Tiny = 0; Small = 1; Large = 2; HashMap<String, String> resdata = new HashMap<String, String>(30); - resdata.put(new String("A"), new String("2,0,0.5,?,?")); - resdata.put(new String("C"), new String("1,0,1,?,0")); - resdata.put(new String("D"), new String("0,-1,1,?,-1")); - resdata.put(new String("E"), new String("0,-1,2,?,-1")); - resdata.put(new String("F"), new String("2,0,2,1,?")); - resdata.put(new String("G"), new String("2,0,0.5,?,?")); - resdata.put(new String("H"), new String("1,1,2,1,1")); - resdata.put(new String("I"), new String("2,0,2,0,?")); - resdata.put(new String("K"), new String("1,1,2,?,1")); - resdata.put(new String("L"), new String("2,0,2,0,?")); - resdata.put(new String("M"), new String("2,0,2,?,?")); - resdata.put(new String("N"), new String("0,0,1,?,0")); - resdata.put(new String("P"), new String("?,0,1,?,?")); - resdata.put(new String("Q"), new String("0,0,2,?,0")); - resdata.put(new String("R"), new String("0,1,2,?,1")); - resdata.put(new String("S"), new String("0,0,0.5,?,0")); - resdata.put(new String("T"), new String("1,0,1,?,0,")); - resdata.put(new String("V"), new String("2,0,1,0,?")); - resdata.put(new String("W"), new String("1,0,2,1,1")); - resdata.put(new String("Y"), new String("1,0,2,1,0")); - resdata.put(new String("U"), new String("?,?,?,?,?")); + resdata.put(new String("A"), new String("1,0,0")); + resdata.put(new String("C"), new String("1,1,0")); + resdata.put(new String("D"), new String("0,3,1")); + resdata.put(new String("E"), new String("0,3,2")); + resdata.put(new String("F"), new String("2,0,2")); + resdata.put(new String("G"), new String("1,0,0")); + resdata.put(new String("H"), new String("2,2,2")); + resdata.put(new String("I"), new String("3,0,2")); + resdata.put(new String("K"), new String("1,2,2")); + resdata.put(new String("L"), new String("3,0,2")); + resdata.put(new String("M"), new String("1,0,2")); + resdata.put(new String("N"), new String("0,1,1")); + resdata.put(new String("O"), new String("?,?,?")); + resdata.put(new String("P"), new String("0,0,1")); + resdata.put(new String("Q"), new String("0,1,2")); + resdata.put(new String("R"), new String("0,2,2")); + resdata.put(new String("S"), new String("0,1,0")); + resdata.put(new String("T"), new String("1,1,1")); + resdata.put(new String("V"), new String("3,0,1")); + resdata.put(new String("W"), new String("2,1,2")); + resdata.put(new String("X"), new String("?,?,?")); // unknown residue (e.g. modified amino acids) + resdata.put(new String("Y"), new String("2,1,2")); + resdata.put(new String("U"), new String("?,?,?")); + return resdata; + } + + public static HashMap<String, String> getAminoAcidNominalArffAttributeMap(){ + // Hydrophobicity hydrophilic = 0; Hydrophobic = 1; aromatic = 2; aliphatic = 3 + // Polarity unpolar = 0 polar = 1; positive = 2; negative = 3; + // Size Tiny = 0; Small = 1; Large = 2; + HashMap<String, String> resdata = new HashMap<String, String>(30); + + resdata.put(new String("A"), new String("Hydrophobic,Unpolar,Tiny")); + resdata.put(new String("C"), new String("Hydrophobic,Polar,Tiny")); + resdata.put(new String("D"), new String("Hydrophilic,Negative,Small")); + resdata.put(new String("E"), new String("Hydrophilic,Negative,Large")); + resdata.put(new String("F"), new String("Aromatic,Unpolar,Large")); + resdata.put(new String("G"), new String("Hydrophobic,Unpolar,Tiny")); + resdata.put(new String("H"), new String("Aromatic,Positive,Large")); + resdata.put(new String("I"), new String("Aliphatic,Unpolar,Large")); + resdata.put(new String("K"), new String("Hydrophobic,Positive,Large")); + resdata.put(new String("L"), new String("Aliphatic,Unpolar,Large")); + resdata.put(new String("M"), new String("Hydrophobic,Unpolar,Large")); + resdata.put(new String("N"), new String("Hydrophilic,Polar,Small")); + resdata.put(new String("O"), new String("?,?,?")); + resdata.put(new String("P"), new String("Hydrophilic,Unpolar,Small")); + resdata.put(new String("Q"), new String("Hydrophilic,Polar,Large")); + resdata.put(new String("R"), new String("Hydrophilic,Positive,Large")); + resdata.put(new String("S"), new String("Hydrophilic,Polar,Tiny")); + resdata.put(new String("T"), new String("Hydrophobic,Polar,Small")); + resdata.put(new String("V"), new String("Aliphatic,Unpolar,Small")); + resdata.put(new String("W"), new String("Aromatic,Polar,Large")); + resdata.put(new String("X"), new String("?,?,?")); // unknown residue (e.g. modified amino acids) + resdata.put(new String("Y"), new String("Aromatic,Polar,Large")); + resdata.put(new String("U"), new String("?,?,?")); return resdata; } - - } Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-11-23 14:24:16 UTC (rev 3432) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-11-23 18:49:11 UTC (rev 3433) @@ -20,8 +20,6 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblemUnsupportedException; - -import com.hp.hpl.jena.rdf.model.NodeIterator; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.ResIterator; import com.hp.hpl.jena.rdf.model.Resource; @@ -176,7 +174,8 @@ if (arff) { ResIterator niter = trainmodel.getFirstAA(); - createArffFile(pdbDir, trainmodel, niter); + createNumericArffFile(pdbDir, trainmodel, niter); + createNominalArffFile(pdbDir, trainmodel, niter); } /* @@ -361,7 +360,7 @@ // add knowledge source definition to <PDB ID>.conf files confFile.println(ks); - + // add knowledge source definition to <PDB ID>_<Amino Acid>.conf files Iterator<Resource> resources = resprint.keySet().iterator(); while (resources.hasNext()){ @@ -451,13 +450,14 @@ } } - private static void createArffFile(String pdbDir, PDBIdRdfModel model, ResIterator firstAAs){ + private static void createNumericArffFile(String pdbDir, PDBIdRdfModel model, ResIterator firstAAs){ try { PDBProtein protein = model.getProtein(); String arffFilePath = pdbDir + protein.getArffFileName(); + arffFilePath = arffFilePath.replace(".arff", ".numeric.arff"); PrintStream out = new PrintStream (arffFilePath); - _logger.debug("Creating ARFF file: " + arffFilePath); + _logger.debug("Creating numeric ARFF file: " + arffFilePath); /* * RELATION @@ -470,14 +470,16 @@ * ATTRIBUTES */ // Integer declaring Position in chain - StringBuffer attributes = new StringBuffer("@ATTRIBUTE hydrophob NUMERIC\n" + // Hydrophilic = 0; Hydrophobic = 1; Very_hydrophobic = 2 - "@ATTRIBUTE charge NUMERIC\n" + // Negative = -1; Neutral = 0; Positive = 1 - "@ATTRIBUTE size NUMERIC\n" + // Large = 2; Small = 1; Tiny = 0.5 - "@ATTRIBUTE aromaticity NUMERIC\n" + // Aliphatic = 0; Aromatic = 1 - "@ATTRIBUTE hydrogen_bonding NUMERIC\n"); // Donor = 1; Donor/Acceptor = 0; Acceptor = -1 + StringBuffer attributes = new StringBuffer( + // Hydrophobicity hydrophilic = 0; Hydrophobic = 1; aromatic = 2; aliphatic = 3 + "@ATTRIBUTE hydrophobicity NUMERIC\n" + + // Polarity unpolar = 0 polar = 1; positive = 2; negative = 3; + "@ATTRIBUTE polarity NUMERIC\n" + + // Size Tiny = 0; Small = 1; Large = 2; + "@ATTRIBUTE size NUMERIC\n"); for (int i = -8; i <= 8; i++) { - attributes.append("@ATTRIBUTE aa_position_" + i + " {A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y}\n"); // amino acid at position $i from current amino acid + attributes.append("@ATTRIBUTE aa_position_" + i + " NUMERIC\n"); // amino acid at position $i from current amino acid } attributes.append("@ATTRIBUTE in_helix NUMERIC\n"); // Helix = 1 Other = 0 @@ -492,14 +494,14 @@ out.println(data); // HashMap containing information about the properties of every amino acid - HashMap<String, String> resdata = AminoAcids.getAminoAcidArffAttributeMap(); + HashMap<String, String> resdata = AminoAcids.getAminoAcidNumericArffAttributeMap(); + HashMap<String, String> resnum = AminoAcids.getAminoAcidNumber(); ArrayList<Resource> positives = model.getPositives(); ArrayList<Resource> negatives = model.getNegatives(); - Property type = ResourceFactory.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "type"); - Property iib = ResourceFactory.createProperty("http://bio2rdf.org/pdb:", "isImmediatelyBefore"); String sequence = protein.getSequence(); HashMap<Integer, Resource> posRes = model.getPositionResource(); + for ( int i = 0; i < sequence.length(); i++) { StringBuffer dataLine = new StringBuffer(""); String key = Character.toString( sequence.charAt(i) ); @@ -509,13 +511,14 @@ dataLine.append( resdata.get(key) + "," ); } else { // - dataLine.append( resdata.get("U") + "," ); + dataLine.append( resdata.get("X") + "," ); } // add information about neighbouring amino acids to dataLine for (int j = (i - 8); j <= (i + 8) ; j++){ try { - dataLine.append( protein.getSequence().charAt(j) + "," ); + dataLine.append( resnum.get( + Character.toString(protein.getSequence().charAt(j))) + "," ); } catch (IndexOutOfBoundsException e) { dataLine.append( "?," ); } @@ -538,50 +541,96 @@ } catch (FileNotFoundException e){ e.printStackTrace(); } + } + + private static void createNominalArffFile(String pdbDir, PDBIdRdfModel model, ResIterator firstAAs){ + + try { + PDBProtein protein = model.getProtein(); + String arffFilePath = pdbDir + protein.getArffFileName(); + arffFilePath = arffFilePath.replace(".arff", ".nominal.arff"); + PrintStream out = new PrintStream (arffFilePath); + _logger.debug("Creating nominal ARFF file: " + arffFilePath); + + /* + * RELATION + */ + String relation = "@RELATION " + protein.getPdbID(); + out.println(relation); + _logger.debug(relation); + /* + * ATTRIBUTES + */ + // Integer declaring Position in chain + StringBuffer attributes = new StringBuffer( + // Hydrophobicity hydrophilic = 0; hydrophobic = 1; aromatic = 2; aliphatic = 3 + "@ATTRIBUTE hydrophob {hydrophilic, hydrophobic, aromatic, aliphatic}\n" + // Hydrophilic = 0; Hydrophobic = 1; Very_hydrophobic = 2 + // Polarity unpolar = 0; polar = 1; positive = 2; negative = 3; + "@ATTRIBUTE charge {unpolar, polar, positive, negative}\n" + // Negative = -1; Neutral = 0; Positive = 1 + // Size tiny = 0; small = 1; large = 2; + "@ATTRIBUTE size {tiny, small, large}\n"); + + for (int i = -8; i <= 8; i++) { + attributes.append("@ATTRIBUTE aa_position_" + i + " {A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y}\n"); // amino acid at position $i from current amino acid + } + attributes.append("@ATTRIBUTE in_helix {Helix, Non_helix}\n"); // Helix = 1 Other = 0 + + _logger.debug(attributes); + out.println(attributes); -/* // to be exchanged - while (firstAAs.hasNext()){ - Resource firstAA = firstAAs.next(); - Resource currentAA = firstAA; - Resource nextAA = firstAA; + /* + * @DATA + */ + String data = "@DATA\n"; + _logger.debug(data); + out.println(data); + + // HashMap containing information about the properties of every amino acid + HashMap<String, String> resdata = AminoAcids.getAminoAcidNominalArffAttributeMap(); + ArrayList<Resource> positives = model.getPositives(); + ArrayList<Resource> negatives = model.getNegatives(); + String sequence = protein.getSequence(); + HashMap<Integer, Resource> posRes = model.getPositionResource(); + + for ( int i = 0; i < sequence.length(); i++) { + StringBuffer dataLine = new StringBuffer(""); + String key = Character.toString( sequence.charAt(i) ); + + // add amino acid description to dataLine + if ( resdata.containsKey(key) ){ + dataLine.append( resdata.get(key) + "," ); + } else { + // + dataLine.append( resdata.get("X") + "," ); + } + // add information about neighbouring amino acids to dataLine + for (int j = (i - 8); j <= (i + 8) ; j++){ + try { + dataLine.append( protein.getSequence().charAt(j) + "," ); + } catch (IndexOutOfBoundsException e) { + dataLine.append( "?," ); + } + } + // add information about positive or negative to dataLine + if (positives.contains( posRes.get( new Integer(i) ))){ + dataLine.append( "Helix" ); + } else if (negatives.contains( posRes.get( new Integer(i) ))){ + dataLine.append( "Non_helix" ); + } else { + dataLine.append( "?" ); + } - for ( int i = 0; currentAA.hasProperty(iib); i++ ) { - StringBuffer dataLine = new StringBuffer(""); - currentAA = nextAA; - - NodeIterator niter = model.getModel().listObjectsOfProperty(currentAA, type); - while (niter.hasNext()){ - Resource key = niter.next().asResource(); - if (resdata.containsKey(key)){ - dataLine.append( resdata.get(key) + "," ); - } - } - - for (int j = (i - 8); j <= (i + 8) ; j++){ - try { - dataLine.append( protein.getSequence().charAt(j) + "," ); - } catch (IndexOutOfBoundsException e) { - dataLine.append( "?," ); - } - } - - if (positives.contains(currentAA)){ - dataLine.append( "1" ); - } else if (negatives.contains(currentAA)){ - dataLine.append( "0" ); - } else { - dataLine.append( "?" ); - } + _logger.info(dataLine); + out.println(dataLine); + + } + + } catch (FileNotFoundException e){ + e.printStackTrace(); + } + } - - - // get next AA if there is one - if (model.getModel().contains(currentAA, iib)){ - nextAA = model.getModel().getProperty(currentAA, iib).getResource(); - } -*/ - } } Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-11-23 14:24:16 UTC (rev 3432) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-11-23 18:49:11 UTC (rev 3433) @@ -52,7 +52,7 @@ this.getProtein().setSpecies(extractSpecies(_pdbIdModel)); System.out.println("Species: " + this.getProtein().getSpecies()); createPositivesAndNegatives(); - _positionResource = createPositionResidueMap(); + this._positionResource = createPositionResidueMap(); } public PdbRdfModel getModel(){ @@ -160,15 +160,15 @@ Resource polymerSequence = ResourceFactory.createResource("http://bio2rdf.org/pdb:PolymerSequence"); ResIterator riter = model.listResourcesWithProperty(type, polymerSequence); - while (riter.hasNext()){ - Resource nextRes = riter.next(); + while (riter.hasNext()) { + Resource nextRes = riter.nextResource(); if (model.contains(nextRes, hasValue)){ NodeIterator niter = model.listObjectsOfProperty(nextRes, hasValue); sequence = niter.next().toString(); System.out.println("Sequence: " + sequence); } - } + } ; return sequence; } @@ -230,7 +230,6 @@ // a amino acid is followed " OPTIONAL { ?x5 pdb:isImmediatelyBefore ?x7 . } . " + " ?x5 pdb:hasChainPosition ?x8 ." + - " ?x8 rdfs:label ?residuePosition ." + " ?x8 pdb:hasValue ?x9 Filter (xsd:int(?x9)) ."; if (chainID.length() == 1 && pdbID.length() == 4) { @@ -283,7 +282,7 @@ Property iib = ResourceFactory.createProperty("http://bio2rdf.org/pdb:", "isImmediatelyBefore"); ResIterator firstAAs = this.getFirstAA(); - while ( firstAAs.hasNext()){ + while ( firstAAs.hasNext()) { Resource firstAA = firstAAs.next(); Resource currentAA = firstAA; posres.put(new Integer(this.getResiduePosition(currentAA)), currentAA); @@ -311,8 +310,7 @@ while ( positionLabelNodes.hasNext() ) { positionLabels.add(positionLabelNodes.next().asLiteral().getInt()); } - - } + } Integer position = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |