From: <jen...@us...> - 2008-02-26 07:13:35
|
Revision: 639 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=639&view=rev Author: jenslehmann Date: 2008-02-25 23:13:31 -0800 (Mon, 25 Feb 2008) Log Message: ----------- - fixed parser problem reported by Maria - Web Service now throws parse exceptions when input strings cannot be parsed correctly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/KBParser.java trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/php-examples/Reasoning.php Added Paths: ----------- trunk/src/dl-learner/org/dllearner/server/jaxws/ParseExceptionBean.java Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-02-25 17:58:40 UTC (rev 638) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-02-26 07:13:31 UTC (rev 639) @@ -19,8 +19,15 @@ } public static Description parseConcept(String string) throws ParseException { - KBParser parser = new KBParser(new StringReader(string)); - return parser.Concept(); + // 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 + // because the brackets were forgotten; + // so instead we create an equivalent class axiom and return its + // right hand side + String eq = "tmp = " + string + "."; + KBParser parser = new KBParser(new StringReader(eq)); + EquivalentClassesAxiom eqAxiom = parser.TBoxEquiv(); + return eqAxiom.getConcept2(); } public static KB parseKBFile(String content) throws IOException, ParseException { @@ -668,39 +675,6 @@ finally { jj_save(5, xla); } } - final private boolean jj_3_1() { - if (jj_3R_2()) return true; - if (jj_scan_token(22)) return true; - if (jj_3R_3()) return true; - if (jj_scan_token(23)) return true; - if (jj_scan_token(COMMAND_END)) return true; - return false; - } - - final private boolean jj_3R_14() { - if (jj_scan_token(20)) 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_17() { - if (jj_3R_21()) return true; - return false; - } - - final private boolean jj_3R_4() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_17()) { - jj_scanpos = xsp; - if (jj_3R_18()) return true; - } - return false; - } - final private boolean jj_3R_13() { if (jj_scan_token(19)) return true; if (jj_3R_20()) return true; @@ -901,6 +875,39 @@ return false; } + final private boolean jj_3_1() { + if (jj_3R_2()) return true; + if (jj_scan_token(22)) return true; + if (jj_3R_3()) return true; + if (jj_scan_token(23)) return true; + if (jj_scan_token(COMMAND_END)) return true; + return false; + } + + final private boolean jj_3R_14() { + if (jj_scan_token(20)) 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_17() { + if (jj_3R_21()) return true; + return false; + } + + final private boolean jj_3R_4() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_17()) { + jj_scanpos = xsp; + if (jj_3R_18()) 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-25 17:58:40 UTC (rev 638) +++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-02-26 07:13:31 UTC (rev 639) @@ -48,8 +48,15 @@ } public static Description parseConcept(String string) throws ParseException { - KBParser parser = new KBParser(new StringReader(string)); - return parser.Concept(); + // 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 + // because the brackets were forgotten; + // so instead we create an equivalent class axiom and return its + // right hand side + String eq = "tmp = " + string + "."; + KBParser parser = new KBParser(new StringReader(eq)); + EquivalentClassesAxiom eqAxiom = parser.TBoxEquiv(); + return eqAxiom.getConcept2(); } public static KB parseKBFile(String content) throws IOException, ParseException { Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-25 17:58:40 UTC (rev 638) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-26 07:13:31 UTC (rev 639) @@ -460,31 +460,20 @@ } @WebMethod - public String[] retrieval(int id, String conceptString) throws ClientNotKnownException { + public String[] retrieval(int id, String conceptString) throws ClientNotKnownException, ParseException { ClientState state = getState(id); // call parser to parse concept Description concept = null; - try { - concept = KBParser.parseConcept(conceptString); - } catch (ParseException e) { - e.printStackTrace(); - } + concept = KBParser.parseConcept(conceptString); Set<Individual> individuals = state.getReasoningService().retrieval(concept); return Datastructures.sortedSet2StringListIndividuals(individuals); } @WebMethod - public int getConceptLength(String conceptString) { + public int getConceptLength(String conceptString) throws ParseException { // call parser to parse concept - Description concept = null; - try { - System.out.println(conceptString); - concept = KBParser.parseConcept(conceptString); - } catch (ParseException e) { - e.printStackTrace(); - } - return concept.getLength(); - } + return KBParser.parseConcept(conceptString).getLength(); + } @WebMethod public String[] getAtomicRoles(int id) throws ClientNotKnownException { Added: trunk/src/dl-learner/org/dllearner/server/jaxws/ParseExceptionBean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/jaxws/ParseExceptionBean.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/jaxws/ParseExceptionBean.java 2008-02-26 07:13:31 UTC (rev 639) @@ -0,0 +1,41 @@ + +package org.dllearner.server.jaxws; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * This class was generated by the JAXWS SI. + * JAX-WS RI 2.0_02-b08-fcs + * Generated source version: 2.0_02 + * + */ +@XmlRootElement(name = "ParseException", namespace = "http://server.dllearner.org/") +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "ParseException", namespace = "http://server.dllearner.org/") +public class ParseExceptionBean { + + private String message; + + /** + * + * @return + * returns String + */ + public String getMessage() { + return this.message; + } + + /** + * + * @param message + * the value for the message property + */ + public void setMessage(String message) { + this.message = message; + } + +} Modified: trunk/src/php-examples/Reasoning.php =================================================================== --- trunk/src/php-examples/Reasoning.php 2008-02-25 17:58:40 UTC (rev 638) +++ trunk/src/php-examples/Reasoning.php 2008-02-26 07:13:31 UTC (rev 639) @@ -47,7 +47,7 @@ // create a concept in internal DL-Learner syntax // ( = all female persons having at least one child) -$concept = '"http://example.com/father#female" AND EXISTS "http://example.com/father#hasChild".TOP'; +$concept = '("http://example.com/father#female" AND EXISTS "http://example.com/father#hasChild".TOP)'; $instances = $client->retrieval($id, $concept); // print instances This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |