Search in sources :

Example 1 with ParserException

use of org.semanticweb.owlapi.expression.ParserException in project ontologies by enanomapper.

the class OntologyHelper method parseQuery.

/**
 * parseQuery
 * @param query as string, in OWL Manchester Syntax and using IDs not labels!!
 * @return the query param as OWLClassExpression
 */
public static OWLClassExpression parseQuery(String query, OWLGraphWrapper graph, OWLOntology o) throws Exception {
    ManchesterSyntaxTool parser = null;
    OWLClassExpression ce = null;
    try {
        parser = new ManchesterSyntaxTool(o);
        System.out.println("--before: " + query);
        ce = parser.parseManchesterExpression(query);
        System.out.println("--after: " + ce);
    } catch (ParserException e) {
        String errMessage = "There was a problem parsing token ";
        String tok = "";
        if (OntologyHelper.getOWLObjectByIdentifier(e.getCurrentToken().replaceAll("CHEBI_", "CHEBI:"), graph) != null)
            tok = graph.getLabel(OntologyHelper.getOWLObjectByIdentifier(e.getCurrentToken().replaceAll("CHEBI_", "CHEBI:"), graph));
        else
            tok = e.getCurrentToken();
        errMessage += "<b>" + tok + "</b> or the query is not compete. <br/>";
        errMessage += "The parser expected one of : " + (e.getMessage().split("Expected one of:")[1]) + ".";
        System.out.println(e.getMessage());
        throw new Exception(errMessage);
    } finally {
        // always dispose parser to avoid a memory leak
        if (parser != null) {
            parser.dispose();
        }
    }
    return ce;
}
Also used : ParserException(org.semanticweb.owlapi.expression.ParserException) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) ManchesterSyntaxTool(org.obolibrary.macro.ManchesterSyntaxTool) ParserException(org.semanticweb.owlapi.expression.ParserException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ManchesterSyntaxTool (org.obolibrary.macro.ManchesterSyntaxTool)1 ParserException (org.semanticweb.owlapi.expression.ParserException)1 OWLClassExpression (org.semanticweb.owlapi.model.OWLClassExpression)1