.TH tracker-sparql 1 "July 2009" GNU "User Commands" .SH NAME tracker-sparql \- Use SparQL to query the Tracker databases. .SH SYNOPSIS .nf \fBtracker sparql\fR \-q <\fIsparql\fR> [\-u] | \-f <\fIfile\fR> \fBtracker sparql\fR \-t [\fIclass\fR] [-s <\fIneedle\fR>] [\-p] \fBtracker sparql\fR [\-c] [\-p] [\-x] [-n [\fIclass\fR]] [\-i [\fIproperty\fR]] [\-s <\fIneedle\fR>] \fBtracker sparql\fR [\-\-get\-longhand <\fIclass\fR>] [\-\-get\-shorthand <\fIclass\fR>] .fi .SH DESCRIPTION This command allows probing of the current database schema (also known as ontology) and running low level queries or updates on the data set. In terms of the database ontology, it's easy to find out what properties are indexed for speed, or notified on changes, what classes are available and the properties belonging to those classes. There are also visual tools to display an ascii tree layout of the classes and their relationships to each other. When the caller runs a query, the query is in RDF and SPARQL. This can be done two ways. Either by providing a \fIfile\fR with the query or by providing a string with the \fIsparql\fR query. The \fIfile\fR argument can be either a local path or a URI. It also does not have to be an absolute path. .SH OPTIONS .TP .B \-f, \-\-file\fR=<\fIfile\fR> Use a \fIfile\fR with SPARQL content to query or update. .TP .B \-q, \-\-query\fR=<\fIsparql\fR> Use a \fIsparql\fR string to query the database with. .TP .B \-u, \-\-update This has to be used with \fB\-\-query\fR. This tells "tracker sparql" to use the SPARQL update extensions so it knows it isn't a regular data lookup request. So if your query is intended to change data in the database, this option is needed. .TP .B \-c, \-\-list\-classes Returns a list of classes which describe the ontology used for storing data. These classes are also used in queries. For example, \fIhttp://www.w3.org/2000/01/rdf-schema#Resource\fR is one of many classes which should be returned here. .TP .B \-x, \-\-list\-class\-prefixes Returns a list of classes and their related prefixes. Prefixes are used to make querying a lot simpler and are much like an alias. For example, \fIhttp://www.w3.org/2000/01/rdf-schema#Resource\fR has the prefix \fIrdfs\fR so queries can be cut down to: "SELECT ?u WHERE { ?u a rdfs:Resource }" .TP .B \-p, \-\-list\-properties\fR=[\fIclass\fR] Returns a list of properties which pertain to a \fIclass\fR. You can use both formats here for the \fIclass\fR, either the full name \fIhttp://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video\fR or the shortened prefix name \fInfo:Video\fR. This gives the following result: .nf $ tracker sparql -p nfo:Video Properties: 2 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameRate http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameCount .fi These properties \fInfo:frameRate\fR and \fInfo:frameCount\fR can then be used in queries. See also \fB\-\-tree\fR and \fB\-\-query\fR. .TP .B \-n, \-\-list\-notifies\fR=[\fIclass\fR] Returns a list of classes which are notified over D-Bus about any changes that occur in the database. The \fIclass\fR does not have to be supplied here. This is optional and filters the results according to any argument supplied. With no \fIclass\fR, all classes are listed. .TP .B \-i, \-\-list\-indexes\fR=[\fIproperty\fR] Returns a list of properties which are indexed in the database. Indexes improves query speed but also add an indexing penalty. The \fIproperty\fR does not have to be supplied here. This is optional and filters the results according to any argument supplied. With no \fIproperty\fR, all properties are listed. .TP .B \-t, \-\-tree\fR=[\fIclass\fR] Prints a tree showing all parent classes of \fIclass\fR in the ontology. The \fIclass\fR can be provided in shorthand or longhand (see \fB\-\-get\-shorthand\fR and \fB\-\-get\-longhand\fR for details). For example: .nf $ tracker sparql -t nmo:MMSMessage ROOT +-- rdfs:Resource (C) | +-- nie:InformationElement (C) | | +-- nfo:Document (C) | | | +-- nfo:TextDocument (C) | | | | `-- nmo:Message (C) | | | | | +-- nmo:PhoneMessage (C) | | | | | | `-- nmo:MMSMessage (C) .fi If no \fIclass\fR is given, the entire tree is shown. The .B \-\-search command line option can be used to highlight parts of the tree you're looking for. The search is case insensitive. The \fB\-\-properties\fR command line option can be used to show properties for each class displayed, for example: .nf $ tracker sparql -t nfo:FileDataObject -p ROOT +-- rdfs:Resource (C) | --> http://purl.org/dc/elements/1.1/contributor (P) | --> http://purl.org/dc/elements/1.1/coverage (P) | --> http://purl.org/dc/elements/1.1/creator (P) | --> http://purl.org/dc/elements/1.1/date (P) | --> http://purl.org/dc/elements/1.1/description (P) | --> http://purl.org/dc/elements/1.1/format (P) | --> http://purl.org/dc/elements/1.1/identifier (P) | --> http://purl.org/dc/elements/1.1/language (P) | --> http://purl.org/dc/elements/1.1/publisher (P) | --> http://purl.org/dc/elements/1.1/relation (P) | --> http://purl.org/dc/elements/1.1/rights (P) | --> http://purl.org/dc/elements/1.1/source (P) | --> http://purl.org/dc/elements/1.1/subject (P) | --> http://purl.org/dc/elements/1.1/title (P) | --> http://purl.org/dc/elements/1.1/type (P) | --> nao:deprecated (P) | --> nao:hasTag (P) | --> nao:identifier (P) | --> nao:isRelated (P) | --> nao:lastModified (P) | --> nao:numericRating (P) | --> rdf:type (P) | --> rdfs:comment (P) | --> rdfs:label (P) | --> tracker:added (P) | --> tracker:damaged (P) | --> tracker:modified (P) | +-- nie:DataObject (C) | | --> nfo:belongsToContainer (P) | | --> nie:byteSize (P) | | --> nie:created (P) | | --> nie:dataSource (P) | | --> nie:interpretedAs (P) | | --> nie:isPartOf (P) | | --> nie:lastRefreshed (P) | | --> nie:url (P) | | --> tracker:available (P) | | +-- nfo:FileDataObject (C) | | | --> nfo:fileCreated (P) | | | --> nfo:fileLastAccessed (P) | | | --> nfo:fileLastModified (P) | | | --> nfo:fileName (P) | | | --> nfo:fileOwner (P) | | | --> nfo:fileSize (P) | | | --> nfo:hasHash (P) | | | --> nfo:permissions (P) .fi .TP .B \-s, \-\-search\fR=<\fIneedle\fR> Returns a list of classes and properties which partially match \fIneedle\fR in the ontology. This is a case insensitive match, for example: .nf $ tracker sparql -s text Classes: 4 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#TextDocument http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PlainTextDocument http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PaginatedTextDocument http://www.tracker-project.org/temp/nmm#SynchronizedText Properties: 4 http://www.tracker-project.org/ontologies/tracker#fulltextIndexed http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent http://www.tracker-project.org/temp/scal#textLocation .fi See also \fB\-\-tree\fR. .TP .B \-\-get\-shorthand\fR=<\fIclass\fR> Returns the shorthand for a class given by a URL. For example: .nf $ tracker sparql --get-shorthand http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent nmo:plainTextMessageContent .fi .TP .B \-\-get\-longhand\fR=<\fIclass\fR> Returns the longhand for a class given in the form of CLASS:PROPERTY. For example: .nf $ tracker sparql --get-longhand nmm:MusicPiece http://www.tracker-project.org/temp/nmm#MusicPiece .fi .SH ENVIRONMENT .TP .B TRACKER_SPARQL_BACKEND This option allows you to choose which backend you use for connecting to the database. This choice can limit your functionality. There are three settings. With "\fBdirect\fR" the connection to the database is made directly to the file itself on the disk, there is no intermediary daemon or process. The "\fBdirect\fR" approach is purely \fIread-only\fR. With "\fBbus\fR" the \fBtracker-store\fR process is used to liase with the database queuing all requests and managing the connections via an IPC / D-Bus. This adds a small overhead \fIBUT\fR this is the only approach you can use if you want to \fIwrite\fR to the database. With "\fBauto\fR" the backend is decided for you, much like it would be if this environment variable was undefined. .SH EXAMPLES .TP List all classes .BR .nf $ tracker sparql -q "SELECT ?cl WHERE { ?cl a rdfs:Class }" .fi .TP List all properties for the Resources class (see \-\-list-properties) .BR .nf $ tracker sparql -q "SELECT ?prop WHERE { ?prop a rdf:Property ; rdfs:domain }" .fi .TP List all class namespace prefixes .BR .nf $ tracker sparql -q "SELECT ?prefix ?ns WHERE { ?ns a tracker:Namespace ; tracker:prefix ?prefix }" .fi .TP List all music files .BR .nf $ tracker sparql -q "SELECT ?song WHERE { ?song a nmm:MusicPiece }" .fi .TP List all music albums, showing title, track count, and length in seconds. .BR .nf $ tracker sparql -q "SELECT ?title COUNT(?song) AS songs SUM(?length) AS totallength WHERE { ?album a nmm:MusicAlbum ; nie:title ?title . ?song nmm:musicAlbum ?album ; nfo:duration ?length } GROUP BY ?album" .fi .TP List all music from a particular artist .BR .nf $ tracker sparql -q "SELECT ?song ?title WHERE { ?song nmm:performer [ nmm:artistName 'Artist Name' ] ; nie:title ?title }" .fi .TP Set the played count for a song .BR .nf $ tracker sparql -u -q "DELETE { nie:usageCounter ?count } WHERE { nie:usageCounter ?count } INSERT { nie:usageCounter 42 }" .fi .TP List all image files .BR .nf $ tracker sparql -q "SELECT ?image WHERE { ?image a nfo:Image }" .fi .TP List all image files with a specific tag .BR .nf $ tracker sparql -q "SELECT ?image WHERE { ?image a nfo:Image ; nao:hasTag [ nao:prefLabel 'tag' ] }" .fi .TP List all image files created on a specific month and order by date .BR .nf $ tracker sparql -q "SELECT ?image ?date WHERE { ?image a nfo:Image ; nie:contentCreated ?date . FILTER (?date >= '2008-07-01T00:00:00' && ?date < '2008-08-01T00:00:00') } ORDER BY ?date" .fi .SH SEE ALSO .BR tracker-sql (1), .BR tracker-store (1), .BR tracker-info (1). .TP .BR http://nepomuk.semanticdesktop.org/ .TP .BR http://www.w3.org/TR/rdf-sparql-query/