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

Added new ontology, revised code.

parent 0bb74d2d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -43,8 +43,9 @@ OwlMaxCardinality : ComplexElement;
OwlObjectProperty : OwlProperty;
OwlOneOf : ComplexElement;
OwlOnProperty : OwlProperty;
OwlSomeValuesFrom : OwlValuesFrom;
OwlRestriction : ComplexElement;
OwlSomeValuesFrom : OwlValuesFrom;
OwlTransitiveProperty : ComplexElement;
OwlUnionOf : ComplexElement;

abstract SimpleElement : Element;
+12 −4
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ SPECIAL_TOKEN : /* COMMENTS */
  | < OWL_ONTOLOGY          : "owl:Ontology" >
  | < OWL_RESTRICTION       : "owl:Restriction" >
  | < OWL_SOMEVALUESFROM    : "owl:someValuesFrom" >
  | < OWL_TRANSITIVEPROPERTY : "owl:TransitiveProperty" >
  | < OWL_UNIONOF           : "owl:unionOf" >
  | < RDF_RDF            : "rdf:RDF"      >
  | < RDF_ABOUT          : "rdf:about" >
@@ -424,8 +425,9 @@ void OwlElement() : {}
	| OwlObjectProperty()
	| OwlOneOf()
	| OwlOnProperty()
	| OwlSomeValuesFrom()
	| OwlRestriction()
	| OwlSomeValuesFrom()
	| OwlTransitiveProperty()
	| OwlUnionOf()
}

@@ -543,16 +545,22 @@ void OwlOnProperty () #OwlOnProperty : {}
	(">" ElementList() "</" <OWL_ONPROPERTY> ">" | ElementList() "/>")
}

void OwlRestriction () #OwlRestriction  : {}
{
    <OWL_RESTRICTION> AttributeList() 
	(">" ElementList() "</" <OWL_RESTRICTION> ">" | ElementList() "/>")
}

void OwlSomeValuesFrom () #OwlSomeValuesFrom  : {}
{
    <OWL_SOMEVALUESFROM> AttributeList() 
	(">" ElementList() "</" <OWL_SOMEVALUESFROM> ">" | ElementList() "/>")
}

void OwlRestriction () #OwlRestriction  : {}
void OwlTransitiveProperty () #OwlTransitiveProperty  : {}
{
    <OWL_RESTRICTION> AttributeList() 
	(">" ElementList() "</" <OWL_RESTRICTION> ">" | ElementList() "/>")
    <OWL_TRANSITIVEPROPERTY> AttributeList() 
	(">" ElementList() "</" <OWL_TRANSITIVEPROPERTY> ">" | ElementList() "/>")
}

void OwlUnionOf () #OwlUnionOf  : {}
+23 −23
Original line number Diff line number Diff line
@@ -7,31 +7,31 @@
 */

aspect Geometry {
    syn lazy String Thing.getGeometryRef() = "NotApplicable";
//     syn lazy String Thing.getGeometryRef() = "NotApplicable";

    eq Product.getGeometryRef(){
//     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_";
    }
// // //         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;
//     syn boolean Element.isGeometryRef() = false;
//     eq ComplexElement.isGeometryRef() = name().equals("hasGeometry"); // Ugly hack!
//     eq Geometry.isGeometryRef() = true;
    
}
 No newline at end of file
+6 −6
Original line number Diff line number Diff line
@@ -52,13 +52,13 @@ public class GeometryDemo extends Parser {
	
	con.readLine("\n\nFind the Teapot instance");

        Product p = (Product) ast.getIndividual("Teapot_1");
 	p.dumpTree("",System.out);
// 	p.prettyPrint("",System.out);
//         Product p = (Product) ast.getIndividual("Teapot_1");
//  	p.dumpTree("",System.out);
// // 	p.prettyPrint("",System.out);

	con.readLine("\n\nFind the geometry reference");
// 	con.readLine("\n\nFind the geometry reference");

	String s = p.getGeometryRef();
	System.out.println("Geometry model: "+s);
// 	String s = p.getGeometryRef();
// 	System.out.println("Geometry model: "+s);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -354,12 +354,12 @@ void StringElement() #StringElement : { Token t;String s; }
{
	t = <IDENTIFIER>
	{
		s = t.image;
		s = t.image+" ";
		if (getToken(1).kind != START_TAG ) {
		s += getData();
	}
	}
        {jjtThis.setLITERAL(s);}
	{jjtThis.setLITERAL(s.trim());}
}

JAVACODE
Loading