Select Git revision
Types.jrag 5.07 KiB
/* -*-Java-*- */
/*
* Copyright (C) 2006 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of OntologyCompiler.
*/
import java.util.ArrayList;
aspect Types {
syn lazy OClass OClass.getSuperClass();
eq OwlClassDecl.getSuperClass() {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsSubClassOf) {
RdfsSubClassOf e = (RdfsSubClassOf) getElement(i);
if (e.getElement(0) instanceof OClass) {
return ((OClass) e.getElement(0)).decl();
}
}
}
// No super class found, return an owl Thing instead.
return new OwlClassDecl(new List(), new List(), "Thing");
}
eq OwlClassUse.getSuperClass() {
return decl().getSuperClass();
}
syn lazy OwlClassDecl OClass.decl();
eq OwlClassDecl.decl() = this;
eq OwlClassUse.decl() {
ComplexElement top = getTopElement();
for (int i=0; i<top.getNumElement(); i++) {
if ((top.getElement(i) instanceof ComplexElement) &&
getId().equals(((ComplexElement) top.getElement(i)).getId())) {
return (OwlClassDecl) top.getElement(i);
}
}
// OK, then let's see if this class is declared by w3.org
String id = getId();
if (id.endsWith("Thing")) {
return new OwlClassDecl(new List(), new List(), "Thing");
}
// No decl found, so let's return null. Not sure if that's
// that the right thing to do though.
return new OwlClassDecl(new List(), new List(), "_Unknown_");
}
syn lazy Properties OwlClassDecl.getProperties() {
List l = new List();
// getTopElement().collectProperties(l);
collectProperties(l);
return new Properties(l);
// Properties p = new Properties();
// for (int i=0; i<l.getNumChild(); i++) {
// OwlProperty op = (OwlProperty) l.getChild(i);
// if (op.domainIncludes(this)) {
// p.addProperty(op);
// }
// }
// return p;
}
syn lazy ArrayList OClass.getSubClasses();
eq OwlClassUse.getSubClasses() = decl().getSubClasses();
eq OwlClassDecl.getSubClasses() {
return goStart().getSubClasses(this,new ArrayList());
}
syn ArrayList ASTNode.getSubClasses(OwlClassDecl klass, ArrayList l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).getSubClasses(klass,l);
}
return l;
}
eq OwlClassDecl.getSubClasses(OwlClassDecl klass, ArrayList l) {
if (getSuperClass() == klass) {
l.add(this);
}
return l;
}
}
aspect Restrictions {
Restrictions OwlClassDecl.restrictions;
Restrictions OwlClassDecl.ownRestrictions;
syn lazy Restrictions OwlClassDecl.getRestrictions() {
if (restrictions == null) {
List l = new List();
collectRestrictions(l);
restrictions = new Restrictions(l);
}
return restrictions;
}
void ASTNode.collectRestrictions(List l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectRestrictions(l);
}
}
void OwlClassDecl.collectRestrictions(List l) {
if (!getSuperClass().getId().equals("Thing")) {
getSuperClass().decl().collectRestrictions(l);
}
super.collectRestrictions(l);
}
void OwlRestriction.collectRestrictions(List l) {
if (allValuesFrom()) {
l.add(this);
}
}
syn int OwlClassDecl.getNumRestriction() = getRestrictions().getNumOwlRestriction();
syn lazy Restrictions OwlClassDecl.getOwnRestrictions() {
if (ownRestrictions == null) {
List l = new List();
collectOwnRestrictions(l);
ownRestrictions = new Restrictions(l);
}
return ownRestrictions;
}
void ASTNode.collectOwnRestrictions(List l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectOwnRestrictions(l);
}
}
void OwlRestriction.collectOwnRestrictions(List l) {
if (allValuesFrom()) {
l.add(this);
}
}
syn int OwlClassDecl.getNumOwnRestriction() =
getOwnRestrictions().getNumOwlRestriction();
}
aspect Properties {
void ASTNode.collectProperties(List l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectProperties(l);
}
}
void OwlProperty.collectProperties(List l) {
l.add(this);
}
boolean ASTNode.domainIncludes(OClass clazz) {
return false;
}
boolean OwlObjectProperty.domainIncludes(OClass clazz) {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsDomain) {
return ((RdfsDomain) getElement(i)).domainIncludes(clazz);
}
}
return false;
}
boolean RdfsDomain.domainIncludes(OClass clazz) {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
}
boolean OwlUnionOf.domainIncludes(OClass clazz) {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
}
boolean OClass.domainIncludes(OClass clazz) {
if (!getId().equals("_Unknown_")) {
return getId().equals(clazz.getId());
}
for (int i=0; i<getNumElement(); i++) {
if (getElement(i).domainIncludes(clazz)) {
return true;
}
}
return false;
}
syn lazy RdfsRange Element.range() = null;
eq OwlObjectProperty.range() {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsRange) {
return (RdfsRange) getElement(i);
}
}
return null;
}
}