Awful Lisp snippet of the day
Too lazy to write Notation 3, convert it into RDF/XML, then give it to Wilbur to parse? Want an easy way to programmatically add a load of triples to your Wilbur store? Try this.It's horrible (and sorry about the <pre> formatting), but it means I can do this:(defun add-triple-list (trips)
(let ((sub nil) (prop nil))
(dolist (x trips)
(if (listp (cadr x))
(progn
(setf sub (car x))
(dolist (y (cadr x))
(if (listp (cadr y))
(progn
(setf prop (car y))
(dolist (z (cadr y))
(db-add-triple
*db*
(triple sub prop z))))
(db-add-triple
*db*
(triple sub (car y)
(cadr y))))))
(if (listp (caddr x))
(progn
(setf sub (car x))
(setf prop (cadr x))
(dolist (y (caddr x))
(db-add-triple
*db*
(triple sub prop y))))
(db-add-triple
*db*
(triple (car x) (cadr x) (caddr x))))))))
which is close enough to the N3, but with fewer punctuation marks.(add-triple-list
'((!rich:John
((!foaf:name "John Smith")
(!foaf:title "Mr")
(!foaf:lastName "Smith")
(!foaf:firstName "John")
(!foaf:knows
(!rich:FredBloggs !rich:JohnDoe))))))
Great dinner tonight, if I do say so myself. It's all down to the pepper.
Posted at 2005-04-29 12:51:54 by Richard • Link to Awful Lisp snippet…
Comments, trackbacks.

