You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "Martin G. Skjæveland" <m....@gmail.com> on 2019/09/04 09:42:35 UTC

Parsing RDFNode.toString()-s (back) to RDFNodes -- or parsing GROUP_CONCAT to RDFLists

Hi all,

in my application there is special support for lists (without going into 
further detail), and I would like to be able to have SPARQL queries that 
return lists. Since this is not supported in SPARQL, my idea is to 
exploit and consider GROUP_CONCAT "columns" in SPARQL result sets as 
lists and split and parse these part of the split to an RDFList (of 
RDFNodes).

Does this sound reasonable? Is there parsing functionality in Jena to 
handle this already? Perhaps there is something like  RDFNode 
parse(String)  which parses strings on the same format as 
RDFNode.toString() would produce back to an RDFNode?

Thanks!

Martin

Re: Parsing RDFNode.toString()-s (back) to RDFNodes -- or parsing GROUP_CONCAT to RDFLists

Posted by "Martin G. Skjæveland" <m....@gmail.com>.
Thanks everyone for pointers and ideas!

I found

   Node NodeFactoryExtra.parseNode(String nodeString, PrefixMap pmap)

which might be what I am looking for:

   
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/sparql/util/NodeFactoryExtra.html

Initial tests reveal that it correctly detects if strings are URIs, 
literals or blanks.

Martin

On 05/09/2019 12:51, Claude Warren wrote:
> I am not certain, but I think that the QueryBuilder AbstractQueryBuilder
> class has static methods that take objects and create nodes from them.  I
> think that passing the string representation the '<' and '>' prefix and
> suffix will work for URLs.  If you have names like dc:name and "dc"  is
> prefixmapped to dublin core than that would also be parsed if you pass the
> prefix map.  Anyway, take a look at the querybuilder to see if will do what
> you want.
> 
> Claude
> 
> On Wed, Sep 4, 2019 at 10:42 AM Martin G. Skjæveland <
> m.g.skjaeveland@gmail.com> wrote:
> 
>> Hi all,
>>
>> in my application there is special support for lists (without going into
>> further detail), and I would like to be able to have SPARQL queries that
>> return lists. Since this is not supported in SPARQL, my idea is to
>> exploit and consider GROUP_CONCAT "columns" in SPARQL result sets as
>> lists and split and parse these part of the split to an RDFList (of
>> RDFNodes).
>>
>> Does this sound reasonable? Is there parsing functionality in Jena to
>> handle this already? Perhaps there is something like  RDFNode
>> parse(String)  which parses strings on the same format as
>> RDFNode.toString() would produce back to an RDFNode?
>>
>> Thanks!
>>
>> Martin
>>
> 
> 

Re: Parsing RDFNode.toString()-s (back) to RDFNodes -- or parsing GROUP_CONCAT to RDFLists

Posted by Claude Warren <cl...@xenei.com>.
I am not certain, but I think that the QueryBuilder AbstractQueryBuilder
class has static methods that take objects and create nodes from them.  I
think that passing the string representation the '<' and '>' prefix and
suffix will work for URLs.  If you have names like dc:name and "dc"  is
prefixmapped to dublin core than that would also be parsed if you pass the
prefix map.  Anyway, take a look at the querybuilder to see if will do what
you want.

Claude

On Wed, Sep 4, 2019 at 10:42 AM Martin G. Skjæveland <
m.g.skjaeveland@gmail.com> wrote:

> Hi all,
>
> in my application there is special support for lists (without going into
> further detail), and I would like to be able to have SPARQL queries that
> return lists. Since this is not supported in SPARQL, my idea is to
> exploit and consider GROUP_CONCAT "columns" in SPARQL result sets as
> lists and split and parse these part of the split to an RDFList (of
> RDFNodes).
>
> Does this sound reasonable? Is there parsing functionality in Jena to
> handle this already? Perhaps there is something like  RDFNode
> parse(String)  which parses strings on the same format as
> RDFNode.toString() would produce back to an RDFNode?
>
> Thanks!
>
> Martin
>


-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: Parsing RDFNode.toString()-s (back) to RDFNodes -- or parsing GROUP_CONCAT to RDFLists

Posted by Andy Seaborne <an...@apache.org>.
There isn't any better way if the list is being buiolt by teh query. If 
it is finding a list then ...

If your query is local, the app can query to find the head of the list 
then use the API and work with an RDFList

If it's remote, then find use of the use of the list (one query) and do 
a DESCRIBE for that resource may work.  The default DESCRIBE algorithm 
is forward-blank node closure which will capture a list that uses blank 
nodes.

Neither is elegant.

     <x:s> <x:p> ( 1 2 ( 3 4 ) ).

then

    DESCRIBE <x:s>  {}

(Various caveats)

Without lists being a part of the SPARQL data model, (and paths) it's messy.

     Andy

On 04/09/2019 21:41, ajs6f wrote:
> I'm not sure there is. There is not a simple way to parse one quad:
> 
> https://lists.apache.org/thread.html/a5c19bbe44109e4812f302462840569971aa732d73397bb8c2182aba@%3Cusers.jena.apache.org%3E
> 
> But perhaps there is, because I'm not very familiar with the output of RDFNode.toString(). In fact, I'm not sure how well-defined it is. Our Javadoc on the override of toString in RDFNode is documented thusly:
> 
>> Answer a String representation of the node. The form of the string  depends on the type of the node and is intended for human consumption, not machine analysis.
> 
> which doesn't imply a good fit for your case. If possible you might want to think about working from something like Turtle, which can be concise for the case of many triples with the same subject and predicate but different objects:
> 
> https://www.w3.org/TR/turtle/#h3_object-lists
> 
> ajs6f
> 
>> On Sep 4, 2019, at 5:42 AM, Martin G. Skjæveland <m....@gmail.com> wrote:
>>
>> Hi all,
>>
>> in my application there is special support for lists (without going into further detail), and I would like to be able to have SPARQL queries that return lists. Since this is not supported in SPARQL, my idea is to exploit and consider GROUP_CONCAT "columns" in SPARQL result sets as lists and split and parse these part of the split to an RDFList (of RDFNodes).
>>
>> Does this sound reasonable? Is there parsing functionality in Jena to handle this already? Perhaps there is something like  RDFNode parse(String)  which parses strings on the same format as RDFNode.toString() would produce back to an RDFNode?
>>
>> Thanks!
>>
>> Martin
> 

Re: Parsing RDFNode.toString()-s (back) to RDFNodes -- or parsing GROUP_CONCAT to RDFLists

Posted by ajs6f <aj...@apache.org>.
I'm not sure there is. There is not a simple way to parse one quad:

https://lists.apache.org/thread.html/a5c19bbe44109e4812f302462840569971aa732d73397bb8c2182aba@%3Cusers.jena.apache.org%3E

But perhaps there is, because I'm not very familiar with the output of RDFNode.toString(). In fact, I'm not sure how well-defined it is. Our Javadoc on the override of toString in RDFNode is documented thusly:

> Answer a String representation of the node. The form of the string  depends on the type of the node and is intended for human consumption, not machine analysis.

which doesn't imply a good fit for your case. If possible you might want to think about working from something like Turtle, which can be concise for the case of many triples with the same subject and predicate but different objects:

https://www.w3.org/TR/turtle/#h3_object-lists

ajs6f

> On Sep 4, 2019, at 5:42 AM, Martin G. Skjæveland <m....@gmail.com> wrote:
> 
> Hi all,
> 
> in my application there is special support for lists (without going into further detail), and I would like to be able to have SPARQL queries that return lists. Since this is not supported in SPARQL, my idea is to exploit and consider GROUP_CONCAT "columns" in SPARQL result sets as lists and split and parse these part of the split to an RDFList (of RDFNodes).
> 
> Does this sound reasonable? Is there parsing functionality in Jena to handle this already? Perhaps there is something like  RDFNode parse(String)  which parses strings on the same format as RDFNode.toString() would produce back to an RDFNode?
> 
> Thanks!
> 
> Martin