From: ueno Date: Tue, 3 Feb 2004 09:57:07 +0000 (+0000) Subject: * rdfdb.el (rdfdb-remove-triple): Check whether the triple is already X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=1e9b39c87d007f1937650501f620b763867b54fe;p=elisp%2Flsdb.git * rdfdb.el (rdfdb-remove-triple): Check whether the triple is already indexed in database. --- diff --git a/rdfdb.el b/rdfdb.el index 0da9aed..250b36d 100644 --- a/rdfdb.el +++ b/rdfdb.el @@ -351,58 +351,75 @@ MATCHER is a triple whose slots can be nil (wildcard)." (defun rdfdb-add-triple (database triple) "Add TRIPLE in DATABASE." - (let (key) - ;; Index by subject and property. - (rdfdb-puthash (setq key (rdfdb-get-key database - (rdfdb-triple-subject triple))) - (cons triple - (rdfdb-gethash key - (rdfdb-database-subject-index - database))) - (rdfdb-database-subject-index database)) - (rdfdb-puthash (setq key (rdfdb-get-key database - (rdfdb-triple-subject triple) - (rdfdb-triple-property triple))) - (cons triple - (rdfdb-gethash key - (rdfdb-database-subject-index - database))) - (rdfdb-database-subject-index database)) - ;; Index by property and object. - (rdfdb-puthash (setq key (rdfdb-get-key database + (let* ((subject-property-key + (rdfdb-get-key database + (rdfdb-triple-subject triple) + (rdfdb-triple-property triple))) + (property-object-key + (rdfdb-get-key database + (rdfdb-triple-property triple) + (rdfdb-triple-object triple))) + (object-subject-key + (rdfdb-get-key database + (rdfdb-triple-object triple) + (rdfdb-triple-subject triple))) + (subject-property-triples + (rdfdb-gethash subject-property-key + (rdfdb-database-subject-index + database))) + (property-object-triples + (rdfdb-gethash property-object-key + (rdfdb-database-property-index + database))) + (object-subject-triples + (rdfdb-gethash object-subject-key + (rdfdb-database-object-index + database))) + (minimum-length-triples subject-property-triples)) + ;; Check whether triple is already in database. + (if (> minimum-length-triples + (length property-object-triples)) + (setq minimum-length-triples property-object-triples)) + (if (> minimum-length-triples + (length object-subject-triples)) + (setq minimum-length-triples object-subject-triples)) + (unless (member triple minimum-length-triples) + ;; Index by subject and property. + (rdfdb-puthash subject-property-key + (cons triple subject-property-triples) + (rdfdb-database-subject-index database)) + (rdfdb-puthash (setq key (rdfdb-get-key database + (rdfdb-triple-subject triple))) + (cons triple + (rdfdb-gethash key + (rdfdb-database-subject-index + database))) + (rdfdb-database-subject-index database)) + ;; Index by property and object. + (rdfdb-puthash property-object-key + (cons triple property-object-triples) + (rdfdb-database-property-index database)) + (rdfdb-puthash (setq key (rdfdb-get-key database (rdfdb-triple-property triple))) - (cons triple - (rdfdb-gethash key - (rdfdb-database-property-index - database))) - (rdfdb-database-property-index database)) - (rdfdb-puthash (setq key (rdfdb-get-key database - (rdfdb-triple-property triple) - (rdfdb-triple-object triple))) - (cons triple - (rdfdb-gethash key - (rdfdb-database-property-index - database))) - (rdfdb-database-property-index database)) - ;; Index by object and subject. - (rdfdb-puthash (setq key (rdfdb-get-key database - (rdfdb-triple-object triple))) - (cons triple - (rdfdb-gethash key - (rdfdb-database-object-index - database))) - (rdfdb-database-object-index database)) - (rdfdb-puthash (setq key (rdfdb-get-key database - (rdfdb-triple-object triple) - (rdfdb-triple-subject triple))) - (cons triple - (rdfdb-gethash key - (rdfdb-database-object-index - database))) - (rdfdb-database-object-index database)) - (rdfdb-database-set-triple-list - database - (cons triple (rdfdb-database-triple-list database))))) + (cons triple + (rdfdb-gethash key + (rdfdb-database-property-index + database))) + (rdfdb-database-property-index database)) + ;; Index by object and subject. + (rdfdb-puthash object-subject-key + (cons triple object-subject-triples) + (rdfdb-database-object-index database)) + (rdfdb-puthash (setq key (rdfdb-get-key database + (rdfdb-triple-object triple))) + (cons triple + (rdfdb-gethash key + (rdfdb-database-object-index + database))) + (rdfdb-database-object-index database)) + (rdfdb-database-set-triple-list + database + (cons triple (rdfdb-database-triple-list database)))))) (defun rdfdb-remove-triple (database triple) "Remove TRIPLE from DATABASE."