From: <ku...@us...> - 2008-09-23 23:06:50
|
Revision: 1243 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1243&view=rev Author: kurzum Date: 2008-09-23 23:06:40 +0000 (Tue, 23 Sep 2008) Log Message: ----------- switched SparqlKnowledgeSource output to RDF/XML. This will be necessary to include blanknodes. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java trunk/src/dl-learner/org/dllearner/core/configurators/Configurator.java trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/DatatypePropertyNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/LiteralNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/scripts/NT2RDF.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBible2.java trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/aquisitors/BlankNodeCollector.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/OWLAPIOntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java Modified: trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; @@ -42,6 +42,7 @@ import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; import org.dllearner.learningproblems.PosOnlyInclusionLP; +import org.dllearner.learningproblems.RoleLearning; import org.dllearner.reasoning.DIGReasoner; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.FastRetrievalReasoner; @@ -167,6 +168,16 @@ } /** +* @param positiveExamples positive examples +* @param negativeExamples negative examples +* @param reasoningService see ReasoningService +* @return a component ready for initialization RoleLearning +**/ +public static RoleLearning getRoleLearning(ReasoningService reasoningService, Set<String> positiveExamples, Set<String> negativeExamples) { +return RoleLearningConfigurator.getRoleLearning(reasoningService, positiveExamples, negativeExamples); +} + +/** * @param learningProblem see LearningProblem * @param reasoningService see ReasoningService * @throws LearningProblemUnsupportedException see Modified: trunk/src/dl-learner/org/dllearner/core/configurators/Configurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/Configurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/Configurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Modified: trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -16,7 +16,7 @@ * 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.core.configurators; Added: trunk/src/dl-learner/org/dllearner/kb/aquisitors/BlankNodeCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/BlankNodeCollector.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/BlankNodeCollector.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -0,0 +1,93 @@ +package org.dllearner.kb.aquisitors; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSetRewindable; + +public class BlankNodeCollector { + + private static int globalBNodeId = 0; + public static synchronized int getNextGlobalBNodeId(){ + int ret = globalBNodeId; + globalBNodeId++; + return ret; + } + + private static Map<Integer, SortedSet<RDFNodeTuple>> blankNodes = new HashMap<Integer, SortedSet<RDFNodeTuple>>(); + + public static void addBlankNode(int id, RDFNodeTuple t){ + if(blankNodes.get(id)==null){ + blankNodes.put(id, new TreeSet<RDFNodeTuple>()); + } + blankNodes.get(id).add(t); + } + + public static SortedSet<RDFNodeTuple> getBlankNode(int id){ + return blankNodes.get(id); + } + + public static Map<Integer, SortedSet<RDFNodeTuple>> getBlankNodeMap(){ + return blankNodes; + } + + + public static boolean testResultSet(ResultSetRewindable rsw, int depth){ + List<String> vars = new ArrayList<String>(); + vars.add("o0"); + for (int i = 1; i <= depth; i++) { + vars.add("o"+i); + } + + while (rsw.hasNext()){ + QuerySolution q = rsw.nextSolution(); + if(!q.get("o0").isAnon()){ + continue; + }else{ + if(!testOneQuerySolution(vars, q)){ + rsw.reset(); + return false; + } + + } + } + rsw.reset(); + return true; + } + private static boolean testOneQuerySolution(List<String> vars, QuerySolution q){ + for (String v : vars) { + if(!q.get(v).isAnon()){ + return true; + } + } + return false; + } + + public static String makeQuery(String uri, String predicate, int maxDepth){ + int currentDepth = 0; + StringBuffer sq = new StringBuffer(); + String init = "SELECT * WHERE { "+ + "<"+uri+"> <"+predicate+"> ?o"+currentDepth+". "; + + sq.append(init); + + for (; currentDepth < maxDepth; currentDepth++) { + String currentO = "?o"+currentDepth; + String nextP = "?p"+(currentDepth+1); + String nextO = "?o"+(currentDepth+1); + sq.append(" { OPTIONAL { "+currentO+" "+nextP+" "+nextO+". }}"); + } + + + sq.append(" } "); + return sq.toString(); + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/RDFBlankNode.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -0,0 +1,104 @@ +/** + * Copyright (C) 2007-2008, 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.kb.aquisitors; + +import com.hp.hpl.jena.graph.Node; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.RDFVisitor; + +/** + * This class is used to save disambiguated information for a blankNode in an RDF + * Graph. It is used to silently transport the info to the layer above. + * + * @author Sebastian Hellmann + * + */ +public class RDFBlankNode implements RDFNode { + + + private RDFNode blankNode; + private int bNodeId; + + public RDFBlankNode(int id, RDFNode blankNode) { + super(); + this.bNodeId = id; + this.blankNode = blankNode; + } + + public int getBNodeId(){ + return bNodeId; + } + //RBC + public String toString(){ + //RBC + return "I'm a blank node with id: "+bNodeId+"||"+blankNode; + } + + // overidden Functions + + public RDFNode as(Class view) { + + return blankNode.as(view); + } + + public boolean canAs(Class view) { + + return blankNode.canAs(view); + } + + public RDFNode inModel(Model m) { + + return blankNode.inModel(m); + } + + public boolean isAnon() { + + return blankNode.isAnon(); + } + + public boolean isLiteral() { + + return blankNode.isLiteral(); + } + + public boolean isResource() { + + return blankNode.isResource(); + } + + public boolean isURIResource() { + + return blankNode.isURIResource(); + } + + public Object visitWith(RDFVisitor rv) { + + return blankNode.visitWith(rv); + } + + public Node asNode() { + + return blankNode.asNode(); + } + + + +} Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -19,6 +19,8 @@ */ package org.dllearner.kb.aquisitors; +import java.util.ArrayList; +import java.util.List; import java.util.SortedSet; import org.apache.log4j.Logger; @@ -26,6 +28,10 @@ import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.datastructures.RDFNodeTuple; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSetRewindable; +import com.hp.hpl.jena.rdf.model.RDFNode; + /** * Can execute different queries. * @@ -42,6 +48,7 @@ protected SparqlQueryMaker sparqlQueryMaker; protected SPARQLTasks sparqlTasks; + //RBC @@ -55,21 +62,107 @@ public SortedSet<RDFNodeTuple> retrieveTupel(String uri){ // getQuery String sparqlQueryString = sparqlQueryMaker.makeSubjectQueryUsingFilters(uri); - return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, PREDICATE, OBJECT); - + SortedSet<RDFNodeTuple> ret = sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, PREDICATE, OBJECT); + disambiguateBlankNodes(uri, ret); + return ret; } @Override public SortedSet<RDFNodeTuple> retrieveClassesForInstances(String uri){ // getQuery String sparqlQueryString = sparqlQueryMaker.makeClassQueryUsingFilters(uri); - return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, PREDICATE, OBJECT); + SortedSet<RDFNodeTuple> ret = sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, PREDICATE, OBJECT); + return ret; } @Override public SortedSet<RDFNodeTuple> retrieveTuplesForClassesOnly(String uri){ - return retrieveTupel(uri); + SortedSet<RDFNodeTuple> ret = retrieveTupel(uri); + return ret; } + + private void disambiguateBlankNodes(String uri, SortedSet<RDFNodeTuple> resultSet){ + try{ + for (RDFNodeTuple tuple : resultSet) { + if(tuple.b.isAnon()){ + int currentId = BlankNodeCollector.getNextGlobalBNodeId(); + tuple.b = new RDFBlankNode(currentId, tuple.b); + System.out.println(uri+" replaced blanknode "+tuple.b); + dissolveBlankNodes(currentId, uri, tuple); + System.out.println(BlankNodeCollector.getBlankNodeMap()); + + } + } + }catch (Exception e) { + e.printStackTrace(); + System.exit(0); + } + } + + private void dissolveBlankNodes(int currentId, String uri, RDFNodeTuple tuple){ + int currentDepth = 1; + int lastDepth = 1; + ResultSetRewindable rsw=null; + do{ + String q = BlankNodeCollector.makeQuery(uri, tuple.a.toString(), currentDepth); + + rsw = sparqlTasks.queryAsResultSet(q); + lastDepth = currentDepth; + }while (!BlankNodeCollector.testResultSet(rsw, currentDepth++)); + + assignIds( currentId, rsw, lastDepth); + + } + + private void assignIds(int currentId, ResultSetRewindable rsw, int lastDepth){ + List<String> vars = new ArrayList<String>(); + vars.add("o0"); + for (int i = 1; i <= lastDepth; i++) { + vars.add("p"+i); + vars.add("o"+i); + } + + final List<String> tmpVars = new ArrayList<String>(); + + while (rsw.hasNext()){ + tmpVars.clear(); + tmpVars.addAll(vars); + QuerySolution q = rsw.nextSolution(); + + if(!q.get("o0").isAnon()){ + continue; + }else{ + tmpVars.remove(0); + assignIdRec(currentId, q, tmpVars); + } + + + } + rsw.reset(); + + } + + private void assignIdRec(int currentId, QuerySolution q, List<String> vars ){ + if(vars.isEmpty()){return;} + String pvar = vars.remove(0); + String ovar = vars.remove(0); + + RDFNode n = q.get(ovar); + if(n.isAnon()){ + int nextId = BlankNodeCollector.getNextGlobalBNodeId(); + RDFNodeTuple tuple = new RDFNodeTuple(q.get(pvar), new RDFBlankNode(nextId,n)); + BlankNodeCollector.addBlankNode(currentId, tuple); + assignIdRec(nextId, q, vars); + }else{ + BlankNodeCollector.addBlankNode(currentId, new RDFNodeTuple(q.get(pvar), n)); + } + + + } + + + + Added: trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -0,0 +1,75 @@ +package org.dllearner.kb.extraction; + +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.aquisitors.BlankNodeCollector; +import org.dllearner.kb.aquisitors.RDFBlankNode; +import org.dllearner.kb.aquisitors.TupleAquisitor; +import org.dllearner.kb.manipulator.Manipulator; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +public class BlankNode extends Node { + + RDFBlankNode bNode; + + private List<ObjectPropertyNode> objectProperties = new ArrayList<ObjectPropertyNode>(); + private List<DatatypePropertyNode> datatypeProperties = new ArrayList<DatatypePropertyNode>(); + + + public BlankNode(RDFBlankNode bNode){ + super("_:internal_"+bNode.getBNodeId()); + this.bNode=bNode; + } + + + + @Override + public List<Node> expand(TupleAquisitor TupelAquisitor, + Manipulator manipulator) { + List<Node> newNodes = new ArrayList<Node>(); + SortedSet<RDFNodeTuple> s = BlankNodeCollector.getBlankNode(bNode.getBNodeId()); + for (RDFNodeTuple tuple : s) { + if(tuple.b.isLiteral()) { + datatypeProperties.add(new DatatypePropertyNode(tuple.a.toString(), this, new LiteralNode(tuple.b) )); + }else if(tuple.b.isAnon()){ + + BlankNode tmp = new BlankNode( (RDFBlankNode)tuple.b); + objectProperties.add(new ObjectPropertyNode(tuple.a.toString(), this, tmp )); + newNodes.add(tmp); + }else{ + objectProperties.add(new ObjectPropertyNode(tuple.a.toString(), this, new ClassNode(tuple.b.toString()) )); + } + } + return newNodes; + } + + @Override + public void expandProperties(TupleAquisitor TupelAquisitor, + Manipulator manipulator) { + } + + @Override + public SortedSet<String> toNTriple() { + SortedSet<String> returnSet = new TreeSet<String>(); + String subject = getNTripleForm(); + for (ObjectPropertyNode one : objectProperties) { + returnSet.add(subject + one.getNTripleForm() + one.getBPart().getNTripleForm()+" . "); + returnSet.addAll(one.getBPart().toNTriple()); + } + return returnSet; + } + + @Override + public String getNTripleForm(){ + return " "+uri+" "; + } + + @Override + public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ + //FIXME + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -25,10 +25,15 @@ import java.util.TreeSet; import org.apache.log4j.Logger; +import org.dllearner.kb.aquisitors.RDFBlankNode; import org.dllearner.kb.aquisitors.TupleAquisitor; import org.dllearner.kb.manipulator.Manipulator; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLCommentAnnotation; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLLabelAnnotation; /** * Is a node in the graph, that is a class. @@ -66,7 +71,7 @@ return newNodes; } - public Node processTuple( RDFNodeTuple tuple) { + private Node processTuple( RDFNodeTuple tuple) { try { String property = tuple.a.toString(); if(tuple.b.isLiteral()) { @@ -74,6 +79,12 @@ return null; }else if(tuple.b.isAnon()){ logger.warn("blanknodes not supported as of now "+ this +" in tuple" + tuple); + RDFBlankNode n = (RDFBlankNode) tuple.b; + //SortedSet<RDFNodeTuple> bNodeTuples = BlankNodeCollector.getBlankNode(n.getBNodeId()); + //BlankNode tmp = new BlankNode(n); + //add it to the graph + //classProperties.add(new ObjectPropertyNode( tuple.a.toString(), this, tmp)); + //return tmp; return null; // substitute rdf:type with owl:subclassof }else if (property.equals(OWLVocabulary.RDF_TYPE) || @@ -110,21 +121,60 @@ @Override public SortedSet<String> toNTriple() { SortedSet<String> returnSet = new TreeSet<String>(); - returnSet.add("<" + this.uri + "><" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_CLASS + ">."); + String subject = getNTripleForm(); + returnSet.add(subject+"<" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_CLASS + ">."); for (ObjectPropertyNode one : classProperties) { - returnSet.add("<" + this.uri + "><" + one.getURI() + "><" - + one.getB().getURI() + ">."); - returnSet.addAll(one.getB().toNTriple()); + returnSet.add(subject + one.getNTripleForm() + + one.getBPart().getNTripleForm()+" ."); + returnSet.addAll(one.getBPart().toNTriple()); } for (DatatypePropertyNode one : datatypeProperties) { - returnSet.add("<" + uri + "><" + one.getURI() + "> " + one.getNTripleFormOfB() + returnSet.add(subject+ one.getNTripleForm() + one.getNTripleFormOfB() + " ."); } return returnSet; } - + @Override + public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ + try{ + OWLDataFactory factory = owlAPIOntologyCollector.getFactory(); + OWLClass me =factory.getOWLClass(getURI()); + for (ObjectPropertyNode one : classProperties) { + OWLClass c = factory.getOWLClass(one.getBPart().getURI()); + if(OWLVocabulary.isStringSubClassVocab(one.getURIString())){ + owlAPIOntologyCollector.addAxiom(factory.getOWLSubClassAxiom(me, c)); + }else if(one.getURIString().equals(OWLVocabulary.OWL_DISJOINT_WITH)){ + owlAPIOntologyCollector.addAxiom(factory.getOWLDisjointClassesAxiom(me, c)); + }else if(one.getURIString().equals(OWLVocabulary.OWL_EQUIVALENT_CLASS)){ + owlAPIOntologyCollector.addAxiom(factory.getOWLEquivalentClassesAxiom(me, c)); + }else { + logger.warn("missing : " +one.getURIString()); + } + one.getBPart().toOWLOntology(owlAPIOntologyCollector); + } + for (DatatypePropertyNode one : datatypeProperties) { + //FIXME add languages + // watch for tail + if(one.getURIString().equals(OWLVocabulary.RDFS_COMMENT)){ + OWLCommentAnnotation comment = factory.getCommentAnnotation(one.getBPart().getLiteral().getString()); + owlAPIOntologyCollector.addAxiom(factory.getOWLEntityAnnotationAxiom(me, comment)); + + }else if(one.getURIString().equals(OWLVocabulary.RDFS_LABEL)) { + OWLLabelAnnotation label = factory.getOWLLabelAnnotation(one.getBPart().getLiteral().getString()); + owlAPIOntologyCollector.addAxiom(factory.getOWLEntityAnnotationAxiom(me, label)); + }else { + logger.warn("missing : " +one.getURIString()); + } + + } + }catch (Exception e) { + System.out.println("aaa"+getURIString()); + e.printStackTrace(); + } + } + } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -25,34 +25,36 @@ /** * Stores all configuration settings. this class collects all configuration * information see the other classes, which are used as attributes here - * + * * @author Sebastian Hellmann */ public class Configuration { - + private OWLAPIOntologyCollector owlAPIOntologyCollector; + private Manipulator manipulator; + private TupleAquisitor tupelAquisitor; - + // the following needs to be moved to // class extraction algorithm or manipulator private boolean optimizeForDLLearner = true; + private int recursiondepth; + private boolean getAllSuperClasses = true; + private boolean closeAfterRecursion = true; + private boolean getPropertyInformation = false; + private int breakSuperClassesAfter = 200; + public Configuration(TupleAquisitor tupelAquisitor, + Manipulator manipulator, int recursiondepth, + boolean getAllSuperClasses, boolean closeAfterRecursion, + boolean getPropertyInformation, int breakSuperClassesAfter) { - public Configuration( - TupleAquisitor tupelAquisitor, - Manipulator manipulator, - int recursiondepth, - boolean getAllSuperClasses, - boolean closeAfterRecursion, - boolean getPropertyInformation, - int breakSuperClassesAfter) { - this.tupelAquisitor = tupelAquisitor; this.manipulator = manipulator; this.recursiondepth = recursiondepth; @@ -61,51 +63,54 @@ this.getPropertyInformation = getPropertyInformation; this.breakSuperClassesAfter = breakSuperClassesAfter; + this.owlAPIOntologyCollector = new OWLAPIOntologyCollector(); } + public Configuration(TupleAquisitor tupelAquisitor, + Manipulator manipulator, int recursiondepth, + boolean getAllSuperClasses, boolean closeAfterRecursion, + boolean getPropertyInformation, int breakSuperClassesAfter, + OWLAPIOntologyCollector owlAPIOntologyCollector) { + this(tupelAquisitor, manipulator, recursiondepth, getAllSuperClasses, + closeAfterRecursion, getAllSuperClasses, breakSuperClassesAfter); + this.owlAPIOntologyCollector = owlAPIOntologyCollector; + } public int getBreakSuperClassesAfter() { return breakSuperClassesAfter; } - public boolean isCloseAfterRecursion() { return closeAfterRecursion; } - public boolean isGetAllSuperClasses() { return getAllSuperClasses; } - public Manipulator getManipulator() { return manipulator; } - public int getRecursiondepth() { return recursiondepth; } - public TupleAquisitor getTupelAquisitor() { return tupelAquisitor; } - public boolean isOptimizeForDLLearner() { return optimizeForDLLearner; } - public boolean isGetPropertyInformation() { return getPropertyInformation; } + public OWLAPIOntologyCollector getOwlAPIOntologyCollector() { + return owlAPIOntologyCollector; + } - - - } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/DatatypePropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/DatatypePropertyNode.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/DatatypePropertyNode.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -34,18 +34,10 @@ * */ -public class DatatypePropertyNode extends Node { +public class DatatypePropertyNode extends PropertyNode { - // the a and b part of a property - private Node a; - private LiteralNode b; - - public DatatypePropertyNode(String uri, Node a, LiteralNode b) { - super(uri); - // this.type = "property"; - this.a = a; - this.b = b; + super(uri, a, b); } // Property Nodes are normally not expanded, @@ -60,15 +52,10 @@ public void expandProperties(TupleAquisitor tupelAquisitor, Manipulator manipulator) { } - - - public Node getA() { - return a; + @Override + public LiteralNode getBPart(){ + return (LiteralNode)b; } - - public Node getB() { - return b; - } public String getNTripleFormOfB() { return b.getNTripleForm(); @@ -77,12 +64,17 @@ @Override public SortedSet<String> toNTriple() { SortedSet<String> s = new TreeSet<String>(); - s.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + s.add(getNTripleForm()+"<" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_DATATYPPROPERTY + ">."); return s; } - + @Override + public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ + + } + + } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -59,6 +59,7 @@ for (String oneURI : uris) { nodeList.add(expandNode(oneURI, tupelAquisitor)); } + return nodeList; } @@ -135,14 +136,32 @@ List<ObjectPropertyNode> l = getObjectPropertyNodes(collectNodes); for (ObjectPropertyNode node : l) { + //FIXME has to be transported to the next step node.expandProperties(tupleAquisitor, configuration.getManipulator()); } } + + expandBlankNodes(getBlankNodes(collectNodes),tupleAquisitor); + return seedNode; } + private List<Node> expandBlankNodes(List<BlankNode> blankNodes, TupleAquisitor tupelAquisitor) { + List<Node> newNodes = new ArrayList<Node>(); + while (!blankNodes.isEmpty()) { + Node next = blankNodes.remove(0); + List<Node> l = next.expand(tupelAquisitor, configuration.getManipulator()); + for (Node node : l) { + blankNodes.add((BlankNode) node); + } + + } + return newNodes; + } + + private List<Node> expandCloseAfterRecursion(List<InstanceNode> instanceNodes, TupleAquisitor tupelAquisitor) { List<Node> newNodes = new ArrayList<Node>(); @@ -179,9 +198,9 @@ Node next = newClasses.remove(0); logger.trace("Getting Superclasses for: " + next); - if (!alreadyQueriedSuperClasses.contains(next.getURI().toString())) { + if (!alreadyQueriedSuperClasses.contains(next.getURIString().toString())) { logger.trace("" + next+" not in cache retrieving"); - alreadyQueriedSuperClasses.add(next.getURI().toString()); + alreadyQueriedSuperClasses.add(next.getURIString().toString()); tupelAquisitor.setNextTaskToClassInformation(); newClasses.addAll(next.expand(tupelAquisitor, configuration.getManipulator())); @@ -226,6 +245,18 @@ return retList; } + public static List<BlankNode> getBlankNodes(List<Node> l ){ + List<BlankNode> retList = new ArrayList<BlankNode>(); + for (Node node : l) { + if (node instanceof BlankNode) { + retList.add( (BlankNode) node); + + } + + } + return retList; + } + public static List<ObjectPropertyNode> getObjectPropertyNodes(List<Node> l ){ List<ObjectPropertyNode> properties = new ArrayList<ObjectPropertyNode>(); for (Node node : l) { Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -24,12 +24,22 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.commons.collections.list.TypedList; import org.apache.log4j.Logger; +import org.dllearner.kb.aquisitors.RDFBlankNode; import org.dllearner.kb.aquisitors.TupleAquisitor; import org.dllearner.kb.manipulator.Manipulator; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; +import org.semanticweb.owl.expression.OWLExpressionParser; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDataProperty; +import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLObjectProperty; +import com.hp.hpl.jena.rdf.model.Literal; + /** * A node in the graph that is an instance. * @@ -47,10 +57,8 @@ private List<ObjectPropertyNode> objectProperties = new ArrayList<ObjectPropertyNode>(); private List<DatatypePropertyNode> datatypeProperties = new ArrayList<DatatypePropertyNode>(); - public InstanceNode(String uri) { super(uri); - } // expands all directly connected nodes @@ -80,6 +88,9 @@ datatypeProperties.add(new DatatypePropertyNode(tuple.a.toString(), this, new LiteralNode(tuple.b) )); return null; }else if(tuple.b.isAnon()){ + RDFBlankNode n = (RDFBlankNode) tuple.b; + System.out.println(n.getBNodeId()); + System.exit(0); logger.warn("blanknodes not supported as of now"+ this +"in tuple" + tuple); return null; @@ -115,30 +126,85 @@ SortedSet<String> returnSet = new TreeSet<String>(); returnSet.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_THING + ">."); for (ClassNode one : classes) { - returnSet.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + one.getURI() + ">."); + returnSet.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + one.getURIString() + ">."); returnSet.addAll(one.toNTriple()); } for (ObjectPropertyNode one : objectProperties) { - returnSet.add("<" + uri + "><" + one.getURI() + "><" + one.getB().getURI() + returnSet.add("<" + uri + "><" + one.getURIString() + "><" + one.getBPart().getURIString() + ">."); returnSet.addAll(one.toNTriple()); - returnSet.addAll(one.getB().toNTriple()); + returnSet.addAll(one.getBPart().toNTriple()); } for (DatatypePropertyNode one : datatypeProperties) { - returnSet.add("<" + uri + "><" + one.getURI() + "> " + one.getNTripleFormOfB() + returnSet.add("<" + uri + "><" + one.getURIString() + "> " + one.getNTripleFormOfB() + " ."); } return returnSet; } + + @Override + public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ + OWLDataFactory factory = owlAPIOntologyCollector.getFactory(); + + + OWLIndividual me = factory.getOWLIndividual(getURI()); + for (ClassNode one : classes) { + OWLClass c = factory.getOWLClass(one.getURI()); + owlAPIOntologyCollector.addAxiom(factory.getOWLClassAssertionAxiom(me, c)); + one.toOWLOntology(owlAPIOntologyCollector); + } + for (ObjectPropertyNode one : objectProperties) { + OWLIndividual o = factory.getOWLIndividual(one.getBPart().getURI()); + OWLObjectProperty p = factory.getOWLObjectProperty(one.getURI()); + factory.getOWLObjectPropertyAssertionAxiom(me, p, o); + one.toOWLOntology(owlAPIOntologyCollector); + one.getBPart().toOWLOntology(owlAPIOntologyCollector); + } + + for (DatatypePropertyNode one : datatypeProperties) { + OWLDataProperty p = factory.getOWLDataProperty(one.getURI()); + Literal ln = one.getBPart().getLiteral(); + try{ + + + if(one.getBPart().isString()){ + owlAPIOntologyCollector.addAxiom( + factory.getOWLDataPropertyAssertionAxiom(me, p, ln.getString())); + } else if(one.getBPart().isDouble()){ + owlAPIOntologyCollector.addAxiom( + factory.getOWLDataPropertyAssertionAxiom(me, p, ln.getDouble())); + } else if(one.getBPart().isFloat()){ + owlAPIOntologyCollector.addAxiom( + factory.getOWLDataPropertyAssertionAxiom(me, p, ln.getFloat())); + } else if(one.getBPart().isInt()){ + owlAPIOntologyCollector.addAxiom( + factory.getOWLDataPropertyAssertionAxiom(me, p, ln.getInt())); + } else if(one.getBPart().isBoolean()){ + owlAPIOntologyCollector.addAxiom( + factory.getOWLDataPropertyAssertionAxiom(me, p, ln.getBoolean())); + } else { + logger.warn("missing : "+one.getURIString()); + } + + + }catch (Exception e) { + e.printStackTrace(); + System.exit(0); + } + + //factory.getOWLDataPropertyAssertionAxiom() + //returnSet.add("<" + uri + "><" + one.getURI() + "> " + one.getNTripleFormOfB() + // + " ."); + } + } + public List<ObjectPropertyNode> getObjectProperties() { return objectProperties; } - - } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/LiteralNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/LiteralNode.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/LiteralNode.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -48,14 +48,17 @@ public LiteralNode(String uri) { super(uri); - // this.type = "instance"; - + } public LiteralNode(RDFNode node) { super(node.toString()); l = (Literal) node; } + + public Literal getLiteral(){ + return l; + } // expands all directly connected nodes @Override @@ -77,7 +80,7 @@ - + @Override public String getNTripleForm() { String quote = "\\\""; quote = """; @@ -92,5 +95,59 @@ } } + + @Override + public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ + + } + + public boolean isDouble(){ + try{ + l.getDouble(); + return true; + }catch (Exception e) { + return false; + } + } + + public boolean isFloat(){ + try{ + l.getFloat(); + return true; + }catch (Exception e) { + return false; + } + } + + public boolean isInt(){ + try{ + l.getInt(); + return true; + }catch (Exception e) { + return false; + } + } + + public boolean isBoolean(){ + try{ + l.getBoolean(); + return true; + }catch (Exception e) { + return false; + } + } + + public boolean isString(){ + try{ + l.getString(); + return true; + }catch (Exception e) { + return false; + } + } + + + + } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -19,11 +19,16 @@ */ package org.dllearner.kb.extraction; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import org.apache.log4j.Logger; +import org.semanticweb.owl.model.OWLOntology; /** * An object of this class encapsulates everything. @@ -36,54 +41,73 @@ private Configuration configuration; private ExtractionAlgorithm extractionAlgorithm; private int nrOfExtractedTriples = 0; + private List<Node> seedNodes = new ArrayList<Node>(); private static Logger logger = Logger .getLogger(Manager.class); public void useConfiguration(Configuration configuration) { - this.configuration = configuration; - //System.out.println(this.configuration); - this.extractionAlgorithm = new ExtractionAlgorithm(configuration); - } - public String extract(String uri) { + public Node extractOneURI(String uri) { - logger.info("Start extracting"); - + logger.info("Start extracting: "+uri); Node n = extractionAlgorithm.expandNode(uri, configuration.getTupelAquisitor()); - SortedSet<String> s = n.toNTriple(); - logger.info("number of triples: "+s.size()); - StringBuffer nt = new StringBuffer(33000); - for (String str : s) { - nt.append(str + "\n"); - } - logger.info("sizeofStringBuffer"+nt.length()); - return nt.toString(); + logger.info("Finished extracting: "+uri ); + seedNodes.add(n); + return n; } + + - public String extract(Set<String> instances) { - // this.TypedSparqlQuery.query(uri); - // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); - logger.info("Start extracting"); - SortedSet<String> tripleCollector = new TreeSet<String>(); + public List<Node> extract(Set<String> instances) { + List<Node> allExtractedNodes = new ArrayList<Node>(); + logger.info("Start extracting "+instances.size() + " instances "); int progress=0; for (String one : instances) { progress++; - //if(progress % 10 == 0) { - logger.info("Progress: "+progress+" of "+instances.size()+" finished: "+one); - //} + logger.info("Progress: "+progress+" of "+instances.size()+" finished: "+one); try { Node n = extractionAlgorithm.expandNode(one, configuration.getTupelAquisitor()); - tripleCollector.addAll(n.toNTriple()); + seedNodes.add(n); + allExtractedNodes.add(n); } catch (Exception e) { + logger.warn("extraction failed for: "+one); e.printStackTrace(); + } } - logger.info("Finished extracting, start conversion"); + logger.info("Finished extraction"); + return allExtractedNodes; + + } + + public OWLOntology getOWLAPIOntologyForNodes(List<Node> nodes){ + for (Node n : nodes) { + n.toOWLOntology(configuration.getOwlAPIOntologyCollector()); + } + configuration.getOwlAPIOntologyCollector().saveOntology(); + return configuration.getOwlAPIOntologyCollector().getCurrentOntology(); + } + + public URL getPhysicalOntologyURL()throws MalformedURLException{ + return configuration.getOwlAPIOntologyCollector().getPhysicalURI().toURL(); + + } + + public String getNTripleForAllExtractedNodes(){ + return getNTripleForNodes(seedNodes); + } + + public String getNTripleForNodes(List<Node> nodes){ + SortedSet<String> tripleCollector = new TreeSet<String>(); + for (Node n : nodes) { + tripleCollector.addAll(n.toNTriple()); + } + logger.info("Converting to NTriple"); StringBuffer nt = new StringBuffer(100000); Object[] arr = tripleCollector.toArray(); nrOfExtractedTriples = arr.length; @@ -93,11 +117,6 @@ logger.info(i + " of " + arr.length + " triples done"); } logger.info(arr.length + " of " + arr.length + " triples done"); - /* - * String tmp=""; while ( ret.size() > 0) { tmp=ret.first(); nt+=tmp; - * ret.remove(tmp); System.out.println(ret.size()); } /*for (String str : - * ret) { nt += str + "\n"; } - */ logger.info("Ontology String size = " + nt.length()); return nt.toString(); } @@ -107,6 +126,7 @@ return configuration; } + @Deprecated public int getNrOfExtractedTriples() { return nrOfExtractedTriples; } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -19,6 +19,7 @@ */ package org.dllearner.kb.extraction; +import java.net.URI; import java.util.List; import java.util.SortedSet; @@ -73,17 +74,34 @@ */ public abstract SortedSet<String> toNTriple(); + public abstract void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector); + + /* + + @Override + public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ + + } + */ + @Override public String toString() { return "Node: " + uri + ":" + this.getClass().getSimpleName(); } - public String getURI() { + public String getURIString() { return uri; } + public URI getURI() { + return URI.create(uri); + } + public String getNTripleForm(){ + return "<"+uri+"> "; + } + Added: trunk/src/dl-learner/org/dllearner/kb/extraction/OWLAPIOntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/OWLAPIOntologyCollector.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/OWLAPIOntologyCollector.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -0,0 +1,80 @@ +package org.dllearner.kb.extraction; + +import java.io.File; +import java.net.URI; + +import org.apache.log4j.Logger; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.AddAxiom; +import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyChangeException; +import org.semanticweb.owl.model.OWLOntologyCreationException; +import org.semanticweb.owl.model.OWLOntologyManager; +import org.semanticweb.owl.util.SimpleURIMapper; + +public class OWLAPIOntologyCollector { + + private static Logger logger = Logger.getLogger(OWLAPIOntologyCollector.class); + + private OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + private OWLDataFactory factory; + private OWLOntology currentOntology; + private URI ontologyURI; + private URI physicalURI; + + + + public OWLAPIOntologyCollector(){ + this("http://www.fragment.org/fragment", "cache/"+System.currentTimeMillis()+".owl"); + } + + public OWLAPIOntologyCollector(String ontologyURI, String physicalURI){ + this.ontologyURI = URI.create(ontologyURI); + this.physicalURI = new File(physicalURI).toURI(); + SimpleURIMapper mapper = new SimpleURIMapper(this.ontologyURI, this.physicalURI); + this.manager.addURIMapper(mapper); + try{ + this.currentOntology = manager.createOntology(this.ontologyURI); + }catch(OWLOntologyCreationException e){ + logger.error("FATAL failed to create Ontology " + this.ontologyURI); + e.printStackTrace(); + } + this.factory = manager.getOWLDataFactory(); + } + + public void addAxiom(OWLAxiom axiom){ + AddAxiom addAxiom = new AddAxiom(currentOntology, axiom); + try{ + manager.applyChange(addAxiom); + }catch (OWLOntologyChangeException e) { + //TODO + e.printStackTrace(); + } + } + + public OWLDataFactory getFactory() { + return factory; + } + + public void saveOntology(){ + try{ + manager.saveOntology(currentOntology); + }catch (Exception e) { + e.printStackTrace(); + + } + } + + public OWLOntology getCurrentOntology() { + return currentOntology; + } + + public URI getPhysicalURI() { + return physicalURI; + } + + + +} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java 2008-09-23 18:35:57 UTC (rev 1242) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java 2008-09-23 23:06:40 UTC (rev 1243) @@ -23,11 +23,12 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.apache.log4j.Logger; import org.dllearner.kb.aquisitors.TupleAquisitor; import org.dllearner.kb.manipulator.Manipulator; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLObjectProperty; @@ -38,24 +39,16 @@ * */ -public class ObjectPropertyNode extends Node { +public class ObjectPropertyNode extends PropertyNode { - public static Logger logger = Logger.getLogger(ObjectPropertyNode.class); - // the a and b part of a property - private Node a; - private Node b; // specialtypes like owl:symmetricproperty private SortedSet<String> specialTypes = new TreeSet<String>(); @SuppressWarnings("unused") private SortedSet<RDFNodeTuple> propertyInformation = new TreeSet<RDFNodeTuple>(); - public ObjectPropertyNode(String uri, Node a, Node b) { - super(uri); - // this.type = "property"; - this.a = a; - this.b = b; - + public ObjectPropertyNode(String propertyURI, Node a, Node b) { + super(propertyURI, a, b); } // Property Nodes are normally not expanded, @@ -88,24 +81,13 @@ } - - - - public Node getA() { - return a; - } - - public Node getB() { - return b; - } - @Override public SortedSet<String> toNTriple() { SortedSet<String> s = new TreeSet<String>(); - s.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + s.add(getNTripleForm()+"<" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_OBJECTPROPERTY + ">."); for (String one : specialTypes) { - s.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + s.add(getNTripleForm()+"<" + OWLVocabulary.RDF_TYPE + "><" + one + ">."); } @@ -115,6 +97,28 @@ return s; } + + @Override + public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ + //FIXME Property information + OWLDataFactory factory = owlAPIOntologyCollector.getFactory(); + OWLObjectProperty me =factory.getOWLObjectPro... [truncated message content] |