A comma-separated values (CSV) file is a text file that uses a comma to separate an ordered sequence of values in a data record and a carriage return to separate the data records of a sequence.
A CSV can be represented as a list of lists in which the outer list captures the sequence of data records (representable as containers), while the inner list captures the sequence of primitive values within a record.
SPARQL Anything selects this transformer for the following file extensions:
- csv
- tab
- tsv
SPARQL Anything selects this transformer for the following media types:
- text/csv
- text/tab-separated-values
email,name,surname
laura@example.com,Laura,Grey
craig@example.com,Craig,Johnson
mary@example.com,Mary,Jenkins
jamie@example.com,Jamie,Smith
Located at https://sparql-anything.cc/examples/simple.csv
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simple.csv>
{ GRAPH ?g
{ ?s ?p ?o }
}
}
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX eg: <http://www.example.org/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rss: <http://purl.org/rss/1.0/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
PREFIX whatwg: <https://html.spec.whatwg.org/#>
PREFIX xhtml: <http://www.w3.org/1999/xhtml#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
[ rdf:type fx:root;
rdf:_1 [ rdf:_1 "email";
rdf:_2 "name";
rdf:_3 "surname"
];
rdf:_2 [ rdf:_1 "laura@example.com";
rdf:_2 "Laura";
rdf:_3 "Grey"
];
rdf:_3 [ rdf:_1 "craig@example.com";
rdf:_2 "Craig";
rdf:_3 "Johnson"
];
rdf:_4 [ rdf:_1 "mary@example.com";
rdf:_2 "Mary";
rdf:_3 "Jenkins"
];
rdf:_5 [ rdf:_1 "jamie@example.com";
rdf:_2 "Jamie";
rdf:_3 "Smith"
]
] .
Option name | Description | Valid Values | Default Value |
---|---|---|---|
csv.headers | It tells the CSV triplifier to use the headers of the CSV file for minting the properties of the generated triples. | true/false | false |
csv.headers-row | It specifies the number of the row to use for extracting column headers. Note this option affects the performance as it requires to pass through input twice. -- see #179 | Any integer | 1 |
csv.format | The format of the input CSV file. | Any predefined CSVFormat of the Apache's commons CSV library. | Default |
csv.delimiter | It sets the column delimiter, usually ,;\t etc. | Any single character | , |
csv.quote-char | It sets the quoting character | Any single character | " |
csv.null-string | It tells the CSV triplifier to not produce triples where the specified string would be in the object position of the triple | Any String | Not set |
csv.ignore-columns-with-no-header | It tells the csv triplifier to ignore from the cells of columns having no headers. Note that if the property is set as true when csv.headers is false, the triplifier does not generate any slot (as no headers are collected). -- see #180 | true/false | false |
It tells the CSV triplifier to use the headers of the CSV file for minting the properties of the generated triples.
true/false
false
Compute the average petal length of the species having sepal length greater than 4.9
Sepal_length Sepal_width Petal_length Petal_width Species
5.1 3.5 1.4 0.2 I. setosa
4.9 3.0 1.4 0.2 I. setosa
4.7 3.2 1.3 0.2 I. setosa
4.6 3.1 1.5 0.2 I. setosa
5.0 3.6 1.4 0.2 I. setosa
https://sparql-anything.cc/examples/simple.tsv
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT (AVG(xsd:float(?petalLength)) AS ?avgPetalLength)
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simple.tsv,csv.headers=true,csv.format=TDF>
{ ?s xyz:Sepal_length ?length ;
xyz:Petal_length ?petalLength
FILTER ( xsd:float(?length) > 4.9 )
}
}
------------------
| avgPetalLength |
==================
| 0 |
------------------
It specifies the number of the row to use for extracting column headers. Note this option affects the performance as it requires to pass through input twice. -- see #179
Any integer
1
Compute the average petal length of the species having sepal length greater than 4.9
Sepal_length Sepal_width Petal_length Petal_width Species
5.1 3.5 1.4 0.2 I. setosa
4.9 3.0 1.4 0.2 I. setosa
4.7 3.2 1.3 0.2 I. setosa
4.6 3.1 1.5 0.2 I. setosa
5.0 3.6 1.4 0.2 I. setosa
https://sparql-anything.cc/examples/simple.tsv
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT (AVG(xsd:float(?petalLength)) AS ?avgPetalLength)
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simple.tsv,csv.headers=true,csv.format=TDF,csv.headers-row=3>
{ ?s xyz:Sepal_length ?length ;
xyz:Petal_length ?petalLength
FILTER ( xsd:float(?length) > 4.9 )
}
}
------------------
| avgPetalLength |
==================
| 0 |
------------------
The format of the input CSV file.
Any predefined CSVFormat of the Apache's commons CSV library.
Default
Constructing a Facade-X RDF graph out of the TSV file available at https://sparql-anything.cc/examples/simple.tsv
Sepal_length Sepal_width Petal_length Petal_width Species
5.1 3.5 1.4 0.2 I. setosa
4.9 3.0 1.4 0.2 I. setosa
4.7 3.2 1.3 0.2 I. setosa
4.6 3.1 1.5 0.2 I. setosa
5.0 3.6 1.4 0.2 I. setosa
https://sparql-anything.cc/examples/simple.tsv
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simple.tsv,csv.format=TDF>
{ ?s ?p ?o }
}
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX eg: <http://www.example.org/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rss: <http://purl.org/rss/1.0/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
PREFIX whatwg: <https://html.spec.whatwg.org/#>
PREFIX xhtml: <http://www.w3.org/1999/xhtml#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
[ rdf:type fx:root;
rdf:_1 [ rdf:_1 "Sepal_length\tSepal_width\tPetal_length\tPetal_width\tSpecies" ];
rdf:_2 [ rdf:_1 "5.1\t3.5\t1.4\t0.2\tI. setosa" ];
rdf:_3 [ rdf:_1 "4.9\t3.0\t1.4\t0.2\tI. setosa" ];
rdf:_4 [ rdf:_1 "4.7\t3.2\t1.3\t0.2\tI. setosa" ];
rdf:_5 [ rdf:_1 "4.6\t3.1\t1.5\t0.2\tI. setosa" ];
rdf:_6 [ rdf:_1 "5.0\t3.6\t1.4\t0.2\tI. setosa" ]
] .
It sets the column delimiter, usually ,;\t etc.
Any single character
,
Compute the maximum petal length of the species having sepal length less than 4.9
Sepal_length Sepal_width Petal_length Petal_width Species
5.1 3.5 1.4 0.2 I. setosa
4.9 3.0 1.4 0.2 I. setosa
4.7 3.2 1.3 0.2 I. setosa
4.6 3.1 1.5 0.2 I. setosa
5.0 3.6 1.4 0.2 I. setosa
https://sparql-anything.cc/examples/simple.tsv
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT (MAX(xsd:float(?petalLength)) AS ?maxPetalLength)
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simple.tsv,csv.headers=true>
{ fx:properties
fx:csv.delimiter "\t" .
?s xyz:Sepal_length ?length ;
xyz:Petal_length ?petalLength
FILTER ( xsd:float(?length) < 4.9 )
}
}
---------------------------------------------------
| maxPetalLength |
===================================================
| "1.5"^^<http://www.w3.org/2001/XMLSchema#float> |
---------------------------------------------------
It sets the quoting character
Any single character
"
Constructing a Facade-X RDF graph out of the CSV available at https://sparql-anything.cc/examples/csv_with_commas.csv
email,name,surname
laura@example.com,'Laura, Nancy',Grey
craig@example.com,Craig,Johnson
mary@example.com,Mary,Jenkins
jamie@example.com,Jamie,Smith
https://sparql-anything.cc/examples/csv_with_commas.csv
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/csv_with_commas.csv,csv.headers=true,csv.quote-char='>
{ ?s ?p ?o }
}
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX eg: <http://www.example.org/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX ja: <http://jena.hpl.hp.com/2005/11/Assembler#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rss: <http://purl.org/rss/1.0/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
PREFIX whatwg: <https://html.spec.whatwg.org/#>
PREFIX xhtml: <http://www.w3.org/1999/xhtml#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
[ rdf:type fx:root;
rdf:_1 [ xyz:email "laura@example.com";
xyz:name "Laura, Nancy";
xyz:surname "Grey"
];
rdf:_2 [ xyz:email "craig@example.com";
xyz:name "Craig";
xyz:surname "Johnson"
];
rdf:_3 [ xyz:email "mary@example.com";
xyz:name "Mary";
xyz:surname "Jenkins"
];
rdf:_4 [ xyz:email "jamie@example.com";
xyz:name "Jamie";
xyz:surname "Smith"
]
] .
It tells the CSV triplifier to not produce triples where the specified string would be in the object position of the triple
Any String
Not set
Retrieving name surname of who doesn't have an email address.
email,name,surname
laura@example.com,Laura,Grey
craig@example.com,Craig,Johnson
,Mary,Jenkins
jamie@example.com,Jamie,Smith
https://sparql-anything.cc/examples/simple_with_null.csv
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT ?name ?surname
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simple_with_null.csv,csv.headers=true>
{ fx:properties
fx:csv.null-string "" .
?c xyz:name ?name ;
xyz:surname ?surname
FILTER NOT EXISTS { ?c xyz:email ?email }
}
}
----------------------
| name | surname |
======================
| "Mary" | "Jenkins" |
----------------------
It tells the csv triplifier to ignore from the cells of columns having no headers. Note that if the property is set as true when csv.headers is false, the triplifier does not generate any slot (as no headers are collected). -- see #180
true/false
false
Inline content
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?fred ?sally
WHERE
{ SERVICE <x-sparql-anything:>
{ fx:properties
fx:csv.headers true ;
fx:content ",state\nfred,CO\nsally,FL" ;
fx:media-type "text/csv" ;
fx:csv.ignore-columns-with-no-header true .
?root rdf:type fx:root ;
rdf:_1 _:b0 .
_:b0 rdf:_1 ?fred .
?root rdf:_2 _:b1 .
_:b1 rdf:_1 ?sally
}
}
----------------
| fred | sally |
================
----------------