use std::collections::HashMap;
use thiserror::Error;
pub type Triple = (String, String, String);
pub type Bindings = HashMap<String, String>;
#[derive(Debug, Error)]
pub enum RlError {
#[error("Ontology inconsistency detected: {0}")]
Inconsistency(String),
#[error("Maximum iterations ({0}) exceeded during materialization")]
MaxIterationsExceeded(usize),
#[error("Invalid axiom: {0}")]
InvalidAxiom(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Owl2RlRule {
ScmSco,
ScmSpo,
ScmEqc1,
ScmEqc2,
ScmEqp1,
ScmEqp2,
ScmDom1,
ScmDom2,
ScmRng1,
ScmRng2,
ScmHv,
ScmInt,
ScmUni,
PrpSpo1,
PrpSpo2,
PrpEqp1,
PrpEqp2,
PrpDom,
PrpRng,
PrpFp,
PrpIfp,
PrpIrp,
PrpSymp,
PrpAsynp,
PrpTrp,
PrpInv1,
PrpInv2,
PrpKey,
PrpPdw,
PrpNpa1,
PrpNpa2,
ClsInt1,
ClsInt2,
ClsUni,
ClsSvf1,
ClsSvf2,
ClsAvf,
ClsHv1,
ClsHv2,
ClsMaxc1,
ClsMaxc2,
ClsMaxqc1,
ClsMaxqc2,
ClsNothing1,
ClsNothing2,
CaxSco,
CaxEqc1,
CaxEqc2,
CaxDw,
CaxAdc,
RdfsSubClassTransitivity,
RdfsSubPropertyPropagation,
RdfsDomainInference,
RdfsRangeInference,
EqRef,
EqSym,
EqTrans,
EqRep1,
EqRep2,
EqRep3,
}
#[derive(Debug, Clone)]
pub struct InferenceReport {
pub iterations: usize,
pub new_triples_count: usize,
pub rules_fired: HashMap<Owl2RlRule, usize>,
pub duration: std::time::Duration,
pub inconsistencies: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PatternElem {
Var(String),
Const(String),
}
impl PatternElem {
pub(crate) fn var(s: &str) -> Self {
Self::Var(s.to_string())
}
pub(crate) fn konst(s: &str) -> Self {
Self::Const(s.to_string())
}
}
#[derive(Debug, Clone)]
pub struct TriplePattern {
pub subject: PatternElem,
pub predicate: PatternElem,
pub object: PatternElem,
}
impl TriplePattern {
pub fn new(s: PatternElem, p: PatternElem, o: PatternElem) -> Self {
Self {
subject: s,
predicate: p,
object: o,
}
}
}
#[derive(Debug, Clone)]
pub(crate) struct CompiledRule {
pub(crate) id: Owl2RlRule,
pub(crate) antecedents: Vec<TriplePattern>,
pub(crate) consequent: TriplePattern,
}
pub const RDF_TYPE: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
pub const RDF_REST: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest";
pub const RDF_FIRST: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first";
pub const RDFS_SUBCLASS_OF: &str = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
pub const RDFS_SUBPROPERTY_OF: &str = "http://www.w3.org/2000/01/rdf-schema#subPropertyOf";
pub const RDFS_DOMAIN: &str = "http://www.w3.org/2000/01/rdf-schema#domain";
pub const RDFS_RANGE: &str = "http://www.w3.org/2000/01/rdf-schema#range";
pub const OWL_SAME_AS: &str = "http://www.w3.org/2002/07/owl#sameAs";
pub const OWL_EQUIVALENT_CLASS: &str = "http://www.w3.org/2002/07/owl#equivalentClass";
pub const OWL_EQUIVALENT_PROPERTY: &str = "http://www.w3.org/2002/07/owl#equivalentProperty";
pub const OWL_INVERSE_OF: &str = "http://www.w3.org/2002/07/owl#inverseOf";
pub const OWL_SYMMETRIC_PROPERTY: &str = "http://www.w3.org/2002/07/owl#SymmetricProperty";
pub const OWL_TRANSITIVE_PROPERTY: &str = "http://www.w3.org/2002/07/owl#TransitiveProperty";
pub const OWL_FUNCTIONAL_PROPERTY: &str = "http://www.w3.org/2002/07/owl#FunctionalProperty";
pub const OWL_INV_FUNCTIONAL_PROPERTY: &str =
"http://www.w3.org/2002/07/owl#InverseFunctionalProperty";
pub const OWL_ASYMMETRIC_PROPERTY: &str = "http://www.w3.org/2002/07/owl#AsymmetricProperty";
pub const OWL_IRREFLEXIVE_PROPERTY: &str = "http://www.w3.org/2002/07/owl#IrreflexiveProperty";
pub const OWL_DISJOINT_WITH: &str = "http://www.w3.org/2002/07/owl#disjointWith";
pub const OWL_NOTHING: &str = "http://www.w3.org/2002/07/owl#Nothing";
pub const OWL_SOME_VALUES_FROM: &str = "http://www.w3.org/2002/07/owl#someValuesFrom";
pub const OWL_ALL_VALUES_FROM: &str = "http://www.w3.org/2002/07/owl#allValuesFrom";
pub const OWL_ON_PROPERTY: &str = "http://www.w3.org/2002/07/owl#onProperty";
pub const OWL_HAS_VALUE: &str = "http://www.w3.org/2002/07/owl#hasValue";
pub const OWL_INTERSECTION_OF: &str = "http://www.w3.org/2002/07/owl#intersectionOf";
pub const OWL_UNION_OF: &str = "http://www.w3.org/2002/07/owl#unionOf";
pub const OWL_THING: &str = "http://www.w3.org/2002/07/owl#Thing";
pub mod vocab {
pub use super::OWL_ALL_VALUES_FROM;
pub use super::OWL_DISJOINT_WITH;
pub use super::OWL_EQUIVALENT_CLASS;
pub use super::OWL_EQUIVALENT_PROPERTY;
pub use super::OWL_FUNCTIONAL_PROPERTY;
pub use super::OWL_HAS_VALUE;
pub use super::OWL_INVERSE_OF;
pub use super::OWL_INV_FUNCTIONAL_PROPERTY;
pub use super::OWL_NOTHING;
pub use super::OWL_ON_PROPERTY;
pub use super::OWL_SAME_AS;
pub use super::OWL_SOME_VALUES_FROM;
pub use super::OWL_SYMMETRIC_PROPERTY;
pub use super::OWL_THING;
pub use super::OWL_TRANSITIVE_PROPERTY;
pub use super::RDFS_DOMAIN;
pub use super::RDFS_RANGE;
pub use super::RDFS_SUBCLASS_OF;
pub use super::RDFS_SUBPROPERTY_OF;
pub use super::RDF_TYPE;
}