Gitlab service upgraded. Please report any problems to dl_gitadmin@cs.lth.se

Commit bb7e74ca authored by Anders Nilsson's avatar Anders Nilsson

Can now dump declared classes with their ancestors using

DumpClasses.java
parent b5cba759
......@@ -15,7 +15,11 @@ aspect CompilerGeneration {
void OwlClassDecl.genAbsGrammar(PrintStream pStream) {
pStream.print("OwlClassDecl: ");
pStream.println(getId());
pStream.print(getId());
if (getSuperClass() != null) {
pStream.print(" extends ");
pStream.println(getSuperClass().getId());
}
super.genAbsGrammar(pStream);
}
......
// package programs;
import AST.Start;
public class DumpClasses extends Parser {
public static void main(String args[]) {
Start ast = parse(args);
// Dump the AST
// ast.dumpTree(" ", System.out);
// Should be generated to a file when sufficiently
// implemented. AndersN 060210
ast.dumpClasses(System.out);
}
}
\ No newline at end of file
/* -*-Java-*- */
import java.io.PrintStream;
aspect DumpClasses {
void ASTNode.dumpClasses(PrintStream pStream) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).dumpClasses(pStream);
}
}
public void Start.dumpClasses(PrintStream pStream) {
super.dumpClasses(pStream);
}
void OwlClassDecl.dumpClasses(PrintStream pStream) {
pStream.print(getId());
pStream.println(" : "+getSuperClass().getId());
}
}
\ No newline at end of file
......@@ -56,6 +56,14 @@ aspect MiscUtilities {
// well known
return "_Unknown_";
}
ComplexElement ComplexElement.getTopElement() {
ComplexElement e = this;
while (e != null && !(e instanceof RdfDeclaration)) {
e = (ComplexElement) e.getParent().getParent();
}
return e;
}
}
aspect RewriteClasses {
......@@ -69,4 +77,15 @@ aspect RewriteClasses {
return new OwlClassUse(new List(), getElementList(), getId());
}
}
rewrite RdfsSubClassOf {
when (getNumAttribute()>0 && getAttribute(0) instanceof RdfResource)
to RdfsSubClassOf {
Value value = getAttribute(0).getValue();
OwlClass oc = new OwlClass(new List().add(new RdfAbout(value)),
new List());
return new RdfsSubClassOf(new List(),
new List().add(oc));
}
}
}
\ No newline at end of file
/* -*-Java-*- */
aspect Types {
// syn lazy Class Class.getSuperClass();
// eq OwlClassDecl.getSuperClass() {
// for (int i=0; i<getNumElement(); i++) {
// if (getElement(i) instanceof RdfsSubClassOf) {
// return getElement(i);
// }
// }
// }
// eq OwlClassUse.getSuperClass() {
// return null;
// }
syn lazy Class Class.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 Class) {
return ((Class) 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 null;
}
syn lazy OwlClassDecl Class.decl();
eq OwlClassDecl.decl() = this;
eq OwlClassUse.decl() {
ComplexElement top = getTopElement();
for (int i=0; i<top.getNumElement(); i++) {
if (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("owl#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 null;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment