'\" t .\" Title: tracker3-sparql .\" Author: The Tracker developers .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 06/27/2023 .\" Manual: Tracker manual .\" Source: \ \& 3.4.2 .\" Language: English .\" .TH "TRACKER3\-SPARQL" "1" "06/27/2023" "\ \& 3\&.4\&.2" "Tracker manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" tracker3-sparql \- Use SparQL to query the Tracker databases\&. .SH "SYNOPSIS" .sp .nf tracker3 sparql \-q [\-u] | \-f tracker3 sparql \-t [class] [\-s ] [\-p] tracker3 sparql [\-c] [\-p] [\-x] [\-n [class]] [\-i [property]] [\-s ] tracker3 sparql [\-\-get\-longhand ] [\-\-get\-shorthand ] .fi .SH "DESCRIPTION" .sp 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\(cqs 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\&. .sp 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\&. .sp 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" .PP \fB\-f, \-\-file=<\fR\fB\fIfile\fR\fR\fB>\fR .RS 4 Use a \fIfile\fR with SPARQL content to query or update\&. .RE .PP \fB\-q, \-\-query=<\fR\fB\fIsparql\fR\fR\fB>\fR .RS 4 Use a \fIsparql\fR string to query the database with\&. .RE .PP \fB\-u, \-\-update\fR .RS 4 This has to be used with \fB\-\-query\fR\&. This tells "tracker3 sparql" to use the SPARQL update extensions so it knows it isn\(cqt a regular data lookup request\&. So if your query is intended to change data in the database, this option is needed\&. .RE .PP \fB\-c, \-\-list\-classes\fR .RS 4 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\&. .RE .PP \fB\-x, \-\-list\-class\-prefixes\fR .RS 4 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: .RE .sp "SELECT ?u WHERE \e{ ?u a rdfs:Resource }" .PP \fB\-p, \-\-list\-properties=[\fR\fB\fIclass\fR\fR\fB]\fR .RS 4 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://tracker\&.api\&.gnome\&.org/ontology/v3/nfo#Video\fR or the shortened prefix name \fInfo:Video\fR\&. .RE .sp This gives the following result: .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-p nfo:Video Properties: 2 http://tracker\&.api\&.gnome\&.org/ontology/v3/nfo#frameRate http://tracker\&.api\&.gnome\&.org/ontology/v3/nfo#frameCount .fi .if n \{\ .RE .\} .sp These properties \fInfo:frameRate\fR and \fInfo:frameCount\fR can then be used in queries\&. .sp See also \fB\-\-tree\fR and \fB\-\-query\fR\&. .PP \fB\-n, \-\-list\-notifies=[\fR\fB\fIclass\fR\fR\fB]\fR .RS 4 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\&. .RE .PP \fB\-i, \-\-list\-indexes=[\fR\fB\fIproperty\fR\fR\fB]\fR .RS 4 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\&. .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \-g, \-\-list\-graphs:: List all the named graphs in the database\&. These are used by the filesystem miner to separate metadata so that apps can only see the information relevant to them\&. .RE .RE .PP \fB\-t, \-\-tree=[\fR\fB\fIclass\fR\fR\fB]\fR .RS 4 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: .RE .sp .if n \{\ .RS 4 .\} .nf $ tracker3 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 n \{\ .RE .\} .sp If no \fIclass\fR is given, the entire tree is shown\&. .sp The \fB\-\-search\fR command line option can be used to highlight parts of the tree you\(cqre looking for\&. The search is case insensitive\&. .sp The \fB\-\-properties\fR command line option can be used to show properties for each class displayed, for example: .sp .if n \{\ .RS 4 .\} .nf $ tracker3 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) | \-\-> nrl:added (P) | \-\-> nrl:damaged (P) | \-\-> nrl: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 .if n \{\ .RE .\} .PP \fB\-s, \-\-search=<\fR\fB\fIneedle\fR\fR\fB>\fR .RS 4 Returns a list of classes and properties which partially match \fIneedle\fR in the ontology\&. This is a case insensitive match, for example: .RE .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-s text Classes: 4 http://tracker\&.api\&.gnome\&.org/ontology/v3/nfo#TextDocument http://tracker\&.api\&.gnome\&.org/ontology/v3/nfo#PlainTextDocument http://tracker\&.api\&.gnome\&.org/ontology/v3/nfo#PaginatedTextDocument http://tracker\&.api\&.gnome\&.org/ontology/v3/nmm#SynchronizedText Properties: 4 http://tracker\&.api\&.gnome\&.org/ontology/v3/tracker#fulltextIndexed http://tracker\&.api\&.gnome\&.org/ontology/v3/nie#plainTextContent http://tracker\&.api\&.gnome\&.org/ontology/v3/nmo#plainTextMessageContent http://tracker\&.api\&.gnome\&.org/ontology/v3/scal#textLocation .fi .if n \{\ .RE .\} .sp See also \fB\-\-tree\fR\&. .PP \fB\-\-get\-shorthand=<\fR\fB\fIclass\fR\fR\fB>\fR .RS 4 Returns the shorthand for a class given by a URL\&. For example: .RE .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-\-get\-shorthand http://tracker\&.api\&.gnome\&.org/ontology/v3/nmo#plainTextMessageContent nmo:plainTextMessageContent .fi .if n \{\ .RE .\} .PP \fB\-\-get\-longhand=<\fR\fB\fIclass\fR\fR\fB>\fR .RS 4 Returns the longhand for a class given in the form of CLASS:PROPERTY\&. For example: .RE .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-\-get\-longhand nmm:MusicPiece http://tracker\&.api\&.gnome\&.org/ontology/v3/nmm#MusicPiece .fi .if n \{\ .RE .\} .SH "EXAMPLES" .PP List all classes .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?cl WHERE { ?cl a rdfs:Class }" .fi .if n \{\ .RE .\} .RE .PP List all properties for the Resources class (see \-\-list\-properties) .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?prop WHERE { ?prop a rdf:Property ; rdfs:domain }" .fi .if n \{\ .RE .\} .RE .PP List all class namespace prefixes .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?prefix ?ns WHERE { ?ns a nrl:Namespace ; nrl:prefix ?prefix }" .fi .if n \{\ .RE .\} .RE .PP List all music files .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?song WHERE { ?song a nmm:MusicPiece }" .fi .if n \{\ .RE .\} .RE .PP List all music albums, showing title, track count, and length in seconds\&. .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 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 .if n \{\ .RE .\} .RE .PP List all music from a particular artist .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?song ?title WHERE { ?song nmm:performer [ nmm:artistName \*(AqArtist Name\*(Aq ] ; nie:title ?title }" .fi .if n \{\ .RE .\} .RE .PP Set the played count for a song .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-u \-q "DELETE { nie:usageCounter ?count } WHERE { nie:usageCounter ?count } INSERT { nie:usageCounter 42 }" .fi .if n \{\ .RE .\} .RE .PP List all image files .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?image WHERE { ?image a nfo:Image }" .fi .if n \{\ .RE .\} .RE .PP List all image files with a specific tag .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?image WHERE { ?image a nfo:Image ; nao:hasTag [ nao:prefLabel \*(Aqtag\*(Aq ] }" .fi .if n \{\ .RE .\} .RE .PP List all image files created on a specific month and order by date .RS 4 .sp .if n \{\ .RS 4 .\} .nf $ tracker3 sparql \-q "SELECT ?image ?date WHERE { ?image a nfo:Image ; nie:contentCreated ?date \&. FILTER (?date >= \*(Aq2008\-07\-01T00:00:00\*(Aq && ?date < \*(Aq2008\-08\-01T00:00:00\*(Aq) } ORDER BY ?date" .fi .if n \{\ .RE .\} .RE .SH "SEE ALSO" .sp \fBtracker3\-sql\fR(1), \fBtracker3\-info\fR(1)\&. .sp \fBhttp://nepomuk\&.semanticdesktop\&.org/\fR \fBhttp://www\&.w3\&.org/TR/rdf\-sparql\-query/\fR