From: <jen...@us...> - 2008-02-18 18:54:41
|
Revision: 606 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=606&view=rev Author: jenslehmann Date: 2008-02-18 10:53:32 -0800 (Mon, 18 Feb 2008) Log Message: ----------- - started jUnit reasoner tests - small addition to KBparser Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/parser/KBParser.java trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java Modified: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2008-02-18 17:28:12 UTC (rev 605) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2008-02-18 18:53:32 UTC (rev 606) @@ -60,6 +60,18 @@ private URL url; private KB kb; + /** + * Constructor allowing you to treat an already existing KB object + * as a KBFile knowledge source. Use it sparingly, because the + * standard way to create components is via + * {@link org.dllearner.core.ComponentManager}. + * + * @param kb A KB object. + */ + public KBFile(KB kb) { + this.kb = kb; + } + public static String getName() { return "KB file"; } @@ -99,7 +111,8 @@ @Override public void init() throws ComponentInitException { try { - kb = KBParser.parseKBFile(url); + if(kb == null) + kb = KBParser.parseKBFile(url); } catch (IOException e) { throw new ComponentInitException("KB file " + url + " could not be read.", e); } catch (ParseException e) { Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-02-18 17:28:12 UTC (rev 605) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-02-18 18:53:32 UTC (rev 606) @@ -23,6 +23,11 @@ return parser.Concept(); } + public static KB parseKBFile(String content) throws IOException, ParseException { + KBParser parser = new KBParser(new StringReader(content)); + return parser.KB(); + } + public static KB parseKBFile(URL url) throws IOException, ParseException { KBParser parser = new KBParser(url.openStream()); return parser.KB(); @@ -494,31 +499,6 @@ finally { jj_save(5, xla); } } - final private boolean jj_3R_13() { - if (jj_scan_token(19)) return true; - if (jj_3R_20()) return true; - if (jj_3R_4()) return true; - if (jj_scan_token(COMMAND_END)) return true; - if (jj_3R_2()) return true; - return false; - } - - final private boolean jj_3R_22() { - if (jj_scan_token(STRING)) return true; - return false; - } - - final private boolean jj_3_2() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(18)) jj_scanpos = xsp; - if (jj_3R_4()) return true; - if (jj_scan_token(22)) return true; - if (jj_3R_3()) return true; - if (jj_scan_token(24)) return true; - return false; - } - final private boolean jj_3_6() { if (jj_scan_token(22)) return true; if (jj_3R_2()) return true; @@ -727,6 +707,31 @@ return false; } + final private boolean jj_3R_13() { + if (jj_scan_token(19)) return true; + if (jj_3R_20()) return true; + if (jj_3R_4()) return true; + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_2()) return true; + return false; + } + + final private boolean jj_3R_22() { + if (jj_scan_token(STRING)) return true; + return false; + } + + final private boolean jj_3_2() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(18)) jj_scanpos = xsp; + if (jj_3R_4()) return true; + if (jj_scan_token(22)) return true; + if (jj_3R_3()) return true; + if (jj_scan_token(24)) return true; + return false; + } + public KBParserTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; Modified: trunk/src/dl-learner/org/dllearner/parser/kb.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-02-18 17:28:12 UTC (rev 605) +++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-02-18 18:53:32 UTC (rev 606) @@ -52,6 +52,11 @@ return parser.Concept(); } + public static KB parseKBFile(String content) throws IOException, ParseException { + KBParser parser = new KBParser(new StringReader(content)); + return parser.KB(); + } + public static KB parseKBFile(URL url) throws IOException, ParseException { KBParser parser = new KBParser(url.openStream()); return parser.KB(); Added: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-18 18:53:32 UTC (rev 606) @@ -0,0 +1,105 @@ +/** + * 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.reasoning; + +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; + +/** + * @author Jens Lehmann + * + */ +public class FastInstanceChecker extends ReasonerComponent { + + /* (non-Javadoc) + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.config.ConfigEntry) + */ + @Override + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicConcepts() + */ + public Set<NamedClass> getAtomicConcepts() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicRoles() + */ + public Set<ObjectProperty> getAtomicRoles() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getIndividuals() + */ + public SortedSet<Individual> getIndividuals() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getReasonerType() + */ + public ReasonerType getReasonerType() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#prepareSubsumptionHierarchy(java.util.Set) + */ + public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { + // TODO Auto-generated method stub + + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} Modified: trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2008-02-18 17:28:12 UTC (rev 605) +++ trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2008-02-18 18:53:32 UTC (rev 606) @@ -33,7 +33,8 @@ public class AllTestsRunner { public static void main(String[] args) { - JUnitCore.main("org.dllearner.test.ComponentTests"); + JUnitCore.main("org.dllearner.test.junit.ComponentTests", + "org.dllearner.test.junit.ReasonerTests"); } } Added: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-02-18 18:53:32 UTC (rev 606) @@ -0,0 +1,87 @@ +/** + * 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.test.junit; + +import java.io.IOException; + +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningMethodUnsupportedException; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KB; +import org.dllearner.kb.KBFile; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * A suite of JUnit tests related to the DL-Learner reasoning. + * + * @author Jens Lehmann + * + */ +public class ReasonerTests { + + private KB getSimpleKnowledgeBase() { + String kb = "person SUB TOP."; + kb += "man SUB person."; + kb += "woman SUB person."; + KB kbObject = null; + try { + kbObject = KBParser.parseKBFile(kb); + } catch (IOException e) { + e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); + } + return kbObject; + } + + @Test + public void instanceCheckTest() { + try { + ComponentManager cm = ComponentManager.getInstance(); + KB kb = getSimpleKnowledgeBase(); + KnowledgeSource ks = new KBFile(kb); + ks.init(); + ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, ks); + reasoner.init(); + Description d; + d = KBParser.parseConcept("man"); + Individual i = new Individual("alex"); + boolean result = reasoner.instanceCheck(d, i); + assertFalse(result); + } catch (ParseException e) { + e.printStackTrace(); + } catch (ReasoningMethodUnsupportedException e) { + e.printStackTrace(); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |