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

Commit 1bad383d authored by Anders Nilsson's avatar Anders Nilsson

Can now print out a complete? abstract grammar using DumpClasses

parent 439a1d8e
......@@ -19,7 +19,12 @@ aspect DumpClasses {
pStream.print(" ::= ");
Properties props = getFunctionalProperties();
for (int i=0; i<props.getNumProperty(); i++) {
pStream.print(props.getProperty(i).getId()+" ");
pStream.print("<");
pStream.print(props.getProperty(i).getId());
pStream.print(":");
pStream.print(props.getProperty(i).range().type());
pStream.print(">");
pStream.print(" ");
}
pStream.println(";");
}
......
......@@ -9,14 +9,28 @@ aspect MiscUtilities {
}
}
String Element.trim(Attribute a) {
String s = a.getValue().getSTRING_LITERAL();
syn lazy String Attribute.trim() {
String s = getValue().getSTRING_LITERAL();
if (s.indexOf('"') == 0) {
s = s.substring(1,s.length()-1).trim();
}
if (s.indexOf('#') == 0) {
s = s.substring(1,s.length()).trim();
if (s.indexOf('#') > -1) {
s = s.substring(s.indexOf('#')+1,s.length()).trim();
}
return s.trim();
}
eq RdfResource.trim() {
String s = getValue().getSTRING_LITERAL();
if (s.indexOf('"') == 0) {
s = s.substring(1,s.length()-1).trim();
}
if (s.indexOf('#') > -1) {
s = s.substring(s.indexOf('#')+1,s.length()).trim();
}
if (s.equals("string")) {
s = "String";
}
return s.trim();
}
......@@ -38,6 +52,15 @@ aspect MiscUtilities {
return false;
}
boolean ComplexElement.hasRdfResource() {
for (int i=0; i<getNumAttribute(); i++) {
if (getAttribute(i) instanceof RdfResource) {
return true;
}
}
return false;
}
syn lazy String Element.getId() {
return new String("Element has no ID");
}
......@@ -46,13 +69,13 @@ aspect MiscUtilities {
if (hasRdfId()) {
for (int i=0; i<getNumAttribute(); i++) {
if (getAttribute(i) instanceof RdfId) {
return trim(getAttribute(i));
return getAttribute(i).trim();
}
}
} else if (hasRdfAbout()) {
for (int i=0; i<getNumAttribute(); i++) {
if (getAttribute(i) instanceof RdfAbout) {
return trim(getAttribute(i));
return getAttribute(i).trim();
}
}
}
......@@ -61,6 +84,56 @@ aspect MiscUtilities {
return "_Unknown_";
}
syn lazy String Element.type() = null;
eq RdfsRange.type() {
if (hasRdfResource()) {
for (int i=0; i<getNumAttribute(); i++) {
if (getAttribute(i) instanceof RdfResource) {
return getAttribute(i).trim();
}
}
}
for (int i=0; i<getNumElement(); i++) {
String s = getElement(i).type();
if (s != null) {
return s;
}
}
// Fall through. Could not find Id, so let's return something
// well known
return "_Unknown_";
}
eq OwlDataRange.type() {
for (int i=0; i<getNumElement(); i++) {
String s = getElement(i).type();
if (s != null) {
return s;
}
}
return null;
}
eq OwlOneOf.type() {
for (int i=0; i<getNumElement(); i++) {
String s = getElement(i).type();
if (s != null) {
return s;
}
}
return null;
}
eq RdfFirst.type() {
for (int i=0; i<getNumAttribute(); i++) {
if (getAttribute(i) instanceof RdfDatatype) {
return getAttribute(i).trim();
}
}
return null;
}
ComplexElement ComplexElement.getTopElement() {
ASTNode e = this;
while (e != null && !(e instanceof RdfDeclaration)) {
......
......@@ -15,7 +15,7 @@ aspect Types {
return new OwlClassDecl(new List(), new List(), "Thing");
}
eq OwlClassUse.getSuperClass() {
return null;
return decl().getSuperClass();
}
syn lazy OwlClassDecl OClass.decl();
......@@ -29,12 +29,12 @@ aspect Types {
}
// OK, then let's see if this class is declared by w3.org
String id = getId();
if (id.endsWith("owl#Thing")) {
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 null;
return new OwlClassDecl(new List(), new List(), "_Unknown_");
}
syn lazy Properties OwlClassDecl.getFunctionalProperties() {
......@@ -84,7 +84,35 @@ aspect Properties {
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) {
return getId().equals(clazz.getId());
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 OwlFunctionalProperty.range() {
for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof RdfsRange) {
return (RdfsRange) getElement(i);
}
}
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