[isidorus-cvs] r387 - trunk/src/TM-SPARQL

Lukas Giessmann lgiessmann at common-lisp.net
Sun Feb 6 09:41:32 UTC 2011


Author: lgiessmann
Date: Sun Feb  6 04:41:31 2011
New Revision: 387

Log:
TM-SPARQL: added a method to process the special uri tms:topicProperty

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	Sun Feb  6 04:41:31 2011
@@ -39,6 +39,8 @@
 		 (filter-for-topicProperties construct :revision revision))
 		((has-identifier (value pred) *tms-role*)
 		 nil) ;TODO: implement
+		((has-identifier (value pred) *tms-player*)
+		 nil) ;TODO: implement
 		)))))
 
 
@@ -51,72 +53,14 @@
     ;; *tms-reifier*
     ;; *tms-scope*
     ;; *tms-value* => only when there is <occ|var|nam> ? <LITERAL>, otherwise the predicate is the type of the characteristic
-    ;; *tms-topicProperty*
+    ;; *tms-topicProperty* ??
     ))
 
+
 (defgeneric filter-for-topicProperties (construct &key revision)
   (:documentation "Returns a list of triples where the subject represents
                    a topic and the object represents a name or occurrence.")
   (:method ((construct SPARQL-Triple) &key (revision *TM-REVISION*))
-    ;TODO: implement
-    ))
-
-
-(defgeneric filter-for-values (construct &key revision)
-  (:documentation "Returns a list of triples that represent a
-                   subject and its literal value as object.")
-  (:method ((construct SPARQL-Triple) &key revision)
-    (declare (ignorable revision))
-    (when (or (literal-p (object construct))
-	      (variable-p (object construct)))
-      (let* ((subj (subject construct))
-	     (pred (predicate construct))
-	     (obj (object construct))
-	     (literal-datatype (literal-datatype obj))
-	     (subj-uri (unless (variable-p subj)
-			 (when-do id (any-id (value subj) :revision revision)
-				  (embrace-uri (uri id)))))
-	     (pred-uri (unless (variable-p pred)
-			 (when-do id (any-id (value pred) :revision revision)
-				  (embrace-uri (uri id))))))
-	(cond ((and (not (variable-p subj))
-		    (not (variable-p obj)))
-	       (when (or (and (typep subj 'NameC)
-			      (string= literal-datatype *xml-string*)
-			      (string= (charvalue subj) obj))
-			 (filter-datatypable-by-value subj obj literal-datatype))
-		 (list (list :subject subj-uri
-			     :predicate pred-uri
-			     :object obj
-			     :literal-datatype literal-datatype))))
-	      ((not (variable-p subj))
-	       (list (list :subject subj-uri
-			   :predicate pred-uri
-			   :object (charvalue subj)
-			   :literal-datatype (datatype subj))))
-	      ((not (variable-p obj))
-	       (loop for char in (return-characteristics obj literal-datatype)
-		  collect (list :subject (when-do id (any-id char :revision revision)
-						  (embrace-uri id))
-				:predicate pred-uri
-				:object (charvalue char)
-				:literal-datatype (datatype char))))
-	      (t ;only pred is given
-	       (let ((chars (append (get-all-names revision)
-				    (get-all-occurrences revision)
-				    (get-all-variants revision))))
-		 (loop for char in chars
-		    collect (list :subject (when-do id (any-id char :revision revision)
-						    (embrace-uri id))
-				  :predicate pred-uri
-				  :object (charvalue char)
-				  :literal-datatype (datatype char))))))))))
-
-
-(defgeneric filter-for-scopes (construct &key revision)
-  (:documentation "Returns a list of triples that represent a subject as the
-                   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))
@@ -132,99 +76,210 @@
 				 (embrace-uri (uri id))))))
 	(cond ((and (not (variable-p subj))
 		    (not (variable-p obj)))
-	       (when (find obj (themes subj :revision revision))
+	       (when (find obj (append (names subj :revision revision)
+				       (occurrences subj :revision revision)))
 		 (list (list :subject subj-uri
 			     :predicate pred-uri
 			     :object obj-uri))))
 	      ((not (variable-p subj))
-	       (loop for scope in (themes subj :revision revision)
+	       (loop for property in (append (names subj :revision revision)
+					     (occurrences subj :revision revision))
 		  collect (list :subject subj-uri
 				:predicate pred-uri
-				:object (when-do id (any-id scope :revision revision)
-						 (embrace-uri (uri id))))))
+				:object (when-do id (any-id property :revision revision)
+						 (embrace-uri id)))))
 	      ((not (variable-p obj))
-	       (let ((scoped-constructs
-		      (used-as-theme (value obj) :revision revision)))
-		 (loop for construct in scoped-constructs
-		    collect (list :subject (when-do id (any-id construct :revision revision)
-						    (embrace-uri (uri id)))
-				  :predicate pred-uri
-				  :object obj-uri))))
-	      (t ;only pred is given
-	       (let ((scoped-constructs
-		      (remove-null
-		       (map 'list #'(lambda(construct)
-				      (when (themes construct :revision revision)
-					construct))
-			    (append (get-all-associations revision)
-				    (get-all-occurrences revision)
-				    (get-all-names revision)
-				    (get-all-variants))))))
-		 (loop for construct in scoped-constructs
-		    append (loop for scope in (themes construct :revision revision)
-			      collect
-				(list :subject (when-do id (any-id construct
-								   :revision revision)
-							(embrace-uri id))
-				      :predicate pred-uri
-				      :object (when-do id (any-id construct
-								  :revision revision)
-						       (embrace-uri id))))))))))))
-
-
-(defgeneric filter-for-reifier (construct &key revision)
-  (:documentation "Returns a list with one triple representing a reifier
-                   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)
-			 (when-do id (any-id (value subj) :revision revision)
-				  (embrace-uri (uri id)))))
-	     (pred-uri (unless (variable-p pred)
-			 (when-do id (any-id (value pred) :revision revision)
-				  (embrace-uri (uri id)))))
-	     (obj-uri (unless (variable-p obj)
-			(when-do id (any-id (value obj) :revision revision)
-				 (embrace-uri (uri id))))))
-	(cond ((and (not (variable-p subj))
-		    (not (variable-p obj)))
-	       (when (eql (reifier (value subj) :revision revision)
-			  (value obj))
-		 (list (list :subject subj-uri
-			     :predicate pred-uri
-			     :object obj-uri))))
-	      ((not (variable-p subj))
-	       (let ((reifier-top
-		      (reifier (value subj) :revision revision)))
-		 (when reifier-top
-		   (list :subject subj-uri
+	       (let ((parent-top (parent obj :revision revision)))
+		 (when revision
+		   (list :subject (when-do id (any-id parent-top :revision revision)
+					   (embrace-uri id))
 			 :predicate pred-uri
-			 :object (when-do id (any-id reifier-top :revision revision)
-					  (embrace-uri (uri id)))))))
-	      ((not (variable-p obj))
-	       (let ((reified-cons
-		      (reified-construct (value obj) :revision revision)))
-		 (when reified-cons
-		   (list (list :subject
-			       (when-do id (any-id reified-cons :revision revision)
-					(embrace-uri (uri id)))
-			       :predicate pred-uri
-			       :object obj-uri)))))
+			 :object obj-uri))))
 	      (t ; only pred is given
 	       (let ((topics
 		      (remove-null
 		       (map 'list #'(lambda(top)
-				      (when (reified-construct top :revision revision)
+				      (when (append
+					     (names top :revision revision)
+					     (occurrences top :revision revision))
 					top))
 			    (get-all-topics revision)))))
 		 (loop for top in topics
-		    collect (list :subject
-				  (when-do id (any-id (reified-construct
-						       top :revision revision))
-					   (embrace-uri (uri id)))
+		      append (loop for prop in (append
+						(names top :revision revision)
+						(occurrences top :revision revision))
+				collect (list :subject
+					      (when-do id (any-id top :revision revision)
+						       (embrace-uri id))
+					      :predicate pred-uri
+					      :object
+					      (when-do id (any-id prop :revision revision)
+						       (embrace-uri id))))))))))))
+
+
+  (defgeneric filter-for-values (construct &key revision)
+    (:documentation "Returns a list of triples that represent a
+                   subject and its literal value as object.")
+    (:method ((construct SPARQL-Triple) &key revision)
+      (declare (ignorable revision))
+      (when (or (literal-p (object construct))
+		(variable-p (object construct)))
+	(let* ((subj (subject construct))
+	       (pred (predicate construct))
+	       (obj (object construct))
+	       (literal-datatype (literal-datatype obj))
+	       (subj-uri (unless (variable-p subj)
+			   (when-do id (any-id (value subj) :revision revision)
+				    (embrace-uri (uri id)))))
+	       (pred-uri (unless (variable-p pred)
+			   (when-do id (any-id (value pred) :revision revision)
+				    (embrace-uri (uri id))))))
+	  (cond ((and (not (variable-p subj))
+		      (not (variable-p obj)))
+		 (when (or (and (typep subj 'NameC)
+				(string= literal-datatype *xml-string*)
+				(string= (charvalue subj) obj))
+			   (filter-datatypable-by-value subj obj literal-datatype))
+		   (list (list :subject subj-uri
+			       :predicate pred-uri
+			       :object obj
+			       :literal-datatype literal-datatype))))
+		((not (variable-p subj))
+		 (list (list :subject subj-uri
+			     :predicate pred-uri
+			     :object (charvalue subj)
+			     :literal-datatype (datatype subj))))
+		((not (variable-p obj))
+		 (loop for char in (return-characteristics obj literal-datatype)
+		    collect (list :subject (when-do id (any-id char :revision revision)
+						    (embrace-uri id))
 				  :predicate pred-uri
-				  :object (when-do id (any-id top :revision revision)
-						   (embrace-uri (uri id))))))))))))
\ No newline at end of file
+				  :object (charvalue char)
+				  :literal-datatype (datatype char))))
+		(t ;only pred is given
+		 (let ((chars (append (get-all-names revision)
+				      (get-all-occurrences revision)
+				      (get-all-variants revision))))
+		   (loop for char in chars
+		      collect (list :subject (when-do id (any-id char :revision revision)
+						      (embrace-uri id))
+				    :predicate pred-uri
+				    :object (charvalue char)
+				    :literal-datatype (datatype char))))))))))
+
+
+  (defgeneric filter-for-scopes (construct &key revision)
+    (:documentation "Returns a list of triples that represent a subject as the
+                   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)
+			   (when-do id (any-id (value subj) :revision revision)
+				    (embrace-uri (uri id)))))
+	       (pred-uri (unless (variable-p pred)
+			   (when-do id (any-id (value pred) :revision revision)
+				    (embrace-uri (uri id)))))
+	       (obj-uri (unless (variable-p obj)
+			  (when-do id (any-id (value obj) :revision revision)
+				   (embrace-uri (uri id))))))
+	  (cond ((and (not (variable-p subj))
+		      (not (variable-p obj)))
+		 (when (find obj (themes subj :revision revision))
+		   (list (list :subject subj-uri
+			       :predicate pred-uri
+			       :object obj-uri))))
+		((not (variable-p subj))
+		 (loop for scope in (themes subj :revision revision)
+		    collect (list :subject subj-uri
+				  :predicate pred-uri
+				  :object (when-do id (any-id scope :revision revision)
+						   (embrace-uri (uri id))))))
+		((not (variable-p obj))
+		 (let ((scoped-constructs
+			(used-as-theme (value obj) :revision revision)))
+		   (loop for construct in scoped-constructs
+		      collect (list :subject (when-do id (any-id construct :revision revision)
+						      (embrace-uri (uri id)))
+				    :predicate pred-uri
+				    :object obj-uri))))
+		(t ;only pred is given
+		 (let ((scoped-constructs
+			(remove-null
+			 (map 'list #'(lambda(construct)
+					(when (themes construct :revision revision)
+					  construct))
+			      (append (get-all-associations revision)
+				      (get-all-occurrences revision)
+				      (get-all-names revision)
+				      (get-all-variants))))))
+		   (loop for construct in scoped-constructs
+		      append (loop for scope in (themes construct :revision revision)
+				collect
+				  (list :subject (when-do id (any-id construct
+								     :revision revision)
+							  (embrace-uri id))
+					:predicate pred-uri
+					:object (when-do id (any-id construct
+								    :revision revision)
+							 (embrace-uri id))))))))))))
+
+
+  (defgeneric filter-for-reifier (construct &key revision)
+    (:documentation "Returns a list with one triple representing a reifier
+                   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)
+			   (when-do id (any-id (value subj) :revision revision)
+				    (embrace-uri (uri id)))))
+	       (pred-uri (unless (variable-p pred)
+			   (when-do id (any-id (value pred) :revision revision)
+				    (embrace-uri (uri id)))))
+	       (obj-uri (unless (variable-p obj)
+			  (when-do id (any-id (value obj) :revision revision)
+				   (embrace-uri (uri id))))))
+	  (cond ((and (not (variable-p subj))
+		      (not (variable-p obj)))
+		 (when (eql (reifier (value subj) :revision revision)
+			    (value obj))
+		   (list (list :subject subj-uri
+			       :predicate pred-uri
+			       :object obj-uri))))
+		((not (variable-p subj))
+		 (let ((reifier-top
+			(reifier (value subj) :revision revision)))
+		   (when reifier-top
+		     (list :subject subj-uri
+			   :predicate pred-uri
+			   :object (when-do id (any-id reifier-top :revision revision)
+					    (embrace-uri (uri id)))))))
+		((not (variable-p obj))
+		 (let ((reified-cons
+			(reified-construct (value obj) :revision revision)))
+		   (when reified-cons
+		     (list (list :subject
+				 (when-do id (any-id reified-cons :revision revision)
+					  (embrace-uri (uri id)))
+				 :predicate pred-uri
+				 :object obj-uri)))))
+		(t ; only pred is given
+		 (let ((topics
+			(remove-null
+			 (map 'list #'(lambda(top)
+					(when (reified-construct top :revision revision)
+					  top))
+			      (get-all-topics revision)))))
+		   (loop for top in topics
+		      collect (list :subject
+				    (when-do id (any-id (reified-construct
+							 top :revision revision))
+					     (embrace-uri (uri id)))
+				    :predicate pred-uri
+				    :object (when-do id (any-id top :revision revision)
+						     (embrace-uri (uri id))))))))))))
\ No newline at end of file




More information about the Isidorus-cvs mailing list