Re: How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Steve Vestal
A toString() buried down in the code was it.  Simple to add the 
datatypeURI.  Thanks!


On 10/26/2023 7:48 AM, Andy Seaborne wrote:



On 26/10/2023 10:17, Steve Vestal wrote:
What is the best way to reconstruct a typed Literal from a SPARQL 
SELECT result?


I have a SPARQL SELECT query issued against an OntModel in this way:

  QueryExecution structureRowsExec = 
QueryExecutionFactory.create(structureRowsQuery, owlOntModel);


Here are some example triples in the query:

   ?a2 
 
?dataVar1.
   ?a2 
 
?dataVar2.




Query results come back as the right RDF term kind.


The OntModel being queried was created using typed literals, e.g.,


 DataPropertyAssertion( struct:floatProperty struct:indivA2 
"123.456"^^xsd:float )
 DataPropertyAssertion( struct:dateTimeProperty struct:indivA2 
"2023-10-06T12:05:10Z"^^xsd:dateTime )


When I look at the ?dataVar1 and ?dataVar2 results in a row, I get 
things like:


  1
  stringB
  123.456
  2023-10-06T12:05:10Z


Are those are just the toString() presentation?
Or is your query returning strings?



What is a good way to reconstruct a typed Literal from the query 
results? 


RDFNode is the class for all RDF term types.

QuerySolution.get

and if you know they are literals:

QuerySolution.getLiteral

Is there a SPARQL option to show full typed literal strings? 
Something that can be added to the query?  A utility method that can 
identify the XSD schema simple data type when given a result value 
string?





Re: How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Andy Seaborne




On 26/10/2023 10:17, Steve Vestal wrote:
What is the best way to reconstruct a typed Literal from a SPARQL SELECT 
result?


I have a SPARQL SELECT query issued against an OntModel in this way:

  QueryExecution structureRowsExec = 
QueryExecutionFactory.create(structureRowsQuery, owlOntModel);


Here are some example triples in the query:

   ?a2 
 ?dataVar1.
   ?a2 
 ?dataVar2.




Query results come back as the right RDF term kind.


The OntModel being queried was created using typed literals, e.g.,


     DataPropertyAssertion( struct:floatProperty struct:indivA2 
"123.456"^^xsd:float )
     DataPropertyAssertion( struct:dateTimeProperty struct:indivA2 
"2023-10-06T12:05:10Z"^^xsd:dateTime )


When I look at the ?dataVar1 and ?dataVar2 results in a row, I get 
things like:


  1
  stringB
  123.456
  2023-10-06T12:05:10Z


Are those are just the toString() presentation?
Or is your query returning strings?



What is a good way to reconstruct a typed Literal from the query 
results? 


RDFNode is the class for all RDF term types.

QuerySolution.get

and if you know they are literals:

QuerySolution.getLiteral

Is there a SPARQL option to show full typed literal strings? 
Something that can be added to the query?  A utility method that can 
identify the XSD schema simple data type when given a result value string?





Re: How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Martynas Jusevičius
OK the documentation is not exhaustive... The 1-argument
createTypedLiteral() attempts to infer the RDF datatype from Java
type, where 'objectDataValue' is a String I'm guessing? Which becomes
xsd:string.
If you want to override this with an explicit datatype URI, you need
the 2-argument version:
https://jena.apache.org/documentation/javadoc/jena/org.apache.jena.core/org/apache/jena/rdf/model/Model.html#createTypedLiteral(java.lang.String,org.apache.jena.datatypes.RDFDatatype)

On Thu, Oct 26, 2023 at 12:55 PM Steve Vestal  wrote:
>
> Literal dataLiteral = resultGraph.createTypedLiteral(objectDataValue);
> System.err.println("objectLiteral: " + objectDataValue + " " +
> dataLiteral.getDatatypeURI());
>
> always says type is http://www.w3.org/2001/XMLSchema#string
>
>
> On 10/26/2023 5:26 AM, Martynas Jusevičius wrote:
> > You need Model::createTypedLiteral
> > https://jena.apache.org/documentation/notes/typed-literals.html#basic-api-operations
> >
> > On Thu, 26 Oct 2023 at 12.24, Steve Vestal  wrote:
> >
> >> If I reconstruct using
> >>
> >>Literal dataLiteral = resultGraph.createLiteral(objectDataValue);
> >>
> >> it always says the type is string
> >>
> >>   1^^xsd:string
> >>   stringB^^ xsd:string
> >>   123.456^^xsd:string
> >>   2023-10-06T12:05:10Z^^xsd:string
> >>
> >> On 10/26/2023 4:17 AM, Steve Vestal wrote:
> >>> What is the best way to reconstruct a typed Literal from a SPARQL
> >>> SELECT result?
> >>>
> >>> I have a SPARQL SELECT query issued against an OntModel in this way:
> >>>
> >>>   QueryExecution structureRowsExec =
> >>> QueryExecutionFactory.create(structureRowsQuery, owlOntModel);
> >>>
> >>> Here are some example triples in the query:
> >>>
> >>>?a2
> >>> <
> >> http://www.galois.com/indigo/test/structure_datatypes_test#floatProperty>
> >>> ?dataVar1.
> >>>?a2
> >>> <
> >> http://www.galois.com/indigo/test/structure_datatypes_test#dateTimeProperty>
> >>
> >>> ?dataVar2.
> >>>
> >>> The OntModel being queried was created using typed literals, e.g.,
> >>>
> >>>
> >>>  DataPropertyAssertion( struct:floatProperty struct:indivA2
> >>> "123.456"^^xsd:float )
> >>>  DataPropertyAssertion( struct:dateTimeProperty struct:indivA2
> >>> "2023-10-06T12:05:10Z"^^xsd:dateTime )
> >>>
> >>> When I look at the ?dataVar1 and ?dataVar2 results in a row, I get
> >>> things like:
> >>>
> >>>   1
> >>>   stringB
> >>>   123.456
> >>>   2023-10-06T12:05:10Z
> >>>
> >>> What is a good way to reconstruct a typed Literal from the query
> >>> results? Is there a SPARQL option to show full typed literal strings?
> >>> Something that can be added to the query?  A utility method that can
> >>> identify the XSD schema simple data type when given a result value
> >>> string?
> >>>
> >>>


Re: How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Steve Vestal

Literal dataLiteral = resultGraph.createTypedLiteral(objectDataValue);
System.err.println("objectLiteral: " + objectDataValue + " " + 
dataLiteral.getDatatypeURI());


always says type is http://www.w3.org/2001/XMLSchema#string


On 10/26/2023 5:26 AM, Martynas Jusevičius wrote:

You need Model::createTypedLiteral
https://jena.apache.org/documentation/notes/typed-literals.html#basic-api-operations

On Thu, 26 Oct 2023 at 12.24, Steve Vestal  wrote:


If I reconstruct using

   Literal dataLiteral = resultGraph.createLiteral(objectDataValue);

it always says the type is string

  1^^xsd:string
  stringB^^ xsd:string
  123.456^^xsd:string
  2023-10-06T12:05:10Z^^xsd:string

On 10/26/2023 4:17 AM, Steve Vestal wrote:

What is the best way to reconstruct a typed Literal from a SPARQL
SELECT result?

I have a SPARQL SELECT query issued against an OntModel in this way:

  QueryExecution structureRowsExec =
QueryExecutionFactory.create(structureRowsQuery, owlOntModel);

Here are some example triples in the query:

   ?a2
<

http://www.galois.com/indigo/test/structure_datatypes_test#floatProperty>

?dataVar1.
   ?a2
<

http://www.galois.com/indigo/test/structure_datatypes_test#dateTimeProperty>


?dataVar2.

The OntModel being queried was created using typed literals, e.g.,


 DataPropertyAssertion( struct:floatProperty struct:indivA2
"123.456"^^xsd:float )
 DataPropertyAssertion( struct:dateTimeProperty struct:indivA2
"2023-10-06T12:05:10Z"^^xsd:dateTime )

When I look at the ?dataVar1 and ?dataVar2 results in a row, I get
things like:

  1
  stringB
  123.456
  2023-10-06T12:05:10Z

What is a good way to reconstruct a typed Literal from the query
results? Is there a SPARQL option to show full typed literal strings?
Something that can be added to the query?  A utility method that can
identify the XSD schema simple data type when given a result value
string?




Re: How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Martynas Jusevičius
You need Model::createTypedLiteral
https://jena.apache.org/documentation/notes/typed-literals.html#basic-api-operations

On Thu, 26 Oct 2023 at 12.24, Steve Vestal  wrote:

> If I reconstruct using
>
>   Literal dataLiteral = resultGraph.createLiteral(objectDataValue);
>
> it always says the type is string
>
>  1^^xsd:string
>  stringB^^ xsd:string
>  123.456^^xsd:string
>  2023-10-06T12:05:10Z^^xsd:string
>
> On 10/26/2023 4:17 AM, Steve Vestal wrote:
> > What is the best way to reconstruct a typed Literal from a SPARQL
> > SELECT result?
> >
> > I have a SPARQL SELECT query issued against an OntModel in this way:
> >
> >  QueryExecution structureRowsExec =
> > QueryExecutionFactory.create(structureRowsQuery, owlOntModel);
> >
> > Here are some example triples in the query:
> >
> >   ?a2
> > <
> http://www.galois.com/indigo/test/structure_datatypes_test#floatProperty>
> > ?dataVar1.
> >   ?a2
> > <
> http://www.galois.com/indigo/test/structure_datatypes_test#dateTimeProperty>
>
> > ?dataVar2.
> >
> > The OntModel being queried was created using typed literals, e.g.,
> >
> >
> > DataPropertyAssertion( struct:floatProperty struct:indivA2
> > "123.456"^^xsd:float )
> > DataPropertyAssertion( struct:dateTimeProperty struct:indivA2
> > "2023-10-06T12:05:10Z"^^xsd:dateTime )
> >
> > When I look at the ?dataVar1 and ?dataVar2 results in a row, I get
> > things like:
> >
> >  1
> >  stringB
> >  123.456
> >  2023-10-06T12:05:10Z
> >
> > What is a good way to reconstruct a typed Literal from the query
> > results? Is there a SPARQL option to show full typed literal strings?
> > Something that can be added to the query?  A utility method that can
> > identify the XSD schema simple data type when given a result value
> > string?
> >
> >
>


Re: How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Steve Vestal

If I reconstruct using

     Literal dataLiteral = resultGraph.createLiteral(objectDataValue);

it always says the type is string

    1^^xsd:string
    stringB^^ xsd:string
    123.456^^xsd:string
    2023-10-06T12:05:10Z^^xsd:string

On 10/26/2023 4:17 AM, Steve Vestal wrote:
What is the best way to reconstruct a typed Literal from a SPARQL 
SELECT result?


I have a SPARQL SELECT query issued against an OntModel in this way:

 QueryExecution structureRowsExec = 
QueryExecutionFactory.create(structureRowsQuery, owlOntModel);


Here are some example triples in the query:

  ?a2 
 
?dataVar1.
  ?a2 
 
?dataVar2.


The OntModel being queried was created using typed literals, e.g.,


    DataPropertyAssertion( struct:floatProperty struct:indivA2 
"123.456"^^xsd:float )
    DataPropertyAssertion( struct:dateTimeProperty struct:indivA2 
"2023-10-06T12:05:10Z"^^xsd:dateTime )


When I look at the ?dataVar1 and ?dataVar2 results in a row, I get 
things like:


 1
 stringB
 123.456
 2023-10-06T12:05:10Z

What is a good way to reconstruct a typed Literal from the query 
results? Is there a SPARQL option to show full typed literal strings?  
Something that can be added to the query?  A utility method that can 
identify the XSD schema simple data type when given a result value 
string?





Re: How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Martynas Jusevičius
I think DATATYPE() is what you are looking for:
https://kgdev.net/specifications/sparql11-query/expressions/SparqlOps/func-rdfTerms/#func-datatype


On Thu, 26 Oct 2023 at 11.17, Steve Vestal  wrote:

> What is the best way to reconstruct a typed Literal from a SPARQL SELECT
> result?
>
> I have a SPARQL SELECT query issued against an OntModel in this way:
>
>   QueryExecution structureRowsExec =
> QueryExecutionFactory.create(structureRowsQuery, owlOntModel);
>
> Here are some example triples in the query:
>
>?a2
> 
>
> ?dataVar1.
>?a2
> <
> http://www.galois.com/indigo/test/structure_datatypes_test#dateTimeProperty>
>
> ?dataVar2.
>
> The OntModel being queried was created using typed literals, e.g.,
>
>
>  DataPropertyAssertion( struct:floatProperty struct:indivA2
> "123.456"^^xsd:float )
>  DataPropertyAssertion( struct:dateTimeProperty struct:indivA2
> "2023-10-06T12:05:10Z"^^xsd:dateTime )
>
> When I look at the ?dataVar1 and ?dataVar2 results in a row, I get
> things like:
>
>   1
>   stringB
>   123.456
>   2023-10-06T12:05:10Z
>
> What is a good way to reconstruct a typed Literal from the query
> results? Is there a SPARQL option to show full typed literal strings?
> Something that can be added to the query?  A utility method that can
> identify the XSD schema simple data type when given a result value string?
>
>
>


How to reconstruct a Literal from a SPARQL SELECT row element?

2023-10-26 Thread Steve Vestal
What is the best way to reconstruct a typed Literal from a SPARQL SELECT 
result?


I have a SPARQL SELECT query issued against an OntModel in this way:

 QueryExecution structureRowsExec = 
QueryExecutionFactory.create(structureRowsQuery, owlOntModel);


Here are some example triples in the query:

  ?a2 
 
?dataVar1.
  ?a2 
 
?dataVar2.


The OntModel being queried was created using typed literals, e.g.,


    DataPropertyAssertion( struct:floatProperty struct:indivA2 
"123.456"^^xsd:float )
    DataPropertyAssertion( struct:dateTimeProperty struct:indivA2 
"2023-10-06T12:05:10Z"^^xsd:dateTime )


When I look at the ?dataVar1 and ?dataVar2 results in a row, I get 
things like:


 1
 stringB
 123.456
 2023-10-06T12:05:10Z

What is a good way to reconstruct a typed Literal from the query 
results? Is there a SPARQL option to show full typed literal strings?  
Something that can be added to the query?  A utility method that can 
identify the XSD schema simple data type when given a result value string?