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.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.semanticweb.owlapi.util.EscapeUtils;
import org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat;
import java.io.IOException;
import org.semanticweb.owlapi.io.OWLParserException;
@SuppressWarnings("javadoc")
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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{
", " "])*">">
}
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();
}
{