Parent: [06b414] (diff)

Download this file

index.txt    446 lines (367 with data), 13.2 kB

  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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
= Indexing PDF XMP-metadata with Recoll
The original document describing XMP metadata usage with Recoll was
written by Jeffrey Dick and is link:original-text.html[still available
here]. However it described using the old shell-based PDF Recoll input
handler, which differs a lot from doing something equivalent with the
current Python-based one (for which XMP capability is available from
recoll 1.23.2, but the new handler can be used with previous Recoll
versions).
I based this page on the text by Jeffrey Dick, using input from Johannes
Menzel for all examples about the new features. The discussion which led to
the updated handler is a
link:https://bitbucket.org/medoc/recoll/issues/300/extracting-xmp-metadata-and-tmsu-tags[Bitbucket
Recoll issue].
== Introduction
Organizing and searching a large collection of PDFs as part of a
research project can be a demanding task.
link:http://en.wikipedia.org/wiki/Extensible_Metadata_Platform[XMP
metadata] stored in a PDF, such as journal title, publication year,
and user-added keywords, are often useful when searching for a
publication.
Here, we describe customizing Recoll to retrieve this metadata, store it,
and defining a result paragraph format to display it. See also a related
wiki entry,
link:http://www.recoll.org/faqsandhowtos/HandleCustomField.html[Generating
a custom field and using it to sort results], for sorting results on PDF
page count.
== Saving metadata to PDFs
Bibliographic metadata can be saved in the PDF file itself. In
the link:http://jabref.sourceforge.net[JabRef] bibliography
manager, this is done with the "Write XMP-metadata to PDFs" menu
item. Note the presence of the keywords in the screenshot below; this
field is a good place to tag the PDF with any words of your choosing
to describe genre, topic, etc.
image::jabref_metadata.png[Editing metadata with jabref]
== Custom indexing short example (fields file)
The following example (extract from a complete configuration shown later)
creates two fields named "refjournal" and "refpages", which are both stored
(so they can be displayed in result list entries), and indexed (you can
specifically search them).
Some other types of metadata, such as title, author and keywords, are
already indexed by Recoll (the default rclpdf finds them using the
*pdftotext* command) so there is no need to add those to the [prefixes]
section.
This is taken from the `fields` file inside the configuration
(e.g. '~/.recoll/fields').
----
[prefixes]
refjournal=RFJOURNAL
refpages=RFPAGES
[stored]
refjournal =
refpages =
[aliases]
refjournal = bibtex:journal bibtex:journaltitle
refpages = bibtex:pages
----
== Telling the handler what fields to extract
As of Recoll 1.23.2, the PDF handler has the capability to use *pdfinfo*
for extracting XMP metadata. The switch for executing *pdfinfo* is the
'pdfextrameta' configuration parameter, and the value of the parameter is a
list of XMP tags to extract, with optional conversion to Recoll field names
(the XMP qualified tag name is kept by default, the translation is
separated by a '|' character). Example (without translations):
----
pdfextrameta = bibtex:year bibtex:journal bibtex:journaltitle
----
Note that it is quite equivalent to translate a field name inside
'pdfextrameta' or to uses aliases inside the 'fields' file.
== Editing the field values
Shortly after the 1.23.2 release, the new rclpdf.py was modified to
enable calling external Python code for editing the values of the XMP
metadata fields. The name of the external script is defined by the
'pdfextrametafix' configuration variable, and it should define a
'MetaFixer' class, with a 'metafix()' method.
In practise, add the following to recoll.conf:
----
pdfextrametafix = /path/to/my/script.py
----
The Python script could look like the following:
----
import sys
import re
# This can be used for local XMP field editing.
#
# A new instance is created for each PDF document (so the object could
# keep state to avoid, e.g. duplicate values)
#
# The metafix method receives an (original) field name, and the text
# value, and should return the possibly modified text.
class MetaFixer(object):
def __init__(self):
pass
def metafix(self, nm, txt):
if nm == 'bibtex:pages':
txt = re.sub(r'--', '-', txt)
elif nm == 'someothername':
# do something else
pass
elif nm == 'stillanother':
# etc.
pass
return txt
----
The metadata-editing script can be modified to fill in the "journal" field for
BibTex entries that aren't journal articles (e.g. bibtex:booktitle
for "InCollection" entries), by defining a 'wrapup()' method which will
be called with the whole metadata array (an array of '(nm,value)'
pairs) for global editing/removing/addition.
== Indexing
Then index away!
Note that you can also run the rclpdf.py script manually,
e.g. `rclpdf.py -d /path/to/some.pdf`, to inspect the
output. If things are working correctly, the <head> consists of the
HTML meta elements, and the <body> contains the text of the PDF.
== Result paragraph format
The result paragraph format defines what fields are displayed inside Recoll
result list, and how they are formatted.
Edit this using the Recoll GUI: Preferences > GUI configuration >
Result List > Edit result paragraph format string.
----
<table class="respar" style="padding-bottom: 10px;" cellspacing="5" cellpadding="5">
<thead style="vertical-align: top;">
<tr>
<td colspan="3" style="border-bottom: 1pt dotted #004070; font-size: smaller;"><a href="E%N">%u</a> | %S | Relevanz: %R</td>
</tr>
</thead>
<tbody style="vertical-align: top;">
<tr>
<td><a href="P%N"><img src="%I" alt="" width="64" height="auto" /></a></td>
<td style="width: 250px;"><span style="color: #004070;">
<div style="font-style: italic;">%(author)</div>
<div style="font-weight: bold;"><a href="E%N">&raquo;%T&laquo;</a></div>
<div style="text-transform: uppercase; margin-top: 5pt">%(reftype)</div></td>
<td>
<div style="font-size: smaller;">
%(refauthor)%(refchapter) %(reftitle)%(refeditor)%(refbooktitle)%(refjournal)%(refvolume)%(refnumber)%(refaddress)%(reflocation)%(refpublisher)%(refyear)%(refpages).</div>
<div style="text-align: justify; font-family: serif; margin-top: 5pt; margin-bottom: 5pt">&raquo;<a href="A%N">%A</a>&laquo;</div>
<div>%(refkeywords)</div>
<div style="font-size: smaller;"><a href="%(refurl)">%(refurl)</a></div>
<div style="font-size: smaller"> %(refkey) %(refisbn) %(refissn) %(refdoi)</div></td>
</tr>
</tbody>
</table>
----
And the result list header (Preferences > GUI configuration >
Result List > Result Page HTML header insert):
----
<!-- Custom Header -->
<script type="text/javascript">
function altRows() {
var rows = document.getElementsByClassName("rclresult");
for (i = 0; i < rows.length; i++) {
if (i % 2 == 0) {
rows[i].style.backgroundColor = "#f0f0f0";
}
}
}
window.onload = function() {
altRows();
}
</script>
<style type="text/css">
a:link {
color: #004070;
text-decoration: none;
}
a:visited {
color: #004070;
text-decoration: none;
}
a:hover {
color: #0050a0;
text-decoration: none;
}
a:active {
color: #005080;
text-decoration: none;
}
</style>
<!-- End of Custom Header -->
----
There are
link:http://www.recoll.org/faqsandhowtos/ResultsThumbnails.html[various
methods for creating the thumbnails]; the ones here were made by opening
the directory containing the PDFs in the Dolphin file manager (part of KDE)
and selecting the Preview option.
And the result:
image::recoll_query.png[Result list display]
== More possibilities
- The sort buttons (up- and down-arrows) in Recoll sort the
results by the modified date on the file at the time of indexing. If
you want this sorting to reflect the publication year, then the
timestamp should be set accordingly. If names of the PDFs contain
the year (e.g. BZS2007.pdf, CKE+2011.pdf), the following one-liner
would set the modified date to January 1st of the year:
----
for i in `ls *.pdf`; do touch -d `echo $i | sed 's/[^0-9]*//g'`-01-01 $i; done
----
Note that the publication year could then be shown in
the result list using the stored date of the file (using "%D" in the
result paragraph format, and date format "%Y") instead of having to
add the year to the index as shown above.
== Complete example
This was designed by Johannes Menzel, who kindly provided the data when we
worked on improving PDF XMP data extraction. The originals are listed in
this
link:https://bitbucket.org/medoc/recoll/issues/300/extracting-xmp-metadata-and-tmsu-tags[BitBucket issue]
The paragraph format is listed above.
=== 'recoll.conf' additions:
----
pdfextrameta = bibtex:journal bibtex:journaltitle bibtex:pages \
bibtex:volume bibtex:number bibtex:booktitle bibtex:year bibtex:author \
bibtex:title bibtex:isbn bibtex:issn bibtex:editor bibtex:address \
bibtex:location bibtex:doi bibtex:chapter bibtex:url bibtex:entrytype \
bibtex:bibtexkey bibtex:abstract bibtex:date bibtex:keywords \
bibtex:comment bibtex:language bibtex:edition bibtex:totalpages \
dc:creator dc:relation dc:publisher dc:title dc:type dc:identifier
defaultcharset = UTF-8//
pdfextrametafix = /home/hannes/.recoll/metafix.py
----
=== 'metafix.py' script:
----
import sys
import re
# This can be used for local XMP field editing.
#
# A new instance is created for each PDF document (so the object could
# keep state to avoid, e.g. duplicate values)
#
# The metafix method receives an (original) field name, and the text
# value, and should return the possibly modified text.
class MetaFixer(object):
def __init__(self):
pass
def metafix(self, nm, txt):
if nm == 'bibtex:pages':
txt = re.sub(r'--', '-', txt)
txt = re.sub(r'^', ', p. ', txt)
elif nm == 'bibtex:author':
txt = re.sub(r'$', ':\ ', txt)
pass
elif nm == 'bibtex:chapter':
txt = re.sub(r'^', ', in: id.: ', txt)
pass
elif nm == 'bibtex:editor':
txt = re.sub(r'^', ', in: ', txt)
txt = re.sub(r'$', ' (ed.):\ ', txt)
pass
elif nm == 'bibtex:year':
txt = re.sub(r'^', ', ', txt)
pass
elif nm == 'bibtex:date':
txt = re.sub(r'^', ', ', txt)
pass
elif nm == 'bibtex:volume':
txt = re.sub(r'^', ', vol. ', txt)
pass
elif nm == 'bibtex:number':
txt = re.sub(r'^', ', no. ', txt)
pass
elif nm == 'bibtex:journaltitle':
txt = re.sub(r'^', ', in: ', txt)
pass
elif nm == 'bibtex:journal':
txt = re.sub(r'^', ', in: ', txt)
pass
elif nm == 'bibtex:title':
txt = re.sub(r'^', '"', txt)
txt = re.sub(r'$', '"', txt)
pass
elif nm == 'bibtex:location':
txt = re.sub(r'^', ', ', txt)
txt = re.sub(r'$', ':\ ', txt)
pass
elif nm == 'bibtex:address':
txt = re.sub(r'^', ', ', txt)
txt = re.sub(r'$', ':\ ', txt)
pass
elif nm == 'bibtex:isbn':
txt = re.sub(r'^', 'ISBN: ', txt)
pass
elif nm == 'bibtex:issn':
txt = re.sub(r'^', 'ISSN: ', txt)
pass
elif nm == 'bibtex:doi':
txt = re.sub(r'^', 'DOI: ', txt)
pass
elif nm == 'bibtex:bibtexkey':
txt = re.sub(r'^', 'Key: ', txt)
pass
return txt
----
=== 'fields' file:
----
[prefixes]
refjournal=RFJOURNAL
refpages=RFPAGES
reftitle=RFTTITLE
refvolume=RFVOLUME
refauthor=RFAUTHOR
refyear=RFYYEAR
refisbn=RFISBN
refissn=RFISSN
refdoi=RFDOI
refeditor=RFEDITOR
refpublisher=RFPUBLISHER
refaddress=RFADDRESS
reflocation=RFLOCATION
refbooktitle=RFBOOKTITLE
refurl=RFURL
reftype=RFTYPE
refkey=RFKEY
refabstract=RFABSTRACT
refkeywords=RFKEYWORDS
refcomment=RFCOMMENT
refedition=RFEDITION
reflanguage=RFLANGUAGE
[stored]
refjournal=
refpages=
reftitle=
refvolume=
refauthor=
refyear=
refisbn=
refissn=
refdoi=
refeditor=
refpublisher=
refaddress=
reflocation=
refbooktitle=
refurl=
reftype=
refkey=
refabstract=
refkeywords=
refcomment=
refedition=
reflanguage=
refid=
[aliases]
refjournal = bibtex:journal bibtex:journaltitle
refpages = bibtex:pages
reftitle = bibtex:title
refvolume = bibtex:volume
refauthor = bibtex:author
refyear = bibtex:year bibtex:date
refid = dc:identifier bibtex:isbn bibtex:issn
refisbn = bibtex:isbn
refissn = bibtex:issn
refdoi = bibtex:doi
refeditor = bibtex:editor
refpublisher = bibtex:publisher
refaddress = bibtex:address
reflocation = bibtex:location
refbooktitle = bibtex:booktitle
refurl = bibtex:url
reftype = bibtex:entrytype bibtex:type
refkey = bibtex:bibtexkey
refabstract = bibtex:abstract
refkeywords = bibtex:keywords
refcomment = bibtex:comment
refedition = bibtex:edition
reflanguage = bibtex:language
author = xesam:author
----