Commit edda20d3 authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Can handle ObjectProperties. DataProperties still missing

parent 86ce4776
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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(" ");
+1 −0
Original line number Diff line number Diff line
@@ -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";
+60 −9
Original line number Diff line number Diff line
@@ -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;

}
+2 −2
Original line number Diff line number Diff line
@@ -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;