About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
See full specifications

linux default iconSparrow for Linux Publisher's description

SPARQL Database connector

Sparrow is a Python library that provides a very high-level abstraction for RDF databases. It provides support for the following basic functions:

* Parsing RDF statements from different formats into a contextual database
* Serializing the RDF statements for a specific context of a database
* Removing statements from a specific context of a database
* Performing SPARQL Queries

Sparrow is completely agnostic to which database backend is used. RDF Statements are loaded into and from databases in specific serialization formats like rdfxml, ntriples or turtle.

Sparrow provides no API for Statements, URIRef and Literal objects. It also does not provide a graph API. This is an intentional choice, since the goal of Sparrow is not to provide a full RDF library, but a lightweight wrapper that can easily be used for several backends.

At the moment there is support for the following backends:

* Redland librdf
* RDFLib
* Sesame openrdf


Normally, you will only need to import the base sparrow module

>>> import sparrow

Most of the database backends will not work out of the box. Since the RDFLib backend is written in python and packaged on pypi, it is always available, and installed with Sparrow.

Let's create an in memory rdflib database

>>> sparrow.database('rdflib', 'memory')
< sparrow.rdflib_backend.RDFLibConnector ... >

This is actually not the database, but a database connector. It manages the different connections to a database. Let's get a connection to the database

>>> db = sparrow.database('rdflib', 'memory').connect()
>>> db
< sparrow.rdflib_backend.RDFLibDatabase ... >

Now that we have the database, we can ask it which RDF serialization formats it supports

>>> db.formats()
['ntriples', 'rdfxml', 'turtle']

Let's add some triples to the database, we will use turtle syntax for this. We'll make some example statements where we will state that john is a person, and that his firstname is "John".

>>> data = """@prefix ex: < http://example.org# > .
... ex:john a ex:Person; ex:name "John" ."""

Now we can add this to the database. We will need to tell the database which format the data is in, and in which context to store it. A 'base URI' for the data should also be provided. We will use the example.org namespace for that.

>>> db.add_triples(StringIO(data), 'turtle', 'http://example.org','persons')

We can now ask the database, which contexts it has:

>>> db.contexts()

You can store data in as many different contexts as you like, or put everything in a single context.

Lets do a simple SPARQL query on the database

>>> result = db.select('SELECT ?x {?x < http://example.org#name > "John".}')

The is only on variable in this query: x

>>> result.variables()

We can get the results as a list of dictionaries. This follows the SPARQL JSON result format.

>>> result.results()
[{u'x': {'type': u'uri', 'value': u'http://example.org#john'}}]

Besides querying, we can also get the data back from the database in any of the supported formats. We specify which format we want, and which context to use.

>>> db.serialize_triples('ntriples', 'persons').read()
'< http://example.org#john > ...'

If the database backend supports it, you can ask how many triples are in a context.

>>> db.count('persons')

If you want to remove triples, you will need to supply data describing which triples to remove.

>>> data = StringIO(' a .')
>>> db.remove_triples(data, 'turtle', 'http://example.org', 'persons')
>>> db.count('persons')

You can also remove all triples in a context

>>> db.clear('persons')
>>> db.count('persons')

Since the 'persons' context is now empty, it is also removed.

>>> db.contexts()
Changelog for Sparrow

What's New in This Release:

В· Picked better default profile

System Requirements:

В· Python
Program Release Status:
Program Install Support: Install and Uninstall

Sparrow for Linux Tags:

Click on a tag to find related softwares

Is Sparrow for Linux your software?

Manage your software

Most Popular

linux default icon A2Billing 1.6.0
A2Billing is a billing system interactive with Asterisk to give any Telecom company traditional offering VOIP... Read more
linux default icon FrontAccounting 2.3.10
FrontAccounting is free and released under the GNU General Public License.
linux default icon PgAdmin III for Linux 1.14.1
pgAdmin is the most popular and feature rich Open Source administration and development platform for... Read more
linux default icon RazorSQL for Linux 5.6.3
RazorSQL is an SQL query tool, database browser, SQL editor,....
linux default icon Salat Book 1.00
Salat / Namaz prayer database and tracking application