1tracker-sparql(1)                User Commands               tracker-sparql(1)
2
3
4

NAME

6       tracker-sparql - Use SparQL to query the Tracker databases.
7
8

SYNOPSIS

10       tracker-sparql [OPTION...] [-q QUERY] | [-f FILE]
11
12

DESCRIPTION

14       tracker-sparql  allows  the caller to run an RDF query on the database.
15       This can be done two ways. Either by providing a FILE with the query or
16       by providing a string with the QUERY string.
17
18       The FILE argument can be either a local path or a URI. It also does not
19       have to be an absolute path.
20
21

OPTIONS

23       -?, --help
24              Show summary of options.
25
26       -f, --file=FILE
27              Use a FILE with SPARQL content to query or update.
28
29       -q, --query=SPARQL
30              Use a SPARQL string to query the database with.
31
32       -u, --update
33              This has to be used with --query.  This tells tracker-sparql  to
34              use  the SPARQL update extensions so it knows it isn't a regular
35              data lookup request. So if your query is intended to change data
36              in the database, this option is needed.
37
38       -c, --list-classes
39              Returns  a  list of classes which describe the ontology used for
40              storing data. These classes are also used in queries. For  exam‐
41              ple,  http://www.w3.org/2000/01/rdf-schema#Resource  is  one  of
42              many classes which should be returned here.
43
44       -x, --list-class-prefixes
45              Returns a list of classes and their related  prefixes.  Prefixes
46              are  used  to  make  querying a lot simpler and are much like an
47              alias.     For      example,      http://www.w3.org/2000/01/rdf-
48              schema#Resource  has  the prefix rdfs so queries can be cut down
49              to:
50
51              "SELECT ?u WHERE { ?u a rdfs:Resource }"
52
53
54       -p, --list-properties=CLASS
55              Returns a list of properties which pertain to a class.  You  can
56              use  both  formats  here  for  the  class,  either the full name
57              http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video
58              or the shortened prefix name nfo:Video.
59
60              This gives the following result:
61
62              $ tracker-sparql -p nfo:Video
63
64              Properties: 2
65                http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fram‐
66              eRate
67                http://www.semanticdesktop.org/ontolo
68              gies/2007/03/22/nfo#frameCount
69
70              These properties nfo:frameRate and nfo:frameCount can be used in
71              more complex queries (see --query).
72
73
74       -n, --list-notifies=CLASS
75              Returns a list of classes which are notified  over  D-Bus  about
76              any  changes  that occur in the database. CLASS does not have to
77              be supplied here. This  is  optional  and  filters  the  results
78              according  to  any argument supplied. With no CLASS, all classes
79              are listed.
80
81
82       -s, --search=TERM
83              Returns a list of classes and properties which  partially  match
84              TERM  in  the  ontology.  This  is a case insensitive match, for
85              example:
86
87              $ tracker-sparql -s text
88
89              Classes: 4
90                http://www.semanticdesktop.org/ontolo
91              gies/2007/03/22/nfo#TextDocument
92                http://www.semanticdesktop.org/ontolo
93              gies/2007/03/22/nfo#PlainTextDocument
94                http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Pagi‐
95              natedTextDocument
96                http://www.tracker-project.org/temp/nmm#SynchronizedText
97
98              Properties: 5
99                http://www.tracker-project.org/ontologies/tracker#fulltextIn‐
100              dexed
101                http://www.tracker-project.org/ontologies/tracker#fulltextNo‐
102              Limit
103                http://www.semanticdesktop.org/ontolo
104              gies/2007/01/19/nie#plainTextContent
105                http://www.semanticdesktop.org/ontolo
106              gies/2007/03/22/nmo#plainTextMessageContent
107                http://www.tracker-project.org/temp/scal#textLocation
108
109       -V, --version
110              Print version.
111
112

EXAMPLES

114       List all classes
115
116               $ tracker-sparql -q "SELECT ?cl WHERE { ?cl a rdfs:Class }"
117
118
119       List all properties for the Resources class (see --list-properties)
120
121               $ tracker-sparql -q "SELECT ?prop WHERE {
122                    ?prop a rdf:Property ;
123                    rdfs:domain                <http://www.w3.org/2000/01/rdf-
124              schema#Resource>
125               }"
126
127
128       List all class namespace prefixes
129
130               $ tracker-sparql -q "SELECT ?prefix ?ns WHERE {
131                    ?ns a tracker:Namespace ;
132                    tracker:prefix ?prefix
133               }"
134
135
136       List all music files
137
138               $ tracker-sparql -q "SELECT ?song WHERE {  ?song  a  nmm:Music‐
139              Piece }"
140
141
142       List all music albums
143
144               $ tracker-sparql -q "SELECT ?album ?title COUNT(?song)
145                                   AS songs
146                                   SUM(?length) AS totallength
147                                   WHERE {
148                    ?album a nmm:MusicAlbum ;
149                    nie:title ?title .
150                    ?song nmm:musicAlbum ?album ;
151                    nfo:duration ?length
152               } GROUP BY ?album"
153
154
155       List all music from a particular artist
156
157               $ tracker-sparql -q "SELECT ?song ?title WHERE {
158                    ?song nmm:performer [ nmm:artistName 'Artist Name' ] ;
159                    nie:title ?title
160               }"
161
162
163       Set the played count for a song
164
165               $ tracker-sparql -u -q "DELETE {
166                    <file:///home/user/Music/song.mp3> nie:usageCounter ?count
167               } WHERE {
168                    <file:///home/user/Music/song.mp3> nie:usageCounter ?count
169               } INSERT {
170                    <file:///home/user/Music/song.mp3> nie:usageCounter 42
171               }"
172
173
174       List all image files
175
176                $  tracker-sparql -q "SELECT ?image WHERE { ?image a nfo:Image
177              }"
178
179
180       List all image files with a specific tag
181
182               $ tracker-sparql -q "SELECT ?image WHERE {
183                    ?image a nfo:Image ;
184                    nao:hasTag [ nao:prefLabel 'tag' ]
185               }"
186
187
188       List all image files created on a specific month and order by date
189
190               $ tracker-sparql -q "SELECT ?image ?date WHERE {
191                    ?image a nfo:Image ;
192                    nie:contentCreated ?date .
193                    FILTER (?date >= '2008-07-01T00:00:00' &&
194                            ?date <  '2008-08-01T00:00:00')
195               } ORDER BY ?date"
196
197

SEE ALSO

199       tracker-store(1), tracker-info(1).
200
201       http://nepomuk.semanticdesktop.org/
202
203       http://www.w3.org/TR/rdf-sparql-query/
204
205
206
207GNU                                July 2009                 tracker-sparql(1)
Impressum