org.semanticweb.owlapi.krss1.parser.KRSSParser.jj Maven / Gradle / Ivy
options {
JAVA_UNICODE_ESCAPE=true;
STATIC=false;
JAVA_TEMPLATE_TYPE = "modern";
EXCEPTIONS_SUPER_CLASS = "org.semanticweb.owlapi.io.OWLParserException";
SUPPORT_CLASS_VISIBILITY_PUBLIC=false;
}
PARSER_BEGIN(KRSSParser)
package org.semanticweb.owlapi.krss1.parser;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.vocab.Namespaces;
import java.net.*;
import java.util.*;
@SuppressWarnings("all")
public class KRSSParser {
private OWLOntology ontology;
private OWLDataFactory df;
private Map string2IRI;
private boolean ignoreAnnotationsAndDeclarations = false;
private String base;
public KRSSParser setOntology(OWLOntology ontology) {
this.ontology = ontology;
this.df = ontology.getOWLOntologyManager().getOWLDataFactory();
string2IRI = new HashMap();
if (!ontology.isAnonymous()) {
base = ontology.getOntologyID().getOntologyIRI() + "#";
} else {
base = Namespaces.OWL.toString();
}
return this;
}
protected void addAxiom(OWLAxiom ax) throws KRSSOWLParserException {
if (ax == null) { return; }
try {
ontology.addAxiom(ax);
}
catch(OWLOntologyChangeException e) {
throw new KRSSOWLParserException(e);
}
}
public IRI getIRI(String s) {
s = base + s;
IRI iri = string2IRI.get(s);
if(iri == null) {
iri = IRI.create(s);
string2IRI.put(s, iri);
}
return iri;
}
public void setIgnoreAnnotationsAndDeclarations(boolean b) {
ignoreAnnotationsAndDeclarations = b;
}
}
PARSER_END(KRSSParser)
SKIP: {" " | "\n" | "\t" | "\r" }
MORE: { : IN_COMMENT }
SKIP: { <"\n"> : DEFAULT }
MORE: { <~[]> }
////////////////////////////////////////////////////////////////////////////////////////////
//
// IRIs
MORE: { : IN_IRI }
TOKEN: { "> : DEFAULT }
MORE: { <~[]> }
/////////////////////////////////////////////////////////////////////////////////////////////
//
// String Literals
//
// When we encounter a double quote, we have found a string literal. The end of the literal
// is marked by an unescaped double quote
//
MORE: { : IN_STRING_LITERAL }
// Escaped double quote - part of the literal
MORE: { <"\\\""> }
// End of the literal
TOKEN: { :DEFAULT }
MORE: { <~[]> }
/////////////////////////////////////////////////////////////////////////////////////////////
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
TOKEN: { }
public void parse() throws KRSSOWLParserException :
{ OWLAxiom ax; }
{ ((LOOKAHEAD(2) ax=TBoxStatement(){ addAxiom(ax); })* (LOOKAHEAD(2) )? (ABoxStatement())* (LOOKAHEAD(2) )? ) }
OWLAxiom TBoxStatement() :
{ OWLAxiom ax; }
{ (LOOKAHEAD(2) ax=DefinePrimitiveConcept()
| LOOKAHEAD(2) ax=DefineConcept()
| LOOKAHEAD(2) ax=DefinePrimitiveRole()
| LOOKAHEAD(2) ax=Transitive()
| LOOKAHEAD(2) ax=Range()) { return ax; }
}
OWLAxiom DefinePrimitiveConcept() :
{
OWLClassExpression subClass;
OWLClassExpression superClass;
}
{ subClass=ConceptName() superClass=ConceptExpression() { return df.getOWLSubClassOfAxiom(subClass, superClass); } }
OWLAxiom DefineConcept() :
{
OWLClassExpression clsA;
OWLClassExpression clsB;
}
{ clsA=ConceptName() clsB=ConceptExpression() { return df.getOWLEquivalentClassesAxiom(clsA, clsB); } }
OWLAxiom DefinePrimitiveRole() :
{
OWLObjectProperty subProp;
OWLObjectProperty superProp;
OWLAxiom ax = null;
}
{
subProp=RoleName() superProp=RoleName() (":right-identity" RoleName())?
{
if(superProp != null) {
ax = df.getOWLSubObjectPropertyOfAxiom(subProp, superProp);
}
return ax;
}
}
OWLAxiom Transitive() :
{ OWLObjectProperty prop; }
{ prop=RoleName() { return df.getOWLTransitiveObjectPropertyAxiom(prop); } }
OWLAxiom Range() :
{
OWLObjectProperty prop;
OWLClassExpression rng;
}
{ prop=RoleName() rng=ConceptExpression() { return df.getOWLObjectPropertyRangeAxiom(prop, rng); } }
OWLClassExpression ConceptExpression() :
{ OWLClassExpression desc; }
{ (desc=ConceptName()
| LOOKAHEAD(2) desc=And()
| LOOKAHEAD(2) desc=Or()
| LOOKAHEAD(2) desc=Not()
| LOOKAHEAD(2) desc=All()
| LOOKAHEAD(2) desc=Some()
| LOOKAHEAD(2) desc=AtLeast()
| LOOKAHEAD(2) desc=AtMost()
| LOOKAHEAD(2) desc=Exactly())
{ return desc; }
}
OWLClassExpression ConceptName() :
{ IRI iri; }
{ iri = Name() { return df.getOWLClass(iri); } }
Set ConceptSet() :
{
Set descs = new HashSet();
OWLClassExpression desc;
}
{ ((desc=ConceptExpression() {descs.add(desc);})+) { return descs; } }
OWLClassExpression And() :
{ Set operands; }
{ (operands=ConceptSet()) { return df.getOWLObjectIntersectionOf(operands); } }
OWLClassExpression Or() :
{ Set operands; }
{ (operands=ConceptSet()) { return df.getOWLObjectUnionOf(operands); } }
OWLClassExpression Not() :
{ OWLClassExpression operand; }
{ (operand=ConceptExpression()) { return df.getOWLObjectComplementOf(operand); } }
OWLClassExpression All() :
{
OWLObjectProperty prop;
OWLClassExpression filler;
}
{ prop=RoleName() filler=ConceptExpression() { return df.getOWLObjectAllValuesFrom(prop, filler); } }
OWLClassExpression Some() :
{
OWLObjectProperty prop;
OWLClassExpression filler;
}
{ prop=RoleName() filler=ConceptExpression(){ return df.getOWLObjectSomeValuesFrom(prop, filler); } }
OWLClassExpression AtLeast() :
{
OWLObjectProperty prop;
OWLClassExpression filler;
int card;
}
{ card=Integer() prop=RoleName() filler=ConceptExpression(){ return df.getOWLObjectMinCardinality(card, prop, filler); } }
OWLClassExpression AtMost() :
{
OWLObjectProperty prop;
OWLClassExpression filler;
int card;
}
{ card=Integer() prop=RoleName() filler=ConceptExpression(){ return df.getOWLObjectMaxCardinality(card, prop, filler); } }
OWLClassExpression Exactly() :
{
OWLObjectProperty prop;
OWLClassExpression filler;
int card;
}
{ card=Integer() prop=RoleName() filler=ConceptExpression(){ return df.getOWLObjectExactCardinality(card, prop, filler); } }
OWLObjectProperty RoleName() :
{ IRI iri; }
{ iri=Name() { return df.getOWLObjectProperty(iri); } }
OWLAxiom ABoxStatement() :
{ OWLAxiom ax; }
{ (LOOKAHEAD(2) ax=Instance()|LOOKAHEAD(2) ax=Related()|LOOKAHEAD(2)ax=Equal()|LOOKAHEAD(2)ax=Distinct()) { return ax; } }
OWLAxiom Instance() :
{
OWLIndividual ind;
OWLClassExpression type;
}
{ ind=IndividualName() type=ConceptExpression() { return df.getOWLClassAssertionAxiom(type, ind); } }
OWLAxiom Related() :
{
OWLIndividual subj;
OWLObjectProperty prop;
OWLIndividual obj;
}
{ subj=IndividualName() prop=RoleName() obj=IndividualName() { return df.getOWLObjectPropertyAssertionAxiom(prop, subj, obj); } }
OWLAxiom Equal() :
{ OWLIndividual indA, indB; }
{ indA=IndividualName() indB=IndividualName() { return df.getOWLSameIndividualAxiom(indA, indB); } }
OWLAxiom Distinct() :
{ OWLIndividual indA, indB; }
{ indA=IndividualName() indB=IndividualName(){ return df.getOWLDifferentIndividualsAxiom(indA, indB); } }
OWLIndividual IndividualName() :
{ IRI name; }
{ name = Name() { return df.getOWLNamedIndividual(name); } }
IRI Name() :
{ Token t; }
{ t= { return getIRI(t.image); } }
int Integer() :
{ Token t; }
{ t= { return Integer.parseInt(t.image); } }