From 1bad383dd89b36e564f239e2b64c4a6eed7a4c76 Mon Sep 17 00:00:00 2001 From: Anders Nilsson <anders.nilsson@cs.lth.se> Date: Thu, 16 Feb 2006 16:01:32 +0100 Subject: [PATCH] Can now print out a complete? abstract grammar using DumpClasses --- DumpClasses.jrag | 7 +++- Rewrites.jrag | 85 ++++++++++++++++++++++++++++++++++++++++++++---- Types.jrag | 36 +++++++++++++++++--- 3 files changed, 117 insertions(+), 11 deletions(-) diff --git a/DumpClasses.jrag b/DumpClasses.jrag index faa8cfe..d973dab 100644 --- a/DumpClasses.jrag +++ b/DumpClasses.jrag @@ -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(";"); } diff --git a/Rewrites.jrag b/Rewrites.jrag index 08de276..74ab30d 100644 --- a/Rewrites.jrag +++ b/Rewrites.jrag @@ -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)) { diff --git a/Types.jrag b/Types.jrag index 1dd46ad..9dbf284 100644 --- a/Types.jrag +++ b/Types.jrag @@ -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 -- GitLab