From: <ku...@us...> - 2008-04-15 10:20:25
|
Revision: 788 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=788&view=rev Author: kurzum Date: 2008-04-15 03:20:23 -0700 (Tue, 15 Apr 2008) Log Message: ----------- added some functions at some places nothing big new approach to KRK Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/examples/KRK.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java trunk/src/dl-learner/org/dllearner/parser/KBParser.java trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/examples/KRKOntologyTBox.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-04-14 22:45:16 UTC (rev 787) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2008-04-15 10:20:23 UTC (rev 788) @@ -174,6 +174,30 @@ return ret; } + //TODO integrate this method with the one above + public String getStats(int nrOfPositiveExamples, int nrOfNegativeExamples) { + String ret = " ["; + + if(isTooWeak) + ret += "q:tw"; + else { + double accuracy = 100 * (coveredPositives.size() + nrOfNegativeExamples - coveredNegatives.size())/(double)(nrOfPositiveExamples+nrOfNegativeExamples); + ret += "acc:" + df.format(accuracy) + "% "; + + // comment this out to display the heuristic score with default parameters + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples); + ret += "h:" +df.format(heuristicScore) + " "; + + int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); + ret += "q:" + wrongPositives + "p-" + coveredNegatives.size() + "n"; + } + + ret += " ("+qualityEvaluationMethod+"), he:" + horizontalExpansion; + ret += " c:" + children.size() + "]"; + + return ret; + } + public double getAccuracy(int nrOfPositiveExamples, int nrOfNegativeExamples) { return (coveredPositives.size() + nrOfNegativeExamples - coveredNegatives.size())/(double)(nrOfPositiveExamples+nrOfNegativeExamples); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-14 22:45:16 UTC (rev 787) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-15 10:20:23 UTC (rev 788) @@ -743,6 +743,7 @@ // searchTree += bestNodeString + "\n"; logger.debug(bestNodeString); + logger.debug(startNode.getStats(nrOfPositiveExamples, nrOfNegativeExamples)); logger.debug(bestNodeStringKBSyntax); String expandedNodeString = "next expanded node: " + candidates.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI); // searchTree += expandedNodeString + "\n"; Modified: trunk/src/dl-learner/org/dllearner/examples/KRK.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-04-14 22:45:16 UTC (rev 787) +++ trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-04-15 10:20:23 UTC (rev 788) @@ -5,6 +5,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.net.URI; import java.util.ArrayList; @@ -17,7 +18,6 @@ import org.dllearner.core.owl.ClassAssertionAxiom; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.InverseObjectPropertyAxiom; import org.dllearner.core.owl.KB; @@ -51,7 +51,9 @@ // // turn off to not write the owl, needs about 30 seconds or more static boolean writeOWL = true; + static boolean writeKB = false; static boolean useTransitivity = false; + static boolean useHigherThan = false; static boolean writeExampleSets = true; static boolean writeConciseOWLAllDifferent = false; @@ -103,6 +105,9 @@ static ObjectProperty rankLessThan = getRole("hasLowerRankThan"); static ObjectProperty fileLessThan = getRole("hasLowerFileThan"); + + static ObjectProperty rankHigherThan = getRole("hasHigherRankThan"); + static ObjectProperty fileHigherThan = getRole("hasHigherFileThan"); // static ObjectProperty lessThan = getRole("strictLessThan"); @@ -142,10 +147,13 @@ + + try { String line = ""; String[] ar = new String[6]; + String currentclass=""; int x = 0; while ((line = in.readLine()) != null) { @@ -154,11 +162,15 @@ System.out.println("Currently at line" + x); ar = tokenize(line); + currentclass = ar[6]; + gameind = getIndividual("game" + x); wkingind = getIndividual("wking_" + ar[0] + ar[1] + "_" + x); wrookind = getIndividual("wrook_" + ar[2] + ar[3] + "_" + x); bkingind = getIndividual("bking_" + ar[4] + ar[5] + "_" + x); + + allInstances.add(gameind+""); allInstances.add(wkingind+""); allInstances.add(wrookind+""); @@ -180,6 +192,34 @@ kb.addABoxAxiom(new ClassAssertionAxiom(WRook, wrookind)); kb.addABoxAxiom(new ClassAssertionAxiom(BKing, bkingind)); + + /**Files and Ranks***/ + // FILES are letters + // RANKS are numbers + + //WKing + NamedClass tmp=getAtomicConcept(ar[0].toUpperCase()); + kb.addABoxAxiom(new ClassAssertionAxiom(tmp, wkingind)); + + tmp=getAtomicConcept("F"+ar[1]); + kb.addABoxAxiom(new ClassAssertionAxiom(tmp , wkingind)); + + //WRook + tmp=getAtomicConcept(ar[2].toUpperCase()); + kb.addABoxAxiom(new ClassAssertionAxiom(tmp, wrookind)); + + tmp=getAtomicConcept("F"+ar[3]); + kb.addABoxAxiom(new ClassAssertionAxiom(tmp , wrookind)); + + //BKing + tmp=getAtomicConcept(ar[4].toUpperCase()); + kb.addABoxAxiom(new ClassAssertionAxiom(tmp, bkingind)); + + tmp=getAtomicConcept("F"+ar[5]); + kb.addABoxAxiom(new ClassAssertionAxiom(tmp, bkingind)); + + + // PROPERTIES kb.addABoxAxiom(new ObjectPropertyAssertion(hasPiece, gameind, wkingind)); @@ -227,11 +267,12 @@ if(writeExampleSets)writeExampleSets(); if(writeConciseOWLAllDifferent)writeConciseOWLAllDifferent(); if (writeOWL)writeOWLFile("test.owl"); - - OntologyCloser oc = new OntologyCloser(kb); + if(writeKB)writeKBFile("test.kb"); + + OntologyCloser oc = null; String kbaddition= "_Closed"; if(closeKB) { - + oc= new OntologyCloser(kb); if(closeConcise) { oc.applyNumberRestrictionsConcise(); kbaddition = "_CloseConcise"; @@ -241,6 +282,7 @@ if (verifySomeConcepts) { + oc.updateReasoner(); verifySomeConcepts(oc); } @@ -252,79 +294,25 @@ System.out.println("Done"); }// end main + + + static void makeOntology(){ + + + + } + + protected static void verifySomeConcepts(OntologyCloser oc) { ArrayList<String> test=new ArrayList<String>(); - //String conceptStr = "ALL \"http://www.test.de/test#hasPiece\".(EXISTS \"http://www.test.de/test#fileDistanceLessThan6\".((NOT \"http://www.test.de/test#WKing\") AND ALL \"http://www.test.de/test#rankDistance1\".(\"http://www.test.de/test#WKing\" AND ALL \"http://www.test.de/test#fileDistanceLessThan2\".\"http://www.test.de/test#BKing\" AND ALL \"http://www.test.de/test#hasLowerFileThan\".\"http://www.test.de/test#WKing\")) AND ALL \"http://www.test.de/test#fileDistance1\".\"http://www.test.de/test#WRook\")"; - //conceptStr = "ALL http://www.test.de/test#hasPiece.(EXISTS http://www.test.de/test#fileDistanceLessThan6.((NOT http://www.test.de/test#WKing) AND ALL http://www.test.de/test#rankDistance1.(http://www.test.de/test#WKing AND ALL http://www.test.de/test#fileDistanceLessThan2.http://www.test.de/test#WKing AND ALL http://www.test.de/test#hasLowerFileThan.http://www.test.de/test#WKing)) AND ALL http://www.test.de/test#fileDistance1.http://www.test.de/test#WRook)"; - //conceptStr = "ALL hasPiece.(EXISTS fileDistanceLessThan6.((NOT WKing) AND ALL rankDistance1.(WKing AND ALL fileDistanceLessThan2.WKing AND ALL hasLowerFileThan.WKing)) AND ALL fileDistance1.WRook)"; - //conceptStr = "ALL \"http://www.test.de/test#hasPiece\".\"http://www.test.de/test#WKing\""; - //conceptStr = "EXISTS \"http://www.test.de/test#hasPiece\".EXISTS \"http://www.test.de/test#hasLowerRankThan\".(\"http://www.test.de/test#WRook\" AND ALL \"http://www.test.de/test#fileDistanceLessThan1\".\"http://www.test.de/test#WKing\")"; - - test.add("\"http://www.test.de/test#WRook\""); - /*test.add("ALL \"http://www.test.de/test#fileDistanceLessThan1\"." + - "\"http://www.test.de/test#WKing\""); - /*test.add("(\"http://www.test.de/test#WRook\" "+ - " AND " + - " ALL \"http://www.test.de/test#fileDistanceLessThan1\"." + - "\"http://www.test.de/test#WKing\") ");*/ - /*test.add("(\"http://www.test.de/test#Piece\" "+ - " AND " + - " ALL \"http://www.test.de/test#fileDistanceLessThan8\"." + - "\"http://www.test.de/test#Piece\") "); - test.add("(\"http://www.test.de/test#Piece\" "+ - " AND ( " + - " ALL \"http://www.test.de/test#fileDistanceLessThan8\"." + - "\"http://www.test.de/test#Piece\" " + - " AND " + - " EXISTS \"http://www.test.de/test#fileDistanceLessThan8\"." + - "\"http://www.test.de/test#Piece\"))") ; - test.add("(\"http://www.test.de/test#Piece\" "+ - " AND ( " + - " ALL \"http://www.test.de/test#fileDistanceLessThan7\"." + - "\"http://www.test.de/test#Piece\" " + - " AND " + - " EXISTS \"http://www.test.de/test#fileDistanceLessThan7\"." + - "\"http://www.test.de/test#Piece\"))") ; - test.add("(\"http://www.test.de/test#Piece\" "+ - " AND ( " + - " ALL \"http://www.test.de/test#fileDistanceLessThan5\"." + - "\"http://www.test.de/test#Piece\" " + - " AND " + - " EXISTS \"http://www.test.de/test#fileDistanceLessThan5\"." + - "\"http://www.test.de/test#Piece\"))") ;*/ - test.add("(\"http://www.test.de/test#Piece\" "+ - " AND ( " + - " ALL \"http://www.test.de/test#fileDistanceLessThan3\"." + - "\"http://www.test.de/test#Piece\" " + - " AND " + - " EXISTS \"http://www.test.de/test#fileDistanceLessThan3\"." + - "\"http://www.test.de/test#Piece\"))") ; - test.add("(\"http://www.test.de/test#BKing\" "+ - " AND ( " + - " ALL \"http://www.test.de/test#fileDistanceLessThan3\"." + - "\"http://www.test.de/test#Piece\" " + - " AND " + - " EXISTS \"http://www.test.de/test#fileDistanceLessThan3\"." + - "\"http://www.test.de/test#Piece\"))") ; - test.add("(\"http://www.test.de/test#BKing\" "+ - " AND ( " + - " ALL \"http://www.test.de/test#fileDistanceLessThan2\"." + - "\"http://www.test.de/test#Piece\" " + - " AND " + - " EXISTS \"http://www.test.de/test#fileDistanceLessThan2\"." + - "\"http://www.test.de/test#Piece\"))") ; + test.add("(EXISTS \"http://www.test.de/test#hasPiece\".EXISTS \"http://www.test.de/test#rankDistanceLessThan2\".(\"http://www.test.de/test#BKing\" AND EXISTS \"http://www.test.de/test#fileDistanceLessThan1\".(\"http://www.test.de/test#A\" OR \"http://www.test.de/test#WKing\")) AND EXISTS \"http://www.test.de/test#hasPiece\".(\"http://www.test.de/test#WKing\" AND ((\"http://www.test.de/test#C\" AND EXISTS \"http://www.test.de/test#hasLowerRankThan\".\"http://www.test.de/test#A\") OR (\"http://www.test.de/test#F3\" AND EXISTS \"http://www.test.de/test#rankDistance2\".\"http://www.test.de/test#WRook\"))))"); - /*test.add("(\"http://www.test.de/test#Piece\" "+ - " AND " + - " ALL \"http://www.test.de/test#fileDistanceLessThan1\"." + - "\"http://www.test.de/test#WKing\") ");*/ + - test.add("EXISTS \"http://www.test.de/test#hasPiece\".EXISTS \"http://www.test.de/test#hasLowerRankThan\".(\"http://www.test.de/test#WRook\" AND ALL \"http://www.test.de/test#fileDistanceLessThan1\".\"http://www.test.de/test#WKing\")") ; - for (int i = 0; i < test.size(); i++) { String conceptStr = test.get(i); oc.verifyConcept(conceptStr); @@ -352,21 +340,37 @@ kb.addABoxAxiom(new ObjectPropertyAssertion(getRole(fdistance + Fdist), A.id, B.id)); symmetricRoleSet.add(fdistance + Fdist); + + - if (A.meHasLowerFileThan(B)) + if (A.meHasLowerFileThan(B)){ kb.addABoxAxiom(new ObjectPropertyAssertion(fileLessThan, A.id, B.id)); + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(fileHigherThan, B.id, + A.id)); + + } // 18:00 - else if (B.meHasLowerFileThan(A)) + else if (B.meHasLowerFileThan(A)){ kb.addABoxAxiom(new ObjectPropertyAssertion(fileLessThan, B.id, A.id)); + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(fileHigherThan, A.id, + B.id)); + } - if (A.meHasLowerRankThan(B)) + if (A.meHasLowerRankThan(B)){ kb.addABoxAxiom(new ObjectPropertyAssertion(rankLessThan, A.id, B.id)); - else if (B.meHasLowerRankThan(A)) + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(rankHigherThan, B.id, + A.id)); + } + else if (B.meHasLowerRankThan(A)){ kb.addABoxAxiom(new ObjectPropertyAssertion(rankLessThan, B.id, A.id)); + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(rankHigherThan, A.id, + B.id)); + + } } public static void init() { @@ -384,7 +388,7 @@ // DisJointClasses1.add(Rank); // DisJointClasses1.add(File); DisJointClasses1.add(Game); - kb.addTBoxAxiom(new DisjointClassesAxiom(DisJointClasses1)); + //kb.addTBoxAxiom(new DisjointClassesAxiom(DisJointClasses1)); SortedSet<Description> DisJointClasses2 = new TreeSet<Description>(); DisJointClasses2 = new TreeSet<Description>(); @@ -395,7 +399,7 @@ // DisJointClasses2.add(File); // DisJointClasses2.add(Game); - kb.addTBoxAxiom(new DisjointClassesAxiom(DisJointClasses2)); + //kb.addTBoxAxiom(new DisjointClassesAxiom(DisJointClasses2)); } public static void initClassHierarchy() { @@ -404,6 +408,19 @@ kb.addTBoxAxiom(new SubClassAxiom(WKing, Piece)); kb.addTBoxAxiom(new SubClassAxiom(WRook, Piece)); kb.addTBoxAxiom(new SubClassAxiom(BKing, Piece)); + + String[] letters=new String[]{"A","B","C","D","E","F","G","H"}; + String[] numbers=new String[8]; + for (int i = 0; i < numbers.length; i++) { + numbers[i]="F"+i; + } + //System.out.println(numbers); + + for (int i = 0; i < numbers.length; i++) { + kb.addTBoxAxiom(new SubClassAxiom(getAtomicConcept(letters[i]),Piece)); + kb.addTBoxAxiom(new SubClassAxiom(getAtomicConcept(letters[i]),Piece)); + } + } static void initClassesForRankAndFile() { @@ -458,10 +475,15 @@ kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(rankLessThan, Piece)); kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(rankLessThan, Piece)); - kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(fileLessThan, Piece)); kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(fileLessThan, Piece)); - + + if(useHigherThan) { + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(rankHigherThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(rankHigherThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(fileHigherThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(fileHigherThan, Piece)); + } } static void finishBackgroundForRoles() { @@ -469,6 +491,11 @@ if (useTransitivity) { kb.addRBoxAxiom(new TransitiveObjectPropertyAxiom(rankLessThan)); kb.addRBoxAxiom(new TransitiveObjectPropertyAxiom(fileLessThan)); + if(useHigherThan) { + kb.addRBoxAxiom(new TransitiveObjectPropertyAxiom(rankHigherThan)); + kb.addRBoxAxiom(new TransitiveObjectPropertyAxiom(fileHigherThan)); + } + } if (useInverse) // INVERSE @@ -677,7 +704,20 @@ OWLAPIReasoner.exportKBToOWL(owlfile, kb, ontologyURI); } + + protected static void writeKBFile(String filename) { + System.out.println("Writing kb"); + try{ + FileWriter fw = new FileWriter(workingDir+"/" + filename,false); + fw.write(kb.toKBSyntaxString(ontologyURI.toString(), null)); + fw.flush(); + }catch (Exception e) {e.printStackTrace();} + System.out.println("done writing kb"); + + + } + protected static Individual getIndividual(String name) { return new Individual(ontologyURI + "#" + name); } Added: trunk/src/dl-learner/org/dllearner/examples/KRKModular.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRKModular.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-04-15 10:20:23 UTC (rev 788) @@ -0,0 +1,775 @@ +package org.dllearner.examples; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.net.URI; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; +import java.util.SortedSet; +import java.util.StringTokenizer; +import java.util.TreeSet; + +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.ClassAssertionAxiom; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KB; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyAssertion; +import org.dllearner.kb.KBFile; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.parser.KBParser; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.dllearner.utilities.SimpleClock; + +/* + * Structure + * + * + * + * + * */ + +public class KRKModular { + + // REMEMBER + // FILES are letters + // RANKS are numbers + + // FLAGS + // + // turn off to not write the owl, needs about 30 seconds or more + /*static boolean writeOWL = true; + static boolean writeKB = false; + static boolean useTransitivity = false; + + static boolean writeExampleSets = true; + static boolean writeConciseOWLAllDifferent = false; + */ + boolean useHigherThan = KRKOntologyTBox.useHigherThan; + + + + //static boolean useInverse = false; + // dependent, love and marriage, horse and carriage + //static boolean useTripleSubProps = useInverse && false; + + + static String workingDir = "examples/krk/"; + static String allData = workingDir+"krkopt_no_draw.data"; + + static URI ontologyURI = KRKOntologyTBox.ontologyURI; + + // static SortedSet<String> fileSet = new TreeSet<String>(); + //static SortedSet<String> allInstances = new TreeSet<String>(); + //static SortedSet<String> classSet = new TreeSet<String>(); + //static SortedSet<String> symmetricRoleSet = new TreeSet<String>(); + + static HashMap<String, SortedSet<Individual>> classToInd = new HashMap<String, SortedSet<Individual>>(); + static HashMap<Individual, String> indToClass = new HashMap<Individual, String>(); + + static Set<ReasonerComponent> allReasoners = new HashSet<ReasonerComponent>(); + static int negativeExamplesAdded = 300; + + // static LinkedList<String> words; + public KB kb; + public ReasonerComponent reasoner; + + + //public FastInstanceChecker fic; + // static HashMap<String,SortedSet<String>> classToInd; + + + public static void init(){ + if (!new File(workingDir).exists()) { + System.out.println("Created directory: " + workingDir + + " : " + new File(workingDir).mkdir()+ "."); + } + } + /** + * @param args + */ + public static void main(String[] args) { + init(); + initAllInstancesAndReasoners(); + System.out.println("initializing finished"); + String currentClass = "ZERO"; + SortedSet<Individual> allPos = classToInd.get(currentClass); + //if(allPos.size()<400)negativeExamplesAdded = allPos.size(); + //else negativeExamplesAdded = 400; + SortedSet<Individual> tmp = new TreeSet<Individual>(); + for (Individual individual : indToClass.keySet()) { + tmp.add(individual); + } + + SortedSet<Individual> neg = getNegativeExamples(currentClass, tmp, negativeExamplesAdded); + SortedSet<Integer> lines = getLines(allPos, neg); + KB kb = getKB(lines); + + + while (true){ + + /*for (String set : classToInd.keySet()) { + for (Individual individual : classToInd.get(set)) { + if(indToClass.get(individual)==null)System.out.println(indToClass.get(individual)); + }}*/ + + + + Description d= learn(kb, allPos, neg); + SortedSet<Individual> result = retrieveAll(d); + System.out.println("still left: " + (result.size()-allPos.size())); + if(verify(currentClass, result)) { + System.out.println("Correct solution: "+ d.toKBSyntaxString(ontologyURI+"#", null)); + break;} + neg.addAll(getNegativeExamples(currentClass, result, negativeExamplesAdded)); + lines = getLines(allPos, neg); + kb = getKB(lines); + + + } + //System.out.println(allPos); + //System.out.println(neg); + + //cm. + + + /*Map<Class<? extends Component>, String> componentPrefixMapping = Start.createComponentPrefixMapping(); + ComponentManager cm = ComponentManager.getInstance(); + + Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); + KnowledgeSource ks = cm.knowledgeSource(KBFile.class); + sources.add(ks); + cm.applyConfigEntry(ks, "url", null); + ks.init(); + */ + + + + + + + //verifyConcept("EXISTS hasPiece.EXISTS fileDistance0.TOP"); + //verifyConcept("(EXISTS \"http://dl-learner.org/krk#hasPiece\".EXISTS \"http://dl-learner.org/krk#rankDistanceLessThan2\".(\"http://dl-learner.org/krk#BKing\" AND EXISTS \"http://dl-learner.org/krk#fileDistanceLessThan1\".(\"http://dl-learner.org/krk#A\" OR \"http://dl-learner.org/krk#F3\")) AND EXISTS \"http://dl-learner.org/krk#hasPiece\".(\"http://dl-learner.org/krk#WKing\" AND ((\"http://dl-learner.org/krk#C\" AND EXISTS \"http://dl-learner.org/krk#hasLowerRankThan\".\"http://dl-learner.org/krk#A\") OR (\"http://dl-learner.org/krk#F3\" AND EXISTS \"http://dl-learner.org/krk#rankDistance2\".\"http://dl-learner.org/krk#WRook\"))))"); + //verifyConcept("EXISTS hasPiece.TOP"); + + //.writeOWLFile("test.owl"); + + } + + static Description learn(KB kb, SortedSet<Individual> pos,SortedSet<Individual> neg){ + + System.out.println(pos); + System.out.println(neg); + + ComponentManager cm = ComponentManager.getInstance(); + LearningAlgorithm la = null; + try { + Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); + sources.add(new KBFile(kb)); + ReasonerComponent r = new FastInstanceChecker(sources); + r.init(); + ReasoningService rs = new ReasoningService(r); + + LearningProblem lp = new PosNegDefinitionLP(rs); + ((PosNegLP)lp).setPositiveExamples(pos); + ((PosNegLP)lp).setNegativeExamples(neg); + lp.init(); + + la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs); + SortedSet<String> ignoredConcepts = getIgnoredConcepts(pos, neg); + + cm.applyConfigEntry(la,"useAllConstructor",false); + cm.applyConfigEntry(la,"useExistsConstructor",true); + cm.applyConfigEntry(la,"useCardinalityRestrictions",false); + cm.applyConfigEntry(la,"useNegation",false); + //cm.applyConfigEntry(la,"quiet",false); + cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts); + + + la.init(); + + System.out.println("start learning"); + + la.start(); + //System.out.println("best"+la.getBestSolution()); + + }catch (Exception e) {e.printStackTrace();} + return la.getBestSolution(); + } + + static KB getKB(SortedSet<Integer> lines){ + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(allData)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + KRKModular km = new KRKModular(); + try { + String line = ""; + int x = 0; + while ((line = in.readLine()) != null) { + Integer tmp = new Integer(x); + if(lines.contains(tmp)) + km.addOneLineToKB(x, line); + x++; + }// endWhile + }catch (Exception e) {e.printStackTrace();} + return km.kb; + + } + + + static SortedSet<Integer> getLines(SortedSet<Individual> pos,SortedSet<Individual> neg){ + SortedSet<Integer> ret = new TreeSet<Integer>(); + + for (Individual individual : pos) { + int a = Integer.parseInt(individual.getName().substring((ontologyURI+"#g").length())); + ret.add(new Integer(a)); + } + for (Individual individual : neg) { + int a = Integer.parseInt(individual.getName().substring((ontologyURI+"#g").length())); + ret.add(new Integer(a)); + } + return ret; + + } + + static SortedSet<String> getIgnoredConcepts(SortedSet<Individual> pos,SortedSet<Individual> neg){ + SortedSet<String> ret = new TreeSet<String>(); + + for (Individual individual : pos) { + String tmp = indToClass.get(individual); + //System.out.println("pos"+tmp+individual); + ret.add(ontologyURI+"#"+tmp); + } + for (Individual individual : neg) { + //String tmp = indToClass.get((Individual)individual); + //System.out.println("neg"+tmp+individual); + for (Individual string : indToClass.keySet()) { + if(string.toString().equals(individual.getName())){ + ret.add(ontologyURI+"#"+indToClass.get(string)); + //System.out.println("aaaaaaaa"+individual.getName()); + } + + } + + } + + //System.out.println(indToClass); + return ret; + + } + + public KRKModular() { + this.kb = makeOntologyTBox(); + } + + public KRKModular(String concept) { + this.kb = makeOntologyTBox(concept); + } + + public static void initAllInstancesAndReasoners(){ + // Datei \xF6ffnen + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(allData)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + SimpleClock sc= new SimpleClock(); + KRKModular km =null; + km = new KRKModular(); + try { + String line = ""; + int x = 0; + while ((line = in.readLine()) != null) { + if (x % 10000 == 0) + {sc.print("Currently at line " + x+" : ");} + km.addOneLineToKBinit(x, line); + if(x%1000==0 && x!=0){ + km.initReasonerFact(); + allReasoners.add(km.reasoner); + km = new KRKModular(); + } + if(x==26000)break; + x++; + }// endWhile + + km.initReasonerFact(); + allReasoners.add(km.reasoner); + km = null; + + + sc.printAndSet("initialization finished"); + + //sc.printAndSet("nach Retrieval"); + //km.writeOWLFile(); + /*SortedSet<Individual> s = new TreeSet<Individual>(); + for (int i = 0; i < x; i++) { + s.add(getIndividual("g"+i)); + //if(km.check2(i))howmany++; + }*/ + //writeExampleSet(s); + + + //sc.printAndSet("before "); + //km.initReasonerFact(); + //sc.printAndSet("after initfact"); + + //SortedSet<Individual> ret = km.checkAllOWLAPI(concept, s); + //sc.print("totalfic ("+ret.size()+") for 1000: "); + + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + + + public static SortedSet<Individual> retrieveAll(String concept){ + Description d = null; + try{ + d = KBParser.parseConcept(concept); + }catch (Exception e) {e.printStackTrace();} + return retrieveAll(d); + } + + public static SortedSet<Individual> retrieveAll(Description d){ + SortedSet<Individual> ret = new TreeSet<Individual>(); + try{ + + for (ReasonerComponent onereasoner : allReasoners) { + ret.addAll(onereasoner.retrieval(d)); + } + + }catch (Exception e) {e.printStackTrace();} + return ret; + } + + + + + + public void initReasonerFact(){ + KBFile kbFile = new KBFile(this.kb); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); + ks.add(kbFile); + reasoner = new OWLAPIReasoner(ks); + ((OWLAPIReasoner)reasoner).setReasonerType("fact"); + try{ + reasoner.init(); + }catch (Exception e) {e.printStackTrace();} + } + + + + public void initFIC(){ + KBFile kbFile = new KBFile(this.kb); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); + ks.add(kbFile); + //System.out.println("blabla"); + reasoner = new FastInstanceChecker(ks); + //fic.setReasonerType("fact"); + try{ + reasoner.init(); + }catch (Exception e) {e.printStackTrace();} + } + + public KB makeOntologyTBox(){ + + KRKOntologyTBox tbox = new KRKOntologyTBox(); + return tbox.getKb(); + + } + + public KB makeOntologyTBox(String concept){ + + KRKOntologyTBox tbox = new KRKOntologyTBox(); + tbox.addConcept(concept); + return tbox.getKb(); + + } + + + public void addOneLineToKBinit(int x, String line){ + + String[] ar = new String[6]; + Individual gameind = KRKOntologyTBox.getIndividual("g" + x); + ar = tokenize(line); + addToHM(ar[6], gameind); + addOneLineToKB( x, line); + + + } + + public void addOneLineToKB(int x, String line){ + + Individual gameind; + Individual wkingind; + Individual wrookind; + Individual bkingind; + + String[] ar = new String[6]; + + ar = tokenize(line); + + //String currentclass = ar[6]; + + gameind = KRKOntologyTBox.getIndividual("g" + x); + wkingind = KRKOntologyTBox.getIndividual("wking_" + ar[0] + ar[1] + "_" + x); + wrookind = KRKOntologyTBox.getIndividual("wrook_" + ar[2] + ar[3] + "_" + x); + bkingind = KRKOntologyTBox.getIndividual("bking_" + ar[4] + ar[5] + "_" + x); + + + + //allInstances.add(gameind+""); + //allInstances.add(wkingind+""); + //allInstances.add(wrookind+""); + //allInstances.add(bkingind+""); + + // save it for examplegeneration + + // .add(gameind.getName()); + //classSet.add(ar[6]); + + // CLASSES + kb.addABoxAxiom(new ClassAssertionAxiom(KRKOntologyTBox.Game, gameind)); + kb.addABoxAxiom(new ClassAssertionAxiom( + getAtomicConcept(ar[6]), gameind)); + kb.addABoxAxiom(new ClassAssertionAxiom(KRKOntologyTBox.WKing, wkingind)); + kb.addABoxAxiom(new ClassAssertionAxiom(KRKOntologyTBox.WRook, wrookind)); + kb.addABoxAxiom(new ClassAssertionAxiom(KRKOntologyTBox.BKing, bkingind)); + + + /**Files and Ranks***/ + // FILES are letters + // RANKS are numbers + + //WKing + kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept(ar[0].toUpperCase()), wkingind)); + kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept("F"+ar[1]) , wkingind)); + + //WRook + kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept(ar[2].toUpperCase()), wrookind)); + kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept("F"+ar[3]) , wrookind)); + + //BKing + kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept(ar[4].toUpperCase()), bkingind)); + kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept("F"+ar[5]), bkingind)); + + + + // PROPERTIES + kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.hasPiece, gameind, + wkingind)); + kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.hasPiece, gameind, + wrookind)); + kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.hasPiece, gameind, + bkingind)); + + // labels + + KRKPiece WKingPiece = new KRKPiece(wkingind, ar[0], Integer + .parseInt(ar[1])); + KRKPiece WRookPiece = new KRKPiece(wrookind, ar[2], Integer + .parseInt(ar[3])); + KRKPiece BKingPiece = new KRKPiece(bkingind, ar[4], Integer + .parseInt(ar[5])); + + makeDistanceRoles(WKingPiece, WRookPiece); + makeDistanceRoles(WKingPiece, BKingPiece); + makeDistanceRoles(WRookPiece, BKingPiece); + + } + + + /*protected static void verifySomeConcepts(OntologyCloser oc) { + + ArrayList<String> test=new ArrayList<String>(); + test.add("(EXISTS \"http://www.test.de/test#hasPiece\".EXISTS \"http://www.test.de/test#rankDistanceLessThan2\".(\"http://www.test.de/test#BKing\" AND EXISTS \"http://www.test.de/test#fileDistanceLessThan1\".(\"http://www.test.de/test#A\" OR \"http://www.test.de/test#WKing\")) AND EXISTS \"http://www.test.de/test#hasPiece\".(\"http://www.test.de/test#WKing\" AND ((\"http://www.test.de/test#C\" AND EXISTS \"http://www.test.de/test#hasLowerRankThan\".\"http://www.test.de/test#A\") OR (\"http://www.test.de/test#F3\" AND EXISTS \"http://www.test.de/test#rankDistance2\".\"http://www.test.de/test#WRook\"))))"); + for (int i = 0; i < test.size(); i++) { + String conceptStr = test.get(i); + oc.verifyConcept(conceptStr); + } + /*conceptStr = "EXISTS \"http://www.test.de/test#hasLowerRankThan\"."+ + "(\"http://www.test.de/test#WRook\""+ + "AND ALL \"http://www.test.de/test#fileDistanceLessThan1\".\"http://www.test.de/test#WKing\") "; + + System.out.println(); + }*/ + + public void makeDistanceRoles(KRKPiece A, KRKPiece B) { + int Fdist = A.getFileDistance(B); + int Rdist = A.getRankDistance(B); + String rdistance = "rankDistance"; + String fdistance = "fileDistance"; + + kb.addABoxAxiom(new ObjectPropertyAssertion(getRole(rdistance + Rdist), + A.id, B.id)); + kb.addABoxAxiom(new ObjectPropertyAssertion(getRole(fdistance + Fdist), + A.id, B.id)); + + if (A.meHasLowerFileThan(B)){ + kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.fileLessThan, A.id, + B.id)); + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.fileHigherThan, B.id, + A.id)); + } + else if (B.meHasLowerFileThan(A)){ + kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.fileLessThan, B.id, + A.id)); + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.fileHigherThan, A.id, + B.id)); + } + + if (A.meHasLowerRankThan(B)){ + kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.rankLessThan, A.id, + B.id)); + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.rankHigherThan, B.id, + A.id)); + } + else if (B.meHasLowerRankThan(A)){ + kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.rankLessThan, B.id, + A.id)); + if(useHigherThan)kb.addABoxAxiom(new ObjectPropertyAssertion(KRKOntologyTBox.rankHigherThan, A.id, + B.id)); + + } + } + + + + + protected static void writeExampleSet(Set<Individual> s) { + for (Individual individual : s) { + writeToFile(workingDir+"example.txt", "+\""+individual.getName()+"\"\n"); + } + + } + + + + + + /*protected static void writeExampleSets() { + StringBuffer collect1 = new StringBuffer(); + StringBuffer collect2 = new StringBuffer(); + System.out.println("start writing sets"); + + for (String keys : classToInd.keySet()) { + System.out.println(keys); + SortedSet<String> tmpset = classToInd.get(keys); + for (String individuals : tmpset) { + collect1.append("+\"" + individuals + "\"\n"); + collect2.append("-\"" + individuals + "\"\n"); + } + + writeToFile(workingDir+"/examples_for_" + keys + ".txt", collect1 + + "\n\n" + collect2 + "\n"); + collect1 = new StringBuffer(); + collect2 = new StringBuffer(); + } + // System.out.println("Sets written"); + collect1 = new StringBuffer(); + collect2 = new StringBuffer(); + for (String key : classToInd.keySet()) { + + SortedSet<String> tmpset = classToInd.get(key); + + if (key.equals("ZERO")) {*/ + // collect1.append("/**" + key + "**/\n"); + /* for (String individuals : tmpset) { + collect1.append("+\"" + individuals + "\"\n"); + } + + continue; + } else { */ + // collect2.append("/**" + key + "**/\n"); + /* for (String individuals : tmpset) { + collect2.append("-\"" + individuals + "\"\n"); + } + } + + } + writeToFile(workingDir+"/examples_for_ZERO_and_Rest.txt", collect1 + + "\n\n" + collect2 + "\n"); + System.out.println("Example sets written"); + } + */ + + + + + + + /*protected void writeOWLFile(String filename) { + + Iterator<String> it = classSet.iterator(); + System.out.println("import(\"" + filename + "\");"); + String collect = "refinement.ignoredConcepts={"; + while (it.hasNext()) { + String tmp = (String) it.next(); + collect += "\n\"" + getAtomicConcept(tmp).getName() + "\","; + } + collect = collect.substring(0, collect.length() - 1); + System.out.println(collect + "};"); + + System.out.println("Writing owl"); + File owlfile = new File(workingDir+"/" + filename); + // System.out.println(kb.toString("http://www.test.de/test", new + // HashMap<String, String>())); + OWLAPIReasoner.exportKBToOWL(owlfile, kb, ontologyURI); + + }*/ + + protected void writeOWLFile() { + writeOWLFile("test.owl"); + } + + protected void writeOWLFile(String filename) { + + System.out.println("Writing owl"); + File owlfile = new File(workingDir+"/" + filename); + OWLAPIReasoner.exportKBToOWL(owlfile, this.kb, ontologyURI); + + } + + + + protected static void writeToFile(String filename, String content) { + // create the file we want to use + File file = new File(filename); + + try { + file.createNewFile(); + FileOutputStream fos = new FileOutputStream(filename, true); + // ObjectOutputStream o = new ObjectOutputStream(fos); + fos.write(content.getBytes()); + fos.flush(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + protected static void addToHM(String className, Individual ind) { + if (classToInd.get(className) == null) + classToInd.put(className, new TreeSet<Individual>()); + + classToInd.get(className).add(ind); + indToClass.put(ind, className); + + } + + + protected static Individual getIndividual(String name) { + return new Individual(ontologyURI + "#" + name); + } + + protected static ObjectProperty getRole(String name) { + return new ObjectProperty(ontologyURI + "#" + name); + } + + protected static NamedClass getAtomicConcept(String name) { + return new NamedClass(ontologyURI + "#" + name); + } + + public static String[] tokenize(String s) { + StringTokenizer st = new StringTokenizer(s, ","); + + String tmp = ""; + String[] ret = new String[7]; + int x = 0; + while (st.hasMoreTokens()) { + tmp = st.nextToken(); + if (x == 6) + tmp = tmp.toUpperCase(); + ret[x] = tmp; + x++; + } + return ret; + + } + + static SortedSet<Individual> getNegativeExamples(String currentClass, SortedSet<Individual> allRetrieved, int howmany) { + SortedSet<Individual> ret = new TreeSet<Individual>(); + + //clean + SortedSet<Individual> allPos = classToInd.get(currentClass); + for (Individual individual : allPos) { + if(!allRetrieved.remove(individual))System.out.println("WARNING, not all positives covered");; + } + + Random r = new Random(); + double treshold = ((double)howmany)/allRetrieved.size(); + //System.out.println("treshold"+howmany); + //System.out.println("treshold"+allRetrieved.size()); + //System.out.println("treshold"+treshold); + int added=0; + for (Individual oneInd : allRetrieved) { + if(r.nextDouble()<treshold) { + ret.add(oneInd); + added++; + } + } + System.out.println(added+" new negs added"); + return ret; + } + static boolean verify(String currentClass, SortedSet<Individual> allRetrieved) { + //clean + SortedSet<Individual> allPos = classToInd.get(currentClass); + boolean hasAll=true; + for (Individual individual : allPos) { + if(!allRetrieved.contains(individual))hasAll=false; + } + if(hasAll && allRetrieved.size()==allPos.size()){return true;} + else return false; + + } + + /*public SortedSet<Individual> checkAll(String concept, SortedSet<Individual> s){ + try{ + Description d = KBParser.parseConcept(concept,ontologyURI.toString()+"#"); + + return reasoner.instanceCheck(d, s); + }catch (Exception e) {e.printStackTrace();} + return null; +} + +public SortedSet<Individual> checkAllOWLAPI(String concept,SortedSet<Individual> s){ + try{ + Description d = KBParser.parseConcept(concept,ontologyURI.toString()+"#"); + return reasoner.instanceCheck(d, s); + }catch (Exception e) {e.printStackTrace();} + return null; +} + +/*public SortedSet<Individual> retrieveAllowlAPI(String concept){ + try{ + Description d = KBParser.parseConcept(concept,ontologyURI.toString()+"#"); + return reasoner.retrieval(d); + }catch (Exception e) {e.printStackTrace();} + return null; +}*/ + +} Added: trunk/src/dl-learner/org/dllearner/examples/KRKOntologyTBox.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRKOntologyTBox.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/examples/KRKOntologyTBox.java 2008-04-15 10:20:23 UTC (rev 788) @@ -0,0 +1,251 @@ +package org.dllearner.examples; + +import java.net.URI; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.owl.ClassAssertionAxiom; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DisjointClassesAxiom; +import org.dllearner.core.owl.EquivalentClassesAxiom; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KB; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyAssertion; +import org.dllearner.core.owl.ObjectPropertyDomainAxiom; +import org.dllearner.core.owl.ObjectPropertyRangeAxiom; +import org.dllearner.core.owl.SubClassAxiom; +import org.dllearner.core.owl.SubObjectPropertyAxiom; +import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; +import org.dllearner.parser.KBParser; + +public class KRKOntologyTBox { + + private KB kb; + static URI ontologyURI = URI.create("http://dl-learner.org/krk"); + + static boolean useHigherThan=false; + static boolean useInverse = false; + + static NamedClass Game = getAtomicConcept("Game"); + static NamedClass WKing = getAtomicConcept("WKing"); + static NamedClass WRook = getAtomicConcept("WRook"); + static NamedClass BKing = getAtomicConcept("BKing"); + // had to rename, too much similarity to java.io.File + static NamedClass FileData = getAtomicConcept("File"); + static NamedClass Rank = getAtomicConcept("Rank"); + static NamedClass Piece = getAtomicConcept("Piece"); + + static ObjectProperty hasPiece = getRole("hasPiece"); + static ObjectProperty hasWKing = getRole("hasWKing"); + static ObjectProperty hasWRook = getRole("hasWRook"); + static ObjectProperty hasBKing = getRole("hasBKing"); + + static ObjectProperty hasPieceInv = getRole("hasGame"); + static ObjectProperty hasWKingInv = getRole("hasWKingInv"); + static ObjectProperty hasWRookInv = getRole("hasWRookInv"); + static ObjectProperty hasBKingInv = getRole("hasBKingInv"); + + static ObjectProperty rankLessThan = getRole("hasLowerRankThan"); + static ObjectProperty fileLessThan = getRole("hasLowerFileThan"); + + static ObjectProperty rankHigherThan = getRole("hasHigherRankThan"); + static ObjectProperty fileHigherThan = getRole("hasHigherFileThan"); + + + /*public KRKOntologyTBox(KB kbin){ + this.kb=kbin; + + }*/ + + public KRKOntologyTBox(){ + this.kb=new KB(); + initOntologyTBox(); + + + } + + public void addConcept(String concept){ + try{ + //make Description + Description d = KBParser.parseConcept(concept,ontologyURI.toString()+"#"); + //d.addChild(oecr); + kb.addTBoxAxiom(new EquivalentClassesAxiom(getAtomicConcept("test"),d)); + + }catch (Exception e) {e.printStackTrace();} + } + + public void initOntologyTBox(){ + + //DISJOINTCLASSES + SortedSet<Description> DisJointClasses1 = new TreeSet<Description>(); + DisJointClasses1.add(Piece); + DisJointClasses1.add(Game); + kb.addTBoxAxiom(new DisjointClassesAxiom(DisJointClasses1)); + + SortedSet<Description> DisJointClasses2 = new TreeSet<Description>(); + DisJointClasses2 = new TreeSet<Description>(); + DisJointClasses2.add(WKing); + DisJointClasses2.add(WRook); + DisJointClasses2.add(BKing); + // DisJointClasses2.add(Rank); + // DisJointClasses2.add(File); + // DisJointClasses2.add(Game); + kb.addTBoxAxiom(new DisjointClassesAxiom(DisJointClasses2)); + + /**CLASSES***/ + // all sub of piece + kb.addTBoxAxiom(new SubClassAxiom(WKing, Piece)); + kb.addTBoxAxiom(new SubClassAxiom(WRook, Piece)); + kb.addTBoxAxiom(new SubClassAxiom(BKing, Piece)); + + String[] letters=new String[]{"A","B","C","D","E","F","G","H"}; + String[] numbers=new String[8]; + for (int i = 0; i < numbers.length; i++) { + numbers[i]="F"+(i+1); + } + //System.out.println(numbers); + + for (int i = 0; i < numbers.length; i++) { + kb.addTBoxAxiom(new SubClassAxiom(getAtomicConcept(letters[i]),Piece)); + kb.addTBoxAxiom(new SubClassAxiom(getAtomicConcept(numbers[i]),Piece)); + } + + + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasPiece, Game)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasPiece, Piece)); + + + if (useInverse) { + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasPieceInv, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasPieceInv, Game)); + + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasWKingInv, WKing)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasWKingInv, Game)); + + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasWRookInv, WRook)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasWRookInv, Game)); + + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasBKingInv, BKing)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasBKingInv, Game)); + } + + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(rankLessThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(rankLessThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(fileLessThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(fileLessThan, Piece)); + + if(useHigherThan) { + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(rankHigherThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(rankHigherThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(fileHigherThan, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(fileHigherThan, Piece)); + } + + finishBackgroundForRoles(); + + //return this.kb; + + } + + + public void finishBackgroundForRoles() { + + for (int i = 8; i > 0; i--) { + + + ObjectProperty rankDistance = getRole("rankDistance"+(i-1)); + ObjectProperty fileDistance = getRole("fileDistance"+(i-1)); + kb.addRBoxAxiom(new SymmetricObjectPropertyAxiom(rankDistance)); + kb.addRBoxAxiom(new SymmetricObjectPropertyAxiom(fileDistance)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(rankDistance, + KRKOntologyTBox.Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(rankDistance, + KRKOntologyTBox.Piece)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(fileDistance, + KRKOntologyTBox.Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(fileDistance, + KRKOntologyTBox.Piece)); + + + + kb.addRBoxAxiom(new SubObjectPropertyAxiom( + getRole("rankDistance" + (i - 1)), + getRole("rankDistanceLessThan" + i))); + kb.addRBoxAxiom(new SubObjectPropertyAxiom( + getRole("fileDistance" + (i - 1)), + getRole("fileDistanceLessThan" + i))); + + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom( + getRole("rankDistanceLessThan" + i), KRKOntologyTBox.Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom( + getRole("rankDistanceLessThan" + i), KRKOntologyTBox.Piece)); + + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom( + getRole("fileDistanceLessThan" + i), KRKOntologyTBox.Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom( + getRole("fileDistanceLessThan" + i), KRKOntologyTBox.Piece)); + + + if(i==1) continue; + + kb.addRBoxAxiom(new SubObjectPropertyAxiom( + getRole("rankDistanceLessThan" + (i - 1)), + getRole("rankDistanceLessThan" + i))); + kb.addRBoxAxiom(new SubObjectPropertyAxiom( + getRole("fileDistanceLessThan" + (i - 1)), + getRole("fileDistanceLessThan" + i))); + + + } + + + } + + + protected static Individual getIndividual(String name) { + return new Individual(ontologyURI + "#" + name); + } + + protected static ObjectProperty getRole(String name) { + return new ObjectProperty(ontologyURI + "#" + name); + } + + @SuppressWarnings("unused") + protected static DatatypeProperty getDatatypeProperty(String name) { + return new DatatypeProperty(ontologyURI + "#" + name); + } + + protected static NamedClass getAtomicConcept(String name) { + return new NamedClass(ontologyURI + "#" + name); + } + + @SuppressWarnings("unused") + protected static String getURI(String name) { + return ontologyURI + "#" + name; + } + + @SuppressWarnings("unused") + protected static ClassAssertionAxiom getConceptAssertion(String concept, + String instance) { + Individual ind = getIndividual(instance); + NamedClass c = getAtomicConcept(concept); + return new ClassAssertionAxiom(c, ind); + } + + @SuppressWarnings("unused") + protected static ObjectPropertyAssertion getRoleAssertion(String role, + String i1, String i2) { + Individual ind1 = getIndividual(i1); + Individual ind2 = getIndividual(i2); + ObjectProperty ar = getRole(role); + return new ObjectPropertyAssertion(ar, ind1, ind2); + } + + public KB getKb() { + return kb; + } + +} Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-04-14 22:45:16 UTC (rev 787) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-04-15 10:20:23 UTC (rev 788) @@ -145,6 +145,14 @@ return positiveExamples; } + public void setNegativeExamples(SortedSet<Individual> set) { + this.negativeExamples=set; + } + + public void setPositiveExamples(SortedSet<Individual> set) { + this.positiveExamples=set; + } + public abstract int coveredNegativeExamplesOrTooWeak(Description concept); public double getPercentPerLengthUnit() { Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-04-14 22:45:16 UTC (rev 787) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-04-15 10:20:23 UTC (rev 788) @@ -18,6 +18,12 @@ return internalNamespace + name; } + //TODO beware of this function it is evil + public static Description parseConcept(String string, String namespace) throws ParseException { + internalNamespace = namespace; + return parseConcept(string); + } + public static Description parseConcept(String string) throws ParseException { // when just parsing the string as concept, we have no guarantee // that the parser uses all symbols, e.g. a AND b returns just a Modified: trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java 2008-04-14 22:45:16 UTC (rev 787) +++ trunk/src/dl-learner/org/dllearner/utilities/SimpleClock.java 2008-04-15 10:20:23 UTC (rev 788) @@ -11,6 +11,10 @@ time=System.currentTimeMillis(); } + + + + /** * prints time needed * and resets the clock @@ -33,6 +37,18 @@ time=now; } + + /** + * prints time needed + * + * @param s String for printing + */ + public void print(String s) { + long now=System.currentTimeMillis(); + System.out.println(s+" needed "+(now-time)+" ms"); + + } + public void setTime() { time=System.currentTimeMillis(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |