All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.coode.owlapi.functionalparser.OWLFunctionalSyntaxParser.jj Maven / Gradle / Ivy

options {
    STATIC=false;
    JAVA_UNICODE_ESCAPE=true;
    LOOKAHEAD=2;
    //DEBUG_TOKEN_MANAGER=true;
}

PARSER_BEGIN(OWLFunctionalSyntaxParser)

package org.coode.owlapi.functionalparser;

import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.vocab.*;
import java.net.*;
import java.util.*;
import org.coode.string.EscapeUtils;
import org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat;
import java.io.IOException;
import org.semanticweb.owlapi.io.OWLParserException;


public class OWLFunctionalSyntaxParser {

    private OWLOntologyManager man;

    private OWLOntologyLoaderConfiguration configuration;

    private OWLOntology ontology;

    private OWLDataFactory dataFactory;

    private Map string2IRI;

    private Map prefixMap;

    private IRI ontologyIRI;

    private boolean ignoreAnnotationsAndDeclarations = false;

    private Set currentAnnotations;

    @Deprecated
    public void setUp(OWLOntologyManager man, OWLOntology ontology, OWLOntologyLoaderConfiguration configuration) {
        setUp(ontology, configuration);
    }

    public void setUp(OWLOntology ontology, OWLOntologyLoaderConfiguration configuration) {
        this.man = ontology.getOWLOntologyManager();
        this.ontology = ontology;
        this.configuration = configuration;
        this.dataFactory = man.getOWLDataFactory();
        this.currentAnnotations = new HashSet();
        if(prefixMap == null) {
            prefixMap = new HashMap();
            prefixMap.put("owl:", Namespaces.OWL.toString());
            prefixMap.put("rdf:", Namespaces.RDF.toString());
            prefixMap.put("rdfs:", Namespaces.RDFS.toString());
            prefixMap.put("xml:", Namespaces.XML.toString());
            prefixMap.put("xsd:", Namespaces.XSD.toString());
        }
        string2IRI = new HashMap();
    }

    public IRI getIRI(String s) {
        IRI iri = string2IRI.get(s);
        if(iri == null) {
            if(s.charAt(0) == '<') {
                iri = IRI.create(s.substring(1, s.length() - 1));
            }
            else {
                int colonIndex = s.indexOf(':');
                String prefixName = s.substring(0, colonIndex + 1);
                String prefix = prefixMap.get(prefixName);
                if(prefix == null) {
                    throw new OWLRuntimeException("Undefined prefix name: " + prefixName);
                }
                String fullIRIString = prefix + s.substring(colonIndex + 1);
                iri = IRI.create(fullIRIString);
            }
            string2IRI.put(s, iri);
        }
        return iri;
    }

    public void setIgnoreAnnotationsAndDeclarations(boolean b) {
        ignoreAnnotationsAndDeclarations = b;
    }

    protected void applyChange(OWLOntologyChange chg) {
        try {
            man.applyChange(chg);
        }
        catch(OWLOntologyChangeException e) {
            e.printStackTrace();
        }
    }

    protected void addAxiom(OWLAxiom ax) {
        if (!(ax instanceof OWLAnnotationAxiom) || configuration.isLoadAnnotationAxioms()) {
            AddAxiom addAxiom = new AddAxiom(ontology, ax);
            applyChange(addAxiom);
        }
    }

    public void setPrefixes(PrefixManager nsm) {
        if(prefixMap == null) {
            prefixMap = new HashMap();
        }
        prefixMap.putAll(nsm.getPrefixName2PrefixMap());
    }
}

PARSER_END(OWLFunctionalSyntaxParser)

SKIP: {" " | "\n" | "\t" | "\r"}




/////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////
//
// Comments
//
//

MORE:
{
     : IN_COMMENT
}

 SKIP:
{
    <~["\n"]>
}

 SKIP:
{
    <"\n"> : DEFAULT
}


/////////////////////////////////////////////////////////////////////////////////////////////
//
// 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
}

 MORE:
{
    
}

 MORE:
{
    
}

 TOKEN:
{
     : DEFAULT
}

//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:
{
    
}


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:
{
    
}


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:
{
    
}

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:
{
    
}


////////////////////////////////////////////////////////////////////////////////////////////
//
// IRIs

TOKEN:
{
    ", " "])*">">
}

TOKEN:
{
    )? ":">
}


TOKEN:
{
     | ["0"-"9"] ) ((|".")* )?>
}

TOKEN:
{
     >
}

TOKEN:
{
    ((|".")* )?>
}

TOKEN:
{
    
}


TOKEN:
{
    
               | "-"
               | ["0"-"9"]
               | "\u00B7"
               | ["\u0300"-"\u036F"]
               | ["\u203F"-"\u2040"]>
}

TOKEN:
{
     | "_">
}



TOKEN:
{
    >
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////


TOKEN:
{
    
}

public OWLFunctionalSyntaxOntologyFormat parse() throws OWLParserException, IOException, UnloadableImportException :
{
}
{
    (Prefix())*Ontology() {
        OWLFunctionalSyntaxOntologyFormat format = new OWLFunctionalSyntaxOntologyFormat();
        for(String pn : prefixMap.keySet()) {
            format.setPrefix(pn, prefixMap.get(pn));
        }
        return format;
    }
}

void Ontology() throws OWLParserException, UnloadableImportException :
{
    OWLAnnotation anno;
    OWLAxiom ax;
    OWLImportsDeclaration decl;
    int count = 0;
    IRI versionIRI = null;
}
{
    (ontologyIRI=IRI()(versionIRI=IRI())?)?{
                OWLOntologyID id = new OWLOntologyID(ontologyIRI, versionIRI);
                applyChange(new SetOntologyID(ontology, id));

        }
    (
    (decl = ImportsDeclaration() {
        applyChange(new AddImport(ontology, decl));
        man.makeLoadImportRequest(decl, configuration);
    })
    |
    (anno=Annotation(){
        applyChange(new AddOntologyAnnotation(ontology, anno));
        currentAnnotations.clear();
    }))*


    ((ax=Axiom(){
        addAxiom(ax);
        currentAnnotations.clear();
    }))*
}

public void Prefix() :
{
    String prefixName="";
    IRI iri;
}
{
    (prefixName=PrefixName()iri=FullIRI()) {
        prefixMap.put(prefixName, iri.toString());
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// IRIs
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

public IRI IRI() :
{
    IRI iri;
}
{
    (iri=FullIRI() | iri=AbbreviatedIRI()) {
        return iri;
    }
}

public IRI FullIRI() :
{
    Token t;
}
{
    t= {
        return getIRI(t.image);
    }
}

public IRI AbbreviatedIRI() :
{
    Token t;
}
{
    t= {
        return getIRI(t.image);
    }
}

public String PrefixName() :
{
    Token t;
}
{
    t= {
        return t.image;
    }
}



/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Class Descriptions
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

OWLClassExpression ClassExpression() :
{
    OWLClassExpression desc;
}
{
    (desc=ClassIRI() | desc=ObjectUnionOf() | desc=ObjectIntersectionOf() | desc=ObjectComplementOf() | desc=ObjectOneOf() |
    desc=ObjectSomeValuesFrom() | desc=ObjectAllValuesFrom() | desc=ObjectHasValue() | desc=ObjectSelf() |
    desc=ObjectMinCardinality() | desc=ObjectExactCardinality() | desc=ObjectMaxCardinality() |
    desc=DataSomeValuesFrom() | desc=DataAllValuesFrom() | desc=DataHasValue() | desc=DataMinCardinality() |
    desc=DataExactCardinality() | desc=DataMaxCardinality()) {
        return desc;
    }
}

OWLClass ClassIRI() :
{
    IRI iri;
}
{
    iri=IRI() {
        return dataFactory.getOWLClass(iri);
    }
}

Set ClassExpressionSet() :
{
    Set classExpressions = new HashSet();
    OWLClassExpression desc;
}
{
    (desc=ClassExpression(){classExpressions.add(desc);}
    desc=ClassExpression(){classExpressions.add(desc);}
    (desc=ClassExpression(){classExpressions.add(desc);})*) {
        return classExpressions;
    }
}

Set IndividualMinOneSet() :
{
    Set individuals = new HashSet();
    OWLIndividual ind;

}
{
    (ind=Individual() {individuals.add(ind);}
    (ind=Individual() {individuals.add(ind);})*) {
        return individuals;
    }
}

OWLClassExpression ObjectUnionOf()  :
{
    Set classExpressions;
}
{
    classExpressions=ClassExpressionSet(){
        return dataFactory.getOWLObjectUnionOf(classExpressions);
    }
}

OWLClassExpression ObjectIntersectionOf()  :
{
    Set classExpressions;
}
{
    classExpressions=ClassExpressionSet(){
        return dataFactory.getOWLObjectIntersectionOf(classExpressions);
    }
}

OWLClassExpression ObjectComplementOf()  :
{
    OWLClassExpression operand;
}
{
    operand=ClassExpression(){
        return dataFactory.getOWLObjectComplementOf(operand);
    }
}

OWLClassExpression ObjectOneOf()  :
{
    Set individuals;
}
{
    individuals=IndividualMinOneSet(){
        return dataFactory.getOWLObjectOneOf(individuals);
    }
}

OWLClassExpression ObjectAllValuesFrom()  :
{
    OWLObjectPropertyExpression prop;
    OWLClassExpression filler;
}
{
    prop=ObjectPropertyExpression() filler=ClassExpression() {
        return dataFactory.getOWLObjectAllValuesFrom(prop, filler);
    }
}

OWLClassExpression ObjectSomeValuesFrom()  :
{
    OWLObjectPropertyExpression prop;
    OWLClassExpression filler;
}
{
    prop=ObjectPropertyExpression() filler=ClassExpression() {
        return dataFactory.getOWLObjectSomeValuesFrom(prop, filler);
    }
}

OWLClassExpression ObjectHasValue()  :
{
    OWLObjectPropertyExpression prop;
    OWLIndividual ind;
}
{
    prop=ObjectPropertyExpression() ind=Individual() {
        return dataFactory.getOWLObjectHasValue(prop, ind);
    }
}

OWLClassExpression ObjectSelf()  :
{
    OWLObjectPropertyExpression prop;
}
{
    prop=ObjectPropertyExpression() {
        return dataFactory.getOWLObjectHasSelf(prop);
    }
}

OWLClassExpression ObjectMinCardinality()  :
{
    int cardinality = 0;
    OWLObjectPropertyExpression prop = null;
    OWLClassExpression filler = null;
}
{
    (cardinality=Cardinality()prop=ObjectPropertyExpression()(filler=ClassExpression())?) {
        if(filler == null) {
            return dataFactory.getOWLObjectMinCardinality(cardinality, prop);
        }
        else {
            return dataFactory.getOWLObjectMinCardinality(cardinality, prop, filler);
        }
    }
}

OWLClassExpression ObjectExactCardinality()  :
{
    int cardinality = 0;
    OWLObjectPropertyExpression prop = null;
    OWLClassExpression filler = null;
}
{
    (cardinality=Cardinality()prop=ObjectPropertyExpression()(filler=ClassExpression())?) {
        if(filler == null) {
            return dataFactory.getOWLObjectExactCardinality(cardinality, prop);
        }
        else {
            return dataFactory.getOWLObjectExactCardinality(cardinality, prop, filler);
        }
    }
}

OWLClassExpression ObjectMaxCardinality()  :
{
    int cardinality = 0;
    OWLObjectPropertyExpression prop = null;
    OWLClassExpression filler = null;
}
{
    (cardinality=Cardinality()prop=ObjectPropertyExpression()(filler=ClassExpression())?) {
        if(filler == null) {
            return dataFactory.getOWLObjectMaxCardinality(cardinality, prop);
        }
        else {
            return dataFactory.getOWLObjectMaxCardinality(cardinality, prop, filler);
        }
    }
}

OWLClassExpression DataAllValuesFrom()  :
{
    OWLDataPropertyExpression prop = null;
    OWLDataRange dataRange = null;
}
{
    (prop=DataPropertyExpression() dataRange=DataRange()) {
        return dataFactory.getOWLDataAllValuesFrom(prop, dataRange);
    }
}

OWLClassExpression DataSomeValuesFrom()  :
{
    OWLDataPropertyExpression prop = null;
    OWLDataRange dataRange = null;
}
{
    prop=DataPropertyExpression() dataRange=DataRange() {
        return dataFactory.getOWLDataSomeValuesFrom(prop, dataRange);
    }
}

OWLClassExpression DataHasValue()  :
{
    OWLDataPropertyExpression prop = null;
    OWLLiteral literal = null;
}
{
    prop=DataPropertyExpression() literal=Literal() {
        return dataFactory.getOWLDataHasValue(prop, literal);
    }
}

OWLClassExpression DataMinCardinality()  :
{
    int cardinality = 0;
    OWLDataPropertyExpression prop = null;
    OWLDataRange rng = null;
}
{
    cardinality=Cardinality()prop=DataPropertyExpression()((rng=DataRange())?) {
        if(rng == null) {
            return dataFactory.getOWLDataMinCardinality(cardinality, prop);
        }
        else {
            return dataFactory.getOWLDataMinCardinality(cardinality, prop, rng);
        }
    }
}

OWLClassExpression DataExactCardinality()  :
{
    int cardinality = 0;
    OWLDataPropertyExpression prop = null;
    OWLDataRange rng = null;
}
{
    cardinality=Cardinality()prop=DataPropertyExpression()((rng=DataRange())?) {
        if(rng == null) {
            return dataFactory.getOWLDataExactCardinality(cardinality, prop);
        }
        else {
            return dataFactory.getOWLDataExactCardinality(cardinality, prop, rng);
        }
    }
}

OWLClassExpression DataMaxCardinality()  :
{
    int cardinality = 0;
    OWLDataPropertyExpression prop = null;
    OWLDataRange rng = null;
}
{
    cardinality=Cardinality()prop=DataPropertyExpression()((rng=DataRange())?) {
         if(rng == null) {
            return dataFactory.getOWLDataMaxCardinality(cardinality, prop);
        }
        else {
            return dataFactory.getOWLDataMaxCardinality(cardinality, prop, rng);
        }
    }
}


OWLClass Class()  :
{
    OWLClass cls;
}
{
    cls=ClassIRI() {
        return cls;
    }
}

OWLObjectPropertyExpression ObjectPropertyExpression()  :
{
    OWLObjectPropertyExpression prop;
}
{
    (prop=InverseObjectProperty() | prop=ObjectPropertyIRI()){return prop;}
}

OWLObjectPropertyExpression InverseObjectProperty()  :
{
    OWLObjectPropertyExpression prop;
}
{
    prop=ObjectPropertyExpression() {
        return dataFactory.getOWLObjectInverseOf(prop);
    }
}

OWLObjectProperty ObjectProperty()  :
{
    OWLObjectProperty prop;
}
{
    prop=ObjectPropertyIRI() {
        return prop;
    }
}

OWLDataPropertyExpression DataPropertyExpression()  :
{
    OWLDataPropertyExpression prop;
}
{
    prop=DataPropertyIRI() {
        return prop;
    }
}

OWLDataProperty DataPropertyIRI() :
{
    IRI iri;
}
{
    iri = IRI() {
        return dataFactory.getOWLDataProperty(iri);
    }
}

OWLDataProperty DataProperty()  :
{
    OWLDataProperty prop;
}
{
    (prop=DataPropertyIRI()) {
        return prop;
    }
}

OWLAnnotationProperty AnnotationProperty()  :
{
    OWLAnnotationProperty prop;
}
{
    (prop=AnnotationPropertyIRI()) {
        return prop;
    }
}

OWLAnnotationProperty AnnotationPropertyIRI() :
{
    IRI iri;
}
{
    iri = IRI() {
        return dataFactory.getOWLAnnotationProperty(iri);
    }
}



OWLNamedIndividual NamedIndividual()  :
{
    OWLNamedIndividual ind;
}
{
   ind=IndividualIRI() {
        return ind;
   }
}

OWLAnonymousIndividual AnonymousIndividual() :
{
    Token t;
}
{
    t= {
        String id = t.image.substring(2, t.image.length());
        return dataFactory.getOWLAnonymousIndividual(id);
    }
}

OWLDatatype Datatype()  :
{
    OWLDatatype dt;
}
{
   (dt=DatatypeIRI()) {
        return dt;
   }
}

OWLDatatype DatatypeIRI() :
{
    IRI iri;
}
{
    iri=IRI() {
        return dataFactory.getOWLDatatype(iri);
    }


}

int Cardinality()  :
{
    int card = 0;
}
{
    card=Integer() {
        return card;
    }
}

int Integer()  :
{
    Token t;
}
{
    t= {
        int i = Integer.parseInt(t.image);
        return i;
    }
}

OWLDatatypeDefinitionAxiom DatatypeDefinitionAxiom() :
{
    OWLDatatype datatype;
    OWLDataRange dr;
    Set axAnnos;
}
{
    (axAnnos = AxiomAnnotationSet() datatype=DatatypeIRI() dr=DataRange()) {
        return dataFactory.getOWLDatatypeDefinitionAxiom(datatype, dr, axAnnos);
    }
}

OWLDataRange DataRange()  :
{
    OWLDataRange rng;
}
{
    (rng=DatatypeIRI() | rng=DataOneOf() | rng=DataComplementOf() | rng=DataRangeRestriction() | rng=DataIntersectionOf() | rng=DataUnionOf()) {
        return rng;
    }
}

OWLDataRange DataComplementOf()  :
{
    OWLDataRange rng;
}
{
    (rng=DataRange()) {
        return dataFactory.getOWLDataComplementOf(rng);
    }
}

OWLDataRange DataOneOf()  :
{
    Set values = new HashSet();
    OWLLiteral con = null;
    OWLDataRange rng = null;
}
{
    (((con=Literal(){values.add(con);})+)) {
        return dataFactory.getOWLDataOneOf(values);
    }
}

OWLDataRange DataUnionOf() :
{
    OWLDataRange dataRange;
    Set ranges = new HashSet();
}
{
    (dataRange=DataRange(){ranges.add(dataRange);})+ {
        return dataFactory.getOWLDataUnionOf(ranges);
    }
}

OWLDataRange DataIntersectionOf() :
{
    OWLDataRange dataRange;
    Set ranges = new HashSet();
}
{
    (dataRange=DataRange(){ranges.add(dataRange);})+ {
        return dataFactory.getOWLDataIntersectionOf(ranges);
    }
}

OWLDataRange DataRangeRestriction() :
{
    OWLFacet v;
    OWLDatatype rng;
    OWLFacetRestriction facetRestriction;
    Set facetRestrictions = new HashSet();
}
{
    (rng=DatatypeIRI()((facetRestriction=DataRangeFacetRestriction()){
        facetRestrictions.add(facetRestriction);
    })+) {
        return dataFactory.getOWLDatatypeRestriction(rng, facetRestrictions);
    }
}

OWLFacetRestriction DataRangeFacetRestriction() :
{
    IRI iri;
    OWLLiteral con;
}
{
    (   iri = IRI()
        con = Literal()
    ) {
        OWLFacet v = OWLFacet.getFacetByShortName(iri.getFragment());
        return dataFactory.getOWLFacetRestriction(v, con);
    }

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Axioms
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////

OWLAxiom Axiom() :
{
    OWLAxiom ax = null;
}
{
    (ax=ClassAxiom()
    | ax=ObjectPropertyAxiom()
    | ax=DataPropertyAxiom()
    | ax=IndividualAxiom()
    | ax=Declaration()
    | ax=HasKey()
    | ax=DatatypeDefinitionAxiom()
    | ax=AnnotationAxiom()
    | ax=DLSafeRule()) {
        return ax;
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Class Axioms
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////

OWLClassAxiom ClassAxiom() :
{
    OWLClassAxiom ax;
}
{
    (ax=SubClassOf() | ax=EquivalentClasses() | ax=DisjointClasses() | ax=DisjointUnion()) {
        return ax;
    }
}

OWLClassAxiom SubClassOf() :
{
    OWLClassExpression subClass;
    OWLClassExpression superClass;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()subClass=ClassExpression() superClass=ClassExpression(){
        return dataFactory.getOWLSubClassOfAxiom(subClass, superClass, axiomAnnos);
    }
}

OWLClassAxiom EquivalentClasses() :
{
    Set classExpressions;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()classExpressions=ClassExpressionSet() {
        return dataFactory.getOWLEquivalentClassesAxiom(classExpressions, axiomAnnos);
    }
}

OWLClassAxiom DisjointClasses() :
{
    Set classExpressions;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()classExpressions=ClassExpressionSet() {
        return dataFactory.getOWLDisjointClassesAxiom(classExpressions, axiomAnnos);
    }
}

OWLClassAxiom DisjointUnion() :
{
    OWLClass cls;
    Set classExpressions;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()cls=ClassIRI() classExpressions=ClassExpressionSet() {
        return dataFactory.getOWLDisjointUnionAxiom(cls, classExpressions, axiomAnnos);
    }
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Object Property Axioms
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////

OWLPropertyAxiom ObjectPropertyAxiom() :
{
    OWLPropertyAxiom ax;
}
{
    (ax=SubObjectPropertyOf() | ax=EquivalentObjectProperties() | ax=DisjointObjectProperties() |
    ax=ObjectPropertyRange() | ax=ObjectPropertyDomain() | ax=FunctionalObjectProperty() |
    ax=InverseFunctionalObjectProperty() | ax=SymmetricObjectProperty() | ax=AsymmetricObjectProperty() |
    ax=ReflexiveObjectProperty() | ax=IrreflexiveObjectProperty() | ax=TransitiveObjectProperty() | ax=InverseObjectProperties()) {
        return ax;
    }
}

List SubObjectPropertyChain() :
{
    OWLObjectPropertyExpression prop;
    List props = new ArrayList();
}
{
    (prop=ObjectPropertyExpression() {props.add(prop);} (prop=ObjectPropertyExpression(){props.add(prop);})*) {
        return props;
    }
}

OWLPropertyAxiom SubObjectPropertyOf() :
{
    OWLObjectPropertyExpression subProperty = null;
    List chain = null;
    OWLObjectPropertyExpression superProperty = null;
    Set axiomAnnos;

}
{
    axiomAnnos = AxiomAnnotationSet()(subProperty=ObjectPropertyExpression() | chain=SubObjectPropertyChain()) superProperty=ObjectPropertyExpression()  {
        if(subProperty != null) {
            return dataFactory.getOWLSubObjectPropertyOfAxiom(subProperty, superProperty, axiomAnnos);
        }
        else if(chain != null) {
            return dataFactory.getOWLSubPropertyChainOfAxiom(chain, superProperty, axiomAnnos);
        }
        else {
            return null;
        }
    }
}

OWLPropertyAxiom EquivalentObjectProperties() :
{
    Set props;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()props=ObjectPropertySet() {
        return dataFactory.getOWLEquivalentObjectPropertiesAxiom(props, axiomAnnos);
    }
}

OWLPropertyAxiom DisjointObjectProperties() :
{
    Set props;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()props=ObjectPropertySet() {
        return dataFactory.getOWLDisjointObjectPropertiesAxiom(props, axiomAnnos);
    }
}

Set ObjectPropertySet() :
{
    OWLObjectPropertyExpression prop;
    Set props = new HashSet();
}
{
    (prop=ObjectPropertyExpression(){props.add(prop);} prop=ObjectPropertyExpression(){props.add(prop);} (prop=ObjectPropertyExpression(){props.add(prop);})*) {
        return props;
    }
}

OWLPropertyAxiom ObjectPropertyRange() :
{
    OWLObjectPropertyExpression prop;
    OWLClassExpression range;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() range=ClassExpression() {
        return dataFactory.getOWLObjectPropertyRangeAxiom(prop, range, axiomAnnos);
    }
}

OWLPropertyAxiom ObjectPropertyDomain() :
{
    OWLObjectPropertyExpression prop;
    OWLClassExpression desc;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() desc=ClassExpression() {
        return dataFactory.getOWLObjectPropertyDomainAxiom(prop, desc, axiomAnnos);
    }
}

OWLPropertyAxiom FunctionalObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos = Collections.emptySet();
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() {
        return dataFactory.getOWLFunctionalObjectPropertyAxiom(prop, axiomAnnos);
    }
}

OWLPropertyAxiom InverseObjectProperties() :
{
    OWLObjectPropertyExpression propA;
    OWLObjectPropertyExpression propB;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()propA=ObjectPropertyExpression() propB=ObjectPropertyExpression(){
        return dataFactory.getOWLInverseObjectPropertiesAxiom(propA, propB, axiomAnnos);
    }
}

OWLPropertyAxiom InverseFunctionalObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() {
        return dataFactory.getOWLInverseFunctionalObjectPropertyAxiom(prop, axiomAnnos);
    }
}

OWLPropertyAxiom SymmetricObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() {
        return dataFactory.getOWLSymmetricObjectPropertyAxiom(prop, axiomAnnos);
    }
}

OWLPropertyAxiom AsymmetricObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() {
        return dataFactory.getOWLAsymmetricObjectPropertyAxiom(prop, axiomAnnos);
    }
}

OWLPropertyAxiom ReflexiveObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() {
        return dataFactory.getOWLReflexiveObjectPropertyAxiom(prop, axiomAnnos);
    }
}

OWLPropertyAxiom IrreflexiveObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() {
        return dataFactory.getOWLIrreflexiveObjectPropertyAxiom(prop, axiomAnnos);
    }
}

OWLPropertyAxiom TransitiveObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() {
        return dataFactory.getOWLTransitiveObjectPropertyAxiom(prop, axiomAnnos);
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Data Property Axioms
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////

OWLPropertyAxiom DataPropertyAxiom() :
{
    OWLPropertyAxiom ax;
}
{
    (ax=SubDataPropertyOf() | ax=EquivalentDataProperties() | ax=DisjointDataProperties() |
    ax=DataPropertyRange() | ax=DataPropertyDomain() | ax=FunctionalDataProperty()) {
        return ax;
    }
}

OWLPropertyAxiom SubDataPropertyOf() :
{
    OWLDataPropertyExpression subProperty;
    OWLDataPropertyExpression superProperty;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()subProperty=DataPropertyExpression() superProperty=DataPropertyExpression()  {
        return dataFactory.getOWLSubDataPropertyOfAxiom(subProperty, superProperty, axiomAnnos);
    }
}

OWLPropertyAxiom EquivalentDataProperties() :
{
    Set props;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()props=DataPropertySet() {
        return dataFactory.getOWLEquivalentDataPropertiesAxiom(props, axiomAnnos);
    }
}

OWLPropertyAxiom DisjointDataProperties() :
{
    Set props;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()props=DataPropertySet() {
        return dataFactory.getOWLDisjointDataPropertiesAxiom(props, axiomAnnos);
    }
}

Set DataPropertySet() :
{
    OWLDataPropertyExpression prop;
    Set props = new HashSet();
}
{
    (prop=DataPropertyExpression(){props.add(prop);} prop=DataPropertyExpression(){props.add(prop);} (prop=DataPropertyExpression(){props.add(prop);})*) {
        return props;
    }
}


OWLPropertyAxiom DataPropertyDomain() :
{
    OWLDataPropertyExpression prop;
    OWLClassExpression domain;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=DataPropertyExpression() domain=ClassExpression() {
        return dataFactory.getOWLDataPropertyDomainAxiom(prop, domain, axiomAnnos);
    }
}

OWLPropertyAxiom DataPropertyRange() :
{
    OWLDataPropertyExpression prop;
    OWLDataRange rng;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=DataPropertyExpression() rng=DataRange() {
        return dataFactory.getOWLDataPropertyRangeAxiom(prop, rng, axiomAnnos);
    }
}

OWLPropertyAxiom FunctionalDataProperty() :
{
    OWLDataPropertyExpression prop;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=DataPropertyExpression() {
        return dataFactory.getOWLFunctionalDataPropertyAxiom(prop, axiomAnnos);
    }

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Individual Axioms
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////

OWLIndividualAxiom IndividualAxiom() :
{
    OWLIndividualAxiom ax;
}
{
    (ax=SameIndividuals() | ax=DifferentIndividuals() | ax=ClassAssertion() | ax=ObjectPropertyAssertion() |
    ax=DataPropertyAssertion() | ax=NegativeObjectPropertyAssertion() | ax=NegativeDataPropertyAssertion()) {
        return ax;
    }
}

Set IndividualSet() :
{
    OWLIndividual ind;
    Set individuals = new HashSet();
}
{
    (ind=Individual(){individuals.add(ind);} ind=Individual(){individuals.add(ind);} (ind=Individual(){individuals.add(ind);})*) {
        return individuals;
    }
}

OWLIndividualAxiom SameIndividuals() :
{
    Set individuals;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()individuals=IndividualSet() {
        return dataFactory.getOWLSameIndividualAxiom(individuals, axiomAnnos);
    }
}

OWLIndividualAxiom DifferentIndividuals() :
{
    Set individuals;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()individuals=IndividualSet() {
        return dataFactory.getOWLDifferentIndividualsAxiom(individuals, axiomAnnos);
    }
}

OWLIndividualAxiom ClassAssertion() :
{
    OWLIndividual ind;
    OWLClassExpression desc;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet() desc=ClassExpression() ind=Individual()   {
        return dataFactory.getOWLClassAssertionAxiom(desc, ind, axiomAnnos);
    }
}

OWLIndividualAxiom ObjectPropertyAssertion() :
{
    OWLIndividual subj;
    OWLObjectPropertyExpression prop;
    OWLIndividual obj;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() subj=Individual() obj=Individual() {
        return dataFactory.getOWLObjectPropertyAssertionAxiom(prop, subj, obj, axiomAnnos);
    }
}

OWLIndividualAxiom NegativeObjectPropertyAssertion() :
{
    OWLIndividual subj;
    OWLObjectPropertyExpression prop;
    OWLIndividual obj;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() subj=Individual() obj=Individual() {
        return dataFactory.getOWLNegativeObjectPropertyAssertionAxiom(prop, subj, obj, axiomAnnos);
    }
}

OWLIndividualAxiom DataPropertyAssertion() :
{
    OWLIndividual subj;
    OWLDataPropertyExpression prop;
    OWLLiteral obj;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=DataPropertyExpression() subj=Individual() obj=Literal() {
        return dataFactory.getOWLDataPropertyAssertionAxiom(prop, subj, obj, axiomAnnos);
    }
}

OWLIndividualAxiom NegativeDataPropertyAssertion() :
{
    OWLIndividual subj;
    OWLDataPropertyExpression prop;
    OWLLiteral obj;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet()prop=DataPropertyExpression() subj=Individual() obj=Literal() {
        return dataFactory.getOWLNegativeDataPropertyAssertionAxiom(prop, subj, obj, axiomAnnos);
    }
}



OWLNamedIndividual IndividualIRI() :
{
    IRI iri;
}
{
    iri=IRI() {return dataFactory.getOWLNamedIndividual(iri);}
}

OWLIndividual Individual() :
{
    OWLIndividual ind;
}
{
    (ind=IndividualIRI() | ind=AnonymousIndividual()) {
        return ind;
    }
}


OWLObjectProperty ObjectPropertyIRI() :
{
    IRI iri;
}
{
    iri=IRI(){return dataFactory.getOWLObjectProperty(iri);}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Annotation Stuff
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

OWLAxiom AnnotationAxiom() :
{
    OWLAxiom axiom;
}
{
    (axiom = AnnotationAssertion() |
     axiom = AnnotationPropertyDomain() |
     axiom = AnnotationPropertyRange() |
     axiom =SubAnnotationPropertyOf()) {
        return axiom;
     }
}

OWLAnnotation Annotation() :
{
    OWLAnnotationProperty prop;
    OWLAnnotationValue val;
    Set annos = null;
    OWLAnnotation anno = null;
}
{
    (({annos = new HashSet();}((anno=Annotation(){annos.add(anno);})*) prop=AnnotationPropertyIRI()val=AnnotationValue()){
        return dataFactory.getOWLAnnotation(prop, val, annos);
    })
}

OWLAnnotationSubject AnnotationSubject() :
{
    OWLAnnotationSubject subj;
}
{
    (subj = IRI() | subj = AnonymousIndividual()) {
        return subj;
    }
}

OWLAnnotationValue AnnotationValue() :
{
    OWLAnnotationValue value;
}
{
    (value = IRI() | value=AnonymousIndividual() | value=Literal()) {
        return value;
    }
}

Set AxiomAnnotationSet() :
{
    Set annos = null;
    OWLAnnotation anno;
}
{
    (anno=Annotation(){
        if(annos == null) {
            annos = new HashSet();
        }
        annos.add(anno);
    })*{
        if(annos  == null) {
            annos = Collections.emptySet();
        }
        return annos;
    }

}

OWLImportsDeclaration ImportsDeclaration() :
{
    IRI iri;
}
{
    iri=IRI() {
        OWLImportsDeclaration importsDeclaration = dataFactory.getOWLImportsDeclaration(iri);
        return importsDeclaration;
    }
}


OWLAnnotationAssertionAxiom AnnotationAssertion() :
{
    OWLAnnotationProperty prop;
    OWLAnnotationSubject subj;
    OWLAnnotationValue val;
    Set axiomAnnos;
}
{
    axiomAnnos=AxiomAnnotationSet() prop=AnnotationPropertyIRI() subj=AnnotationSubject() val=AnnotationValue()   {
        return dataFactory.getOWLAnnotationAssertionAxiom(prop, subj, val, axiomAnnos);
    }
}

OWLSubAnnotationPropertyOfAxiom SubAnnotationPropertyOf() :
{
    OWLAnnotationProperty subProp;
    OWLAnnotationProperty superProperty;
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet() subProp = AnnotationPropertyIRI() superProperty = AnnotationPropertyIRI() {
        return dataFactory.getOWLSubAnnotationPropertyOfAxiom(subProp, superProperty, axiomAnnos);
    }
}

OWLAnnotationPropertyDomainAxiom AnnotationPropertyDomain() :
{
    IRI domain;
    OWLAnnotationProperty prop;
    Set axiomAnnos;

}
{
     axiomAnnos = AxiomAnnotationSet() prop=AnnotationPropertyIRI() domain=IRI() {
        return dataFactory.getOWLAnnotationPropertyDomainAxiom(prop, domain, axiomAnnos);
    }
}

OWLAnnotationPropertyRangeAxiom AnnotationPropertyRange() :
{
    IRI range;
    OWLAnnotationProperty prop;
    Set axiomAnnos;
}
{
     axiomAnnos=AxiomAnnotationSet() prop=AnnotationPropertyIRI() range=IRI() {
        return dataFactory.getOWLAnnotationPropertyRangeAxiom(prop, range, axiomAnnos);
    }
}



OWLHasKeyAxiom HasKey() :
{
    OWLClassExpression ce;
    OWLPropertyExpression prop;
    Set> props = new HashSet>();
    Set axiomAnnos;
}
{
    axiomAnnos = AxiomAnnotationSet() ce=ClassExpression()
     (prop=ObjectPropertyExpression() {props.add(prop);})*
     (prop=DataPropertyExpression() {props.add(prop);})*
      {
        return dataFactory.getOWLHasKeyAxiom(ce, props, axiomAnnos);
    }
}

OWLAxiom Declaration() :
{
    OWLEntity entity = null;
    IRI iri = null;
    OWLLiteral con = null;
    Set axiomAnnos;
}
{
    ((axiomAnnos = AxiomAnnotationSet() entity = Entity())) {
        if(ignoreAnnotationsAndDeclarations) {
            return null;
        }
        else {
            return dataFactory.getOWLDeclarationAxiom(entity, axiomAnnos);
        }
        }

}

OWLEntity Entity() :
{
    OWLEntity entity;
}
{
    (entity=Class() | entity=ObjectProperty() | entity=DataProperty() | entity=NamedIndividual() | entity=Datatype() | entity=AnnotationProperty()) {
        return entity;
    }

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Data Stuff
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

OWLLiteral Literal() :
{
    boolean plain = true;
    String literal;
    OWLDatatype datatype = null;
    String lang = "";
}
{

    (literal=QuotedString()
        (
            ({plain=false;}datatype=DatatypeIRI())
            |
            ((lang=LangTag()))
        )?

        
    ) {
        if(plain) {
            return dataFactory.getOWLLiteral(literal, lang);
        }
        else {
        	// a float value in this syntax has an extra 'f' or 'F' character that must be removed to make a valid OWL literal
            if(datatype.isFloat() && (literal.endsWith("f")||literal.endsWith("F")) && !(literal.endsWith("inf")||literal.endsWith("INF"))){
                    literal=literal.substring(0, literal.length()-1);
            }
            return dataFactory.getOWLLiteral(literal, datatype);
        }
    }
}


String QuotedString() :
{
    Token t;
}
{
    t={
        String raw = t.image.substring(1, t.image.length() - 1);
        return EscapeUtils.unescapeString(raw);
    }
}

String LangTag() :
{
    String lang = "";
        Token t;
}
{
    ((t=){lang += t.image;}) {
        return lang;
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Rules
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

SWRLRule DLSafeRule() :
{
    Set annos;
    SWRLAtom atom;
    Set body;
    Set head;
}
{
      annos = AxiomAnnotationSet()  {body=new HashSet();}  (atom=Atom(){body.add(atom);})*   {head= new HashSet();}  (atom=Atom(){head.add(atom);})*  {
        return dataFactory.getSWRLRule(body, head, annos);
    }
}

SWRLAtom Atom() :
{
    SWRLAtom atom;
}
{
    ( atom=ClassAtom()
    | atom=DataRangeAtom()
    | atom=ObjectPropertyAtom()
    | atom=DataPropertyAtom()
    | atom=BuiltInAtom()
    | atom=SameIndividualAtom()
    | atom=DifferentIndividualsAtom()
    ) {return atom;}
}


SWRLClassAtom ClassAtom() :
{
    OWLClassExpression ce;
    SWRLIArgument arg0;
}
{
      ce=ClassExpression() arg0=IArg()  {return dataFactory.getSWRLClassAtom(ce, arg0);}
}

SWRLDataRangeAtom DataRangeAtom() :
{
    OWLDataRange rng;
    SWRLDArgument arg0;
}
{
      rng=DataRange() arg0=DArg()  {return dataFactory.getSWRLDataRangeAtom(rng, arg0);}
}

SWRLObjectPropertyAtom ObjectPropertyAtom() :
{
    OWLObjectPropertyExpression prop;
    SWRLIArgument arg0;
    SWRLIArgument arg1;
}
{
      prop=ObjectPropertyExpression() arg0=IArg() arg1=IArg() {return dataFactory.getSWRLObjectPropertyAtom(prop, arg0, arg1);}
}

SWRLDataPropertyAtom DataPropertyAtom() :
{
    OWLDataProperty prop;
    SWRLIArgument arg0;
    SWRLDArgument arg1;
}
{
      prop=DataPropertyIRI() arg0=IArg() arg1=DArg()  {return dataFactory.getSWRLDataPropertyAtom(prop, arg0, arg1);}
}


SWRLBuiltInAtom BuiltInAtom() :
{
    IRI iri;
    List args;;
    SWRLDArgument arg;
}
{
      {args=new ArrayList();} iri=IRI() arg=DArg(){args.add(arg);} (arg=DArg(){args.add(arg);})*  {return dataFactory.getSWRLBuiltInAtom(iri, args);}
}


SWRLSameIndividualAtom SameIndividualAtom() :
{
    SWRLIArgument arg0;
    SWRLIArgument arg1;
}
{
      arg0=IArg() arg1=IArg() {return dataFactory.getSWRLSameIndividualAtom(arg0, arg1);}
}

SWRLDifferentIndividualsAtom DifferentIndividualsAtom() :
{
    SWRLIArgument arg0;
    SWRLIArgument arg1;
}
{
      arg0=IArg() arg1=IArg()  {return dataFactory.getSWRLDifferentIndividualsAtom(arg0, arg1);}
}

SWRLIArgument IArg() :
{
    OWLNamedIndividual ind;
    SWRLIArgument arg;
    IRI iri;
}
{
    (  iri = IRI() { return dataFactory.getSWRLVariable(iri);})
    |
    (ind = IndividualIRI() {return dataFactory.getSWRLIndividualArgument(ind);})


}


SWRLDArgument DArg() :
{
    OWLLiteral literal;
    IRI iri;
}
{
    (  iri=IRI() {return dataFactory.getSWRLVariable(iri);})
    |
    (literal = Literal(){return dataFactory.getSWRLLiteralArgument(literal);})
}




//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Description Graphs
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////




© 2015 - 2024 Weber Informatics LLC | Privacy Policy