aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-03-08 23:25:35 -0500
committerDavid Robillard <d@drobilla.net>2021-03-09 01:43:52 -0500
commit7b954f5667e82de1b64984a9aeb26b8ebb5cab81 (patch)
tree5668f80ce2dc7a52cf66bbe2f4e4429b18f09e08 /include
parentc579186c5dd4e11bffddd353cef8978a66ef9c10 (diff)
downloadserd1-meson.tar.gz
serd1-meson.tar.bz2
serd1-meson.zip
WIP: Validationserd1-meson
Diffstat (limited to 'include')
-rw-r--r--include/serd/serd.h116
1 files changed, 108 insertions, 8 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 88d3178b..feac5f17 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -243,10 +243,26 @@ typedef uint32_t SerdNodeFlags;
typedef enum {
SERD_SUBJECT = 0, ///< Subject
SERD_PREDICATE = 1, ///< Predicate ("key")
- SERD_OBJECT = 2, ///< Object ("value")
- SERD_GRAPH = 3 ///< Graph ("context")
+ SERD_OBJECT = 2, ///< Object ("value")
+ SERD_GRAPH = 3, ///< Graph ("context")
} SerdField;
+/// Statement ordering
+typedef enum {
+ SERD_ORDER_SPO, ///< Subject, Predicate, Object
+ SERD_ORDER_SOP, ///< Subject, Object, Predicate
+ SERD_ORDER_OPS, ///< Object, Predicate, Subject
+ SERD_ORDER_OSP, ///< Object, Subject, Predicate
+ SERD_ORDER_PSO, ///< Predicate, Subject, Object
+ SERD_ORDER_POS, ///< Predicate, Object, Subject
+ SERD_ORDER_GSPO, ///< Graph, Subject, Predicate, Object
+ SERD_ORDER_GSOP, ///< Graph, Subject, Object, Predicate
+ SERD_ORDER_GOPS, ///< Graph, Object, Predicate, Subject
+ SERD_ORDER_GOSP, ///< Graph, Object, Subject, Predicate
+ SERD_ORDER_GPSO, ///< Graph, Predicate, Subject, Object
+ SERD_ORDER_GPOS ///< Graph, Predicate, Object, Subject
+} SerdStatementOrder;
+
/// Flags that control model storage and indexing
typedef enum {
SERD_INDEX_SPO = 1u << 0u, ///< Subject, Predicate, Object
@@ -256,7 +272,7 @@ typedef enum {
SERD_INDEX_PSO = 1u << 4u, ///< Predicate, Subject, Object
SERD_INDEX_POS = 1u << 5u, ///< Predicate, Object, Subject
SERD_INDEX_GRAPHS = 1u << 6u, ///< Support multiple graphs in model
- SERD_STORE_CURSORS = 1u << 7u ///< Store original cursor of statements
+ SERD_STORE_CURSORS = 1u << 7u, ///< Store original cursor of statements
} SerdModelFlag;
/// Bitwise OR of SerdModelFlag values
@@ -1798,7 +1814,8 @@ serd_model_end(const SerdModel* SERD_NONNULL model);
/// Return a range of all statements in `model`
SERD_API
SerdRange* SERD_ALLOCATED
-serd_model_all(const SerdModel* SERD_NONNULL model);
+serd_model_all(const SerdModel* SERD_NONNULL model,
+ const SerdStatementOrder order);
/**
Search for statements by a quad pattern
@@ -1934,20 +1951,103 @@ SerdStatus
serd_model_erase_range(SerdModel* SERD_NONNULL model,
SerdRange* SERD_NONNULL range);
+/// Validator
+typedef struct SerdValidatorImpl SerdValidator;
+
+typedef enum {
+ SERD_CHECK_ALL_VALUES_FROM,
+ SERD_CHECK_ANY_URI,
+ SERD_CHECK_CARDINALITY_EQUAL,
+ SERD_CHECK_CARDINALITY_MAX,
+ SERD_CHECK_CARDINALITY_MIN,
+ SERD_CHECK_CLASS_CYCLE,
+ SERD_CHECK_CLASS_LABEL,
+ SERD_CHECK_CLASS_TYPE,
+ SERD_CHECK_DATATYPE_PROPERTY,
+ SERD_CHECK_DATATYPE_TYPE,
+ SERD_CHECK_DEPRECATED_CLASS,
+ SERD_CHECK_DEPRECATED_PROPERTY,
+ SERD_CHECK_FUNCTIONAL_PROPERTY,
+ SERD_CHECK_INSTANCE_LITERAL,
+ SERD_CHECK_INSTANCE_TYPE,
+ SERD_CHECK_INVERSE_FUNCTIONAL_PROPERTY,
+ SERD_CHECK_LITERAL_INSTANCE,
+ SERD_CHECK_LITERAL_MAX_EXCLUSIVE,
+ SERD_CHECK_LITERAL_MAX_INCLUSIVE,
+ SERD_CHECK_LITERAL_MIN_EXCLUSIVE,
+ SERD_CHECK_LITERAL_MIN_INCLUSIVE,
+ SERD_CHECK_LITERAL_PATTERN,
+ SERD_CHECK_LITERAL_RESTRICTION,
+ SERD_CHECK_LITERAL_VALUE,
+ SERD_CHECK_OBJECT_PROPERTY,
+ SERD_CHECK_PLAIN_LITERAL_DATATYPE,
+ SERD_CHECK_PREDICATE_TYPE,
+ SERD_CHECK_PROPERTY_CYCLE,
+ SERD_CHECK_PROPERTY_DOMAIN,
+ SERD_CHECK_PROPERTY_LABEL,
+ SERD_CHECK_PROPERTY_RANGE,
+ SERD_CHECK_SOME_VALUES_FROM,
+} SerdValidatorCheck;
+
+typedef uint64_t SerdValidatorChecks;
+
+SERD_API
+SerdValidatorChecks
+serd_validator_checks_enable(const SerdValidatorChecks checks,
+ const char* SERD_NONNULL);
+
+SERD_API
+SerdValidatorChecks
+serd_validator_checks_disable(SerdValidatorChecks checks,
+ const char* SERD_NONNULL);
+
+SERD_MALLOC_API
+SerdValidator* SERD_ALLOCATED
+serd_validator_new(SerdWorld* SERD_NONNULL world);
+
+/// Free `validator`
+SERD_API
+void
+serd_validator_free(SerdValidator* SERD_NULLABLE validator);
+
+SERD_API
+SerdStatus
+serd_validator_enable_checks(SerdValidator* SERD_NONNULL validator,
+ const char* SERD_NONNULL pattern);
+
+SERD_API
+SerdStatus
+serd_validator_disable_checks(SerdValidator* SERD_NONNULL validator,
+ const char* SERD_NONNULL pattern);
+
/**
Validate model.
- This performs validation based on the RDFS and OWL vocabularies. All
- necessary data, including those vocabularies and any property/class
+ This performs validation based on the XSD, RDF, RDFS, and OWL vocabularies.
+ All necessary data, including those vocabularies and any property/class
definitions that use them, are assumed to be in `model`.
Validation errors are reported to the world's error sink.
- @return 0 on success.
+ @param validator Validator configured to run the desired checks.
+
+ @param model The model to run the validator on.
+
+ @param graph Optional graph to check. Is this is non-null, then top-level
+ checks will be initiated only by statements in the given graph. The entire
+ model is still searched while running a check so that, for example, schemas
+ that define classes and properties can be stored in separate graphs. If
+ this is null, then the validator simply ignores graphs and searches the
+ entire model for everything.
+
+ @return #SERD_SUCCESS if no errors are found, or #SERD_ERR_INVALID if
+ validation checks failed.
*/
SERD_API
SerdStatus
-serd_validate(const SerdModel* SERD_NONNULL model);
+serd_validate_model(SerdValidator* SERD_NONNULL const validator,
+ const SerdModel* SERD_NONNULL model,
+ const SerdNode* SERD_NONNULL graph);
/**
@}