summaryrefslogtreecommitdiff
path: root/docs/manpages/tracker-sparql.1
blob: b4a6b1cac6773539668efbebccf19db0f1e5b1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
.TH tracker-sparql 1 "July 2009" GNU "User Commands"

.SH NAME
tracker-sparql \- Use SparQL to query the Tracker databases.

.SH SYNOPSIS
\fBtracker-sparql\fR [\fIOPTION\fR...] [-q \fIQUERY\fR] | [-f \fIFILE\fR]

.SH DESCRIPTION
.B tracker-sparql
allows the caller to run an RDF query on the database. This can be
done two ways. Either by providing a \fIFILE\fR with the query or by
providing a string with the \fIQUERY\fR string.

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 \-?, \-\-help
Show summary of options.
.TP
.B \-f, \-\-file=FILE
Use a \fIFILE\fR with SPARQL content to query or update.
.TP
.B \-q, \-\-query=SPARQL
Use a \fISPARQL\fR string to query the database with.
.TP
.B \-u, \-\-update
This has to be used with 
.B \-\-query.
This tells
.B 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=CLASS
Returns a list of properties which pertain to a class. You can use
both formats here for the class, 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 be
used in more complex queries (see --query).

.TP
.B \-n, \-\-list-notifies=CLASS
Returns a list of classes which are notified over D-Bus about any
changes that occur in the database. \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=PROPERTY
Returns a list of properties which are indexed in the database.
Indexes improves query speed but also add an indexing penalty.
\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 \-s, \-\-search=TERM
Returns a list of classes and properties which partially match
\fITERM\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: 5
  http://www.tracker-project.org/ontologies/tracker#fulltextIndexed
  http://www.tracker-project.org/ontologies/tracker#fulltextNoLimit
  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
.TP
.B \-V, \-\-version
Print version.

.SH EXAMPLES
.TP
List all classes

.BR
$ tracker-sparql -q "SELECT ?cl WHERE { ?cl a rdfs:Class }"

.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 <http://www.w3.org/2000/01/rdf-schema#Resource>
 }"
.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
$ tracker-sparql -q "SELECT ?song WHERE { ?song a nmm:MusicPiece }"

.TP
List all music albums

.BR
.NF
$ tracker-sparql -q "SELECT ?album ?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 {
      <file:///home/user/Music/song.mp3> nie:usageCounter ?count
 } WHERE {
      <file:///home/user/Music/song.mp3> nie:usageCounter ?count
 } INSERT {
      <file:///home/user/Music/song.mp3> nie:usageCounter 42
 }"
.FI

.TP
List all image files

.BR
$ tracker-sparql -q "SELECT ?image WHERE { ?image a nfo:Image }"

.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-store (1),
.BR tracker-info (1).
.TP
.BR http://nepomuk.semanticdesktop.org/
.TP
.BR http://www.w3.org/TR/rdf-sparql-query/