use crate::graph::rdf::Term;
pub struct SH;
#[allow(missing_docs)]
impl SH {
pub const NS: &str = "http://www.w3.org/ns/shacl#";
pub const NODE_SHAPE: &str = "http://www.w3.org/ns/shacl#NodeShape";
pub const PROPERTY_SHAPE: &str = "http://www.w3.org/ns/shacl#PropertyShape";
pub const TARGET_CLASS: &str = "http://www.w3.org/ns/shacl#targetClass";
pub const TARGET_NODE: &str = "http://www.w3.org/ns/shacl#targetNode";
pub const TARGET_SUBJECTS_OF: &str = "http://www.w3.org/ns/shacl#targetSubjectsOf";
pub const TARGET_OBJECTS_OF: &str = "http://www.w3.org/ns/shacl#targetObjectsOf";
pub const PROPERTY: &str = "http://www.w3.org/ns/shacl#property";
pub const PATH: &str = "http://www.w3.org/ns/shacl#path";
pub const INVERSE_PATH: &str = "http://www.w3.org/ns/shacl#inversePath";
pub const ALTERNATIVE_PATH: &str = "http://www.w3.org/ns/shacl#alternativePath";
pub const ZERO_OR_MORE_PATH: &str = "http://www.w3.org/ns/shacl#zeroOrMorePath";
pub const ONE_OR_MORE_PATH: &str = "http://www.w3.org/ns/shacl#oneOrMorePath";
pub const ZERO_OR_ONE_PATH: &str = "http://www.w3.org/ns/shacl#zeroOrOnePath";
pub const CLASS: &str = "http://www.w3.org/ns/shacl#class";
pub const DATATYPE: &str = "http://www.w3.org/ns/shacl#datatype";
pub const NODE_KIND: &str = "http://www.w3.org/ns/shacl#nodeKind";
pub const BLANK_NODE: &str = "http://www.w3.org/ns/shacl#BlankNode";
pub const IRI: &str = "http://www.w3.org/ns/shacl#IRI";
pub const LITERAL: &str = "http://www.w3.org/ns/shacl#Literal";
pub const BLANK_NODE_OR_IRI: &str = "http://www.w3.org/ns/shacl#BlankNodeOrIRI";
pub const BLANK_NODE_OR_LITERAL: &str = "http://www.w3.org/ns/shacl#BlankNodeOrLiteral";
pub const IRI_OR_LITERAL: &str = "http://www.w3.org/ns/shacl#IRIOrLiteral";
pub const MIN_COUNT: &str = "http://www.w3.org/ns/shacl#minCount";
pub const MAX_COUNT: &str = "http://www.w3.org/ns/shacl#maxCount";
pub const MIN_EXCLUSIVE: &str = "http://www.w3.org/ns/shacl#minExclusive";
pub const MAX_EXCLUSIVE: &str = "http://www.w3.org/ns/shacl#maxExclusive";
pub const MIN_INCLUSIVE: &str = "http://www.w3.org/ns/shacl#minInclusive";
pub const MAX_INCLUSIVE: &str = "http://www.w3.org/ns/shacl#maxInclusive";
pub const MIN_LENGTH: &str = "http://www.w3.org/ns/shacl#minLength";
pub const MAX_LENGTH: &str = "http://www.w3.org/ns/shacl#maxLength";
pub const PATTERN: &str = "http://www.w3.org/ns/shacl#pattern";
pub const FLAGS: &str = "http://www.w3.org/ns/shacl#flags";
pub const LANGUAGE_IN: &str = "http://www.w3.org/ns/shacl#languageIn";
pub const UNIQUE_LANG: &str = "http://www.w3.org/ns/shacl#uniqueLang";
pub const EQUALS: &str = "http://www.w3.org/ns/shacl#equals";
pub const DISJOINT: &str = "http://www.w3.org/ns/shacl#disjoint";
pub const LESS_THAN: &str = "http://www.w3.org/ns/shacl#lessThan";
pub const LESS_THAN_OR_EQUALS: &str = "http://www.w3.org/ns/shacl#lessThanOrEquals";
pub const NOT: &str = "http://www.w3.org/ns/shacl#not";
pub const AND: &str = "http://www.w3.org/ns/shacl#and";
pub const OR: &str = "http://www.w3.org/ns/shacl#or";
pub const XONE: &str = "http://www.w3.org/ns/shacl#xone";
pub const NODE: &str = "http://www.w3.org/ns/shacl#node";
pub const QUALIFIED_VALUE_SHAPE: &str = "http://www.w3.org/ns/shacl#qualifiedValueShape";
pub const QUALIFIED_MIN_COUNT: &str = "http://www.w3.org/ns/shacl#qualifiedMinCount";
pub const QUALIFIED_MAX_COUNT: &str = "http://www.w3.org/ns/shacl#qualifiedMaxCount";
pub const QUALIFIED_VALUE_SHAPES_DISJOINT: &str =
"http://www.w3.org/ns/shacl#qualifiedValueShapesDisjoint";
pub const CLOSED: &str = "http://www.w3.org/ns/shacl#closed";
pub const IGNORED_PROPERTIES: &str = "http://www.w3.org/ns/shacl#ignoredProperties";
pub const HAS_VALUE: &str = "http://www.w3.org/ns/shacl#hasValue";
pub const IN: &str = "http://www.w3.org/ns/shacl#in";
pub const SPARQL: &str = "http://www.w3.org/ns/shacl#sparql";
pub const SELECT: &str = "http://www.w3.org/ns/shacl#select";
pub const PREFIXES: &str = "http://www.w3.org/ns/shacl#prefixes";
pub const DECLARE: &str = "http://www.w3.org/ns/shacl#declare";
pub const PREFIX_DECL: &str = "http://www.w3.org/ns/shacl#prefix";
pub const NAMESPACE: &str = "http://www.w3.org/ns/shacl#namespace";
pub const MESSAGE: &str = "http://www.w3.org/ns/shacl#message";
pub const DEACTIVATED: &str = "http://www.w3.org/ns/shacl#deactivated";
pub const SEVERITY: &str = "http://www.w3.org/ns/shacl#severity";
pub const SEVERITY_VIOLATION: &str = "http://www.w3.org/ns/shacl#Violation";
pub const SEVERITY_WARNING: &str = "http://www.w3.org/ns/shacl#Warning";
pub const SEVERITY_INFO: &str = "http://www.w3.org/ns/shacl#Info";
pub const NAME: &str = "http://www.w3.org/ns/shacl#name";
pub const DESCRIPTION: &str = "http://www.w3.org/ns/shacl#description";
pub const ORDER: &str = "http://www.w3.org/ns/shacl#order";
pub const GROUP: &str = "http://www.w3.org/ns/shacl#group";
pub const VALIDATION_REPORT: &str = "http://www.w3.org/ns/shacl#ValidationReport";
pub const CONFORMS: &str = "http://www.w3.org/ns/shacl#conforms";
pub const RESULT: &str = "http://www.w3.org/ns/shacl#result";
pub const VALIDATION_RESULT: &str = "http://www.w3.org/ns/shacl#ValidationResult";
pub const FOCUS_NODE: &str = "http://www.w3.org/ns/shacl#focusNode";
pub const RESULT_PATH: &str = "http://www.w3.org/ns/shacl#resultPath";
pub const VALUE: &str = "http://www.w3.org/ns/shacl#value";
pub const RESULT_SEVERITY: &str = "http://www.w3.org/ns/shacl#resultSeverity";
pub const RESULT_MESSAGE: &str = "http://www.w3.org/ns/shacl#resultMessage";
pub const SOURCE_CONSTRAINT_COMPONENT: &str =
"http://www.w3.org/ns/shacl#sourceConstraintComponent";
pub const SOURCE_SHAPE: &str = "http://www.w3.org/ns/shacl#sourceShape";
}
pub struct RDF;
#[allow(missing_docs)]
impl RDF {
pub const TYPE: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
pub const FIRST: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first";
pub const REST: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest";
pub const NIL: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
}
#[derive(Debug, Clone)]
pub enum Shape {
Node(NodeShape),
Property(PropertyShape),
}
impl Shape {
#[must_use]
pub fn id(&self) -> &Term {
match self {
Shape::Node(s) => &s.id,
Shape::Property(s) => &s.id,
}
}
#[must_use]
pub fn is_deactivated(&self) -> bool {
match self {
Shape::Node(s) => s.deactivated,
Shape::Property(s) => s.deactivated,
}
}
#[must_use]
pub fn targets(&self) -> &[Target] {
match self {
Shape::Node(s) => &s.targets,
Shape::Property(s) => &s.targets,
}
}
#[must_use]
pub fn severity(&self) -> Severity {
match self {
Shape::Node(s) => s.severity,
Shape::Property(s) => s.severity,
}
}
#[must_use]
pub fn constraints(&self) -> &[Constraint] {
match self {
Shape::Node(s) => &s.constraints,
Shape::Property(s) => &s.constraints,
}
}
#[must_use]
pub fn messages(&self) -> &[String] {
match self {
Shape::Node(s) => &s.messages,
Shape::Property(s) => &s.messages,
}
}
}
#[derive(Debug, Clone)]
pub struct NodeShape {
pub id: Term,
pub targets: Vec<Target>,
pub property_shapes: Vec<PropertyShape>,
pub constraints: Vec<Constraint>,
pub deactivated: bool,
pub severity: Severity,
pub messages: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct PropertyShape {
pub id: Term,
pub path: PropertyPath,
pub targets: Vec<Target>,
pub constraints: Vec<Constraint>,
pub deactivated: bool,
pub severity: Severity,
pub messages: Vec<String>,
pub name: Option<String>,
pub description: Option<String>,
}
#[derive(Debug, Clone)]
pub enum PropertyPath {
Predicate(Term),
Inverse(Box<PropertyPath>),
Sequence(Vec<PropertyPath>),
Alternative(Vec<PropertyPath>),
ZeroOrMore(Box<PropertyPath>),
OneOrMore(Box<PropertyPath>),
ZeroOrOne(Box<PropertyPath>),
}
#[derive(Debug, Clone)]
pub enum Target {
Class(Term),
Node(Term),
SubjectsOf(Term),
ObjectsOf(Term),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Severity {
Violation,
Warning,
Info,
}
impl Default for Severity {
fn default() -> Self {
Self::Violation
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeKindValue {
BlankNode,
Iri,
Literal,
BlankNodeOrIri,
BlankNodeOrLiteral,
IriOrLiteral,
}
#[derive(Debug, Clone)]
pub enum Constraint {
Class(Term),
Datatype(Term),
NodeKind(NodeKindValue),
MinCount(usize),
MaxCount(usize),
MinExclusive(Term),
MaxExclusive(Term),
MinInclusive(Term),
MaxInclusive(Term),
MinLength(usize),
MaxLength(usize),
Pattern {
pattern: String,
flags: Option<String>,
},
LanguageIn(Vec<String>),
UniqueLang,
Equals(Term),
Disjoint(Term),
LessThan(Term),
LessThanOrEquals(Term),
Not(Box<Shape>),
And(Vec<Shape>),
Or(Vec<Shape>),
Xone(Vec<Shape>),
ShapeNode(Box<Shape>),
QualifiedValueShape {
shape: Box<Shape>,
min_count: Option<usize>,
max_count: Option<usize>,
disjoint: bool,
},
Closed {
ignored_properties: Vec<Term>,
},
HasValue(Term),
In(Vec<Term>),
Sparql(SparqlConstraint),
}
#[derive(Debug, Clone)]
pub struct SparqlConstraint {
pub select: String,
pub message: Option<String>,
pub prefixes: Vec<PrefixDeclaration>,
pub deactivated: bool,
}
#[derive(Debug, Clone)]
pub struct PrefixDeclaration {
pub prefix: String,
pub namespace: String,
}
#[derive(Debug, Clone)]
pub enum ShaclError {
InvalidShape(String),
InvalidPath(String),
ConstraintError(String),
SparqlError(String),
}
impl std::fmt::Display for ShaclError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ShaclError::InvalidShape(msg) => write!(f, "Invalid SHACL shape: {msg}"),
ShaclError::InvalidPath(msg) => write!(f, "Invalid SHACL path: {msg}"),
ShaclError::ConstraintError(msg) => write!(f, "SHACL constraint error: {msg}"),
ShaclError::SparqlError(msg) => write!(f, "SHACL SPARQL error: {msg}"),
}
}
}
impl std::error::Error for ShaclError {}