Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple values in single CSV column #329

Closed
milvld opened this issue Jan 19, 2023 · 3 comments
Closed

Multiple values in single CSV column #329

milvld opened this issue Jan 19, 2023 · 3 comments
Labels
Question Further information is requested

Comments

@milvld
Copy link

milvld commented Jan 19, 2023

Hi

I'm trying to convert a CSV in which a single column/cell can contain multiple values separated by a dedicated delimiter (in this case a semicolon). Instead of resulting in a single property with the complete column's content as the value, I want two properties with two separate values.

I'm currently using Apache Jena's strsplit function, as has previously been discussed in the issues, cf. #197 . However, this results in no output. When I take the facade-x output and then try to transform that using regular SPARQL via Jena, everything works as expected.

Any pointers as to what is going on?

Sample CSV

terms,values
term1,val1
term2,val2;val3
term3,val4

SPARQL Anything query
With the file being given as input via command: java -jar ../../sparql_anything/sparql-anything-0.8.1.jar -q ./test_strsplit2.rq -v file=./test_strsplit.csv

PREFIX apf: <http://jena.hpl.hp.com/ARQ/property#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX myns: <http://example.org/myns/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>

CONSTRUCT {
    ?term myns:value    ?value .
}
WHERE {
    SERVICE <x-sparql-anything:csv.headers=true>
    {
        fx:properties   fx:location       ?_file ;
                        fx:media-type "text/csv" ;
                        fx:csv.null-string          "" .

        ?c  xyz:terms ?term_temp;
            xyz:values  ?value_temp.
        ?value apf:strSplit    (?value_temp ";") .
        BIND (IRI(CONCAT("http://example.org/myns/", ?term_temp)) AS ?term)
    }
}

Expected output

@prefix apf:  <http://jena.hpl.hp.com/ARQ/property#> .
@prefix fx:   <http://sparql.xyz/facade-x/ns/> .
@prefix myns: <http://example.org/myns/> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xyz:  <http://sparql.xyz/facade-x/data/> .

myns:term2  myns:value  "val2","val3" .

myns:term1  myns:value  "val1" .

myns:term3  myns:value  "val4" .

Current output

@prefix apf:  <http://jena.hpl.hp.com/ARQ/property#> .
@prefix fx:   <http://sparql.xyz/facade-x/ns/> .
@prefix myns: <http://example.org/myns/> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xyz:  <http://sparql.xyz/facade-x/data/> .
@milvld milvld changed the title Multiple values in single CSV cell Multiple values in single CSV column Jan 19, 2023
@enridaga
Copy link
Member

This seems to work:

PREFIX apf: <http://jena.hpl.hp.com/ARQ/property#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX myns: <http://example.org/myns/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>

CONSTRUCT {
    ?term myns:value    ?value .
}
WHERE {
    SERVICE <x-sparql-anything:csv.headers=true>
    {
        fx:properties   fx:location       ?_file ;
                        fx:media-type "text/csv" ;
                        fx:csv.null-string          "" .

        ?c  xyz:terms ?term_temp ;
            xyz:values  ?value_temp .
        BIND (IRI(CONCAT("http://example.org/myns/", ?term_temp)) AS ?term) .
    }
    ?value apf:strSplit    (?value_temp ";") .
}

Curious, it may be possible that the apf magic property is not properly processed within the SERVICE clause; this needs double-checking.

@luigi-asprino
Copy link
Member

Curious, it may be possible that the apf magic property is not properly processed within the SERVICE clause; this needs double-checking.

It is possible as the SERVICE clause is supposed to be executed by another endpoint which couldn't implement the the apfs properties. I faced the same issue while implementing fx:anySlot.

@milvld
Copy link
Author

milvld commented Jan 19, 2023

Hi @enridaga , thanks for the quick reply, that works indeed! I'm closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants