pub struct TriplePattern {
pub subject: Option<NodeId>,
pub predicate: Option<Predicate>,
pub object: Option<Value>,
}Expand description
A pattern for matching (Subject, Predicate, Object) triples.
A pattern specifies constraints on the components of a triple. Any component
can be None, which acts as a wildcard that matches any value.
§Examples
Match all triples with a specific subject:
use aingle_graph::{TriplePattern, NodeId};
let pattern = TriplePattern::subject(NodeId::named("user:alice"));Match triples with specific subject and predicate:
use aingle_graph::{TriplePattern, NodeId, Predicate};
let pattern = TriplePattern::subject(NodeId::named("user:alice"))
.with_predicate(Predicate::named("has_name"));Match all triples (wildcard pattern):
use aingle_graph::TriplePattern;
let pattern = TriplePattern::any();
assert!(pattern.is_wildcard());Fields§
§subject: Option<NodeId>An optional constraint on the triple’s subject.
predicate: Option<Predicate>An optional constraint on the triple’s predicate.
object: Option<Value>An optional constraint on the triple’s object.
Implementations§
Source§impl TriplePattern
impl TriplePattern
Sourcepub fn any() -> Self
pub fn any() -> Self
Creates a new pattern that matches any triple.
This is equivalent to a wildcard pattern with no constraints.
§Examples
use aingle_graph::TriplePattern;
let pattern = TriplePattern::any();
assert!(pattern.is_wildcard());Sourcepub fn subject(subject: NodeId) -> Self
pub fn subject(subject: NodeId) -> Self
Creates a new pattern that matches a specific subject.
§Examples
use aingle_graph::{TriplePattern, NodeId};
let pattern = TriplePattern::subject(NodeId::named("user:alice"));Sourcepub fn predicate(predicate: Predicate) -> Self
pub fn predicate(predicate: Predicate) -> Self
Creates a new pattern that matches a specific predicate.
Sourcepub fn with_subject(self, subject: NodeId) -> Self
pub fn with_subject(self, subject: NodeId) -> Self
Adds a subject constraint to the pattern.
Sourcepub fn with_predicate(self, predicate: Predicate) -> Self
pub fn with_predicate(self, predicate: Predicate) -> Self
Adds a predicate constraint to the pattern.
Sourcepub fn with_object(self, object: Value) -> Self
pub fn with_object(self, object: Value) -> Self
Adds an object constraint to the pattern.
Sourcepub fn matches(&self, triple: &Triple) -> bool
pub fn matches(&self, triple: &Triple) -> bool
Returns true if the given Triple matches this pattern.
A triple matches the pattern if all non-None constraints are satisfied.
§Examples
use aingle_graph::{Triple, TriplePattern, NodeId, Predicate, Value};
let triple = Triple::new(
NodeId::named("user:alice"),
Predicate::named("has_name"),
Value::literal("Alice"),
);
let pattern = TriplePattern::subject(NodeId::named("user:alice"));
assert!(pattern.matches(&triple));
let wrong_pattern = TriplePattern::subject(NodeId::named("user:bob"));
assert!(!wrong_pattern.matches(&triple));Sourcepub fn is_exact(&self) -> bool
pub fn is_exact(&self) -> bool
Returns true if all components (subject, predicate, object) of the pattern are specified.
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
Returns true if the pattern is a wildcard (all components are None).
Trait Implementations§
Source§impl Clone for TriplePattern
impl Clone for TriplePattern
Source§fn clone(&self) -> TriplePattern
fn clone(&self) -> TriplePattern
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more