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

org.semanticweb.owlapi.functional.parser.OWLFunctionalSyntaxParser.jj Maven / Gradle / Ivy

There is a newer version: 5.5.1
Show newest version
/*
LOOKAHEAD=2,JAVA_UNICODE_ESCAPE,KEEP_LINE_COLUMN     4.61s         <=== Original
LOOKAHEAD=1,JAVA_UNICODE_ESCAPE,KEEP_LINE_COLUMN,    3.9869s
LOOKAHEAD=1,UNICODE_INPUT,KEEP_LINE_COLUMN, :        3.65s
LOOKAHEAD=1,UNICODE_INPUT,                           3.18s
LOOKAHEAD=1,UNICODE_INPUT,USER_TOKEN_MANAGER         1.98s
LOOKAHEAD=1,UNICODE_INPUT,USER_TOKEN_MANAGER,KEEP:   2.00s        <=== Now
*/
options {
    STATIC=false;
    LOOKAHEAD=1;
    UNICODE_INPUT=true;
    //JAVA_TEMPLATE_TYPE = "modern";
    USER_TOKEN_MANAGER=true;
    //KEEP_LINE_COLUMN=false;
    //DEBUG_TOKEN_MANAGER=true;
}

PARSER_BEGIN(OWLFunctionalSyntaxParser)

package org.semanticweb.owlapi.functional.parser;

import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.vocab.*;
import java.net.*;
import java.util.*;
import org.semanticweb.owlapi.util.*;
import org.semanticweb.owlapi.formats.FunctionalSyntaxDocumentFormat;
import java.io.IOException;
import org.semanticweb.owlapi.io.OWLParserException;

@SuppressWarnings("all")
public class OWLFunctionalSyntaxParser {

    private OWLOntologyManager man;

    private OWLOntologyLoaderConfiguration configuration;

    private OWLOntology ontology;

    private OWLDataFactory df;

    private Map string2IRI;

    private Map prefixMap;

    private IRI ontologyIRI;

    private boolean ignoreAnnotationsAndDeclarations = false;

    private Set currentAnnotations;

    protected RemappingIndividualProvider anonProvider;

    public void setUp(OWLOntology ontology, OWLOntologyLoaderConfiguration configuration) {
        this.man = ontology.getOWLOntologyManager();
        this.ontology = ontology;
        this.configuration = configuration;
        this.df = man.getOWLDataFactory();
        anonProvider=new RemappingIndividualProvider(df);
        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) == '<') {
                String iriString = s.substring(1, s.length() - 1);
                iri = IRI.create(iriString);
                if (iri.isAbsolute()) {
                  return iri;
                }
                // relative IRIs must be made absolute with the ontology default prefix, if one exists
                String prefix = prefixMap.get(":");
                if (prefix == null) {
                  prefix = "";
                }
                return IRI.create(prefix + iriString);
            }
            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) {
        man.applyChange(chg);
    }

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

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

PARSER_END(OWLFunctionalSyntaxParser)

SKIP: {" " | "\n" | "\t" | "\r"}
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: {  }

////////////////////////////////////////////////////////////////////////////////////////////
//
// IRIs
TOKEN: { ", " "])*">"> }
TOKEN: { )? ":"> }
TOKEN: {  | ["0"-"9"] ) ((|".")* )?> }
TOKEN: {  >}
TOKEN: { ((|".")* )?> }
TOKEN: {  }
TOKEN: {  | "-" | ["0"-"9"] | "\u00B7" | ["\u0300"-"\u036F"] | ["\u203F"-"\u2040"]> }
TOKEN: {  | "_"> }
TOKEN: { > }
TOKEN: {  }

public FunctionalSyntaxDocumentFormat parse() throws OWLParserException, UnloadableImportException : { }
{
    (Prefix())*Ontology() {
        FunctionalSyntaxDocumentFormat format = new FunctionalSyntaxDocumentFormat();
        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 df.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 df.getOWLObjectUnionOf(classExpressions); } }

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

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

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

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

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

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

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

OWLClassExpression ObjectMinCardinality()  :
{
    int cardinality = 0;
    OWLObjectPropertyExpression prop = null;
    OWLClassExpression filler = null;
}
{
    (cardinality=Cardinality()prop=ObjectPropertyExpression()(filler=ClassExpression())?) {
        if(filler == null) {
            return df.getOWLObjectMinCardinality(cardinality, prop);
        }
        return df.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 df.getOWLObjectExactCardinality(cardinality, prop);
        }
        return df.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 df.getOWLObjectMaxCardinality(cardinality, prop);
        }
        return df.getOWLObjectMaxCardinality(cardinality, prop, filler);
    }
}

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

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

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

OWLClassExpression DataMinCardinality()  :
{
    int cardinality = 0;
    OWLDataPropertyExpression prop = null;
    OWLDataRange rng = null;
}
{
    cardinality=Cardinality()prop=DataPropertyExpression()((rng=DataRange())?)
    {
        if(rng == null) {
            return df.getOWLDataMinCardinality(cardinality, prop);
        }
        return df.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 df.getOWLDataExactCardinality(cardinality, prop);
        }
        return df.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 df.getOWLDataMaxCardinality(cardinality, prop);
        }
        return df.getOWLDataMaxCardinality(cardinality, prop, rng);
    }
}


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

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

OWLObjectPropertyExpression InverseObjectProperty()  :
{ OWLObjectProperty prop; }
{ prop=ObjectPropertyIRI() { return df.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 df.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 df.getOWLAnnotationProperty(iri); } }

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

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

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

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

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

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

OWLDatatypeDefinitionAxiom DatatypeDefinitionAxiom() :
{
    OWLDatatype datatype;
    OWLDataRange dr;
    Set axAnnos;
}
{ (axAnnos = AxiomAnnotationSet() datatype=DatatypeIRI() dr=DataRange()) { return df.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 df.getOWLDataComplementOf(rng); } }

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

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

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

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

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


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

OWLAxiom Axiom() :
{ OWLAxiom ax; }
{
    (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 df.getOWLSubClassOfAxiom(subClass, superClass, axiomAnnos); } }

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

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

OWLClassAxiom DisjointUnion() :
{
    OWLClass cls;
    Set classExpressions;
    Set axiomAnnos;
}
{ axiomAnnos = AxiomAnnotationSet()cls=ClassIRI() classExpressions=ClassExpressionSet() { return df.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 df.getOWLSubObjectPropertyOfAxiom(subProperty, superProperty, axiomAnnos);
        }
        if(chain != null) {
            return df.getOWLSubPropertyChainOfAxiom(chain, superProperty, axiomAnnos);
        }
        return null;
    }
}

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

OWLPropertyAxiom DisjointObjectProperties() :
{
    Set props;
    Set axiomAnnos;
}
{ axiomAnnos = AxiomAnnotationSet()props=ObjectPropertySet() { return df.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 df.getOWLObjectPropertyRangeAxiom(prop, range, axiomAnnos); } }

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

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

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

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

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

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

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

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

OWLPropertyAxiom TransitiveObjectProperty() :
{
    OWLObjectPropertyExpression prop;
    Set axiomAnnos;
}
{ axiomAnnos = AxiomAnnotationSet()prop=ObjectPropertyExpression() { return df.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 df.getOWLSubDataPropertyOfAxiom(subProperty, superProperty, axiomAnnos); } }

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

OWLPropertyAxiom DisjointDataProperties() :
{
    Set props;
    Set axiomAnnos;
}
{ axiomAnnos = AxiomAnnotationSet()props=DataPropertySet() { return df.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 df.getOWLDataPropertyDomainAxiom(prop, domain, axiomAnnos); } }

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

OWLPropertyAxiom FunctionalDataProperty() :
{
    OWLDataPropertyExpression prop;
    Set axiomAnnos;
}
{ axiomAnnos = AxiomAnnotationSet()prop=DataPropertyExpression() { return df.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 df.getOWLSameIndividualAxiom(individuals, axiomAnnos); } }

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

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

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

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

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

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

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

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

OWLObjectProperty ObjectPropertyIRI() :
{ IRI iri; }
{ iri=IRI(){return df.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 = new HashSet();
    OWLAnnotation anno = null;
}
{ (((anno=Annotation(){annos.add(anno);})*) prop=AnnotationPropertyIRI() val=AnnotationValue()) { return df.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);
    })*{ return annos  == null ? Collections.emptySet() : annos; } }

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


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

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

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

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

OWLAnnotationPropertyRangeAxiom AnnotationPropertyRange() :
{
    IRI range;
    OWLAnnotationProperty prop;
    Set axiomAnnos;
}
{  axiomAnnos=AxiomAnnotationSet() prop=AnnotationPropertyIRI() range=IRI() { return df.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 df.getOWLHasKeyAxiom(ce, props, axiomAnnos); } }

OWLAxiom Declaration() :
{
    OWLEntity entity = null;
    IRI iri = null;
    OWLLiteral con = null;
    Set axiomAnnos;
}
{ ((axiomAnnos = AxiomAnnotationSet() entity = Entity())) { return ignoreAnnotationsAndDeclarations? null: df.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 df.getOWLLiteral(literal, lang); }
        	// 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 df.getOWLLiteral(literal, datatype);
    }
}


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

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

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

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

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

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

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

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

SWRLDataPropertyAtom DataPropertyAtom() :
{
    OWLDataProperty prop;
    SWRLIArgument arg0;
    SWRLDArgument arg1;
}
{   prop=DataPropertyIRI() arg0=IArg() arg1=DArg()  {return df.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 df.getSWRLBuiltInAtom(iri, args);} }

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy