https://github.com/sage-org/sage-client
🦄 JS client for evaluating SPARQL queries against a SaGe server
https://github.com/sage-org/sage-client
preemptive rdf sage sparql sparql-client sparql-query
Last synced: 5 months ago
JSON representation
🦄 JS client for evaluating SPARQL queries against a SaGe server
- Host: GitHub
- URL: https://github.com/sage-org/sage-client
- Owner: sage-org
- License: mit
- Created: 2018-04-11T08:32:59.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-27T05:14:41.000Z (over 2 years ago)
- Last Synced: 2025-10-19T01:53:37.192Z (8 months ago)
- Topics: preemptive, rdf, sage, sparql, sparql-client, sparql-query
- Language: TypeScript
- Homepage:
- Size: 1.73 MB
- Stars: 3
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sage-client
[](https://badge.fury.io/js/sage-client) [](https://travis-ci.org/sage-org/sage-client)
Javascript/typescript client for querying a [SaGe server](http://sage.univ-nantes.fr), built on top of the [`sparql-engine` framework](https://github.com/Callidon/sparql-engine).
# Installation
Requirements:
* [Node.js](https://nodejs.org/en/) v8.11.2 or higher
* [npm](https://nodejs.org/en/) v5.6.0 or higher
## npm installation
```bash
npm install -g sage-client
```
## Manual installation
```bash
git clone https://github.com/Callidon/sage-client.git
cd sage-client
npm install --production
```
# CLI Usage
```
Usage: sage-client [options]
Execute a SPARQL query using a SaGe server and the IRI of the default RDF graph
Options:
-q, --query evaluates the given SPARQL query
-f, --file evaluates the SPARQL query stored in the given file
-h, --help output usage information
```
# Library usage
The SaGe client can also be used as a regular Javascript/Typescript library
```javascript
const { SageClient, Spy } = require('sage-client')
// Create a spy to collect stats during query execution
const spy = new Spy()
// The URL of the SaGe server
const serverURL = 'http://sage.univ-nantes.fr/sparql'
// The IRI of the default graph
const defaultGraph = 'http://sage.univ-nantes.fr/sparql/dbpedia-2016-04'
// The SPARQL query to execute
const query = `
prefix dbo:
prefix rdfs:
SELECT ?movie ?title ?name WHERE {
?movie dbo:starring [ rdfs:label 'Brad Pitt'@en ];
rdfs:label ?title;
dbo:director [ rdfs:label ?name ].
FILTER LANGMATCHES(LANG(?title), 'EN')
FILTER LANGMATCHES(LANG(?name), 'EN')
}`
// Create a new SaGe client
const client = new SageClient(serverURL, defaultGraph, spy)
// Execute the SPARQL query
client.execute(query).subscribe(b => {
// Print solutions bindings (in simple JSON format)
console.log(b.toObject())
}, (error) => {
// Report errors
console.error('ERROR: An error occurred during query execution.')
console.error(error.stack)
}, () => {
// Print some starts after the end of query execution
console.log('Query execution completed!')
console.log(`SPARQL query evaluated with ${spy.nbHTTPCalls} HTTP request(s)`)
})
```