1tracker-sparql(1) User Commands tracker-sparql(1)
2
3
4
6 tracker-sparql - Use SparQL to query the Tracker databases.
7
8
10 tracker sparql -q <sparql> [-u] | -f <file>
11 tracker sparql -t [class] [-s <needle>] [-p]
12 tracker sparql [-c] [-p] [-x] [-n [class]] [-i [property]] [-s <needle>]
13 tracker sparql [--get-longhand <class>] [--get-shorthand <class>]
14
15
17 This command allows probing of the current database schema (also known
18 as ontology) and running low level queries or updates on the data set.
19 In terms of the database ontology, it's easy to find out what proper‐
20 ties are indexed for speed, or notified on changes, what classes are
21 available and the properties belonging to those classes. There are also
22 visual tools to display an ascii tree layout of the classes and their
23 relationships to each other.
24
25 When the caller runs a query, the query is in RDF and SPARQL. This can
26 be done two ways. Either by providing a file with the query or by pro‐
27 viding a string with the sparql query.
28
29 The file argument can be either a local path or a URI. It also does not
30 have to be an absolute path.
31
32
34 -f, --file=<file>
35 Use a file with SPARQL content to query or update.
36
37 -q, --query=<sparql>
38 Use a sparql string to query the database with.
39
40 -u, --update
41 This has to be used with --query. This tells "tracker sparql" to
42 use the SPARQL update extensions so it knows it isn't a regular
43 data lookup request. So if your query is intended to change data
44 in the database, this option is needed.
45
46 -c, --list-classes
47 Returns a list of classes which describe the ontology used for
48 storing data. These classes are also used in queries. For exam‐
49 ple, http://www.w3.org/2000/01/rdf-schema#Resource is one of
50 many classes which should be returned here.
51
52 -x, --list-class-prefixes
53 Returns a list of classes and their related prefixes. Prefixes
54 are used to make querying a lot simpler and are much like an
55 alias. For example, http://www.w3.org/2000/01/rdf-
56 schema#Resource has the prefix rdfs so queries can be cut down
57 to:
58
59 "SELECT ?u WHERE { ?u a rdfs:Resource }"
60
61
62 -p, --list-properties=[class]
63 Returns a list of properties which pertain to a class. You can
64 use both formats here for the class, either the full name
65 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video
66 or the shortened prefix name nfo:Video.
67
68 This gives the following result:
69
70 $ tracker sparql -p nfo:Video
71
72 Properties: 2
73 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameRate
74 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameCount
75
76 These properties nfo:frameRate and nfo:frameCount can then be
77 used in queries.
78
79 See also --tree and --query.
80
81
82 -n, --list-notifies=[class]
83 Returns a list of classes which are notified over D-Bus about
84 any changes that occur in the database. The class does not have
85 to be supplied here. This is optional and filters the results
86 according to any argument supplied. With no class, all classes
87 are listed.
88
89
90 -i, --list-indexes=[property]
91 Returns a list of properties which are indexed in the database.
92 Indexes improves query speed but also add an indexing penalty.
93 The property does not have to be supplied here. This is optional
94 and filters the results according to any argument supplied. With
95 no property, all properties are listed.
96
97
98 -t, --tree=[class]
99 Prints a tree showing all parent classes of class in the ontol‐
100 ogy. The class can be provided in shorthand or longhand (see
101 --get-shorthand and --get-longhand for details). For example:
102
103 $ tracker sparql -t nmo:MMSMessage
104 ROOT
105 +-- rdfs:Resource (C)
106 | +-- nie:InformationElement (C)
107 | | +-- nfo:Document (C)
108 | | | +-- nfo:TextDocument (C)
109 | | | | `-- nmo:Message (C)
110 | | | | | +-- nmo:PhoneMessage (C)
111 | | | | | | `-- nmo:MMSMessage (C)
112
113 If no class is given, the entire tree is shown.
114
115 The --search command line option can be used to highlight parts
116 of the tree you're looking for. The search is case insensitive.
117
118 The --properties command line option can be used to show proper‐
119 ties for each class displayed, for example:
120
121 $ tracker sparql -t nfo:FileDataObject -p
122 ROOT
123 +-- rdfs:Resource (C)
124 | --> http://purl.org/dc/elements/1.1/contributor (P)
125 | --> http://purl.org/dc/elements/1.1/coverage (P)
126 | --> http://purl.org/dc/elements/1.1/creator (P)
127 | --> http://purl.org/dc/elements/1.1/date (P)
128 | --> http://purl.org/dc/elements/1.1/description (P)
129 | --> http://purl.org/dc/elements/1.1/format (P)
130 | --> http://purl.org/dc/elements/1.1/identifier (P)
131 | --> http://purl.org/dc/elements/1.1/language (P)
132 | --> http://purl.org/dc/elements/1.1/publisher (P)
133 | --> http://purl.org/dc/elements/1.1/relation (P)
134 | --> http://purl.org/dc/elements/1.1/rights (P)
135 | --> http://purl.org/dc/elements/1.1/source (P)
136 | --> http://purl.org/dc/elements/1.1/subject (P)
137 | --> http://purl.org/dc/elements/1.1/title (P)
138 | --> http://purl.org/dc/elements/1.1/type (P)
139 | --> nao:deprecated (P)
140 | --> nao:hasTag (P)
141 | --> nao:identifier (P)
142 | --> nao:isRelated (P)
143 | --> nao:lastModified (P)
144 | --> nao:numericRating (P)
145 | --> rdf:type (P)
146 | --> rdfs:comment (P)
147 | --> rdfs:label (P)
148 | --> tracker:added (P)
149 | --> tracker:damaged (P)
150 | --> tracker:modified (P)
151 | +-- nie:DataObject (C)
152 | | --> nfo:belongsToContainer (P)
153 | | --> nie:byteSize (P)
154 | | --> nie:created (P)
155 | | --> nie:dataSource (P)
156 | | --> nie:interpretedAs (P)
157 | | --> nie:isPartOf (P)
158 | | --> nie:lastRefreshed (P)
159 | | --> nie:url (P)
160 | | --> tracker:available (P)
161 | | +-- nfo:FileDataObject (C)
162 | | | --> nfo:fileCreated (P)
163 | | | --> nfo:fileLastAccessed (P)
164 | | | --> nfo:fileLastModified (P)
165 | | | --> nfo:fileName (P)
166 | | | --> nfo:fileOwner (P)
167 | | | --> nfo:fileSize (P)
168 | | | --> nfo:hasHash (P)
169 | | | --> nfo:permissions (P)
170
171
172 -s, --search=<needle>
173 Returns a list of classes and properties which partially match
174 needle in the ontology. This is a case insensitive match, for
175 example:
176
177 $ tracker sparql -s text
178
179 Classes: 4
180 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#TextDocument
181 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PlainTextDocument
182 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PaginatedTextDocument
183 http://www.tracker-project.org/temp/nmm#SynchronizedText
184
185 Properties: 4
186 http://www.tracker-project.org/ontologies/tracker#fulltextIndexed
187 http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent
188 http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent
189 http://www.tracker-project.org/temp/scal#textLocation
190
191 See also --tree.
192
193
194 --get-shorthand=<class>
195 Returns the shorthand for a class given by a URL. For example:
196
197 $ tracker sparql --get-shorthand http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent
198 nmo:plainTextMessageContent
199
200
201 --get-longhand=<class>
202 Returns the longhand for a class given in the form of
203 CLASS:PROPERTY. For example:
204
205 $ tracker sparql --get-longhand nmm:MusicPiece
206 http://www.tracker-project.org/temp/nmm#MusicPiece
207
208
210 TRACKER_SPARQL_BACKEND
211 This option allows you to choose which backend you use for con‐
212 necting to the database. This choice can limit your functional‐
213 ity. There are three settings.
214
215 With "direct" the connection to the database is made directly to
216 the file itself on the disk, there is no intermediary daemon or
217 process. The "direct" approach is purely read-only.
218
219 With "bus" the tracker-store process is used to liase with the
220 database queuing all requests and managing the connections via
221 an IPC / D-Bus. This adds a small overhead BUT this is the only
222 approach you can use if you want to write to the database.
223
224 With "auto" the backend is decided for you, much like it would
225 be if this environment variable was undefined.
226
227
228 TRACKER_PRAGMAS_FILE
229 Tracker has a fixed set of PRAGMA settings for creating its
230 SQLite connection. With this environment variable pointing to a
231 text file you can override these settings. The file is a \n sep‐
232 arated list of SQLite queries to execute on any newly created
233 SQLite connection in tracker-store.
234
235
237 List all classes
238
239
240 $ tracker sparql -q "SELECT ?cl WHERE { ?cl a rdfs:Class }"
241
242
243 List all properties for the Resources class (see --list-properties)
244
245
246 $ tracker sparql -q "SELECT ?prop WHERE {
247 ?prop a rdf:Property ;
248 rdfs:domain <http://www.w3.org/2000/01/rdf-schema#Resource>
249 }"
250
251
252 List all class namespace prefixes
253
254
255 $ tracker sparql -q "SELECT ?prefix ?ns WHERE {
256 ?ns a tracker:Namespace ;
257 tracker:prefix ?prefix
258 }"
259
260
261 List all music files
262
263
264 $ tracker sparql -q "SELECT ?song WHERE { ?song a nmm:MusicPiece }"
265
266
267 List all music albums, showing title, track count, and length in sec‐
268 onds.
269
270
271 $ tracker sparql -q "SELECT ?title COUNT(?song)
272 AS songs
273 SUM(?length) AS totallength
274 WHERE {
275 ?album a nmm:MusicAlbum ;
276 nie:title ?title .
277 ?song nmm:musicAlbum ?album ;
278 nfo:duration ?length
279 } GROUP BY ?album"
280
281
282 List all music from a particular artist
283
284
285 $ tracker sparql -q "SELECT ?song ?title WHERE {
286 ?song nmm:performer [ nmm:artistName 'Artist Name' ] ;
287 nie:title ?title
288 }"
289
290
291 Set the played count for a song
292
293
294 $ tracker sparql -u -q "DELETE {
295 <file:///home/user/Music/song.mp3> nie:usageCounter ?count
296 } WHERE {
297 <file:///home/user/Music/song.mp3> nie:usageCounter ?count
298 } INSERT {
299 <file:///home/user/Music/song.mp3> nie:usageCounter 42
300 }"
301
302
303 List all image files
304
305
306 $ tracker sparql -q "SELECT ?image WHERE { ?image a nfo:Image }"
307
308
309 List all image files with a specific tag
310
311
312 $ tracker sparql -q "SELECT ?image WHERE {
313 ?image a nfo:Image ;
314 nao:hasTag [ nao:prefLabel 'tag' ]
315 }"
316
317
318 List all image files created on a specific month and order by date
319
320
321 $ tracker sparql -q "SELECT ?image ?date WHERE {
322 ?image a nfo:Image ;
323 nie:contentCreated ?date .
324 FILTER (?date >= '2008-07-01T00:00:00' &&
325 ?date < '2008-08-01T00:00:00')
326 } ORDER BY ?date"
327
328
330 tracker-sql(1), tracker-store(1), tracker-info(1).
331
332 http://nepomuk.semanticdesktop.org/
333
334 http://www.w3.org/TR/rdf-sparql-query/
335
336
337
338GNU July 2009 tracker-sparql(1)