Commit 8598e4c4 authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Added new ontology, revised code.

parent 0bb74d2d
...@@ -43,8 +43,9 @@ OwlMaxCardinality : ComplexElement; ...@@ -43,8 +43,9 @@ OwlMaxCardinality : ComplexElement;
OwlObjectProperty : OwlProperty; OwlObjectProperty : OwlProperty;
OwlOneOf : ComplexElement; OwlOneOf : ComplexElement;
OwlOnProperty : OwlProperty; OwlOnProperty : OwlProperty;
OwlSomeValuesFrom : OwlValuesFrom;
OwlRestriction : ComplexElement; OwlRestriction : ComplexElement;
OwlSomeValuesFrom : OwlValuesFrom;
OwlTransitiveProperty : ComplexElement;
OwlUnionOf : ComplexElement; OwlUnionOf : ComplexElement;
abstract SimpleElement : Element; abstract SimpleElement : Element;
......
...@@ -87,6 +87,7 @@ SPECIAL_TOKEN : /* COMMENTS */ ...@@ -87,6 +87,7 @@ SPECIAL_TOKEN : /* COMMENTS */
| < OWL_ONTOLOGY : "owl:Ontology" > | < OWL_ONTOLOGY : "owl:Ontology" >
| < OWL_RESTRICTION : "owl:Restriction" > | < OWL_RESTRICTION : "owl:Restriction" >
| < OWL_SOMEVALUESFROM : "owl:someValuesFrom" > | < OWL_SOMEVALUESFROM : "owl:someValuesFrom" >
| < OWL_TRANSITIVEPROPERTY : "owl:TransitiveProperty" >
| < OWL_UNIONOF : "owl:unionOf" > | < OWL_UNIONOF : "owl:unionOf" >
| < RDF_RDF : "rdf:RDF" > | < RDF_RDF : "rdf:RDF" >
| < RDF_ABOUT : "rdf:about" > | < RDF_ABOUT : "rdf:about" >
...@@ -424,8 +425,9 @@ void OwlElement() : {} ...@@ -424,8 +425,9 @@ void OwlElement() : {}
| OwlObjectProperty() | OwlObjectProperty()
| OwlOneOf() | OwlOneOf()
| OwlOnProperty() | OwlOnProperty()
| OwlSomeValuesFrom()
| OwlRestriction() | OwlRestriction()
| OwlSomeValuesFrom()
| OwlTransitiveProperty()
| OwlUnionOf() | OwlUnionOf()
} }
...@@ -543,16 +545,22 @@ void OwlOnProperty () #OwlOnProperty : {} ...@@ -543,16 +545,22 @@ void OwlOnProperty () #OwlOnProperty : {}
(">" ElementList() "</" <OWL_ONPROPERTY> ">" | ElementList() "/>") (">" ElementList() "</" <OWL_ONPROPERTY> ">" | ElementList() "/>")
} }
void OwlRestriction () #OwlRestriction : {}
{
<OWL_RESTRICTION> AttributeList()
(">" ElementList() "</" <OWL_RESTRICTION> ">" | ElementList() "/>")
}
void OwlSomeValuesFrom () #OwlSomeValuesFrom : {} void OwlSomeValuesFrom () #OwlSomeValuesFrom : {}
{ {
<OWL_SOMEVALUESFROM> AttributeList() <OWL_SOMEVALUESFROM> AttributeList()
(">" ElementList() "</" <OWL_SOMEVALUESFROM> ">" | ElementList() "/>") (">" ElementList() "</" <OWL_SOMEVALUESFROM> ">" | ElementList() "/>")
} }
void OwlRestriction () #OwlRestriction : {} void OwlTransitiveProperty () #OwlTransitiveProperty : {}
{ {
<OWL_RESTRICTION> AttributeList() <OWL_TRANSITIVEPROPERTY> AttributeList()
(">" ElementList() "</" <OWL_RESTRICTION> ">" | ElementList() "/>") (">" ElementList() "</" <OWL_TRANSITIVEPROPERTY> ">" | ElementList() "/>")
} }
void OwlUnionOf () #OwlUnionOf : {} void OwlUnionOf () #OwlUnionOf : {}
......
...@@ -7,31 +7,31 @@ ...@@ -7,31 +7,31 @@
*/ */
aspect Geometry { aspect Geometry {
syn lazy String Thing.getGeometryRef() = "NotApplicable"; // syn lazy String Thing.getGeometryRef() = "NotApplicable";
eq Product.getGeometryRef(){ // eq Product.getGeometryRef(){
// // if (getNumAttribute() > 0) { // // // if (getNumAttribute() > 0) {
// // return getAttribute(0).name(); // // // return getAttribute(0).name();
// // } else { // // // } else {
// // return "unknown_id"; // // // return "unknown_id";
// // } // // // }
for (int i=0; i<getNumElement(); i++) { // for (int i=0; i<getNumElement(); i++) {
// System.out.println(" Checking "+getElement(i)); // // System.out.println(" Checking "+getElement(i));
if (getElement(i).isGeometryRef()) { // if (getElement(i).isGeometryRef()) {
System.out.println("Found Geometry ref"); // System.out.println("Found Geometry ref");
// System.out.println(" Found identifier: "+((ComplexElement) getElement(i)).getAttribute(0).name()); // // System.out.println(" Found identifier: "+((ComplexElement) getElement(i)).getAttribute(0).name());
Geometry g = (Geometry) ((ClassUse) getElement(i)).decl(); // Geometry g = (Geometry) ((ClassUse) getElement(i)).decl();
// System.out.println(" "+((ComplexElement) ident.getElement(0)).name()); // // System.out.println(" "+((ComplexElement) ident.getElement(0)).name());
// return ident.value(); // // return ident.value();
return g.getValue(); // return g.getValue();
} // }
} // }
return "_No_GeometryRef_"; // return "_No_GeometryRef_";
} // }
syn boolean Element.isGeometryRef() = false; // syn boolean Element.isGeometryRef() = false;
eq ComplexElement.isGeometryRef() = name().equals("hasGeometry"); // Ugly hack! // eq ComplexElement.isGeometryRef() = name().equals("hasGeometry"); // Ugly hack!
eq Geometry.isGeometryRef() = true; // eq Geometry.isGeometryRef() = true;
} }
\ No newline at end of file
...@@ -52,13 +52,13 @@ public class GeometryDemo extends Parser { ...@@ -52,13 +52,13 @@ public class GeometryDemo extends Parser {
con.readLine("\n\nFind the Teapot instance"); con.readLine("\n\nFind the Teapot instance");
Product p = (Product) ast.getIndividual("Teapot_1"); // Product p = (Product) ast.getIndividual("Teapot_1");
p.dumpTree("",System.out); // p.dumpTree("",System.out);
// p.prettyPrint("",System.out); // // p.prettyPrint("",System.out);
con.readLine("\n\nFind the geometry reference"); // con.readLine("\n\nFind the geometry reference");
String s = p.getGeometryRef(); // String s = p.getGeometryRef();
System.out.println("Geometry model: "+s); // System.out.println("Geometry model: "+s);
} }
} }
...@@ -354,12 +354,12 @@ void StringElement() #StringElement : { Token t;String s; } ...@@ -354,12 +354,12 @@ void StringElement() #StringElement : { Token t;String s; }
{ {
t = <IDENTIFIER> t = <IDENTIFIER>
{ {
s = t.image; s = t.image+" ";
if (getToken(1).kind != START_TAG ) { if (getToken(1).kind != START_TAG ) {
s += getData(); s += getData();
} }
} }
{jjtThis.setLITERAL(s);} {jjtThis.setLITERAL(s.trim());}
} }
JAVACODE JAVACODE
......
...@@ -51,7 +51,7 @@ aspect SkillserverInterface { ...@@ -51,7 +51,7 @@ aspect SkillserverInterface {
public Thing Thing.getIndividual(String id) { public Thing Thing.getIndividual(String id) {
// System.out.println(" "+name()); // System.out.println(" "+name());
// System.out.println("Looking for: "+id+" in: "+id()+" ("+name()+")"); // System.out.println("Looking for: "+id+" in: "+id()+" ("+name()+")");
// System.out.println("Looking in: "+id()+" "+" ("+name()+")"); // System.out.println("Looking in: "+id());
// if (id().contains(id) && // if (id().contains(id) &&
// (this instanceof Device)) { // (this instanceof Device)) {
if (id.equals(id())) { if (id.equals(id())) {
...@@ -96,7 +96,6 @@ aspect SkillserverInterface { ...@@ -96,7 +96,6 @@ aspect SkillserverInterface {
* getPropertyValues(String name) * getPropertyValues(String name)
********************************/ ********************************/
public Collection Thing.getPropertyValues(String name) { public Collection Thing.getPropertyValues(String name) {
// System.out.println("Looking for property: "+name+" in "+id());
LinkedList l = new LinkedList(); LinkedList l = new LinkedList();
for (int i=0; i<getNumElement(); i++) { for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof ClassUse) { if (getElement(i) instanceof ClassUse) {
...@@ -114,6 +113,17 @@ aspect SkillserverInterface { ...@@ -114,6 +113,17 @@ aspect SkillserverInterface {
return l; return l;
} }
public Collection Device.getPropertyValues(String name) {
LinkedList l = new LinkedList();
for (int i=0; i<getNumProperty(); i++) {
ClassUse c = (ClassUse) getProperty(i);
if (c.name().equals(name)) {
l.add(c.decl());
}
}
return l;
}
/******************************** /********************************
* Thing Thing.getDirectType() * Thing Thing.getDirectType()
********************************/ ********************************/
...@@ -227,32 +237,32 @@ aspect Misc { ...@@ -227,32 +237,32 @@ aspect Misc {
// } else { // } else {
// return "unknown_id"; // return "unknown_id";
// } // }
for (int i=0; i<getNumElement(); i++) { // for (int i=0; i<getNumElement(); i++) {
// System.out.println(" Checking "+getElement(i)); // System.out.println(" Checking "+getElement(i));
if (getElement(i).isIdentifier()) { // if (getElement(i).isIdentifier()) {
// System.out.println(" Found identifier: "+((ComplexElement) getElement(i)).getAttribute(0).name()); // System.out.println(" Found identifier: "+((ComplexElement) getElement(i)).getAttribute(0).name());
Identifier ident = (Identifier) ((ClassUse) getElement(i)).decl(); // Identifier ident = (Identifier) ((ClassUse) getElement(i)).decl();
// System.out.println(" "+((ComplexElement) ident.getElement(0)).name()); // System.out.println(" "+((ComplexElement) ident.getElement(0)).name());
// return ident.value(); // return ident.value();
return ident.getValue(); // return ident.getValue();
} // }
} // }
return "unknown_id"; return "unknown_id";
} }
syn boolean Element.isIdentifier() = false; syn boolean Element.isIdentifier() = false;
eq ComplexElement.isIdentifier() = name().equals("hasIdentifier"); // Ugly hack! eq ComplexElement.isIdentifier() = name().equals("hasIdentifier"); // Ugly hack!
eq Identifier.isIdentifier() = true; // eq Identifier.isIdentifier() = true;
// eq ClassUse.isIdentifier() = decl().isIdentifier(); // eq ClassUse.isIdentifier() = decl().isIdentifier();
syn lazy String Identifier.value() { // syn lazy String Identifier.value() {
for (int i=0; i<getNumElement(); i++) { // for (int i=0; i<getNumElement(); i++) {
if (getElement(i) instanceof StringElement) { // if (getElement(i) instanceof StringElement) {
return ((StringElement) getElement(i)).getLITERAL(); // return ((StringElement) getElement(i)).getLITERAL();
} // }
} // }
return "#valueNotFound"; // return "#valueNotFound";
} // }
} }
......
...@@ -21,6 +21,10 @@ public class Statistics extends Parser { ...@@ -21,6 +21,10 @@ public class Statistics extends Parser {
ast.getSensors(System.out); ast.getSensors(System.out);
System.out.println(); System.out.println();
// System.out.println("Test");
// System.out.println(ast.getIndividual("Asentics_CR723-A073").id());
// System.out.println();
} }
} }
...@@ -55,7 +55,8 @@ aspect Statistics { ...@@ -55,7 +55,8 @@ aspect Statistics {
} }
public void Sensor.getSensors(PrintStream pStream) { public void Sensor.getSensors(PrintStream pStream) {
pStream.println(" "+getOwlIdentifier().getIDENTIFIER()+ pStream.println(" "+getOwlIdentifier().getIDENTIFIER()+
" : "+getAttribute(0).getValue().getSTRING_LITERAL()); " : "+getAttribute(0).getValue().getSTRING_LITERAL()+
" ("+id()+")");
super.getSensors(pStream); super.getSensors(pStream);
} }
......
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