diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag index 6880ef7ab9004ea3fedb44141f5ab98badd0e92b..53a4709f40e0a41afd707265b9b019a38d9f3f86 100644 --- a/CompilerGeneration.jrag +++ b/CompilerGeneration.jrag @@ -95,14 +95,14 @@ aspect AbsGrammarGeneration { pStream.print(name()); pStream.print(" : "+getSuperClass().name()); pStream.print(" ::="); - // getProperties().genAbsGrammar(pStream); + getProperties().genAbsGrammar(pStream); pStream.println(";"); } void Properties.genAbsGrammar(PrintStream pStream) { for (int i=0; i<getNumProperty(); i++) { pStream.print(" "); - ((OwlProperty) getProperty(i)).genAbsGrammarEntry(pStream); + getProperty(i).genAbsGrammarEntry(pStream); } } @@ -114,6 +114,13 @@ aspect AbsGrammarGeneration { // } } + void Element.genAbsGrammarEntry(PrintStream pStream) {} + + void ObjectPropertyDomain.genAbsGrammarEntry(PrintStream pStream) { + pStream.print(objectProperty().name()); + pStream.print(":Thing*"); + } + void Restrictions.genAbsGrammar(PrintStream pStream) { for (int i=0; i<getNumOwlRestriction(); i++) { pStream.print(" "); diff --git a/Names.jrag b/Names.jrag index 0a9289e4f9efb0668402f45a4138050d1635e6d2..5c54c22f91693da1be33f4dcb0b601b46291d846 100644 --- a/Names.jrag +++ b/Names.jrag @@ -27,6 +27,7 @@ aspect Names { eq Declaration.name() = getElement(0).name(); eq Clazz.name() = iri().trim(); eq NamedIndividual.name() = iri().trim(); + eq ObjectProperty.name() = iri().trim(); static String ASTNode.gName = "owl"; diff --git a/Types.jrag b/Types.jrag index 57dc348599849766ddee6cbdd85baefddcfd378c..6207a3a7d588e89f7bffa6568a0914edffa7bfd5 100644 --- a/Types.jrag +++ b/Types.jrag @@ -22,6 +22,17 @@ import java.util.ArrayList; aspect Types { + syn Clazz Element.clazz() = null; + eq ComplexElement.clazz() { + for (Element e: getElements()) { + if (e.clazz() != null) { + return e.clazz(); + } + } + return null; + } + eq Clazz.clazz() = this; + syn lazy Declaration Declaration.getSuperClass() = null; eq ClassDeclaration.getSuperClass() { return goStart().getSuperClass(name()); @@ -80,7 +91,7 @@ aspect Types { return null; } - syn lazy OClass OClass.getSuperClass(); + syn lazy Declaration OClass.getSuperClass(); eq OwlClassDecl.getSuperClass() { for (int i=0; i<getNumElement(); i++) { if (getElement(i) instanceof RdfsSubClassOf) { @@ -97,7 +108,7 @@ aspect Types { return decl().getSuperClass(); } - syn lazy OwlClassDecl OClass.decl(); + syn lazy OwlClassDecl Declaration.decl() = null; eq OwlClassDecl.decl() = this; eq OwlClassUse.decl() { ComplexElement top = getTopElement(); @@ -140,6 +151,22 @@ aspect Types { } return p; } + syn lazy Properties ClassDeclaration.getProperties() { + List l = new List(); + goStart().collectProperties(l); +// collectProperties(l); +// return new Properties(l); + Properties p = new Properties(); + for (int i=0; i<l.getNumChild(); i++) { + ObjectPropertyDomain op = (ObjectPropertyDomain) l.getChild(i); + if (op.domainIncludes(this)) { + p.addProperty(op); + } else { +// System.out.println(op); + } + } + return p; + } syn lazy ArrayList OClass.getSubClasses(); eq OwlClassUse.getSubClasses() = decl().getSubClasses(); @@ -232,11 +259,11 @@ aspect Properties { l.add(this); } - boolean ASTNode.domainIncludes(OClass clazz) { + boolean ASTNode.domainIncludes(Declaration clazz) { return false; } - boolean OwlObjectProperty.domainIncludes(OClass clazz) { + boolean OwlObjectProperty.domainIncludes(Declaration clazz) { for (int i=0; i<getNumElement(); i++) { if (getElement(i) instanceof RdfsDomain) { return ((RdfsDomain) getElement(i)).domainIncludes(clazz); @@ -245,7 +272,7 @@ aspect Properties { return false; } - boolean OwlFunctionalProperty.domainIncludes(OClass clazz) { + boolean OwlFunctionalProperty.domainIncludes(Declaration clazz) { for (int i=0; i<getNumElement(); i++) { if (getElement(i) instanceof RdfsDomain) { return ((RdfsDomain) getElement(i)).domainIncludes(clazz); @@ -254,7 +281,7 @@ aspect Properties { return false; } - boolean OwlDatatypeProperty.domainIncludes(OClass clazz) { + boolean OwlDatatypeProperty.domainIncludes(Declaration clazz) { for (int i=0; i<getNumElement(); i++) { if (getElement(i) instanceof RdfsDomain) { return ((RdfsDomain) getElement(i)).domainIncludes(clazz); @@ -263,7 +290,7 @@ aspect Properties { return false; } - boolean RdfsDomain.domainIncludes(OClass clazz) { + boolean RdfsDomain.domainIncludes(Declaration clazz) { for (int i=0; i<getNumElement(); i++) { if (getElement(i).domainIncludes(clazz)) { return true; @@ -272,7 +299,7 @@ aspect Properties { return false; } - boolean OwlUnionOf.domainIncludes(OClass clazz) { + boolean OwlUnionOf.domainIncludes(Declaration clazz) { for (int i=0; i<getNumElement(); i++) { if (getElement(i).domainIncludes(clazz)) { return true; @@ -281,7 +308,7 @@ aspect Properties { return false; } - boolean OClass.domainIncludes(OClass clazz) { + boolean Declaration.domainIncludes(Declaration clazz) { if (!getId().equals("_Unknown_")) { return getId().equals(clazz.getId()); } @@ -293,6 +320,16 @@ aspect Properties { return false; } + boolean ObjectPropertyDomain.domainIncludes(Declaration clazz) { + while (!clazz.name().equals("Thing")) { + if (clazz().name().equals(clazz.name())) { + return true; + } + clazz = clazz.getSuperClass(); + } + return false; + } + syn lazy RdfsRange Element.range() = null; eq OwlObjectProperty.range() { @@ -319,4 +356,18 @@ aspect Properties { } return null; } + + syn ObjectProperty ObjectPropertyDomain.objectProperty() { + for (Element e : getElements()) { + if (e.isObjectProperty()) { + return (ObjectProperty) e; + } + } + System.err.println("ObjectPropertyDomain.objectProperty(): not found"); + return null; + } + + syn boolean Element.isObjectProperty() = false; + eq ObjectProperty.isObjectProperty() = true; + } diff --git a/owl.ast b/owl.ast index f40a0d870ca6c5229865c1c53d74e27ef06e677b..eba2627282182a554ed444ed1922ba20dcc0f00c 100644 --- a/owl.ast +++ b/owl.ast @@ -46,7 +46,7 @@ ObjectMinCardinality : ComplexElement; ObjectSomeValuesFrom : ComplexElement; ObjectProperty : ComplexElement; ObjectPropertyAssertion : ComplexElement; -ObjectPropertyDomain : ComplexElement; +ObjectPropertyDomain : OwlProperty; Ontology : OntoDeclaration; Prefix : ComplexElement; SubClassOf : ComplexElement; @@ -174,7 +174,7 @@ Value ::= <STRING_LITERAL>; Identifier ::= <IDENTIFIER>; // Types used by rewrite rules -abstract OClass : ComplexElement ::= <Id:String>; +abstract OClass : Declaration ::= <Id:String>; OwlClassDecl : OClass; OwlClassUse : OClass;