From 1e9b39c87d007f1937650501f620b763867b54fe Mon Sep 17 00:00:00 2001 From: ueno Date: Tue, 3 Feb 2004 09:57:07 +0000 Subject: [PATCH] * rdfdb.el (rdfdb-remove-triple): Check whether the triple is already indexed in database. --- rdfdb.el | 119 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 68 insertions(+), 51 deletions(-) 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." -- 1.7.10.4