[x3d-public] X3D Ontology: initial SPARQL query for MetadataSet structures

Don Brutzman brutzman at nps.edu
Thu Apr 1 21:20:04 PDT 2021


Hi Jakub.  Following the path as discussed in last few calls about X3D Ontology, have crafted an initial query for MetadataSet structures.

* https://www.web3d.org/x3d/content/semantics/examples/MetadataNodeExamples.x3d

* https://www.web3d.org/x3d/content/semantics/examples/MetadataNodeExamples.ttl

* https://www.web3d.org/x3d/content/semantics/queries/DocumentMetadataValues.rq.txt

This is quite simple, it is not looking at hierarchical structure at all.  So far so good.

Still having difficulty with numeric arrays.  As you are likely aware, the RDF data model doesn't do well with arrays.  Thus SPARQL query for array structures like

<MetadataFloat containerField='value' name='coefficients' value='3.141592653 2.7128 1 0'/>

:MetadataFloat_2_2_1_1_4 a owl:NamedIndividual, x3do:MetadataFloat ;
   x3do:hasParent :NestedMetadataSetNode ;
   x3do:name 'coefficients' ;
   x3do:value ( 3.141592653 2.7128 1 0 ) .

have to recurse across array elements one at a time before turning them into strings, otherwise no value is returned (even when converted to string).

The pattern "x3do:value/rdf:rest*/rdf:first" and corresponding results follow.  Visible at least, but clumsy and a bit misleading.

================================================================================

# DocumentMetadataValues.rq    Query to list all values found in Metadata nodes.

SELECT ?ID ?nodeType ?name ((?value1) AS ?value) ?reference

WHERE
{
     ?metadataNode a ?nodeType1 .

     ?nodeType1    rdfs:subClassOf x3do:X3DMetadataObject .

     OPTIONAL { ?metadataNode x3do:name                       ?name1      . }
     OPTIONAL { ?metadataNode x3do:value/rdf:rest*/rdf:first  ?value1     . }
     OPTIONAL { ?metadataNode x3do:reference                  ?reference1 . }

     BIND (strafter(xsd:string(?metadataNode),"#") AS ?ID) # DEF if available, otherwise assigned identifier
     BIND (strafter(xsd:string(?nodeType1),"#")    AS ?nodeType)
     BIND (str(?name1)       AS    ?name)
#   BIND (?value1           AS    ?value)     # evaluates value1, converts to string
     BIND (str(?reference1)  AS    ?reference)
}
ORDER by ASC(?ID) # alphabetize, approximately

# TODO non-string values

###############################################
----------------------------------------------------------------------------------------------------------------------------------------------------
| ID                            | nodeType          | name                         | value       | reference                                       |
====================================================================================================================================================
| "MetadataFloat_2_2_1_1_4"     | "MetadataFloat"   | "coefficients"               | 2.7128      |                                                 |
| "MetadataFloat_2_2_1_1_4"     | "MetadataFloat"   | "coefficients"               | 3.141592653 |                                                 |
| "MetadataFloat_2_2_1_1_4"     | "MetadataFloat"   | "coefficients"               | 0           |                                                 |
| "MetadataFloat_2_2_1_1_4"     | "MetadataFloat"   | "coefficients"               | 1           |                                                 |
| "MetadataString_2_1"          | "MetadataString"  | "TestRootMetadataNode"       |             |                                                 |
| "MyMetadataBooleanNode"       | "MetadataBoolean" | "Coin Flip"                  | false       | "MetadataBoolean allowed in X3D v3.3 and later" |
| "MyMetadataBooleanNode"       | "MetadataBoolean" | "Coin Flip"                  | true        | "MetadataBoolean allowed in X3D v3.3 and later" |
| "MyMetadataBooleanNode"       | "MetadataBoolean" | "Coin Flip"                  | true        | "MetadataBoolean allowed in X3D v3.3 and later" |
| "MyMetadataBooleanNode"       | "MetadataBoolean" | "Coin Flip"                  | false       | "MetadataBoolean allowed in X3D v3.3 and later" |
| "MyMetadataDoubleNode"        | "MetadataDouble"  | "Metadata_name"              | 3.141592658 | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataDoubleNode"        | "MetadataDouble"  | "Metadata_name"              | 2.71812181  | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataFloatNode"         | "MetadataFloat"   | "Metadata_name"              | 6.023e+23   | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataFloatNode"         | "MetadataFloat"   | "Metadata_name"              | 9.8         | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataFloatNode-USE-1"   | "MetadataFloat"   |                              |             |                                                 |
| "MyMetadataIntegerNode"       | "MetadataInteger" | "Metadata_name"              | 6           | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataIntegerNode"       | "MetadataInteger" | "Metadata_name"              | 28          | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataIntegerNode"       | "MetadataInteger" | "Metadata_name"              | 496         | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataIntegerNode-USE-1" | "MetadataInteger" |                              |             |                                                 |
| "MyMetadataSetNode"           | "MetadataSet"     | "Metadata_name"              |             | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataStringNode"        | "MetadataString"  | "Metadata_name"              |             | "SomeReferenceStandard 1.2.3c"                  |
| "MyMetadataStringNode-USE-1"  | "MetadataString"  |                              |             |                                                 |
| "NestedMetadataSetNode"       | "MetadataSet"     | "TestNestedMetadataSetNodes" |             |                                                 |
----------------------------------------------------------------------------------------------------------------------------------------------------

I'll be studying our references further, especially Bob DuCharme's blog on RDF lists and SPARQL.  Perhaps the recursive split of the floats can be turned into a concatenation of multiple string values, will see.

* https://www.web3d.org/x3d/content/semantics/semantics.html#References

* Bob DuCharme's weblog, 21 April 2014, RDF lists and SPARQL
   http://www.snee.com/bobdc.blog/2014/04/rdf-lists-and-sparql.html

and maybe

* Andy Seaborne 2011 blog entry, Updating RDF Lists with SPARQL
   http://seaborne.blogspot.com/2011/03/updating-rdf-lists-with-sparql.html

Current impression: we may be able to be able to display list (array) values but operations appear to be difficult.

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list