summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sord.c25
-rw-r--r--src/sord_test.c16
2 files changed, 41 insertions, 0 deletions
diff --git a/src/sord.c b/src/sord.c
index 9510d50..cad3c4d 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -844,6 +844,31 @@ sord_search(SordModel* model,
return sord_find(model, pat);
}
+const SordNode*
+sord_get(SordModel* model,
+ const SordNode* s,
+ const SordNode* p,
+ const SordNode* o,
+ const SordNode* g)
+{
+ if ((bool)s + (bool)p + (bool)o != 2) {
+ return NULL;
+ }
+
+ SordIter* i = sord_search(model, s, p, o, g);
+ const SordNode* ret = NULL;
+ if (!s) {
+ ret = sord_iter_get_node(i, SORD_SUBJECT);
+ } else if (!p) {
+ ret = sord_iter_get_node(i, SORD_PREDICATE);
+ } else if (!o) {
+ ret = sord_iter_get_node(i, SORD_OBJECT);
+ }
+
+ sord_iter_free(i);
+ return ret;
+}
+
bool
sord_ask(SordModel* model,
const SordNode* s,
diff --git a/src/sord_test.c b/src/sord_test.c
index a7a74e5..36fc408 100644
--- a/src/sord_test.c
+++ b/src/sord_test.c
@@ -238,6 +238,22 @@ test_read(SordWorld* world, SordModel* sord, SordNode* g,
TUP_FMT_ARGS(nomatch));
}
+ if (sord_get(sord, NULL, NULL, uri(world, 3), g)) {
+ return test_fail("Fail: Get *,*,3 succeeded\n");
+ } else if (!sord_node_equals(
+ sord_get(sord, uri(world, 1), uri(world, 2), NULL, g),
+ uri(world, 3))) {
+ return test_fail("Fail: Get 1,2,* != 3\n");
+ } else if (!sord_node_equals(
+ sord_get(sord, uri(world, 1), NULL, uri(world, 3), g),
+ uri(world, 2))) {
+ return test_fail("Fail: Get 1,*,3 != 2\n");
+ } else if (!sord_node_equals(
+ sord_get(sord, NULL, uri(world, 2), uri(world, 3), g),
+ uri(world, 1))) {
+ return test_fail("Fail: Get *,2,3 != 1\n");
+ }
+
for (unsigned i = 0; i < NUM_PATTERNS; ++i) {
QueryTest test = patterns[i];
SordQuad pat = { test.query[0], test.query[1], test.query[2], g };