1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! DLSafe SWRL rule atoms stored on an ontology.
use serde::{Deserialize, Serialize};
use crate::EntityId;
/// SWRL individual argument: named individual or variable.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SwrlIArg {
/// Named individual entity.
Individual(EntityId),
/// Rule variable name (local, without leading `:`).
Variable(String),
}
/// SWRL data argument: literal or variable.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SwrlDArg {
/// Typed or plain literal value.
Literal {
/// Lexical form.
lexical: String,
/// XSD datatype entity when known.
datatype: Option<EntityId>,
},
/// Rule variable name.
Variable(String),
}
/// A single SWRL atom in rule body or head.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SwrlAtom {
/// `C(x)` class atom.
Class {
/// Named class entity.
class: EntityId,
/// Individual or variable.
arg: SwrlIArg,
},
/// `P(x, y)` object property atom.
ObjectProperty {
/// Object property entity.
property: EntityId,
/// Subject individual or variable.
subject: SwrlIArg,
/// Object individual or variable.
object: SwrlIArg,
},
/// `P(x, v)` data property atom.
DataProperty {
/// Data property entity.
property: EntityId,
/// Subject individual or variable.
subject: SwrlIArg,
/// Literal or variable.
value: SwrlDArg,
},
/// `sameAs(x, y)`.
SameIndividual(SwrlIArg, SwrlIArg),
/// `differentFrom(x, y)`.
DifferentIndividuals(SwrlIArg, SwrlIArg),
/// `D(v)` data range atom constraining a data variable.
DataRange {
/// Data range expression id in the DL store.
range: crate::DeId,
/// Literal or variable argument.
arg: SwrlDArg,
},
}
/// Parsed DLSafe SWRL rule.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SwrlRule {
/// Body atoms (conjunction).
pub body: Vec<SwrlAtom>,
/// Head atoms (conjunction).
pub head: Vec<SwrlAtom>,
}