From: <ku...@us...> - 2008-09-01 10:50:13
|
Revision: 1167 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1167&view=rev Author: kurzum Date: 2008-09-01 10:50:00 +0000 (Mon, 01 Sep 2008) Log Message: ----------- added additional option to get property information Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.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/ObjectPropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.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 Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -40,6 +40,7 @@ private int recursiondepth; private boolean getAllSuperClasses = true; private boolean closeAfterRecursion = true; + private boolean getPropertyInformation = false; private int breakSuperClassesAfter = 200; @@ -49,6 +50,7 @@ int recursiondepth, boolean getAllSuperClasses, boolean closeAfterRecursion, + boolean getPropertyInformation, int breakSuperClassesAfter) { this.tupelAquisitor = tupelAquisitor; @@ -56,6 +58,7 @@ this.recursiondepth = recursiondepth; this.getAllSuperClasses = getAllSuperClasses; this.closeAfterRecursion = closeAfterRecursion; + this.getPropertyInformation = getPropertyInformation; this.breakSuperClassesAfter = breakSuperClassesAfter; @@ -97,6 +100,11 @@ } + public boolean isGetPropertyInformation() { + return getPropertyInformation; + } + + Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -71,11 +71,11 @@ * @param typedSparqlQuery * @return */ - public Node expandNode(String uri, TupleAquisitor tupelAquisitor) { + public Node expandNode(String uri, TupleAquisitor tupleAquisitor) { SimpleClock sc = new SimpleClock(); - if(tupelAquisitor instanceof SparqlTupleAquisitorImproved){ - ((SparqlTupleAquisitorImproved)tupelAquisitor).removeFromCache(uri); + if(tupleAquisitor instanceof SparqlTupleAquisitorImproved){ + ((SparqlTupleAquisitorImproved)tupleAquisitor).removeFromCache(uri); } Node seedNode = getFirstNode(uri); @@ -97,8 +97,8 @@ logger.info("Expanding " + nextNode); // these are the new not expanded nodes // the others are saved in connection with the original node - tupelAquisitor.setNextTaskToNormal(); - tmp.addAll(nextNode.expand(tupelAquisitor, + tupleAquisitor.setNextTaskToNormal(); + tmp.addAll(nextNode.expand(tupleAquisitor, configuration.getManipulator())); //System.out.println(tmpVec); @@ -116,20 +116,29 @@ Monitor m = JamonMonitorLogger.getTimeMonitor(ExtractionAlgorithm.class, "TimeCloseAfterRecursion").start(); List<InstanceNode> l = getInstanceNodes(newNodes); logger.info("Getting classes for remaining instances: "+l.size() + " instances"); - tupelAquisitor.setNextTaskToClassesForInstances(); - collectNodes.addAll(expandCloseAfterRecursion(l, tupelAquisitor)); + tupleAquisitor.setNextTaskToClassesForInstances(); + collectNodes.addAll(expandCloseAfterRecursion(l, tupleAquisitor)); m.stop(); } // gets All Class Nodes and expands them further if (configuration.isGetAllSuperClasses()) { Monitor m = JamonMonitorLogger.getTimeMonitor(ExtractionAlgorithm.class, "TimeGetAllSuperClasses").start(); List<ClassNode> allClassNodes = getClassNodes(collectNodes); - tupelAquisitor.setNextTaskToClassInformation(); + tupleAquisitor.setNextTaskToClassInformation(); logger.info("Get all superclasses for "+allClassNodes.size() + " classes"); - expandAllSuperClassesOfANode(allClassNodes, tupelAquisitor); + expandAllSuperClassesOfANode(allClassNodes, tupleAquisitor); m.stop(); } + + if(configuration.isGetPropertyInformation() ){ + + List<ObjectPropertyNode> l = getObjectPropertyNodes(collectNodes); + for (ObjectPropertyNode node : l) { + node.expandProperties(tupleAquisitor, configuration.getManipulator()); + } + } + return seedNode; } @@ -216,5 +225,17 @@ } return retList; } + + public static List<ObjectPropertyNode> getObjectPropertyNodes(List<Node> l ){ + List<ObjectPropertyNode> properties = new ArrayList<ObjectPropertyNode>(); + for (Node node : l) { + if (node instanceof InstanceNode) { + properties.addAll(( (InstanceNode) node).getObjectProperties()); + + } + + } + return properties; + } } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -133,6 +133,12 @@ return returnSet; } + public List<ObjectPropertyNode> getObjectProperties() { + return objectProperties; + } + + + } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -23,11 +23,14 @@ 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; + + /** * Property node, has connection to a and b part * @@ -37,18 +40,22 @@ public class ObjectPropertyNode extends Node { + 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; + 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; - this.specialTypes = new TreeSet<String>(); + } // Property Nodes are normally not expanded, @@ -65,11 +72,16 @@ SortedSet<RDFNodeTuple> newTypes = tupelAquisitor.getTupelForResource(uri); for (RDFNodeTuple tuple : newTypes) { try { - if (tuple.a.equals(OWLVocabulary.RDF_TYPE)) { + if (tuple.a.toString().equals(OWLVocabulary.RDF_TYPE)) { specialTypes.add(tuple.b.toString()); + }else if(tuple.b.isAnon()){ + logger.warn("blanknodes currently not implemented in this tuple aquisitor"); + }else{ + propertyInformation.add(tuple); + } } catch (Exception e) { - System.out.println(tuple); + logger.warn("resource "+uri+" with "+ tuple); e.printStackTrace(); } } @@ -96,6 +108,10 @@ s.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + one + ">."); } + + for (RDFNodeTuple one : propertyInformation) { + s.add(one.getNTriple(uri)); + } return s; } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -104,6 +104,7 @@ private boolean useLits = false; private boolean getAllSuperClasses = true; private boolean closeAfterRecursion = true; + private boolean getPropertyInformation = true; private int breakSuperClassRetrievalAfter = 1000; private String cacheDir = "cache"; // private boolean learnDomain = false; @@ -197,8 +198,6 @@ "learns the Range for a Role")); options.add(new StringConfigOption("role", "role to learn Domain/Range from")); - options.add(new StringConfigOption("blankNodeIdentifier", - "used to identify blanknodes in Tripels")); options.add(new StringTupleListConfigOption("example", "example")); options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); @@ -210,6 +209,8 @@ "numberOfInstancesUsedForRoleLearning", "")); options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); + options.add(new BooleanConfigOption("getPropertyInformation", + "gets all types for extracted ObjectProperties")); options.add(CommonConfigOptions.getVerbosityOption()); options.add(new StringSetConfigOption("defaultGraphURIs", @@ -267,7 +268,9 @@ useCache = (Boolean) entry.getValue(); }else if (option.equals("getAllSuperClasses")) { getAllSuperClasses = (Boolean) entry.getValue(); - } else if (option.equals("example")) { + }else if (option.equals("getPropertyInformation")) { + getPropertyInformation = (Boolean) entry.getValue(); + }else if (option.equals("example")) { // System.out.println(entry.getValue()); } else if (option.equals("replacePredicate")) { replacePredicate = (LinkedList) entry.getValue(); @@ -317,6 +320,7 @@ recursionDepth, getAllSuperClasses, closeAfterRecursion, + getPropertyInformation, breakSuperClassRetrievalAfter); // give everything to the manager Modified: trunk/src/dl-learner/org/dllearner/scripts/SemanticBible2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SemanticBible2.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/scripts/SemanticBible2.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -20,12 +20,9 @@ package org.dllearner.scripts; import java.io.File; -import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Locale; import java.util.SortedSet; import java.util.StringTokenizer; import java.util.TreeSet; @@ -70,7 +67,7 @@ public static String normaldir = dir+"normal/"; public static String tmpFilename = dir + "tmp.conf"; - static File log = new File(dir+"results.txt"); + static File log = new File(dir+"results+prop.txt"); private static Stat accFragment = new Stat(); private static Stat accOnOnto = new Stat(); @@ -116,9 +113,8 @@ initLogger(); logger.warn("Start"); File tmpFile = new File(tmpFilename); - String del="\t"; - String cr="\n"; + List<File> confs = getFilesContaining(useSPARQL,"ten","all", "99+"); //analyzeFiles(confs); @@ -161,7 +157,7 @@ SortedSet<Individual> retrieved = reasoningService.retrieval(onFragment.getDescription()); EvaluatedDescription onOnto = reEvaluateDescription( onFragment.getDescription(), retrieved, posEx, negEx); - double reachedAccuracy = onOnto.getAccuracy(); + accOnOnto.addNumber(onOnto.getAccuracy()); int tmp = (int)(Math.floor(onOnto.getAccuracy()*100)); @@ -212,6 +208,7 @@ cm.freeAllComponents(); writeLog(); + }//end for }catch (Exception e) { e.printStackTrace(); @@ -226,8 +223,8 @@ public static void writeLog(){ String l = "\n\n\n*********************\n"; l +="COUNT: "+accFragment.getCount()+"\n"; - l +="ALL: "+fragHasAll+" BOOL: "+fragHasBooleanData+" NOT: "+fragHasNot+" <>=: "+fragHasNrRes+"\n"; - l +="ALL: "+wholeHasAll+" BOOL: "+wholeHasBooleanData+" NOT: "+wholeHasNot+" <>=: "+wholeHasNrRes+"\n"; + l +="FRAGMENT: ALL: "+fragHasAll+" BOOL: "+fragHasBooleanData+" NOT: "+fragHasNot+" <>=: "+fragHasNrRes+"\n"; + l +="WHOLE: ALL: "+wholeHasAll+" BOOL: "+wholeHasBooleanData+" NOT: "+wholeHasNot+" <>=: "+wholeHasNrRes+"\n"; l+="accFragment\t\t"+accFragment.getMeanAsPercentage()+" +-"+accFragment.getStandardDeviation()+"\n"; @@ -395,6 +392,8 @@ "sparql.recursionDepth = 2;\n"+ "sparql.useLits = true;\n"+ "sparql.predefinedEndpoint = \"LOCALJOSEKIBIBLE\";\n"+ + "sparql.getPropertyInformation = true;\n"+ + "refexamples.maxExecutionTimeInSeconds = "+sparqllMaxExecution+";\n"+ "import(\"lalala\",\"SPARQL\");\n"+ getCombinedOptions()+ ""; Modified: trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -72,6 +72,7 @@ recursionDepth, true, true, + false, 200 ); m.useConfiguration(conf); Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java 2008-09-01 00:30:08 UTC (rev 1166) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java 2008-09-01 10:50:00 UTC (rev 1167) @@ -19,6 +19,8 @@ */ package org.dllearner.utilities.datastructures; +import org.dllearner.kb.extraction.LiteralNode; + import com.hp.hpl.jena.rdf.model.RDFNode; /** @@ -59,5 +61,18 @@ public boolean bPartContains(String partOf) { return b.toString().contains(partOf); } + + public String getNTriple (String subject){ + String ret = "<"+subject+"> "; + ret+="<"+a.toString()+"> "; + if(b.isLiteral()){ + ret+=new LiteralNode(b).getNTripleForm(); + + }else{ + ret+="<"+b.toString()+"> "; + } + ret+="."; + return ret; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |