Note: this discussion was abandoned, in stead polygon vertices are now represented as a single formatted string.
It was proposed that in our definition of the oslc_am:Diagram resource the list of polygon points use the rdf:Seq mechanism instead of the currently proposed oslc linked list like structure.
Lets take a very simple oslc_am:Diagram
example, one with only a single polygon area in it.
The current proposal (in Turtle) looks like:
@prefix oslc_am: <http://open-services.net/ns/am#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<https://rory:9444/dm/models/84>
a oslc_am:Diagram ;
oslc_am:area [
a oslc_am:DiagramPolygon ;
oslc_am:points _:point1
] .
_:point1
a oslc_am:DiagramPoint ;
oslc_am:x 200 ;
oslc_am:y 250 ;
oslc_am:next _:point2 .
_:point2
a oslc_am:DiagramPoint ;
oslc_am:x 300 ;
oslc_am:y 345 ;
oslc_am:next _:point3 .
_:point3
a oslc_am:DiagramPoint ;
oslc_am:x 200 ;
oslc_am:y 250 .
If we use the rdf:Seq
to order the diagram points this same resource would look like this:
@prefix oslc_am: <http://open-services.net/ns/am#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<https://rory:9444/dm/models/84>
a oslc_am:Diagram ;
oslc_am:area
[ a oslc_am:DiagramPolygon ;
oslc_am:points
[ a rdf:Seq ;
rdf:_1 [ a oslc_am:DiagramPoint ;
oslc_am:x 200;
oslc_am:y 250
] ;
rdf:_2 [ a oslc_am:DiagramPoint ;
oslc_am:x 300;
oslc_am:y 345
] ;
rdf:_3 [ a oslc_am:DiagramPoint ;
oslc_am:x 200;
oslc_am:y 250
]
]
] .
The other aspect to examine is how either structure would affect the processing of the resources with an API like that of Jena.
An example of the Jena API creating and working with the rdf:Seq
version of the resource can be found:
private void testRdfSeq() {
createModel(); // local method that creates a Jean model with namespace prefixes,
// and define some useful properties and resources
Resource oslcDiagram = model.createResource("https://rory:9444/dm/models/84"); // create a resource URI
model.add(oslcDiagram, propRdfType, resDiagram); // define our resource and make it a oslc_am:Diagram
Resource area = model.createResource(); // create new anonymous node
area.addProperty(propRdfType, resPolygon); // and type it a polygon
Seq seq = model.createSeq(); // define a new rdf:Seq
seq.add(createDiagramPoint(200, 250)); // add points
seq.add(createDiagramPoint(300, 345));
seq.add(createDiagramPoint(200, 250));
area.addProperty(propPoints, seq); // now add the sequence as a property of the area
oslcDiagram.addProperty(propDiagramArea, area); // add the area as a property of our diagram resource
model.write(System.out, "TURTLE");
// now iterate through the points given a populated model
Statement foundArea = oslcDiagram.getProperty(propDiagramArea);
Statement foundPoints = foundArea.getProperty(propPoints);
if( foundPoints.getSeq().isSeq() ) {
// this property is a sequence so we can iterate through it
Seq foundSeq = foundPoints.getSeq();
int size = foundSeq.size();
for( int i=1; i<=size; i++ ) { // note that seq is a 1 based array
Resource res = foundSeq.getResource(i);
// lets assume it is a oslc_am:DiagramPoint for clarity
int x = res.getProperty(propOslcX).getInt();
int y = res.getProperty(propOslcY).getInt();
System.out.println( "(" + x + "," + y + ")");
}
}
}
private Resource createDiagramPoint(int x, int y){
Resource point = model.createResource();
point.addProperty(propRdfType, resOslcPoint);
point.addLiteral(propOslcX, x);
point.addLiteral(propOslcY, y);
return point;
}
Here is the code snippet doing the same thing when the Diagram resource uses the built in linked list approach.
private void testOslcList() {
createModel(); // local method that creates a Jean model with namespace
// prefixes, and define some useful propertes and resources
Resource oslcDiagram = model.createResource("https://rory:9444/dm/models/84"); // create a resource URI
model.add(oslcDiagram, propRdfType, resDiagram); // define our resource and make it a oslc_am:Diagram
Resource area = model.createResource(); // create new anonymous node
area.addProperty(propRdfType, resPolygon); // and type it a polygon
// create linked oslc_am:Diagram points, must create in reverse order to facilitate linked list
Resource point3 = createDiagramPoint(200, 250, null, 3);
Resource point2 = createDiagramPoint(300, 345, point3, 2);
Resource point1 = createDiagramPoint(200, 250, point2, 1);
area.addProperty(propPoints, point1);
oslcDiagram.addProperty(propDiagramArea, area);
model.write(System.out, "TURTLE");
// now iterate through the points given a populated model
Statement foundArea = oslcDiagram.getProperty(propDiagramArea);
Statement foundPoints = foundArea.getProperty(propPoints);
Resource point = (Resource) foundPoints.getObject(); // assume oslc_am:DiagramPoint for clarity
while( point != null ) {
int x = point.getProperty(propOslcX).getInt();
int y = point.getProperty(propOslcY).getInt();
System.out.println( "(" + x + "," + y + ")");
point = point.getPropertyResourceValue(propOslcNext);
}
}
private Resource createDiagramPoint(int x, int y, RDFNode next, int index){
Resource point = model.createResource(AnonId.create("_:point" + index));
point.addProperty(propRdfType, resOslcPoint);
point.addLiteral(propOslcX, x);
point.addLiteral(propOslcY, y);
if( next != null ) point.addProperty(propOslcNext, next);
return point;
}