1TRACKER3-SPARQL(1) Tracker manual TRACKER3-SPARQL(1)
2
3
4
6 tracker3-sparql - Use SparQL to query the Tracker databases.
7
9 tracker3 sparql -q <sparql> [-u] | -f <file>
10 tracker3 sparql -t [class] [-s <needle>] [-p]
11 tracker3 sparql [-c] [-p] [-x] [-n [class]] [-i [property]] [-s <needle>]
12 tracker3 sparql [--get-longhand <class>] [--get-shorthand <class>]
13
15 This command allows probing of the current database schema (also known
16 as ontology) and running low level queries or updates on the data set.
17 In terms of the database ontology, it’s easy to find out what
18 properties are indexed for speed, or notified on changes, what classes
19 are available and the properties belonging to those classes. There are
20 also visual tools to display an ascii tree layout of the classes and
21 their relationships to each other.
22
23 When the caller runs a query, the query is in RDF and SPARQL. This can
24 be done two ways. Either by providing a file with the query or by
25 providing a string with the sparql query.
26
27 The file argument can be either a local path or a URI. It also does not
28 have to be an absolute path.
29
31 -f, --file=<file>
32 Use a file with SPARQL content to query or update.
33
34 -q, --query=<sparql>
35 Use a sparql string to query the database with.
36
37 -u, --update
38 This has to be used with --query. This tells "tracker3 sparql" to
39 use the SPARQL update extensions so it knows it isn’t a regular
40 data lookup request. So if your query is intended to change data in
41 the database, this option is needed.
42
43 -c, --list-classes
44 Returns a list of classes which describe the ontology used for
45 storing data. These classes are also used in queries. For example,
46 http://www.w3.org/2000/01/rdf-schema#Resource is one of many
47 classes which should be returned here.
48
49 -x, --list-class-prefixes
50 Returns a list of classes and their related prefixes. Prefixes are
51 used to make querying a lot simpler and are much like an alias. For
52 example, http://www.w3.org/2000/01/rdf-schema#Resource has the
53 prefix rdfs so queries can be cut down to:
54
55 "SELECT ?u WHERE \{ ?u a rdfs:Resource }"
56
57 -p, --list-properties=[class]
58 Returns a list of properties which pertain to a class. You can use
59 both formats here for the class, either the full name
60 http://tracker.api.gnome.org/ontology/v3/nfo#Video or the shortened
61 prefix name nfo:Video.
62
63 This gives the following result:
64
65 $ tracker3 sparql -p nfo:Video
66
67 Properties: 2
68 http://tracker.api.gnome.org/ontology/v3/nfo#frameRate
69 http://tracker.api.gnome.org/ontology/v3/nfo#frameCount
70
71 These properties nfo:frameRate and nfo:frameCount can then be used in
72 queries.
73
74 See also --tree and --query.
75
76 -n, --list-notifies=[class]
77 Returns a list of classes which are notified over D-Bus about any
78 changes that occur in the database. The class does not have to be
79 supplied here. This is optional and filters the results according
80 to any argument supplied. With no class, all classes are listed.
81
82 -i, --list-indexes=[property]
83 Returns a list of properties which are indexed in the database.
84 Indexes improves query speed but also add an indexing penalty. The
85 property does not have to be supplied here. This is optional and
86 filters the results according to any argument supplied. With no
87 property, all properties are listed.
88
89 • -g, --list-graphs:: List all the named graphs in the database.
90 These are used by the filesystem miner to separate metadata so
91 that apps can only see the information relevant to them.
92
93 -t, --tree=[class]
94 Prints a tree showing all parent classes of class in the ontology.
95 The class can be provided in shorthand or longhand (see
96 --get-shorthand and --get-longhand for details). For example:
97
98 $ tracker3 sparql -t nmo:MMSMessage
99 ROOT
100 +-- rdfs:Resource (C)
101 | +-- nie:InformationElement (C)
102 | | +-- nfo:Document (C)
103 | | | +-- nfo:TextDocument (C)
104 | | | | `-- nmo:Message (C)
105 | | | | | +-- nmo:PhoneMessage (C)
106 | | | | | | `-- nmo:MMSMessage (C)
107
108 If no class is given, the entire tree is shown.
109
110 The --search command line option can be used to highlight parts of the
111 tree you’re looking for. The search is case insensitive.
112
113 The --properties command line option can be used to show properties for
114 each class displayed, for example:
115
116 $ tracker3 sparql -t nfo:FileDataObject -p
117 ROOT
118 +-- rdfs:Resource (C)
119 | --> http://purl.org/dc/elements/1.1/contributor (P)
120 | --> http://purl.org/dc/elements/1.1/coverage (P)
121 | --> http://purl.org/dc/elements/1.1/creator (P)
122 | --> http://purl.org/dc/elements/1.1/date (P)
123 | --> http://purl.org/dc/elements/1.1/description (P)
124 | --> http://purl.org/dc/elements/1.1/format (P)
125 | --> http://purl.org/dc/elements/1.1/identifier (P)
126 | --> http://purl.org/dc/elements/1.1/language (P)
127 | --> http://purl.org/dc/elements/1.1/publisher (P)
128 | --> http://purl.org/dc/elements/1.1/relation (P)
129 | --> http://purl.org/dc/elements/1.1/rights (P)
130 | --> http://purl.org/dc/elements/1.1/source (P)
131 | --> http://purl.org/dc/elements/1.1/subject (P)
132 | --> http://purl.org/dc/elements/1.1/title (P)
133 | --> http://purl.org/dc/elements/1.1/type (P)
134 | --> nao:deprecated (P)
135 | --> nao:hasTag (P)
136 | --> nao:identifier (P)
137 | --> nao:isRelated (P)
138 | --> nao:lastModified (P)
139 | --> nao:numericRating (P)
140 | --> rdf:type (P)
141 | --> rdfs:comment (P)
142 | --> rdfs:label (P)
143 | --> nrl:added (P)
144 | --> nrl:damaged (P)
145 | --> nrl:modified (P)
146 | +-- nie:DataObject (C)
147 | | --> nfo:belongsToContainer (P)
148 | | --> nie:byteSize (P)
149 | | --> nie:created (P)
150 | | --> nie:dataSource (P)
151 | | --> nie:interpretedAs (P)
152 | | --> nie:isPartOf (P)
153 | | --> nie:lastRefreshed (P)
154 | | --> nie:url (P)
155 | | --> tracker:available (P)
156 | | +-- nfo:FileDataObject (C)
157 | | | --> nfo:fileCreated (P)
158 | | | --> nfo:fileLastAccessed (P)
159 | | | --> nfo:fileLastModified (P)
160 | | | --> nfo:fileName (P)
161 | | | --> nfo:fileOwner (P)
162 | | | --> nfo:fileSize (P)
163 | | | --> nfo:hasHash (P)
164 | | | --> nfo:permissions (P)
165
166 -s, --search=<needle>
167 Returns a list of classes and properties which partially match
168 needle in the ontology. This is a case insensitive match, for
169 example:
170
171 $ tracker3 sparql -s text
172
173 Classes: 4
174 http://tracker.api.gnome.org/ontology/v3/nfo#TextDocument
175 http://tracker.api.gnome.org/ontology/v3/nfo#PlainTextDocument
176 http://tracker.api.gnome.org/ontology/v3/nfo#PaginatedTextDocument
177 http://tracker.api.gnome.org/ontology/v3/nmm#SynchronizedText
178
179 Properties: 4
180 http://tracker.api.gnome.org/ontology/v3/tracker#fulltextIndexed
181 http://tracker.api.gnome.org/ontology/v3/nie#plainTextContent
182 http://tracker.api.gnome.org/ontology/v3/nmo#plainTextMessageContent
183 http://tracker.api.gnome.org/ontology/v3/scal#textLocation
184
185 See also --tree.
186
187 --get-shorthand=<class>
188 Returns the shorthand for a class given by a URL. For example:
189
190 $ tracker3 sparql --get-shorthand http://tracker.api.gnome.org/ontology/v3/nmo#plainTextMessageContent
191 nmo:plainTextMessageContent
192
193 --get-longhand=<class>
194 Returns the longhand for a class given in the form of
195 CLASS:PROPERTY. For example:
196
197 $ tracker3 sparql --get-longhand nmm:MusicPiece
198 http://tracker.api.gnome.org/ontology/v3/nmm#MusicPiece
199
201 List all classes
202
203 $ tracker3 sparql -q "SELECT ?cl WHERE { ?cl a rdfs:Class }"
204
205 List all properties for the Resources class (see --list-properties)
206
207 $ tracker3 sparql -q "SELECT ?prop WHERE {
208 ?prop a rdf:Property ;
209 rdfs:domain <http://www.w3.org/2000/01/rdf-schema#Resource>
210 }"
211
212 List all class namespace prefixes
213
214 $ tracker3 sparql -q "SELECT ?prefix ?ns WHERE {
215 ?ns a nrl:Namespace ;
216 nrl:prefix ?prefix
217 }"
218
219 List all music files
220
221 $ tracker3 sparql -q "SELECT ?song WHERE { ?song a nmm:MusicPiece }"
222
223 List all music albums, showing title, track count, and length in
224 seconds.
225
226 $ tracker3 sparql -q "SELECT ?title COUNT(?song)
227 AS songs
228 SUM(?length) AS totallength
229 WHERE {
230 ?album a nmm:MusicAlbum ;
231 nie:title ?title .
232 ?song nmm:musicAlbum ?album ;
233 nfo:duration ?length
234 } GROUP BY ?album"
235
236 List all music from a particular artist
237
238 $ tracker3 sparql -q "SELECT ?song ?title WHERE {
239 ?song nmm:performer [ nmm:artistName 'Artist Name' ] ;
240 nie:title ?title
241 }"
242
243 Set the played count for a song
244
245 $ tracker3 sparql -u -q "DELETE {
246 <file:///home/user/Music/song.mp3> nie:usageCounter ?count
247 } WHERE {
248 <file:///home/user/Music/song.mp3> nie:usageCounter ?count
249 } INSERT {
250 <file:///home/user/Music/song.mp3> nie:usageCounter 42
251 }"
252
253 List all image files
254
255 $ tracker3 sparql -q "SELECT ?image WHERE { ?image a nfo:Image }"
256
257 List all image files with a specific tag
258
259 $ tracker3 sparql -q "SELECT ?image WHERE {
260 ?image a nfo:Image ;
261 nao:hasTag [ nao:prefLabel 'tag' ]
262 }"
263
264 List all image files created on a specific month and order by date
265
266 $ tracker3 sparql -q "SELECT ?image ?date WHERE {
267 ?image a nfo:Image ;
268 nie:contentCreated ?date .
269 FILTER (?date >= '2008-07-01T00:00:00' &&
270 ?date < '2008-08-01T00:00:00')
271 } ORDER BY ?date"
272
274 tracker3-sql(1), tracker3-info(1).
275
276 http://nepomuk.semanticdesktop.org/
277 http://www.w3.org/TR/rdf-sparql-query/
278
279
280
281 3.6.0 09/19/2023 TRACKER3-SPARQL(1)