Gitlab service upgraded. Please report any problems to dl_gitadmin@cs.lth.se

Commit e691adb1 authored by Anders Nilsson's avatar Anders Nilsson

Implemented just enough to be able to find and print out the geometry reference, if exists.

parent 61c4200e
/* -*-Java-*- */
/*
* Copyright (C) 2007 Anders Nilsson <anders.nilsson@cs.lth.se>
*
* This file is part of OntologyCompiler.
*/
aspect Geometry {
syn lazy String Thing.getGeometryRef() = "NotApplicable";
eq Product.getGeometryRef(){
// // if (getNumAttribute() > 0) {
// // return getAttribute(0).name();
// // } else {
// // return "unknown_id";
// // }
for (int i=0; i<getNumElement(); i++) {
// System.out.println(" Checking "+getElement(i));
if (getElement(i).isGeometryRef()) {
System.out.println("Found Geometry ref");
// System.out.println(" Found identifier: "+((ComplexElement) getElement(i)).getAttribute(0).name());
Geometry g = (Geometry) ((ClassUse) getElement(i)).decl();
// System.out.println(" "+((ComplexElement) ident.getElement(0)).name());
// return ident.value();
return g.getValue();
}
}
return "_No_GeometryRef_";
}
syn boolean Element.isGeometryRef() = false;
eq ComplexElement.isGeometryRef() = name().equals("hasGeometry"); // Ugly hack!
eq Geometry.isGeometryRef() = true;
}
\ No newline at end of file
......@@ -5,62 +5,60 @@
* This file is part of OntologyCompiler.
*/
import AST.Start;
import AST.SiarasParser;
import AST.ParseException;
import AST.*;
import java.io.*;
import java.net.*;
public class GeometryDemo extends Parser {
public static Start getAST(String ontologyURL) {
Start ast = null;
// String outfile = null;
// int i=0;
// for (i=0; i<args.length; i++) {
// if (args[i].equals("-o")) {
// outfile = args[++i];
// if (outfile.endsWith(".owl")) {
// outfile = outfile.substring(0,outfile.indexOf('.'));
// }
// }
// }
try {
Reader r = new FileReader(new URL(ontologyURL).getFile());
SiarasParser parser = new SiarasParser(r);
public static Start getAST(String ontologyURL) {
Start ast = null;
// String outfile = null;
// int i=0;
// for (i=0; i<args.length; i++) {
// if (args[i].equals("-o")) {
// outfile = args[++i];
// if (outfile.endsWith(".owl")) {
// outfile = outfile.substring(0,outfile.indexOf('.'));
// }
// }
// }
try {
Reader r = new FileReader(new URL(ontologyURL).getFile());
SiarasParser parser = new SiarasParser(r);
ast = parser.Start();
ast = parser.Start();
ast.traverseAST();
} catch (ParseException e) {
System.out.println(e.getMessage());
}
catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
catch (FileNotFoundException e) {
System.err.println("file " + ontologyURL + " not found");
}
} catch (ParseException e) {
System.out.println(e.getMessage());
}
catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
catch (FileNotFoundException e) {
System.err.println("file " + ontologyURL + " not found");
}
return ast;
// try {
// // Generate OWL ontology, possibly transformed from Owl
// // Full to OWL DL
// if (outfile == null) {
// outfile = "ontology";
// }
// PrintStream pStream = new PrintStream(new File(outfile+".owl"));
// ast.genOntology("",pStream);
// // have to create a matching repository file, otherwise
// // Protege will complain severely.
// pStream = new PrintStream(new File(outfile+".repository"));
// pStream.println("[Dublin Core DL Redirect]");
// } catch (java.io.FileNotFoundException e) {
// System.out.println("Could not create file: "+outfile);
// e.printStackTrace();
// }
}
}
public static void main(String[] args) {
Console con = System.console();
con.readLine("\n\nParse ontology from file: %s",(Object) args[0]);
Start ast = getAST(args[0]);
ast.getIndividual("Teapot_1").dumpTree("",System.out);
con.readLine("\n\nFind the Teapot instance");
Product p = (Product) ast.getIndividual("Teapot_1");
p.dumpTree("",System.out);
// p.prettyPrint("",System.out);
con.readLine("\n\nFind the geometry reference");
String s = p.getGeometryRef();
System.out.println("Geometry model: "+s);
}
}
......@@ -15,6 +15,7 @@ aspect Qualification {
getElementList());
}
when ((name().equals("hasProperty") ||
name().equals("hasGeometry") ||
name().equals("hasIdentifier") ||
name().equals("hasSubskill") ||
name().equals("hasSkill") ||
......@@ -31,6 +32,7 @@ aspect Qualification {
setElementList(new List());
}
when ((name().equals("hasProperty") ||
name().equals("hasGeometry") ||
name().equals("hasIdentifier") ||
name().equals("hasSubskill") ||
name().equals("hasSkill") ||
......
......@@ -51,7 +51,7 @@ aspect SkillserverInterface {
public Thing Thing.getIndividual(String id) {
// System.out.println(" "+name());
// System.out.println("Looking for: "+id+" in: "+id()+" ("+name()+")");
System.out.println("Looking in: "+id()+" "+" ("+name()+")");
// System.out.println("Looking in: "+id()+" "+" ("+name()+")");
// if (id().contains(id) &&
// (this instanceof Device)) {
if (id.equals(id())) {
......
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