summaryrefslogtreecommitdiffstats
path: root/src/sord_validate.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-02-07 22:53:58 +0100
committerDavid Robillard <d@drobilla.net>2017-02-07 22:53:58 +0100
commit99458ff38158e80b58663df5b6ff2e7a91a7fd0f (patch)
treeefd3052cfb51f76d4f331543f4b41ed9c33ab416 /src/sord_validate.c
parentf5e6b2cded8fd778171213fbfecd4901cdf52e9f (diff)
downloadsord-99458ff38158e80b58663df5b6ff2e7a91a7fd0f.tar.gz
sord-99458ff38158e80b58663df5b6ff2e7a91a7fd0f.tar.bz2
sord-99458ff38158e80b58663df5b6ff2e7a91a7fd0f.zip
Fix functional properties with blank nodes
Diffstat (limited to 'src/sord_validate.c')
-rw-r--r--src/sord_validate.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/sord_validate.c b/src/sord_validate.c
index 8856d2f..e30bbc0 100644
--- a/src/sord_validate.c
+++ b/src/sord_validate.c
@@ -420,6 +420,19 @@ check_type(SordModel* model,
return false;
}
+static uint64_t
+count_non_blanks(SordIter* i, SordQuadIndex field)
+{
+ uint64_t n = 0;
+ for (; !sord_iter_end(i); sord_iter_next(i)) {
+ const SordNode* node = sord_iter_get_node(i, field);
+ if (sord_node_get_type(node) != SORD_BLANK) {
+ ++n;
+ }
+ }
+ return n;
+}
+
static int
check_properties(SordModel* model, URIs* uris)
{
@@ -474,14 +487,23 @@ check_properties(SordModel* model, URIs* uris)
st = errorf(quad, "Object property with literal value");
}
- if (is_FunctionalProperty &&
- sord_count(model, subj, pred, NULL, NULL) > 1) {
- st = errorf(quad, "Functional property with many objects");
+ if (is_FunctionalProperty) {
+ SordIter* o = sord_search(model, subj, pred, NULL, NULL);
+ const uint64_t n = count_non_blanks(o, SORD_OBJECT);
+ if (n > 1) {
+ st = errorf(quad, "Functional property with %u objects", n);
+ }
+ sord_iter_free(o);
}
- if (is_InverseFunctionalProperty &&
- sord_count(model, NULL, pred, obj, NULL) > 1) {
- st = errorf(quad, "Inverse functional property with many subjects");
+ if (is_InverseFunctionalProperty) {
+ SordIter* s = sord_search(model, NULL, pred, obj, NULL);
+ const unsigned n = count_non_blanks(s, SORD_SUBJECT);
+ if (n > 1) {
+ st = errorf(
+ quad, "Inverse functional property with %u subjects", n);
+ }
+ sord_iter_free(s);
}
if (sord_node_equals(pred, uris->rdf_type) &&