diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag index 88efcb87f5f1452689fc8e60bdc3d87b581e9ce8..0bdec48ac5c16bd76b68ada24d776598ff9b06e6 100644 --- a/CompilerGeneration.jrag +++ b/CompilerGeneration.jrag @@ -27,7 +27,7 @@ aspect AbsGrammarGeneration { pStream.println("StringElement : SimpleElement ::= <IDENTIFIER>;"); pStream.println("IntElement : SimpleElement ::= <INTEGER_LITERAL>;"); pStream.println("FloatElement : SimpleElement ::= <FLOAT_LITERAL>;"); - pStream.println("abstract ClassUse : ComplexElement ::= /decl:Thing/;"); + pStream.println("ClassUse : Thing ::= /decl:Thing/;"); pStream.println("Attribute ::= Value;"); pStream.println("RdfDatatype : Attribute ::= ;"); pStream.println("RdfId : Attribute ::= ;"); @@ -59,9 +59,6 @@ aspect AbsGrammarGeneration { pStream.print(" ::="); getOwnRestrictions().genAbsGrammar(pStream); pStream.println(";"); - pStream.print(getId()+"Use"); - pStream.print(" : ClassUse"); - pStream.println(";"); } void Restrictions.genAbsGrammar(PrintStream pStream) { @@ -73,6 +70,7 @@ aspect AbsGrammarGeneration { void OwlRestriction.genAbsGrammar(PrintStream pStream) { pStream.print(name()); + pStream.print(":Thing"); if (allValuesFrom()) { pStream.print("*"); } @@ -156,11 +154,20 @@ aspect GenPrettyPrinter { pStream.println(ind(2)+"System.out.println(indent+\" \"+value());"); pStream.println(ind(2)+"System.out.println(indent+\"</value>\");"); pStream.println(ind(1)+"}\n"); + // Generate prettyprinter for ClassUse + pStream.println(ind(1)+"public void ClassUse.prettyPrint(String indent, PrintStream pStream) {"); + pStream.println(ind(2)+"System.out.print(indent+\"<\"+name());"); + pStream.println(ind(2)+"for (int i=0; i<getNumAttribute(); i++) {"); + pStream.println(ind(3)+"getAttribute(i).prettyPrint(indent,pStream);"); + pStream.println(ind(2)+"}"); + pStream.println(ind(2)+"System.out.println(\"/>\");"); + pStream.println(ind(1)+"}\n"); super.genPrettyPrinter(pStream); pStream.println("}\n"); } public void OwlClassDecl.genPrettyPrinter(PrintStream pStream) { + // Generate prettyprinter for class declaration pStream.print(ind(1)+"public void "+name()); pStream.println(".prettyPrint(String indent, PrintStream pStream) {"); pStream.println(ind(2)+"System.out.print(indent+\"<"+name()+"\");"); @@ -201,7 +208,7 @@ aspect GenRewrites { pStream.println(); pStream.println("aspect Rewrites {"); pStream.println(ind(1)+"rewrite ComplexElement {"); - pStream.println(ind(2)+"when (getOwlIdentifier().getIDENTIFIER().equals(\"value\") && !(this instanceof ValueElement))"); + pStream.println(ind(2)+"when (!(this instanceof ClassUse) && getOwlIdentifier().getIDENTIFIER().equals(\"value\") && !(this instanceof ValueElement))"); pStream.println(ind(3)+"to ValueElement {"); pStream.println(ind(3)+"ValueElement node = new ValueElement();"); pStream.println(ind(3)+"node.setOwlIdentifier(getOwlIdentifier());"); @@ -219,7 +226,7 @@ aspect GenRewrites { int ix = 0; // Specialize ComplexElements to the actual class in the ontology pStream.println(ind(1)+"rewrite ComplexElement {"); - pStream.println(ind(2)+"when (getOwlIdentifier().getIDENTIFIER().equals(\""+ + pStream.println(ind(2)+"when (!(this instanceof ClassUse) && getOwlIdentifier().getIDENTIFIER().equals(\""+ name()+"\") && !(this instanceof Thing))"); pStream.println(ind(3)+"to "+name()+" {"); @@ -260,9 +267,13 @@ aspect GenRewrites { // current diagonal style from Protege pStream.println(ind(1)+"rewrite "+name()+" {"); pStream.println(ind(2)+"when (!isTopElement())"); - pStream.println(ind(2)+"to "+name()+"Use {"); + pStream.println(ind(2)+"to ClassUse {"); + pStream.println(ind(3)+"ClassUse use = new ClassUse();"); + pStream.println(ind(3)+"use.setOwlIdentifier(new OwlIdentifier(\""+name()+"\"));"); + pStream.println(ind(3)+"use.setAttributeList(new List().add(new RdfResource(getAttribute(0).getValue())));"); + pStream.println(ind(3)+"use.setElementList(new List());"); pStream.println(ind(3)+"getStart().addElement(this);"); - pStream.println(ind(3)+"return new "+name()+"Use();"); + pStream.println(ind(3)+"return use;"); pStream.println(ind(2)+"}"); pStream.println(ind(1)+"}"); } @@ -306,6 +317,10 @@ aspect GenMisc { pStream.println(ind(2)+"return this;"); pStream.println(ind(1)+"}"); + pStream.println(ind(1)+"String ComplexElement.name() {"); + pStream.println(ind(2)+"return getOwlIdentifier().getIDENTIFIER();"); + pStream.println(ind(1)+"}"); + super.genMisc(pStream); pStream.println("}"); diff --git a/siaras/Statistics.jrag b/siaras/Statistics.jrag index b1d984fd70c56fd0dd93a269d575aac22f8fe8aa..6c87aa3b15490993b7a680b443389da29fe2c3dc 100644 --- a/siaras/Statistics.jrag +++ b/siaras/Statistics.jrag @@ -1,3 +1,4 @@ +/* -*-Java-*- */ /* * Copyright (C) 2006 Anders Nilsson <anders.nilsson@cs.lth.se> @@ -9,15 +10,23 @@ import java.io.PrintStream; aspect Statistics { public void ASTNode.getManipulationDevices(PrintStream pStream) { - for (int i=0; i<getNumChild(); i++) { - getChild(i).getManipulationDevices(pStream); +// for (int i=0; i<getNumChild(); i++) { +// getChild(i).getManipulationDevices(pStream); +// } + } + + public void Start.getManipulationDevices(PrintStream pStream) { + for (int i=0; i<getNumElement(); i++) { + getElement(i).getManipulationDevices(pStream); } } + public void Thing.getManipulationDevices(PrintStream pStream) { for (int i=0; i<getNumElement(); i++) { getElement(i).getManipulationDevices(pStream); } } + public void ManipulationAndHandling.getManipulationDevices(PrintStream pStream) { pStream.println(" "+getOwlIdentifier().getIDENTIFIER()+ " : "+getAttribute(0).getValue().getSTRING_LITERAL()); @@ -26,10 +35,17 @@ aspect Statistics { public void ASTNode.getSensors(PrintStream pStream) { - for (int i=0; i<getNumChild(); i++) { - getChild(i).getSensors(pStream); +// for (int i=0; i<getNumChild(); i++) { +// getChild(i).getSensors(pStream); +// } + } + + public void Start.getSensors(PrintStream pStream) { + for (int i=0; i<getNumElement(); i++) { + getElement(i).getSensors(pStream); } } + public void Thing.getSensors(PrintStream pStream) { for (int i=0; i<getNumElement(); i++) { getElement(i).getSensors(pStream);