Commit 337d8322 authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Added ontology version 9. Started to implement output module generating an OWL file.

parent 0dcf91e5
......@@ -12,3 +12,4 @@ siaras/log.tmp
siaras/GeneratedAspects.jrag
testontologies/*.xmi
testontologies/*.pprj
siaras/ontology.owl
......@@ -24,9 +24,9 @@ aspect AbsGrammarGeneration {
pStream.println("ComplexElement : Element ::= OwlIdentifier Attribute* Element*;");
pStream.println("ValueElement : ComplexElement;");
pStream.println("abstract SimpleElement : Element;");
pStream.println("StringElement : SimpleElement ::= <IDENTIFIER>;");
pStream.println("IntElement : SimpleElement ::= <INTEGER_LITERAL>;");
pStream.println("FloatElement : SimpleElement ::= <FLOAT_LITERAL>;");
pStream.println("StringElement : SimpleElement ::= <LITERAL>;");
pStream.println("IntElement : SimpleElement ::= <LITERAL>;");
pStream.println("FloatElement : SimpleElement ::= <LITERAL>;");
pStream.println("ClassUse : Thing ::= /decl:Thing/;");
pStream.println("Attribute ::= Value;");
pStream.println("RdfDatatype : Attribute ::= ;");
......@@ -234,17 +234,17 @@ aspect GenRewrites {
pStream.println(ind(3)+"use.setElementList(new List());");
pStream.println(ind(3)+"return use;");
pStream.println(ind(2)+"}");
pStream.println(ind(2)+"when ((name().equals(\"isSkillOf\")");
pStream.println(ind(2)+"|| name().equals(\"isPropertyOf\"))");
pStream.println("&& getNumAttribute() > 0 && getAttribute(0) instanceof RdfResource)");
pStream.println(ind(2)+"to ClassUse {");
pStream.println(ind(3)+"ClassUse use = new ClassUse();");
pStream.println(ind(3)+"String att = getAttribute(0).name();");
pStream.println(ind(3)+"use.setOwlIdentifier(new OwlIdentifier(att.substring(att.indexOf('#')+1,att.indexOf('_'))));");
pStream.println(ind(3)+"use.setAttributeList(getAttributeList());");
pStream.println(ind(3)+"use.setElementList(new List());");
pStream.println(ind(3)+"return use;");
pStream.println(ind(2)+"}");
// pStream.println(ind(2)+"when ((name().equals(\"isSkillOf\")");
// pStream.println(ind(2)+"|| name().equals(\"isPropertyOf\"))");
// pStream.println("&& getNumAttribute() > 0 && getAttribute(0) instanceof RdfResource)");
// pStream.println(ind(2)+"to ClassUse {");
// pStream.println(ind(3)+"ClassUse use = new ClassUse();");
// pStream.println(ind(3)+"String att = getAttribute(0).name();");
// pStream.println(ind(3)+"use.setOwlIdentifier(new OwlIdentifier(att.substring(att.indexOf('#')+1,att.indexOf('_'))));");
// pStream.println(ind(3)+"use.setAttributeList(getAttributeList());");
// pStream.println(ind(3)+"use.setElementList(new List());");
// pStream.println(ind(3)+"return use;");
// pStream.println(ind(2)+"}");
pStream.println(ind(1)+"}");
......@@ -335,9 +335,9 @@ aspect GenMisc {
// SimpleElement.value()
pStream.println(ind(1)+"syn String SimpleElement.value() = \"\";");
pStream.println(ind(1)+"eq StringElement.value() = getIDENTIFIER();");
pStream.println(ind(1)+"eq IntElement.value() = getINTEGER_LITERAL();");
pStream.println(ind(1)+"eq FloatElement.value() = getFLOAT_LITERAL();");
pStream.println(ind(1)+"eq StringElement.value() = getLITERAL();");
pStream.println(ind(1)+"eq IntElement.value() = getLITERAL();");
pStream.println(ind(1)+"eq FloatElement.value() = getLITERAL();");
// Thing.isTopElement()
pStream.println(ind(1)+"boolean Thing.isTopElement() {");
......
/*
* Copyright (C) 2006 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of OntologyCompiler.
*/
import AST.Start;
import java.io.*;
public class GenOntology extends Parser {
public static void main(String args[]) {
Start ast = parse(args);
String fileName = null;
try {
// Generate OWL ontology, possibly transformed from Owl
// Full to OWL DL
fileName = "ontology.owl";
PrintStream pStream = new PrintStream(new File(fileName));
ast.genOntology("",pStream);
} catch (java.io.FileNotFoundException e) {
System.out.println("Could not create file: "+fileName);
e.printStackTrace();
}
}
}
/* -*-Java-*- */
/*
* Copyright (C) 2006 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of OntologyCompiler.
*/
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);
}
}
public void Start.genOntology(String ind, PrintStream pStream) {
pStream.println("<?xml version=\"1.0\"?>");
super.genOntology(ind, pStream);
}
}
......@@ -14,7 +14,7 @@ options {
NODE_PREFIX = "";
JAVA_UNICODE_ESCAPE = true;
STATIC = false;
// DEBUG_PARSER = true;
DEBUG_PARSER = true;
// DEBUG_LOOKAHEAD = true;
// DEBUG_TOKEN_MANAGER = true;
} // options
......@@ -340,22 +340,55 @@ void SimpleElement() : {}
void IntElement() #IntElement : { Token t; }
{
t = <INTEGER_LITERAL>
{jjtThis.setINTEGER_LITERAL(t.image);}
{jjtThis.setLITERAL(t.image);}
}
void FloatElement() #FloatElement : { Token t; }
{
t = <FLOAT_LITERAL>
{jjtThis.setFLOAT_LITERAL(t.image);}
{jjtThis.setLITERAL(t.image);}
}
void StringElement() #StringElement : {Token t;}
void StringElement() #StringElement : { Token t;String s; }
{
t = <IDENTIFIER>
{jjtThis.setIDENTIFIER(t.image);}
// Identifier() | OtherToken()
}
{
s = t.image;
if (getToken(1).kind != START_TAG ) {
s += getData();
}
}
{jjtThis.setLITERAL(s);}
}
JAVACODE
String getData() {
StringBuffer s = new StringBuffer();
// jjtThis.someData = true;
while ((getToken(1)).kind != START_TAG && (getToken(1)).kind != START_ENDTAG) {
Token t = getNextToken();
if (t.specialToken != null) {
Token tmp_t = t.specialToken;
while (tmp_t.specialToken != null) {
tmp_t = tmp_t.specialToken;
}
while (tmp_t != null) {
s.append(tmp_t.image);
tmp_t = tmp_t.next;
}
}
s.append(t.image);
}
return s.toString();
}
// void StringElement() #StringElement : {Token t;}
// {
// t = <IDENTIFIER>
// {jjtThis.setIDENTIFIER(t.image);}
// // Identifier() | OtherToken()
// }
......
This diff is collapsed.
Supports Markdown
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