Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.semanticweb.owlapi.functional.parser.OWLFunctionalSyntaxParser.jj Maven / Gradle / Ivy
/*
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.EscapeUtils;
import org.semanticweb.owlapi.formats.OWLFunctionalSyntaxOntologyFormat;
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) == '<') {
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) {
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: { }
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, 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 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