[isidorus-cvs] r394 - trunk/src/TM-SPARQL
Lukas Giessmann
lgiessmann at common-lisp.net
Fri Feb 11 12:01:37 UTC 2011
Author: lgiessmann
Date: Fri Feb 11 07:01:37 2011
New Revision: 394
Log:
TM-SPARQL: added the macro with-triple-nodes to reduce code-duplications
Modified:
trunk/src/TM-SPARQL/sparql_special_uris.lisp
Modified: trunk/src/TM-SPARQL/sparql_special_uris.lisp
==============================================================================
--- trunk/src/TM-SPARQL/sparql_special_uris.lisp (original)
+++ trunk/src/TM-SPARQL/sparql_special_uris.lisp Fri Feb 11 07:01:37 2011
@@ -14,6 +14,22 @@
;TODO: create a macro for "filter-for-scopes", "filter-for-reifier", ...
+(defmacro with-triple-nodes (construct &body body)
+ `(let* ((subj (subject ,construct))
+ (pred (predicate ,construct))
+ (obj (object ,construct))
+ (subj-uri (unless (variable-p subj)
+ (sparql-node (value subj) :revision revision)))
+ (pred-uri (unless (variable-p pred)
+ (sparql-node (value pred) :revision revision)))
+ (obj-uri (when (and (not (variable-p obj))
+ (not (literal-p obj)))
+ (sparql-node (value obj) :revision revision)))
+ (literal-datatype (when (literal-p obj)
+ (literal-datatype obj))))
+ (declare (Ignorable subj-uri pred-uri obj-uri literal-datatype))
+ , at body))
+
(defgeneric filter-by-special-uris (construct &key revision)
(:documentation "Returns lists representing triples that handles special
@@ -82,15 +98,7 @@
represents a role and the object represents a player.")
(:method ((construct SPARQL-Triple) &key (revision *TM-REVISION*))
(unless (literal-p (object construct))
- (let* ((subj (subject construct))
- (pred (predicate construct))
- (obj (object construct))
- (subj-uri (unless (variable-p subj)
- (sparql-node (value subj) :revision revision)))
- (pred-uri (unless (variable-p pred)
- (sparql-node (value pred) :revision revision)))
- (obj-uri (unless (variable-p obj)
- (sparql-node (value obj) :revision revision))))
+ (with-triple-nodes construct
(when (and (or (typep (value subj) 'RoleC)
(variable-p subj))
(or (typep (value obj) 'TopicC)
@@ -136,15 +144,7 @@
an Association and the object represents a role.")
(:method((construct SPARQL-Triple) &key (revision *TM-REVISION*))
(unless (literal-p (object construct))
- (let* ((subj (subject construct))
- (pred (predicate construct))
- (obj (object construct))
- (subj-uri (unless (variable-p subj)
- (sparql-node (value subj) :revision revision)))
- (pred-uri (unless (variable-p pred)
- (sparql-node (value pred) :revision revision)))
- (obj-uri (unless (variable-p obj)
- (sparql-node (value obj) :revision revision))))
+ (with-triple-nodes construct
(when (and (or (variable-p subj)
(typep (value subj) 'd:AssociationC))
(or (variable-p obj)
@@ -187,15 +187,7 @@
a topic and the object represents a name or occurrence.")
(:method ((construct SPARQL-Triple) &key (revision *TM-REVISION*))
(unless (literal-p (object construct))
- (let* ((subj (subject construct))
- (pred (predicate construct))
- (obj (object construct))
- (subj-uri (unless (variable-p subj)
- (sparql-node (value subj) :revision revision)))
- (pred-uri (unless (variable-p pred)
- (sparql-node (value pred) :revision revision)))
- (obj-uri (unless (variable-p obj)
- (sparql-node (value obj) :revision revision))))
+ (with-triple-nodes construct
(when (and (or (variable-p subj)
(typep (value subj) 'd:TopicC))
(or (variable-p obj)
@@ -247,14 +239,7 @@
subject and its literal value as object.")
(:method ((construct SPARQL-Triple) &key revision)
(declare (ignorable revision))
- (let* ((subj (subject construct))
- (pred (predicate construct))
- (obj (object construct))
- (literal-datatype (literal-datatype obj))
- (subj-uri (unless (variable-p subj)
- (sparql-node (value subj) :revision revision)))
- (pred-uri (unless (variable-p pred)
- (sparql-node(value pred) :revision revision))))
+ (with-triple-nodes construct
(when (and (or (variable-p subj)
(typep (value subj) 'd:OccurrenceC)
(typep (value subj) 'd:NameC)
@@ -304,15 +289,7 @@
scoped item and the object as the scope-topic.")
(:method ((construct SPARQL-Triple) &key (revision *TM-REVISION*))
(unless (literal-p (object construct))
- (let* ((subj (subject construct))
- (pred (predicate construct))
- (obj (object construct))
- (subj-uri (unless (variable-p subj)
- (sparql-node (value subj) :revision revision)))
- (pred-uri (unless (variable-p pred)
- (sparql-node (value pred) :revision revision)))
- (obj-uri (unless (variable-p obj)
- (sparql-node (value obj) :revision revision))))
+ (with-triple-nodes construct
(when (and (or (variable-p subj)
(typep (value subj) 'd:ScopableC))
(or (variable-p obj)
@@ -360,15 +337,7 @@
and the corresponding reified construct.")
(:method ((construct SPARQL-Triple) &key (revision *TM-REVISION*))
(unless (literal-p (object construct))
- (let* ((subj (subject construct))
- (pred (predicate construct))
- (obj (object construct))
- (subj-uri (unless (variable-p subj)
- (sparql-node (value subj) :revision revision)))
- (pred-uri (unless (variable-p pred)
- (sparql-node (value pred) :revision revision)))
- (obj-uri (unless (variable-p obj)
- (sparql-node (value obj) :revision revision))))
+ (with-triple-nodes construct
(when (and (or (variable-p subj)
(typep (value subj) 'd:ReifiableConstructC))
(or (variable-p obj)
More information about the Isidorus-cvs
mailing list