| Paste number 55056: | cxml code |
| Pasted by: | Krystof |
| When: | 1 year, 5 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+16HC |
| Channel: | #lisp |
| Paste contents: |
(defmacro with-rdf-namespaces ((&rest ignore) &body body)
(declare (ignore ignore))
`(cxml:with-namespace ("rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
(cxml:with-namespace ("rdfs" "http://www.w3.org/2000/01/rdf-schema#")
,@body)))
(defmacro with-chord-labelling-namespaces ((&rest ignore) &body body)
(declare (ignore ignore))
`(cxml:with-namespace ("chord" "http://purl.org/ontology/chord/")
(cxml:with-namespace ("timeline" "http://purl.org/NET/c4dm/timeline.owl#")
(cxml:with-namespace ("event" "http://purl.org/NET/c4dm/event.owl#")
,@body))))
(defun time-to-rdf (thing)
(declare (type single-float thing))
(format nil "P~,2FS" thing))
(defun interval-description (start end label)
(cxml:with-element* ("rdf" "Description")
(cxml:attribute* "rdf" "about" (format nil "#i~4,'0D" label))
(cxml:with-element* ("rdf" "type")
(cxml:attribute* "rdf" "resource" "http://purl.org/NET/c4dm/timeline.owl#Interval"))
(cxml:with-element* ("timeline" "onTimeLine")
(cxml:attribute* "rdf" "resource" "#tl"))
(cxml:with-element* ("timeline" "beginsAtDuration")
(cxml:text (time-to-rdf start)))
(cxml:with-element* ("timeline" "endsAtDuration")
(cxml:text (time-to-rdf end)))))
(defun chord-symbol (root flavour)
(case flavour
((:|sus9|) (format nil "~A:(1,5,9)" root))
(t (format nil "~A:~A" root flavour))))
(defun chord-url (root flavour)
(format nil "http://purl.org/ontology/chord/symbol/~A"
(chord-symbol root flavour)))
(defun chord-description (root flavour label)
(cxml:with-element* ("rdf" "Description")
(cxml:attribute* "rdf" "about" (format nil "#ce~4,'0D" label))
(cxml:with-element* ("rdf" "type")
(cxml:attribute* "rdf" "resource" "http://purl.org/ontology/chord/ChordEvent"))
(cxml:with-element* ("rdfs" "label")
(cxml:text (format nil "~A:~A" root flavour)))
(cxml:with-element* ("chord" "chord")
(cxml:attribute* "rdf" "resource" (chord-url root flavour)))
(cxml:with-element* ("event" "time")
(cxml:attribute* "rdf" "resource" (format nil "#i~4,'0D" label)))))
(defun generate-rdf/xml (data)
(let ((sink (cxml:make-string-sink :canonical nil :indentation 1)))
(cxml:with-xml-output sink
(with-rdf-namespaces ()
(with-chord-labelling-namespaces ()
(cxml:with-element* ("rdf" "RDF")
(cxml:with-element* ("rdf" "Description")
(cxml:attribute* "rdf" "about" "#tl")
(cxml:with-element* ("rdf" "type")
(cxml:attribute* "rdf" "resource" "http://purl.org/NET/c4dm/timeline.owl#RelativeTimeLine"))
(cxml:with-element* ("rdfs" "label")
(cxml:text "Timeline for random chord labels")))
(let ((label 0))
(dolist (datum data)
(destructuring-bind (start end root flavour) datum
(interval-description start end label)
(chord-description root flavour label))
(incf label)))))))))This paste has no annotations.