[DL-Learner SVN] SF.net SVN: dl-learner: [708]
trunk/src/dl-learner/org/dllearner/examples/ KRK.java
From: <ku...@us...> - 2008-03-13 08:12:02
|
Revision: 708 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=708&view=rev Author: kurzum Date: 2008-03-13 01:11:59 -0700 (Thu, 13 Mar 2008) Log Message: ----------- intermediate working owl, still missing conf files Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/examples/KRK.java Modified: trunk/src/dl-learner/org/dllearner/examples/KRK.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-03-13 06:55:13 UTC (rev 707) +++ trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-03-13 08:11:59 UTC (rev 708) @@ -5,8 +5,8 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.net.URI; -import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; import java.util.SortedSet; import java.util.StringTokenizer; import java.util.TreeSet; @@ -18,9 +18,23 @@ 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.core.owl.TransitiveObjectPropertyAxiom; import org.dllearner.reasoning.OWLAPIReasoner; +/* + * Structure + * + * + * + * + * */ + + public class KRK { // REMEMBER @@ -28,71 +42,48 @@ // RANKS are numbers private static URI ontologyURI = URI.create("http://www.test.de/test"); - static SortedSet<String> fileSet; - static SortedSet<String> rankSet; - static SortedSet<String> classSet; - static HashMap<String,SortedSet<String>> classToInd; + static SortedSet<String> fileSet = new TreeSet<String>();; + static SortedSet<String> rankSet = new TreeSet<String>();; + static SortedSet<String> classSet = new TreeSet<String>();; + static LinkedList<String> words ; + static KB kb; + + + static NamedClass Game =getAtomicConcept("Game"); + static NamedClass WKing = getAtomicConcept("WKing"); + static NamedClass WRook = getAtomicConcept("WRook"); + static NamedClass BKing = getAtomicConcept("BKing"); + static NamedClass File = getAtomicConcept("File"); + static NamedClass Rank = getAtomicConcept("Rank"); + static NamedClass Piece = getAtomicConcept("Piece"); + + static ObjectProperty hasRank= getRole("hasRank"); + static ObjectProperty hasFile= getRole("hasFile"); + static ObjectProperty hasPiece= getRole("hasPiece"); + static ObjectProperty lessThan= getRole("strictLessThan"); + + + //static HashMap<String,SortedSet<String>> classToInd; /** * @param args */ public static void main(String[] args) { - classToInd = new HashMap<String,SortedSet<String>>(); - fileSet = new TreeSet<String>(); - rankSet = new TreeSet<String>(); - classSet = new TreeSet<String>(); - KB kb=new KB(); - + //classToInd = new HashMap<String,SortedSet<String>>(); + initVarsAndClasses(); + initBackgroundRoles(); + - fileSet.add("a"); fileSet.add("b"); fileSet.add("c"); fileSet.add("d"); fileSet.add("e"); fileSet.add("f"); fileSet.add("g"); fileSet.add("h"); + Individual gameind; + Individual wkingind; + Individual wrookind; + Individual bkingind; - for (int count = 1; count < 9; count++) { - rankSet.add("f"+count); - } - NamedClass[] nc=new NamedClass[]{ - getAtomicConcept("Game"), - getAtomicConcept("WKing"), - getAtomicConcept("WRook"), - getAtomicConcept("BKing")}; - ObjectProperty rank= getRole("hasRank"); - ObjectProperty file= getRole("hasFile"); - ObjectProperty piece= getRole("hasPiece"); - ObjectProperty lessThan= getRole("strictLessThan"); - //ObjectProperty rank= getRole("hasRank"); - - Individual game; - Individual wking; - Individual wrook; - Individual bking; - - kb.addRBoxAxiom(new TransitiveObjectPropertyAxiom(lessThan)); - - Iterator<String> it = fileSet.iterator(); - Individual current = getIndividual(it.next()); - Individual next; - while (it.hasNext()){ - next=getIndividual(it.next()); - kb.addABoxAxiom(new ObjectPropertyAssertion(lessThan,current,next)); - current=next; - - } - - it = rankSet.iterator(); - current = getIndividual(it.next()); - next=null; - while (it.hasNext()){ - next=getIndividual(it.next()); - kb.addABoxAxiom(new ObjectPropertyAssertion(lessThan,current,next)); - current=next; - - } - - String fileIn = "examples/krk/krkopt.data"; - // Datei öffnen + // Datei \xF6ffnen BufferedReader in = null; try { in = new BufferedReader(new FileReader(fileIn)); @@ -110,36 +101,35 @@ { x++; //if(x % 3000 == 0 ) System.out.println("Currently at line "+x); ar = tokenize(line); - game = getIndividual("game"+x); - wking = getIndividual("wking"+x); - wrook = getIndividual("wrook"+x); - bking = getIndividual("bking"+x); + gameind = getIndividual("game"+x); + wkingind = getIndividual("wking"+x); + wrookind = getIndividual("wrook"+x); + bkingind = getIndividual("bking"+x); classSet.add(ar[6]); - //ar[0]); - + // CLASSES - kb.addABoxAxiom(new ClassAssertionAxiom(nc[0],game)); - kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept(ar[6]),game)); - kb.addABoxAxiom(new ClassAssertionAxiom(nc[1],wking)); - kb.addABoxAxiom(new ClassAssertionAxiom(nc[2],wrook)); - kb.addABoxAxiom(new ClassAssertionAxiom(nc[3],bking)); + kb.addABoxAxiom(new ClassAssertionAxiom(Game,gameind)); + kb.addABoxAxiom(new ClassAssertionAxiom(getAtomicConcept(ar[6]),gameind)); + kb.addABoxAxiom(new ClassAssertionAxiom(WKing,wkingind)); + kb.addABoxAxiom(new ClassAssertionAxiom(WRook,wrookind)); + kb.addABoxAxiom(new ClassAssertionAxiom(BKing,bkingind)); //PROPERTIES - kb.addABoxAxiom(new ObjectPropertyAssertion(piece,game,wking)); - kb.addABoxAxiom(new ObjectPropertyAssertion(piece,game,wrook)); - kb.addABoxAxiom(new ObjectPropertyAssertion(piece,game,bking)); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasPiece,gameind,wkingind)); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasPiece,gameind,wrookind)); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasPiece,gameind,bkingind)); - kb.addABoxAxiom(new ObjectPropertyAssertion(rank,wking,getIndividual(ar[0]))); - kb.addABoxAxiom(new ObjectPropertyAssertion(file,wking,getIndividual("f"+ar[1]))); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasRank,wkingind,getIndividual(ar[0]))); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasFile,wkingind,getIndividual("f"+ar[1]))); - kb.addABoxAxiom(new ObjectPropertyAssertion(rank,wrook,getIndividual(ar[2]))); - kb.addABoxAxiom(new ObjectPropertyAssertion(file,wrook,getIndividual("f"+ar[3]))); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasRank,wrookind,getIndividual(ar[2]))); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasFile,wrookind,getIndividual("f"+ar[3]))); - kb.addABoxAxiom(new ObjectPropertyAssertion(rank,bking,getIndividual(ar[4]))); - kb.addABoxAxiom(new ObjectPropertyAssertion(file,bking,getIndividual("f"+ar[5]))); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasRank,bkingind,getIndividual(ar[4]))); + kb.addABoxAxiom(new ObjectPropertyAssertion(hasFile,bkingind,getIndividual("f"+ar[5]))); //kb.addABoxAxiom(new ClassAssertionAxiom(new NamedClass("Game"),new Individual(names[0]+(x++)))); //kb.addABoxAxiom(new ClassAssertionAxiom(new NamedClass("Game"),new Individual(names[0]+(x++)))); @@ -156,6 +146,108 @@ }catch (Exception e) {e.printStackTrace();} System.out.println("Done"); + }//end main + + + static void initVarsAndClasses(){ + kb=new KB(); + fileSet.add("a"); fileSet.add("b"); fileSet.add("c"); fileSet.add("d"); fileSet.add("e"); fileSet.add("f"); fileSet.add("g"); fileSet.add("h"); + for (int count = 1; count < 9; count++) { + rankSet.add("r"+count); + } + + // all sub of piece + kb.addTBoxAxiom(new SubClassAxiom(WKing,Piece)); + kb.addTBoxAxiom(new SubClassAxiom(WRook,Piece)); + kb.addTBoxAxiom(new SubClassAxiom(BKing,Piece)); + + // Classes for files + Iterator<String> it = fileSet.iterator(); + Individual next; + while (it.hasNext()){ + next=getIndividual(it.next()); + kb.addABoxAxiom(new ClassAssertionAxiom(File, next)); + } + + // Classes for rank + it = rankSet.iterator(); + while (it.hasNext()){ + next=getIndividual(it.next()); + kb.addABoxAxiom(new ClassAssertionAxiom(Rank, next)); + } + + + }//end init + + + static void initBackgroundRoles() + { + + //TODO test + kb.addRBoxAxiom(new TransitiveObjectPropertyAxiom(lessThan)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(lessThan,Rank)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(lessThan, Rank)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(lessThan, File)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(lessThan, File)); + //TODO test + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasRank, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasRank, Rank)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasFile, Piece)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasFile, File)); + kb.addRBoxAxiom(new ObjectPropertyDomainAxiom(hasPiece, Game)); + kb.addRBoxAxiom(new ObjectPropertyRangeAxiom(hasPiece, Piece)); + + // assigning lessthan to file + Iterator<String> it = fileSet.iterator(); + Individual current = getIndividual(it.next()); + Individual next; + while (it.hasNext()){ + next=getIndividual(it.next()); + kb.addABoxAxiom(new ObjectPropertyAssertion(lessThan,current,next)); + current=next; + + } + // assigning lessthan to rank + it = rankSet.iterator(); + current = getIndividual(it.next()); + next=null; + while (it.hasNext()){ + next=getIndividual(it.next()); + kb.addABoxAxiom(new ObjectPropertyAssertion(lessThan,current,next)); + current=next; + + } + + + + + //new PropertyRangeAxiom(rank, (PropertyRange) nc[5]); + + String str="hasDistanceOf"; + String str2="hasDistanceLessThan"; + //ObjectProperty tmp; + String[] rankarray=new String[8]; + String[] filearray=new String[8]; + rankSet.toArray(rankarray); + fileSet.toArray(filearray); + + // assigning has DistanceOf to Rank and File + for (int count = 0; count < filearray.length; count++) { + for (int inner = count+1 , dist = 1; inner < filearray.length; inner++, dist++) { + //ObjectProperty op = getRole(str+inner); + kb.addABoxAxiom(getRoleAssertion( str+dist, rankarray[count], rankarray[inner])); + kb.addABoxAxiom(getRoleAssertion( str+dist, filearray[count], filearray[inner])); + + } + } + //make it symmetric + subproperty of + for (int count = 1; count < 8; count++) { + kb.addRBoxAxiom(new SymmetricObjectPropertyAxiom(getRole(str+count))); + kb.addRBoxAxiom(new SubObjectPropertyAxiom(getRole(str+count),getRole(str2+(count+1)))); + kb.addRBoxAxiom(new SubObjectPropertyAxiom(getRole(str2+count),getRole(str2+(count+1)))); + } + + } public static String[] tokenize (String s) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[DL-Learner SVN] SF.net SVN: dl-learner: [723]
trunk/src/dl-learner/org/dllearner/examples/ KRK.java
From: <ku...@us...> - 2008-03-25 19:06:46
|
Revision: 723 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=723&view=rev Author: kurzum Date: 2008-03-25 12:05:07 -0700 (Tue, 25 Mar 2008) Log Message: ----------- krk source Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/examples/KRK.java Modified: trunk/src/dl-learner/org/dllearner/examples/KRK.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-03-25 14:28:25 UTC (rev 722) +++ trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-03-25 19:05:07 UTC (rev 723) @@ -48,7 +48,7 @@ // FLAGS // static boolean useInverse = false; - //dependent, love and marriage, horse and carriage + // dependent, love and marriage, horse and carriage static boolean useTripleSubProps = useInverse && false; static URI ontologyURI = URI.create("http://www.test.de/test"); @@ -471,6 +471,31 @@ collect1 = ""; collect2 = ""; } + + collect1 = ""; + collect1 = ""; + for (String key : classToInd.keySet()) { + + SortedSet<String> tmpset = classToInd.get(key); + + if (key.equals("ZERO")) { + collect1 += "/**" + key + "**/\n"; + for (String individuals : tmpset) { + collect1 += "+\"" + individuals + "\"\n"; + } + + continue; + } else { + collect2 += "/**" + key + "**/\n"; + for (String individuals : tmpset) { + collect2 += "-\"" + individuals + "\"\n"; + } + } + + } + writeToFile("examples/krk/examples_for_ZERO_and_Rest.txt", collect1 + + "\n\n" + collect2 + "\n"); + } protected static void writeOWLFile(String filename) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[DL-Learner SVN] SF.net SVN: dl-learner: [724]
trunk/src/dl-learner/org/dllearner/examples/ KRK.java
From: <ku...@us...> - 2008-03-25 19:09:25
|
Revision: 724 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=724&view=rev Author: kurzum Date: 2008-03-25 12:08:48 -0700 (Tue, 25 Mar 2008) Log Message: ----------- last commit failed, maybe Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/examples/KRK.java Modified: trunk/src/dl-learner/org/dllearner/examples/KRK.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-03-25 19:05:07 UTC (rev 723) +++ trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-03-25 19:08:48 UTC (rev 724) @@ -471,7 +471,7 @@ collect1 = ""; collect2 = ""; } - + collect1 = ""; collect1 = ""; for (String key : classToInd.keySet()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
[DL-Learner SVN] SF.net SVN: dl-learner: [760]
trunk/src/dl-learner/org/dllearner/examples/ KRK.java
From: <ku...@us...> - 2008-04-03 09:37:12
|
Revision: 760 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=760&view=rev Author: kurzum Date: 2008-04-03 02:36:39 -0700 (Thu, 03 Apr 2008) Log Message: ----------- includes validating Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/examples/KRK.java Modified: trunk/src/dl-learner/org/dllearner/examples/KRK.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-04-03 09:34:16 UTC (rev 759) +++ trunk/src/dl-learner/org/dllearner/examples/KRK.java 2008-04-03 09:36:39 UTC (rev 760) @@ -47,6 +47,7 @@ // FLAGS // + // turn off to not write the owl, needs about 30 seconds or more static boolean writeOWL = true; static boolean writeClosedOWL = true ; static boolean useTransitivity = false; @@ -55,10 +56,15 @@ static boolean useInverse = false; // dependent, love and marriage, horse and carriage static boolean useTripleSubProps = useInverse && false; + + + static String workingDir = "examples/krkworking"; + static String fileIn = workingDir+"/krkopt.data"; + static URI ontologyURI = URI.create("http://www.test.de/test"); // static SortedSet<String> fileSet = new TreeSet<String>(); - // static SortedSet<String> rankSet = new TreeSet<String>(); + static SortedSet<String> allInstances = new TreeSet<String>(); static SortedSet<String> classSet = new TreeSet<String>(); static SortedSet<String> symmetricRoleSet = new TreeSet<String>(); @@ -71,7 +77,8 @@ static NamedClass WKing = getAtomicConcept("WKing"); static NamedClass WRook = getAtomicConcept("WRook"); static NamedClass BKing = getAtomicConcept("BKing"); - static NamedClass File = getAtomicConcept("File"); + // 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"); @@ -101,7 +108,19 @@ */ public static void main(String[] args) { System.out.println("Start"); - // turn off to not write the owl, needs about 30 seconds or more + workingDir = workingDir + File.separator; + if (!new File(workingDir).exists()) { + System.out.println("Created directory: " + workingDir + " : " + new File(workingDir).mkdir() + + "."); + } + + // Datei \xF6ffnen + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(fileIn)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } // classToInd = new HashMap<String,SortedSet<String>>(); init(); @@ -110,19 +129,12 @@ Individual wkingind; Individual wrookind; Individual bkingind; - // String currentClass = ""; + + + + - String fileIn = "examples/krk/krkopt.data"; - - // Datei \xF6ffnen - BufferedReader in = null; try { - in = new BufferedReader(new FileReader(fileIn)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - try { String line = ""; String[] ar = new String[6]; @@ -137,6 +149,11 @@ 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+""); + allInstances.add(bkingind+""); // if (x == 1) // currentClass = ar[6]; @@ -199,6 +216,7 @@ System.out.println("Finished Background"); // WRITE writeExampleSets(); + writeConciseOWLAllDifferent(); if (writeOWL) { @@ -208,6 +226,7 @@ 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\""; OntologyCloser oc = new OntologyCloser(kb); oc.applyNumberRestrictions(); oc.verifyConcept(conceptStr); @@ -486,7 +505,7 @@ collect2.append("-\"" + individuals + "\"\n"); } - writeToFile("examples/krk/examples_for_" + keys + ".txt", collect1 + writeToFile(workingDir+"/examples_for_" + keys + ".txt", collect1 + "\n\n" + collect2 + "\n"); collect1 = new StringBuffer(); collect2 = new StringBuffer(); @@ -513,11 +532,31 @@ } } - writeToFile("examples/krk/examples_for_ZERO_and_Rest.txt", collect1 + writeToFile(workingDir+"/examples_for_ZERO_and_Rest.txt", collect1 + "\n\n" + collect2 + "\n"); System.out.println("Example sets written"); } + + protected static void writeConciseOWLAllDifferent() { + StringBuffer collect = new StringBuffer(); + System.out.println("start writing OWLAllDifferent"); + collect.append("<owl:AllDifferent>\n" + + "<owl:distinctMembers rdf:parseType=\"Collection\">\n"); + + for (String inst : allInstances) { + collect.append("<owl:Thing rdf:about=\"" + inst + "\" />\n"); + } + collect.append("</owl:distinctMembers>"+ + "</owl:AllDifferent>"); + + writeToFile(workingDir+"/owlAllDifferent.txt", collect.toString()); + + } + + + + protected static void writeOWLFile(String filename) { Iterator<String> it = classSet.iterator(); @@ -531,7 +570,7 @@ System.out.println(collect + "};"); System.out.println("Writing owl"); - File owlfile = new File("examples/krk/" + filename); + 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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |