The OP has said on StackOverflow that the wrong data file was being used.
Andy
On 04/11/2021 08:30, Andy Seaborne wrote:
David,
> This produces the following result:
> -------------------------------------------------
> | f | vv1 | t1 | t |
> =================================================
> | "NY635615" | | | "2014-06-30 00:00:00" |
> | "NY635615" | | | "2014-06-10 00:00:00" |
That does not look like an xsd:dateTime for ?t.
A plain string prints like that.
If ?t isn't an xsd:dateTime, the you would get ?vv1 and ?t1 being unset.
It has to be "2014-05-27T00:00:00Z"^^xsd:dateTime - not even
"2014-05-27T00:00:00Z" - there is no automatic cast in SPARQL.
Andy
On 04/11/2021 06:59, Lorenz Buehmann wrote:
Hi,
I cannot reproduce this.
Works for me with
java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2, mixed mode,
sharing)
In-memory:
apache-jena-4.2.0/bin/sparql --data data.ttl --query query.rq
|-------------------------------------------------------------------||
||| f | vv1 | t1 | t |||
||===================================================================||
||| "CT992639" | 2014 | 2014 | "2014-05-27T00:00:00Z"^^xsd:dateTime |||
||-------------------------------------------------------------------|
TDB2
apache-jena-4.2.0/bin/tdb2.tdbloader --loc tdb2-test data.ttl
apache-jena-4.2.0/bin/tdb2.tdbquery --loc tdb2-test --query query.rq
|-------------------------------------------------------------------||
||| f | vv1 | t1 | t |||
||===================================================================||
||| "CT992639" | 2014 | 2014 | "2014-05-27T00:00:00Z"^^xsd:dateTime |||
||-------------------------------------------------------------------|
|
|
TDB1
apache-jena-4.2.0/bin/tdbloader2 --loc tdb1-test data.ttl
apache-jena-4.2.0/bin/tdbquery --loc tdb1-test --query query.rq
|-------------------------------------------------------------------||
||| f | vv1 | t1 | t |||
||===================================================================||
||| "CT992639" | 2014 | 2014 | "2014-05-27T00:00:00Z"^^xsd:dateTime |||
||-------------------------------------------------------------------|
Minor comment:
the prefix declaration in your sample data has to be either
i) @prefix XXX: <> . (dot mandatory)
ii) prefix XXX: <> (no dot allowed, this is same as in SPARQL)
On 04.11.21 00:08, David Shumway wrote:
SPARQL:
prefix sosa: <http://www.w3.org/ns/sosa/>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?f ?vv1 (year(?t) as ?t1) ?t
WHERE {
?s a sosa:Observation .
?s sosa:hasFeatureOfInterest ?f .
?s sosa:resultTime ?t .
bind(YEAR(?t) as ?vv1)
}
Where the data is e.g.:
prefix sosa: <http://www.w3.org/ns/sosa/> .
prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
prefix ex: <http://www.example.org/> .
ex:beachSample-2014-0 a sosa:Observation ;
sosa:hasFeatureOfInterest "CT992639"^^xsd:string ;
sosa:resultTime "2014-05-27T00:00:00Z"^^xsd:dateTime .
Loaded as follows:
./apache-jena-4.2.0/bin/tdbloader2 --loc=/A ./tmp.n3
And queried with (where q1.rq contains the SPARQL query above):
./apache-jena-4.2.0/bin/tdbquery --loc=/A --query=./q1.rq
This produces the following result:
-------------------------------------------------
| f | vv1 | t1 | t |
=================================================
| "NY635615" | | | "2014-06-30 00:00:00" |
| "NY635615" | | | "2014-06-10 00:00:00" |
With the expected (hopeful) behavior being an output like this (which is
not the actual query result):
-----------------------------------------------------
| f | vv1 | t1 | t |
=====================================================
| "NY635615" | 2014 | 2014 | "2014-06-30T00:00:00Z" |
| "NY635615" | 2014 | 2014 | "2014-06-10T00:00:00Z" |
Columns *vv1* and *t1* are both attempts to get the year value to
appear in
the query result, without success. And column *t* is simply showing the
data being held as sosa:resultTime, where I would assume it would be
formatted as an XSD:dateTime value but instead is appearing a little
differently?
Any help is much appreciated!