summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2020-09-07 14:34:55 +0200
committerpukkamustard <pukkamustard@posteo.net>2020-09-07 14:34:55 +0200
commit62528289f4bbc68290e16b79013ca773faad05a6 (patch)
tree5e9445c9ee3a64065554c7c50d6e96fc909d6aa4
parent326ea4afab84d65eb3d7e54e6b20e0cfce79b567 (diff)
(schemantic fragment-graph): fix query logic by transforming match terms
to fragment-references
-rw-r--r--schemantic/fragment-graph.scm41
-rw-r--r--tests/schemantic/fragment-graph.scm12
2 files changed, 36 insertions, 17 deletions
diff --git a/schemantic/fragment-graph.scm b/schemantic/fragment-graph.scm
index d600b76..ce378e6 100644
--- a/schemantic/fragment-graph.scm
+++ b/schemantic/fragment-graph.scm
@@ -132,7 +132,8 @@
fg)
(define-method (graph-match (fg <fragment-graph>) (s <term>) (p <term>) (o <term>))
- (let ((fragment-reference (term->fragment-reference (fragment-graph-base-subject fg) s)))
+ (let ((fragment-reference (term->fragment-reference (fragment-graph-base-subject fg) s))
+ (base-subject (fragment-graph-base-subject fg)))
(cond
;; s is not base-subject or fragment, return empty list
((not fragment-reference) '())
@@ -141,28 +142,34 @@
((lvar? fragment-reference)
(append
(map (match-lambda ((p o) (make-triple
- (fragment-graph-base-subject fg)
- (fragment-reference->term (fragment-graph-base-subject fg) p)
- (fragment-reference->term (fragment-graph-base-subject fg) o))))
- (index-match (statements fg) (list p o)))
+ base-subject
+ (fragment-reference->term base-subject p)
+ (fragment-reference->term base-subject o))))
+ (index-match (statements fg) (list (term->fragment-reference base-subject p)
+ (term->fragment-reference base-subject o))))
(map (match-lambda ((fr p o) (make-triple
- (fragment-reference->term (fragment-graph-base-subject fg) fr)
- (fragment-reference->term (fragment-graph-base-subject fg) p)
- (fragment-reference->term (fragment-graph-base-subject fg) o))))
- (index-match (fragment-statements fg) (list fragment-reference p o)))))
+ (fragment-reference->term base-subject fr)
+ (fragment-reference->term base-subject p)
+ (fragment-reference->term base-subject o))))
+ (index-match (fragment-statements fg) (list fragment-reference
+ (term->fragment-reference base-subject p)
+ (term->fragment-reference base-subject o))))))
((fragment-reference? fragment-reference)
(if (not (fragment-reference-id fragment-reference))
;; s is base subject, only match statements
(map (match-lambda ((p o) (make-triple
- (fragment-graph-base-subject fg)
- (fragment-reference->term (fragment-graph-base-subject fg) p)
- (fragment-reference->term (fragment-graph-base-subject fg) o))))
- (index-match (statements fg) (list p o)))
+ base-subject
+ (fragment-reference->term base-subject p)
+ (fragment-reference->term base-subject o))))
+ (index-match (statements fg) (list (term->fragment-reference base-subject p)
+ (term->fragment-reference base-subject o))))
;; s is a proper fragment-reference
(map (match-lambda ((fr p o) (make-triple
- (fragment-reference->term (fragment-graph-base-subject fg) fr)
- (fragment-reference->term (fragment-graph-base-subject fg) p)
- (fragment-reference->term (fragment-graph-base-subject fg) o))))
- (index-match (fragment-statements fg) (list fragment-reference p o))))))))
+ (fragment-reference->term base-subject fr)
+ (fragment-reference->term base-subject p)
+ (fragment-reference->term base-subject o))))
+ (index-match (fragment-statements fg) (list fragment-reference
+ (term->fragment-reference base-subject p)
+ (term->fragment-reference base-subject o)))))))))
diff --git a/tests/schemantic/fragment-graph.scm b/tests/schemantic/fragment-graph.scm
index 1e53af1..d0d8316 100644
--- a/tests/schemantic/fragment-graph.scm
+++ b/tests/schemantic/fragment-graph.scm
@@ -50,5 +50,17 @@
2 (length
(graph-match my-fg (make-triple (lvar) (lvar) (lvar)))))
+(graph-add my-fg (make-triple (ex "bar") (rdf "type") (ex "foo2")))
+
+(test-equal 3 (length
+ (graph-match my-fg (make-triple (lvar) (lvar) (lvar)))))
+
+(graph-match my-fg (make-triple (lvar) (lvar) (lvar)))
+
+(test-equal "can query statement and fragment statement"
+ 2 (length
+ (graph-match my-fg (make-triple (lvar) (lvar) (ex "foo")))))
+
+(graph-match my-fg (make-triple (lvar) (lvar) (ex "foo")))
(test-end "fragment-graph")