Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gatenlp/sesamesparql

Query a SPARQL Endpoint and Retrieve Result as a TSV file
https://github.com/gatenlp/sesamesparql

cli command-line-tool openrdf sparql sparql-query tsv

Last synced: about 2 months ago
JSON representation

Query a SPARQL Endpoint and Retrieve Result as a TSV file

Awesome Lists containing this project

README

        

# Tool for Accessing a SPARQL endpoint and fetching query results from there.

Simple API and command line tool to retrieve the result of SPARQL queries from a
Sesame repository.

The tool can be used to retrieve large result sets without overwhelming the server by retrieving
small batches of data (see option -b below) and allows to increase the maxmimum query timeout
for queries over a large repository.

## Setup

* clone the repository and change into the directory
* run `mvn package`

This creates a single jar in `./target` which contains all the dependencies.

## Usage

Run the command:
```
./bin/query.sh -u -i [OTHEROPTIONS]
```

The result rows are written to standard output.

To get usage information:
```
./bin/query.sh -h
```

This outputs:
```
usage: ./bin/query.sh [options]
-b Batchsize for queries, default: retrieve all at once
-ee error on invalid strings: true or false, default=false
-h Show help information
-i Query input file (required)
-ii include inferred: true or false, default=true
-mt maximum query time in seconds, default=3600
-ph print headers: true or false, default=false
-u endpoint URL (required)
```

### Examples

Query DBPedia and get the URI and English language film title of films starring Charlie Chaplin:

Query file `examples/example2.sparql`:
```
PREFIX dbo:
PREFIX res:
PREFIX rdf:
PREFIX rdfs:
SELECT DISTINCT ?uri ?string
WHERE {
?uri rdf:type dbo:Film .
?uri dbo:starring res:Charlie_Chaplin .
OPTIONAL {?uri rdfs:label ?string . FILTER (lang(?string) = 'en') }
}
```

Run the command to retrieve the result, write to file `chaplin_films.tsv` with column headers:
```
./bin/query.sh -ph true -u http://DBpedia.org/sparql -i examples/example2.sparql > chaplin_films.tsv
```