Commit b183530a authored by Anders Nilsson's avatar Anders Nilsson

GenOntology generates a correct (acc. to Protege) ontology, without instances at the moment

parent c205da6b
......@@ -13,3 +13,4 @@ siaras/GeneratedAspects.jrag
testontologies/*.xmi
testontologies/*.pprj
siaras/ontology.owl
siaras/javadoc
......@@ -140,9 +140,21 @@ aspect GenPrettyPrinter {
pStream.println(" }");
pStream.println(" }\n");
pStream.println(" syn String Attribute.id() = \"\";");
pStream.println(" eq RdfId.id() = \"Rdf:ID\";");
pStream.println(" eq RdfDatatype.id() = \"Rdf:datatype\";");
pStream.println(" eq RdfResource.id() = \"Rdf:resource\";");
pStream.println(" eq RdfAbout.id() = \"rdf:about\";");
pStream.println(" eq RdfDatatype.id() = \"rdf:datatype\";");
pStream.println(" eq RdfId.id() = \"rdf:ID\";");
pStream.println(" eq RdfParseType.id() = \"rdf:parseType\";");
pStream.println(" eq RdfResource.id() = \"rdf:resource\";");
pStream.println(" eq XmlBase.id() = \"xml:base\";");
pStream.println(" eq Xmlns.id() = \"xmlns\";");
pStream.println(" eq XmlnsDaml.id() = \"xmlns:daml\";");
pStream.println(" eq XmlnsDc.id() = \"xmlns:dc\";");
pStream.println(" eq XmlnsOwl.id() = \"xmlns:owl\";");
pStream.println(" eq XmlnsP1.id() = \"xmlns:p1\";");
pStream.println(" eq XmlnsProtege.id() = \"xmlns:protege\";");
pStream.println(" eq XmlnsRdf.id() = \"xmlns:rdf\";");
pStream.println(" eq XmlnsRdfs.id() = \"xmlns:rdfs\";");
pStream.println(" eq XmlnsXsd.id() = \"xmlns:xsd\";");
pStream.println(" public void Attribute.prettyPrint(String indent, PrintStream pStream) {");
pStream.println(" System.out.print(\" \"+id()+\"=\"+getValue().getSTRING_LITERAL());");
pStream.println(" }\n");
......@@ -353,10 +365,10 @@ aspect GenMisc {
pStream.println(ind(1)+"}");
// ComplexElement.name()
pStream.println(ind(1)+"String ComplexElement.name() {");
pStream.println(ind(1)+"public String ComplexElement.name() {");
pStream.println(ind(2)+"return getOwlIdentifier().getIDENTIFIER();");
pStream.println(ind(1)+"}");
pStream.println(ind(1)+"String Attribute.name() {");
pStream.println(ind(1)+"public String Attribute.name() {");
pStream.println(ind(2)+"return getValue().getSTRING_LITERAL();");
pStream.println(ind(1)+"}");
......
......@@ -15,6 +15,7 @@ XmlHeader ::= Attribute*;
abstract Element;
abstract ComplexElement : Element ::= Attribute* Element*;
RdfDeclaration : ComplexElement;
RdfDescription : ComplexElement;
RdfFirst : ComplexElement;
RdfRest : ComplexElement;
RdfType : ComplexElement;
......@@ -38,6 +39,7 @@ OwlImports : ComplexElement;
OwlIntersectionOf : ComplexElement;
OwlInverseOf : ComplexElement;
OwlMinCardinality : ComplexElement;
OwlMaxCardinality : ComplexElement;
OwlObjectProperty : OwlProperty;
OwlOneOf : ComplexElement;
OwlOnProperty : OwlProperty;
......
......@@ -79,6 +79,7 @@ SPECIAL_TOKEN : /* COMMENTS */
| < OWL_IMPORTS : "owl:imports" >
| < OWL_INTERSECTIONOF : "owl:intersectionOf" >
| < OWL_INVERSEOF : "owl:inverseOf" >
| < OWL_MAXCARDINALITY : "owl:maxCardinality" >
| < OWL_MINCARDINALITY : "owl:minCardinality" >
| < OWL_OBJECTPROPERTY : "owl:ObjectProperty" >
| < OWL_ONPROPERTY : "owl:onProperty" >
......@@ -90,6 +91,7 @@ SPECIAL_TOKEN : /* COMMENTS */
| < RDF_RDF : "rdf:RDF" >
| < RDF_ABOUT : "rdf:about" >
| < RDF_DATATYPE : "rdf:datatype" >
| < RDF_DESCRIPTION : "rdf:Description" >
| < RDF_ID : "rdf:ID" >
| < RDF_FIRST : "rdf:first" >
| < RDF_REST : "rdf:rest" >
......@@ -377,6 +379,7 @@ void OwlElement() : {}
| OwlImports()
| OwlIntersectionOf()
| OwlInverseOf()
| OwlMaxCardinality()
| OwlMinCardinality()
| OwlObjectProperty()
| OwlOneOf()
......@@ -470,6 +473,12 @@ void OwlInverseOf () #OwlInverseOf : {}
(">" ElementList() "</" <OWL_INVERSEOF> ">" | ElementList() "/>")
}
void OwlMaxCardinality () #OwlMaxCardinality : {}
{
<OWL_MAXCARDINALITY> AttributeList()
(">" ElementList() "</" <OWL_MAXCARDINALITY> ">" | ElementList() "/>")
}
void OwlMinCardinality () #OwlMinCardinality : {}
{
<OWL_MINCARDINALITY> AttributeList()
......@@ -515,6 +524,7 @@ void OwlUnionOf () #OwlUnionOf : {}
void RdfElement() : {}
{
RdfType()
| RdfDescription()
| RdfFirst()
| RdfRest()
| RdfsComment()
......@@ -530,6 +540,12 @@ void RdfType() #RdfType : {}
(">" ElementList() "</" <RDF_TYPE> ">" | ElementList() "/>")
}
void RdfDescription() #RdfDescription : {}
{
<RDF_DESCRIPTION> AttributeList()
(">" ElementList() "</" <RDF_DESCRIPTION> ">" | ElementList() "/>")
}
void RdfFirst() #RdfFirst : {}
{
<RDF_FIRST> AttributeList()
......
......@@ -10,13 +10,58 @@ import java.io.PrintStream;
aspect Statistics {
public void ASTNode.genOntology(String ind, PrintStream pStream) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).genOntology(ind, pStream);
// for (int i=0; i<getNumChild(); i++) {
// getChild(i).genOntology(ind, pStream);
// }
}
public void ComplexElement.genOntology(String ind, PrintStream pStream) {
pStream.print(ind+"<"+name());
for (int i=0; i<getNumAttribute(); i++) {
pStream.print(" ");
getAttribute(i).genOntology(pStream);
}
if (getNumElement() > 0) {
pStream.println(">");
for (int i=0; i<getNumElement(); i++) {
getElement(i).genOntology(ind+" ", pStream);
}
pStream.println(ind+"</"+name()+">");
} else {
pStream.println("/>");
}
}
public void Thing.genOntology(String ind, PrintStream pStream) {
}
public void Start.genOntology(String ind, PrintStream pStream) {
pStream.println("<?xml version=\"1.0\"?>");
super.genOntology(ind, pStream);
for (int i=0; i<getNumElement(); i++) {
getElement(i).genOntology(ind+" ", pStream);
}
}
public void RdfDeclaration.genOntology(String ind, PrintStream pStream) {
pStream.print(ind+"<rdf:RDF");
for (int i=0; i<getNumAttribute(); i++) {
pStream.println();
pStream.print(ind+" ");
getAttribute(i).genOntology(pStream);
}
pStream.println(">");
for (int i=0; i<getNumElement(); i++) {
getElement(i).genOntology(ind+" ", pStream);
}
pStream.println(ind+"</rdf:RDF>");
}
// public void OwlOntology.genOntology(String ind, PrintStream pStream) {
// pStream.print(ind+"<"+name()
// }
public void Attribute.genOntology(PrintStream pStream) {
pStream.print(id()+"="+getValue().getSTRING_LITERAL());
}
}
/* -*-Java-*- */
/*
* Copyright (C) 2006 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of OntologyCompiler.
*/
aspect Qualification {
rewrite ComplexElement {
when (name().equals("rdf:RDF") && !(this instanceof RdfDeclaration))
to RdfDeclaration {
return new RdfDeclaration(getOwlIdentifier(),
getAttributeList(),
getElementList());
}
}
}
// -*-Java-*-
// Copyright (C) 2006 Anders Nilsson <anders.nilsson@cs.lth.se>
//
// This file is part of OntologyCompiler.
RdfDeclaration : ComplexElement;
RdfDescription : ComplexElement;
RdfFirst : ComplexElement;
RdfRest : ComplexElement;
RdfType : ComplexElement;
RdfsComment : ComplexElement;
RdfsDomain : ComplexElement;
RdfsRange : ComplexElement;
RdfsSubClassOf : ComplexElement;
RdfsSubPropertyOf : ComplexElement;
OwlOntology : ComplexElement;
OwlAllDifferent : ComplexElement;
OwlAllValuesFrom : OwlValuesFrom;
OwlCardinality : ComplexElement;
OwlClass : ComplexElement;
OwlDataRange : ComplexElement;
OwlDatatypeProperty : ComplexElement;
OwlDisjointWith : ComplexElement;
OwlDistinctMembers: ComplexElement;
OwlEquivalentClass : ComplexElement;
OwlFunctionalProperty : OwlProperty;
OwlImports : ComplexElement;
OwlIntersectionOf : ComplexElement;
OwlInverseOf : ComplexElement;
OwlMaxCardinality : ComplexElement;
OwlMinCardinality : ComplexElement;
OwlObjectProperty : OwlProperty;
OwlOneOf : ComplexElement;
OwlOnProperty : OwlProperty;
OwlSomeValuesFrom : OwlValuesFrom;
OwlRestriction : ComplexElement;
OwlUnionOf : ComplexElement;
// Types used by rewrite rules
abstract OClass : ComplexElement ::= <Id:String>;
OwlClassDecl : OClass;
OwlClassUse : OClass;
abstract OwlValuesFrom: ComplexElement;
// Properties ::= Property:Element*;
// Restrictions ::= OwlRestriction*;
abstract OwlProperty : ComplexElement;
This diff is collapsed.
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