tarql + split string function

100 views
Skip to first unread message

Andersen, Petter

unread,
Apr 30, 2019, 5:21:38 AM4/30/19
to ta...@googlegroups.com

Hi

I am working with building ontologies and use Excel as input sheet.

The Excel file is converted to CSV and we use tarql to create ttl file.

 

Tarql version 1.1 (2016-12-24) Upgrade from Jena 2 to Jena 3.1.1

 

 

My question:

·         Will there be any update of tarql to cover functionality of Jena 3.11, latest version : http://jena.apache.org/download/index.cgi

·         I have been looking for a solution where I can split a text string in TARQL. This would be very helpful.
I found this: https://github.com/tarql/tarql/issues/54, and the functionality works fine in SPARQL.

·         I would like to add multiple values into one column in the excel sheet and that TARQL give me result as separated values.
optional{BIND (apf:strSplit (?excelColumnXX,",") AS ?SplitValue}

 

 

http://jena.apache.org/documentation/query/library-propfunc.html

Prefix apf: which is <http://jena.hpl.hp.com/ARQ/property#>.

var apf:strSplit (arg arg)

Split a string and return a binding for each result. The subject variable should be unbound. The first argument to the object list is the string to be split. The second argument to the object list is a regular expression by which to split the string. The subject var is bound for each result of the split, and each result has the whitespace trimmed from it.

 

 

Best regards,

Petter Andersen

Ontology and COMOS system architect |Information Management
 Aker Solutions

 
Tel: +4767594868 |  Mob: +4747305209
petter....@akersolutions.com  |  www.akersolutions.com
 
Aker Solutions AS
Visiting address: Oksenøyveien 8, 1360 Fornebu, Norway
Postal address: PO Box 222, 1326 Lysaker, Norway
Registered in Norway, registration no. 929 877 950 VAT
 
Aker Solutions logo

 

This e-mail and any attachment are confidential and may be privileged or otherwise protected from disclosure. It is solely intended for the person(s) named above. If you are not the intended recipient, any reading, use, disclosure, copying or distribution of all or parts of this e-mail or associated attachments is strictly prohibited. If you are not an intended recipient, please notify the sender immediately by replying to this message or by telephone and delete this e-mail and any attachments permanently from your system.

Richard Cyganiak

unread,
Apr 30, 2019, 7:04:22 AM4/30/19
to Andersen, Petter, ta...@googlegroups.com
Hi Petter,

You can use apf:strSplit in Tarql 1.1. Example CSV file:

ID,value
1,foo
2,"bar baz"
3,

Example Tarql mapping:

    SELECT ?ID ?value ?valueSplit {
        # Split ?value on spaces into ?valueSplit
        BIND (COALESCE(?value, "") AS ?valueNotUnbound)
        ?valueSplitNotUnbound apf:strSplit (?valueNotUnbound " ")
        BIND (IF(?valueSplitNotUnbound, ?valueSplitNotUnbound, ?unbound) AS ?valueSplit)
    }

Output:

--------------------------------
| ID  | value     | valueSplit |
================================
| "1" | "foo"     | "foo"      |
| "2" | "bar baz" | "bar"      |
| "2" | "bar baz" | "baz"      |
| "3" |           |            |
--------------------------------

apf:strSplit is a property function, and not a normal SPARQL function. So it cannot be used in BIND like in your example. It needs to be used in the way shown in line 5 of the query above and shown in the Jena documentation.

The two extra BINDs on line 4 and 6 are needed to work around the bug mentioned in #54.

Hope that helps,
Richard



<image001.jpg>

 

This e-mail and any attachment are confidential and may be privileged or otherwise protected from disclosure. It is solely intended for the person(s) named above. If you are not the intended recipient, any reading, use, disclosure, copying or distribution of all or parts of this e-mail or associated attachments is strictly prohibited. If you are not an intended recipient, please notify the sender immediately by replying to this message or by telephone and delete this e-mail and any attachments permanently from your system.

-- 
You received this message because you are subscribed to the Google Groups "Tarql" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tarql+un...@googlegroups.com.
To post to this group, send email to ta...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tarql/HE1PR0601MB255511A9721331F85F56604CEA3A0%40HE1PR0601MB2555.eurprd06.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Andersen, Petter

unread,
Apr 30, 2019, 7:16:30 AM4/30/19
to Richard Cyganiak, ta...@googlegroups.com

Hi Richard

 

Thank you very much for a fast answer.

 

This works just perfect :-)

 

This example should be added to http://tarql.github.io/examples/

If you have other good examples then these should also be added.

 

Best regards

Petter

Reply all
Reply to author
Forward
0 new messages