1 ;;; planner-rdf.el --- RDF export for Emacs PlannerMode
3 ;; Copyright (C) 2004 Rainer Volz
4 ;; Parts copyright (C) 2005 Free Software Foundation, Inc.
6 ;; Author: Rainer Volz, http://www.rainervolz.de
8 ;; Keywords: PlannerMode OWL RDF
9 ;; X-URL: not distributed yet
11 ;; This file is part of Planner. It is not part of GNU Emacs.
13 ;; Planner is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; Planner is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with Planner; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; planner-rdf is an add-on to Planner. It provides functions to
31 ;; publish Planner information in RDF format, so that the Planner
32 ;; information can be processed in an automated way by RDF-aware
33 ;; tools. To do this planner-rdf adds itself to the hook
34 ;; muse-after-publish-hook, which is run whenever Planner pages are
37 ;; The source distribution and the HTML edition of the documentation is
38 ;; available at http://www.rainervolz.de/planner-rdf/
40 ;; To use planner-rdf put this file into your load-path and the following into
41 ;; your ~/.emacs file:
42 ;; (require 'planner-rdf)
43 ;; (add-hook 'muse-after-publish-hook 'planner-rdf-publish-file)
44 ;; (add-hook 'muse-after-publish-hook 'planner-rdf-publish-index)
46 ;; To minimise interference with the publication of other (non-Planner)
47 ;; Muse projects, planner-rdf-publish-file checks whether the current
48 ;; major mode is planner-mode. If yes, RDF publication is started, if not, the
51 ;; planner-rdf creates two files for every published Planner file: a .rdf and
52 ;; a .owl file. The .owl file contains
55 ;; of the respective Planner page in OWL format. The OWL schema used is
56 ;; documented in planner-rdf.owl, which is part of this distribution.
57 ;; For a detailed explanation of the format please look at the planner-rdf
58 ;; documentation included.
60 ;; The .rdf file contains Dublin Core metadata about the source file, the HTML
61 ;; file, and the OWL file produced. It is mainly used to provide information
62 ;; about the relation of the different page versions to various tools.
64 ;; Please note: Currently the .rdf/.owl files are meant for local processing,
65 ;; not Internet publishing. Therefore they contain file-URIs pointing to the
68 ;; Tested with GNU Emacs 21.3.50...
72 ;; By default the RDF files are stored in the
73 ;; planner-publishing-directory. For a different location change variable
74 ;; planner-rdf-directory.
81 (defvar planner-rdf-version
"0.1"
84 (defvar planner-rdf-directory planner-publishing-directory
85 "Directory where the RDF files are stored. Defaults to planner-publishing-directory.")
87 (defvar planner-rdf-schema-planner
88 "http://www.rainervolz.de/schema/2004/11/planner-rdf#"
89 "The Planner schema.")
91 (defvar planner-rdf-base
92 "http://localhost/planner/"
93 "The base URI for Planner info")
94 (defvar planner-rdf-task-prefix
(concat planner-rdf-base
"task-"))
95 (defvar planner-rdf-note-prefix
(concat planner-rdf-base
"note-"))
96 (defvar planner-rdf-tag-prefix
(concat planner-rdf-base
"tag-"))
97 (defvar planner-rdf-link-prefix
(concat planner-rdf-base
"link-"))
98 (defvar planner-rdf-page-prefix
(concat planner-rdf-base
"page-"))
99 (defvar planner-rdf-pagetype-prefix
(concat planner-rdf-base
"page-type-"))
100 (defvar planner-rdf-pagetype-day
(concat planner-rdf-base
"day-page"))
101 (defvar planner-rdf-pagetype-project
(concat planner-rdf-base
"topic-page"))
102 (defvar planner-rdf-pagetype-other
(concat planner-rdf-base
"other-page"))
104 ;; common match strings - tasks
105 (defvar planner-rdf-matchstr-ptaskids
106 "{{Tasks:\\([0-9]+\\)}}"
107 "Finds task ids of the form {{Tasks:<Number>}} in Planner tasks.")
108 (defvar planner-rdf-matchstr-ptask
109 "^#\\([A-C]\\)\\([0-9]*\\)\\s-*\\([_oXDCP]\\)\\s-*\\(.+\\)$"
110 "Finds a Planner task in a buffer.")
112 ;; common match strings - notes
113 (defvar planner-rdf-matchstr-pnote
114 "^.#\\([0-9]+\\)\\s-+\\(.+\\)"
115 "Finds the beginning of a Planner note in a buffer. Matches id.")
116 (defvar planner-rdf-matchstr-pnote1
117 "^\\(.+\\)\\s-+[0-9][0-9]:[0-9][0-9]\\s-+(\\[\\[[0-9]+.[0-9]+.[0-9]+#[0-9]+\\]\\])$"
118 "Note title with time and day page link. Match text.")
119 (defvar planner-rdf-matchstr-pnote2
120 "^\\(.+\\)\\s-+[0-9][0-9]:[0-9][0-9]\\s-+(\\[\\[.+#[0-9]+\\]\\])$"
121 "Note title with time and project page link. Match text.")
122 (defvar planner-rdf-matchstr-pnote3
123 "^\\(.+\\)\\s-+[0-9][0-9]:[0-9][0-9]$"
124 "Note title with time, no page link. Match text.")
125 (defvar planner-rdf-matchstr-pnote4
126 "^.+\\s-+[0-9][0-9]:[0-9][0-9]\\s-+(\\[\\[\\([0-9]+.[0-9]+.[0-9]+#[0-9]+\\)\\]\\])$"
127 "Note title with time and day page link. Match page link.")
128 (defvar planner-rdf-matchstr-pnote5
129 "^.+\\s-+[0-9][0-9]:[0-9][0-9]\\s-+(\\[\\[\\(.+#[0-9]+\\)\\]\\])$"
130 "Note title with time and project page link. Match page link.")
132 ;; common match strings - links
133 (defvar planner-rdf-matchstr-plink1
134 "\\[\\[\\([^[\n]+?\\)\\]\\[\\(.+?\\)\\]\\]"
135 "Link like [[<link>][<text>]]. Match link and text.")
136 (defvar planner-rdf-matchstr-plink2
137 "\\[\\[\\([^[\n]+?\\)\\]\\]"
138 "Link like [[<link>]]. Match link.")
140 (defvar planner-rdf-matchstr-pagenotelink
142 "Matches the page part of a page/note reference.")
144 (defvar planner-rdf-matchstr-pagenotelink1
145 "\\(.+\\)#note[0-9]+"
146 "Matches the page part of a page/note reference.")
148 ;; common match strings - tags
149 (defvar planner-rdf-matchstr-ptag
151 "Tag like {{<type>:<id>}}. Match everything.")
154 (defvar planner-rdf-analysis-note-functions nil
155 "A hook called when the standard note content has been saved.
156 Hook functions must take one parameter, the vector with the note content.
157 Their return value is ignored. Output must be to the current buffer, and in
160 (defvar planner-rdf-analysis-task-functions nil
161 "A hook called when the standard task content has been saved.
162 Hook functions must take one parameter, the vector with the task content.
163 Their return value is ignored. Output must be to the current buffer, and in
166 (defvar planner-rdf-prolog-hook nil
167 "A hook called when the standard turtle file prolog has been saved.
168 Output must be to the current buffer, and in Turtle syntax.")
170 (defvar planner-rdf-epilog-hook nil
171 "A hook called when all standard content has been saved.
172 Output must be to the current buffer, and in Turtle syntax.")
175 (defun planner-rdf-curtz ()
176 "Return a string representation of the current time zone."
177 (let* ((tz (current-time-zone))
179 (mins (/ (abs secs
) 60))
186 (format "%s%02d:%02d" tzstr hours rmins
)))
190 (defun planner-rdf-replace-sth (input replace with
)
191 "Replace <replace> with <with> in <input>."
194 (while (not (null (string-match (regexp-opt (list replace
)) input2 start
)))
195 (setq input2
(replace-match with t t input2
))
196 (setq start
(match-end 0)))
199 (defun planner-rdf-get-taskid (taskdesc)
200 "Retrieve or generate a task id from the description."
201 (if (string-match planner-rdf-matchstr-ptaskids taskdesc
)
202 (planner-match-string-no-properties 1 taskdesc
)
203 (concat "-" (number-to-string(abs (sxhash taskdesc
))))))
205 (defun planner-rdf-get-task-info ()
206 "Retrieve the task information from the current buffer."
208 (goto-char (point-min))
210 (when (looking-at planner-rdf-matchstr-ptask
)
211 (let ((info (planner-task-info-from-string
216 (vector (buffer-name)
217 (planner-task-priority info
)
218 (planner-task-status info
)
219 (planner-task-date info
)
220 (planner-task-plan info
)
221 (planner-task-description info
)
222 (planner-task-number info
)
223 (planner-rdf-get-taskid (planner-task-description info
))
228 (defun planner-rdf-get-note-info ()
229 "Retrieve the note information from the current buffer."
231 (let ((results '())(in-notes 'nil
)
233 (curr-note-headline "")
235 (goto-char (point-min))
237 (if (looking-at planner-rdf-matchstr-pnote
)
241 (progn ; save previous note
244 (vector (buffer-name)
248 ;; (planner-rdf-log (concat "Note " curr-note-id " " curr-note-headline))
249 (setq curr-note-txt
"")
250 (setq curr-note-id
0)))
251 (setq curr-note-id
(planner-match-string-no-properties 1))
252 (setq curr-note-headline
(planner-match-string-no-properties 2))
253 ;; zur nächsten - sonst wird der Titel als Text mitgenommen
256 (setq curr-note-txt
(concat curr-note-txt
(thing-at-point 'line
))))
258 ; save the last note if there
259 (if (and in-notes
(> (string-to-number curr-note-id
) 0))
263 (vector (buffer-name)
267 ;; (planner-rdf-log (concat "Note " curr-note-id " " curr-note-headline))
271 (defun planner-rdf-insert-prolog ()
272 "Insert a file prolog, necessary schema references etc.
273 Runs the hook planner-rdf-prolog-hook at the end to allow
277 "\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
278 "\txmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\"\n"
279 "\txmlns:planner=\"http://www.rainervolz.de/schema/2004/11/planner-rdf#\"\n"
280 "\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"
281 "\txmlns=\"http://localhost/planner/\"\n"
282 "\txmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n"
283 "\txml:base=\"http://localhost/planner/\"\n"
285 (run-hooks 'planner-rdf-prolog-hook
))
287 (defun planner-rdf-insert-dcprolog ()
288 "Insert a file prolog, necessary schema references etc."
290 (concat "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n")
291 (concat "\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n")
294 (defun planner-rdf-insert-epilog ()
295 "Insert a file epilog.
296 Runs the hook planner-rdf-epilog-hook at the end to allow
298 (run-hooks 'planner-rdf-epilog-hook
)
299 (insert "</rdf:RDF>\n"))
302 (defun planner-rdf-retrieve-links (id ctr input parent
)
303 "Collect Planner-style links, [[link][text]] or [...]."
304 (let ((start 0)(results '()))
305 (while (not (null (string-match planner-rdf-matchstr-plink1 input start
)))
307 (match-string 1 input
)
308 (match-string 2 input
)
309 (concat id
"-" (number-to-string ctr
))
312 (setq ctr
(incf ctr
))
313 (setq start
(match-end 0)))
315 (while (not (null (string-match planner-rdf-matchstr-plink2 input start
)))
317 (match-string 1 input
)
319 (concat id
"-" (number-to-string ctr
))
322 (setq ctr
(incf ctr
))
323 (setq start
(match-end 0)))
326 (defun planner-rdf-retrieve-tags (id ctr input parent
)
327 "Collect Planner-style tags, {{text:id}}."
328 (let ((start 0)(results '()))
329 (while (not (null (string-match planner-rdf-matchstr-ptag input start
)))
331 (match-string 1 input
)
332 (concat id
"-" (number-to-string ctr
))
335 (setq ctr
(incf ctr
))
336 (setq start
(match-end 0)))
339 (defun planner-rdf-replace-links (input)
340 "replace Planner-style links, [[link][text]] or [...], with text."
341 (while (not (null (string-match planner-rdf-matchstr-plink1 input
0)))
342 (setq input
(replace-match (planner-match-string-no-properties 2 input
) t t input
)))
343 (while (not (null (string-match planner-rdf-matchstr-plink2 input
0)))
344 (setq input
(replace-match "*link*" t t input
)))
347 (defun planner-rdf-link-type (uri)
348 "Retrieve the link protocol."
349 (if (string-match "\\(\\w+\\):.+" uri
)
353 (defun planner-rdf-tag-id (tag)
354 "Retrieve the id part of a tag."
355 (if (string-match "\\w+:\\(.+\\)" tag
)
359 (defun planner-rdf-escape-uri (uri)
360 "Apply various escapes to the URI."
361 (let* ((uri2 (planner-rdf-replace-sth uri
"<" "\\u003c"))
362 (uri3 (planner-rdf-replace-sth uri2
">" "\\u003e"))
363 (uri4 (planner-rdf-replace-sth uri3
"&" "&")))
366 (defun planner-rdf-escape-string (input)
367 "Apply various escapes to strings."
368 (let* ((input2 (planner-rdf-replace-sth input
"\"" "\\u0022"))
369 (input3 (planner-rdf-replace-sth input2
"&" "&"))
370 (input4 (planner-rdf-replace-sth input3
"<" "<"))
371 (input5 (planner-rdf-replace-sth input4
">" ">"))
375 (defun planner-rdf-print-link (link)
376 "Output a RDF representation of a link.
377 If the link has no name, insert the defined unknown string."
378 (let ((lt (planner-rdf-link-type (elt link
0)))
380 (insert "<planner:Link rdf:about=\"" planner-rdf-link-prefix
(elt link
2) "\">\n")
381 (if (not (null (elt link
1)))
382 (insert "\t<link-text>" (planner-rdf-escape-string(elt link
1)) "</link-text>\n")
383 (insert "\t<link-text>"
384 (planner-rdf-escape-string
385 (if (string= lt
"unknown")
387 (substring uri
(+ (length lt
) 3) 10)))
389 (insert "\t<link-type>" lt
"</link-type>\n")
390 (insert "\t<link-uri>"(planner-rdf-escape-uri uri
) "</link-uri>\n")
391 (insert "</planner:Link>\n")))
393 (defun planner-rdf-print-link2 (link)
394 "Output a resource statement for a link."
395 (insert "\t<link rdf:resource=\"" planner-rdf-link-prefix
(elt link
2) "\"/>\n"))
397 (defun planner-rdf-print-tag (tag)
398 "Output a RDF representation of a tag."
399 (insert "<planner:Tag rdf:about=\"" planner-rdf-tag-prefix
(elt tag
1) "\">\n")
400 (insert "\t<tag-type>" (planner-rdf-link-type (elt tag
0)) "</tag-type>\n")
401 (insert "\t<tag-id>" (planner-rdf-escape-uri(planner-rdf-tag-id (elt tag
0))) "</tag-id>\n")
402 (insert "</planner:Tag>\n"))
404 (defun planner-rdf-print-tag2 (tag)
405 "Output a resource statement for a tag."
406 (insert "\t<tag rdf:resource=\"" planner-rdf-tag-prefix
(elt tag
1) "\"/>\n"))
408 (defun planner-rdf-task-get-nice-description (input)
409 "Extract a nice, readable description.
410 Remove the task ids e.g., {{Tasks:XX}}."
411 (let ((pos (string-match planner-rdf-matchstr-ptaskids input
))
414 (setq input
(substring input
0 (decf pos
))))
415 (setq title
(planner-rdf-replace-links input
))
416 (planner-rdf-replace-sth title
"<nop>" "")
420 (defun planner-rdf-task (taskvector)
421 "Transform task information to turtle syntax.
422 Run the hook 'planner-rdf-task-functions' at the end
423 of the standard output to provide customised content."
424 ;; Generate a task-id
429 (setq task-id
(elt taskvector
7))
430 ;; (setq task-unique-id (concat (elt taskvector 0) "-" task-id))
431 ;; (setq task-unique-id (concat
432 ;; (elt taskvector 0)
434 ;; (elt taskvector 1)
435 ;; (elt taskvector 6)))
436 (setq task-unique-id
(concat
440 (setq linkes
(planner-rdf-retrieve-links
444 (concat planner-rdf-task-prefix task-unique-id
)))
445 (mapcar 'planner-rdf-print-link linkes
)
446 (setq tags
(planner-rdf-retrieve-tags
450 (concat planner-rdf-task-prefix task-unique-id
)))
451 (mapcar 'planner-rdf-print-tag tags
)
452 (insert "<planner:Task rdf:about=\"" planner-rdf-task-prefix task-unique-id
"\">\n")
453 (insert "\t<task-priority>" (elt taskvector
1) "</task-priority>\n")
454 (insert "\t<task-number>" (elt taskvector
6) "</task-number>\n")
455 (insert "\t<task-status>" (elt taskvector
2) "</task-status>\n")
456 (insert "\t<date>" (planner-rdf-replace-sth (elt taskvector
3) "." "-") "</date>\n")
457 (if (not (null (elt taskvector
4)))
458 (insert "\t<alias rdf:resource=\"" planner-rdf-task-prefix
(elt taskvector
4) "-" task-id
"\" />\n"))
459 (insert "\t<description>"
460 (planner-rdf-escape-string
461 (planner-rdf-task-get-nice-description
464 ;; if the task-id is negative, it is generated, not good for linking
465 (when (> (string-to-number task-id
) -
1)
466 (insert "\t<task-id>" task-id
"</task-id>\n"))
467 (mapcar 'planner-rdf-print-link2 linkes
)
468 (mapcar 'planner-rdf-print-tag2 tags
)
469 (run-hook-with-args 'planner-rdf-analysis-task-functions taskvector
)
470 (insert "</planner:Task>\n")))
472 (defun planner-rdf-note-get-nice-description (input)
473 "Extract a nice description, text only if possible."
476 ;; title with time and day page link
477 ((string-match planner-rdf-matchstr-pnote1 input
)
478 (setq title
(planner-rdf-escape-string(planner-match-string-no-properties 1 input
))))
479 ;; title with time and project page link
480 ((string-match planner-rdf-matchstr-pnote2 input
)
481 (setq title
(planner-rdf-escape-string(planner-match-string-no-properties 1 input
))))
482 ;; title with time, no page link
483 ((string-match planner-rdf-matchstr-pnote3 input
)
484 (setq title
(planner-rdf-escape-string (planner-match-string-no-properties 1 input
))))
485 ;; ok, take evrything
486 (t (setq title
(planner-rdf-escape-string input
))))
487 (setq title
(planner-rdf-replace-links title
))
488 (planner-rdf-replace-sth title
"<nop>" "")
491 (defun planner-rdf-note-get-alias (input)
492 "Extract the alias page link from title string."
495 ;; title with time and day page link
496 ((string-match planner-rdf-matchstr-pnote4 input
)
497 (setq alias
(planner-rdf-escape-string(planner-match-string-no-properties 1 input
))))
498 ;; title with time and project page link
499 ((string-match planner-rdf-matchstr-pnote5 input
)
500 (setq alias
(planner-rdf-escape-string(planner-match-string-no-properties 1 input
))))
503 (planner-rdf-replace-sth alias
"#" "-")))
505 (defun planner-rdf-note-get-plan (page input
)
506 "Extract the alias page link from title string."
508 (alias (planner-rdf-note-get-alias input
)))
510 ;; there is something
511 ((string-match planner-rdf-matchstr-pagenotelink alias
)
512 (setq plan
(planner-rdf-escape-string(planner-match-string-no-properties 1 alias
))))
513 ((string-match planner-rdf-matchstr-pagenotelink1 alias
)
514 (setq plan
(planner-rdf-escape-string(planner-match-string-no-properties 1 alias
))))
516 (t (setq plan page
)))
519 (defun planner-rdf-note (notevector)
520 "Transform note information to RDF.
521 Run the hook 'planner-rdf-note-functions' at the end
522 of the standard output to provide customised content."
523 ;; Generate a note-id
524 (let ((note-id (concat (elt notevector
0) "-" (elt notevector
1)))
525 (title (planner-rdf-note-get-nice-description (elt notevector
2)))
526 (alias (planner-rdf-note-get-alias (elt notevector
2)))
529 ;; links from title and body
530 (let* ((linkst (planner-rdf-retrieve-links
534 (concat planner-rdf-note-prefix note-id
)))
535 (linksb (planner-rdf-retrieve-links
539 (concat planner-rdf-note-prefix note-id
))))
540 (setq linksall
(append linkst linksb
))
541 (mapcar 'planner-rdf-print-link linksall
))
542 (let* ((tagst (planner-rdf-retrieve-tags
546 (concat planner-rdf-note-prefix note-id
)))
547 (tagsb (planner-rdf-retrieve-tags
551 (concat planner-rdf-note-prefix note-id
))))
552 (setq tagsall
(append tagst tagsb
))
553 (mapcar 'planner-rdf-print-tag tagsall
))
554 (insert "<planner:Note rdf:about=\"" planner-rdf-note-prefix note-id
"\">\n")
555 (insert "\t<note-id>" note-id
"</note-id>\n")
556 ; find a date - first try buffer name
557 (if (string-match "^\\([0-9]+.[0-9]+.[0-9]+\\)$" (elt notevector
0))
558 (insert "\t<date>" (planner-rdf-replace-sth (elt notevector
0) "." "-") "</date>\n")
560 ; no luck, try title line
561 (if (string-match "(\\[\\[\\([0-9]+.[0-9]+.[0-9]+\\)#[0-9]+\\]\\])" (elt notevector
2))
564 (planner-rdf-replace-sth
565 (planner-match-string-no-properties 1 (elt notevector
2)) "." "-")
569 (if (string-match "\\s-+\\([0-9][0-9]:[0-9][0-9]\\)\\s-+\\|\\s-+\\([0-9][0-9]:[0-9][0-9]\\)$"
573 (if (planner-match-string-no-properties 1 (elt notevector
2))
574 (planner-match-string-no-properties 1 (elt notevector
2))
575 (planner-match-string-no-properties 2 (elt notevector
2)))
576 ":00</note-time>\n"))
577 (insert "\t<description>" title
"</description>\n")
578 (when (not (string= "" alias
))
579 (insert "\t<alias rdf:resource=\"" planner-rdf-note-prefix alias
"\" />\n"))
580 (mapcar 'planner-rdf-print-link2 linksall
)
581 (mapcar 'planner-rdf-print-tag2 tagsall
)
582 (run-hook-with-args 'planner-rdf-analysis-note2turtle-functions notevector
)
583 (insert "</planner:Note>\n")))
585 (defun planner-rdf-insert-page-info (name tasks notes
)
586 "Create a page object."
587 (insert "<planner:Page rdf:about=\"" planner-rdf-page-prefix name
"\">\n")
588 (let ((type (if (string-match "^[0-9]\\{4\\}\\.[0-9]\\{2\\}\\.[0-9]\\{2\\}" name
)
589 planner-rdf-pagetype-day
590 planner-rdf-pagetype-project
)))
591 (insert "\t<page-type rdf:resource=\"" type
"\"/>\n")
595 (insert "\t<task rdf:resource=\""
596 planner-rdf-task-prefix
604 (insert "\t<note rdf:resource=\""
605 planner-rdf-note-prefix
606 (concat (elt note
0) "-" (elt note
1))
609 (insert "</planner:Page>\n"))
611 (defun planner-rdf-metadata (file)
612 "Create Dublin Core metadata for the varous files involved."
614 (let ((name (file-name-nondirectory file
))
615 (rdfdir (file-name-as-directory planner-rdf-directory
)))
616 (insert "<rdf:Description rdf:about=\"file:"
617 (expand-file-name file
)
619 (insert "\t<dc:Title>" (file-name-nondirectory file
) "</dc:Title>\n")
620 (insert "\t<dc:Identifier>" planner-rdf-base
"page-" name
"</dc:Identifier>\n")
621 (insert "\t<dc:Format>text</dc:Format>\n")
622 (if (string-match "^[0-9]\\{4\\}\\.[0-9]\\{2\\}\\.[0-9]\\{2\\}" name
)
624 (insert "\t<dc:Type>" planner-rdf-pagetype-day
"</dc:Type>\n")
629 (planner-rdf-replace-sth name
"." "-")
632 (insert "\t<dc:Type>" planner-rdf-pagetype-project
"</dc:Type>\n")
633 (insert "\t<dc:Coverage>"
637 "</dc:Coverage>\n")))
638 (insert "</rdf:Description>\n")
640 (insert "<rdf:Description rdf:about=\"file:"
641 (expand-file-name (concat rdfdir name
".html"))
643 (insert "\t<dc:Title>" name
"</dc:Title>\n")
644 (insert "\t<dc:Source>file:" file
"</dc:Source>\n")
645 (insert "\t<dc:Format>text/html</dc:Format>\n")
646 (insert "</rdf:Description>\n")
648 (insert "<rdf:Description rdf:about=\"file:"
649 (expand-file-name (concat rdfdir name
".owl"))
651 (insert "\t<dc:Title>" name
"</dc:Title>\n")
652 (insert "\t<dc:Source>file:" file
"</dc:Source>\n")
653 (insert "\t<dc:Format>application/rdf+xml</dc:Format>\n")
654 (insert "</rdf:Description>\n")
659 (defun planner-rdf-publish-file (file)
660 "Publish the file in RDF format, if called by PlannerMode.
661 Designed to be called via `muse-after-publish-hook'.
662 Non-Planner files, matching `muse-image-regexp' will be treated
663 differently. Currently they are simply ignored."
665 (when (eq major-mode
'planner-mode
)
666 (if (string-match muse-image-regexp file
)
667 (message (concat "planner-rdf: Ignored file " file
))
670 (let ((mybuff (get-file-buffer file
))
673 (setq mybuff
(find-file file
))
675 (with-current-buffer mybuff
676 (setq tasks
(planner-rdf-get-task-info)))
677 (with-current-buffer mybuff
678 (setq notes
(planner-rdf-get-note-info)))
679 (if (and (not (buffer-modified-p mybuff
)) opened
)
680 (kill-buffer mybuff
)))
681 (let ((mybuff2 (find-file
683 (concat (file-name-as-directory planner-rdf-directory
)
684 (file-name-nondirectory file
)
686 (with-current-buffer mybuff2
688 (planner-rdf-insert-prolog)
689 (mapcar 'planner-rdf-task tasks
)
690 (mapcar 'planner-rdf-note notes
)
691 (planner-rdf-insert-page-info (file-name-nondirectory file
) tasks notes
)
692 (planner-rdf-insert-epilog)
693 (let ((backup-inhibited t
))
695 (kill-buffer mybuff2
))
696 (let ((mybuff3 (find-file
698 (concat (file-name-as-directory planner-rdf-directory
)
699 (file-name-nondirectory file
)
701 (with-current-buffer mybuff3
703 (planner-rdf-insert-dcprolog)
704 (planner-rdf-metadata file
)
705 (planner-rdf-insert-epilog)
706 (let ((backup-inhibited t
))
708 (kill-buffer mybuff3
))
712 (defun planner-rdf-publish-index ()
713 "Create an index for the .rdf files.
714 Will be called via `muse-after-publish-hook'.
715 Creates index.rdf, a rdf:bag, with all existing .rdf files as
718 (let ((rdf-index (expand-file-name
720 (file-name-as-directory planner-rdf-directory
)
722 (when (file-exists-p rdf-index
)
723 (delete-file rdf-index
))
726 (message "Creating RDF index...")
727 (insert "<?xml version=\"1.0\"?>\n")
728 (insert "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n")
729 (insert "\t<rdf:Bag>\n")
730 (let ((rdf-files (directory-files
731 (file-name-as-directory planner-rdf-directory
)
739 "\t\t<rdf:li rdf:resource=\"file:"
744 (insert "\n\t</rdf:Bag>\n")
745 (insert "</rdf:RDF>\n")
746 (let ((backup-inhibited t
))
747 (write-file rdf-index nil
)))))
750 (provide 'planner-rdf
)