pub struct GroundingSpace<D: DuplicationStrategy = AllowDuplication> { /* private fields */ }Expand description
In-memory space which can contain grounded atoms.
Implementations§
Source§impl<D: DuplicationStrategy> GroundingSpace<D>
impl<D: DuplicationStrategy> GroundingSpace<D>
Sourcepub fn with_strategy(strategy: D) -> Self
pub fn with_strategy(strategy: D) -> Self
Constructs new empty space using duplication strategy.
Sourcepub fn add(&mut self, atom: Atom)
pub fn add(&mut self, atom: Atom)
Adds atom into space.
§Examples
use hyperon_atom::sym;
use hyperon_atom::matcher::BindingsSet;
use hyperon::space::grounding::GroundingSpace;
let mut space = GroundingSpace::from_vec(vec![sym!("A")]);
space.add(sym!("B"));
assert_eq!(space.query(&sym!("A")), BindingsSet::single());
assert_eq!(space.query(&sym!("B")), BindingsSet::single());
assert_eq!(space.query(&sym!("C")), BindingsSet::empty());Sourcepub fn remove(&mut self, atom: &Atom) -> bool
pub fn remove(&mut self, atom: &Atom) -> bool
Removes atom from space. Returns true if atom was found and removed,
and false otherwise.
§Examples
use hyperon_atom::sym;
use hyperon_atom::matcher::BindingsSet;
use hyperon::space::grounding::GroundingSpace;
let mut space = GroundingSpace::from_vec(vec![sym!("A")]);
space.remove(&sym!("A"));
assert_eq!(space.query(&sym!("A")), BindingsSet::empty());Sourcepub fn replace(&mut self, from: &Atom, to: Atom) -> bool
pub fn replace(&mut self, from: &Atom, to: Atom) -> bool
Replaces from atom to to atom inside space. Doesn’t add to when
from is not found. Returns true if atom was found and replaced, and
false otherwise.
§Examples
use hyperon_atom::sym;
use hyperon_atom::matcher::BindingsSet;
use hyperon::space::grounding::GroundingSpace;
let mut space = GroundingSpace::from_vec(vec![sym!("A")]);
space.replace(&sym!("A"), sym!("B"));
assert_eq!(space.query(&sym!("A")), BindingsSet::empty());
assert_eq!(space.query(&sym!("B")), BindingsSet::single());Sourcepub fn query(&self, query: &Atom) -> BindingsSet
pub fn query(&self, query: &Atom) -> BindingsSet
Executes query on the space and returns variable bindings found.
Query may include sub-queries glued by [COMMA_SYMBOL] symbol.
Each Bindings instance in the returned [BindingsSet]
represents single result.
§Examples
use hyperon_atom::{expr, bind_set, sym};
use hyperon_atom::matcher::BindingsSet;
use hyperon::space::grounding::GroundingSpace;
let space = GroundingSpace::from_vec(vec![expr!("A" "B"), expr!("B" "C")]);
let query = expr!("," ("A" x) (x "C"));
let result = space.query(&query);
assert_eq!(result, bind_set![{x: sym!("B")}]);Trait Implementations§
Source§impl<D: Clone + DuplicationStrategy> Clone for GroundingSpace<D>
impl<D: Clone + DuplicationStrategy> Clone for GroundingSpace<D>
Source§fn clone(&self) -> GroundingSpace<D>
fn clone(&self) -> GroundingSpace<D>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<D: DuplicationStrategy> Debug for GroundingSpace<D>
impl<D: DuplicationStrategy> Debug for GroundingSpace<D>
Source§impl<D: DuplicationStrategy> Display for GroundingSpace<D>
impl<D: DuplicationStrategy> Display for GroundingSpace<D>
Source§impl Space for GroundingSpace
impl Space for GroundingSpace
Source§fn atom_count(&self) -> Option<usize>
fn atom_count(&self) -> Option<usize>
Returns the number of Atoms in the space, or None if this can’t be determined
Source§fn visit(&self, v: &mut dyn SpaceVisitor) -> Result<(), ()>
fn visit(&self, v: &mut dyn SpaceVisitor) -> Result<(), ()>
Visit each atom of the space and call [SpaceVisitor::accept] method.
This method is optional. Return
Err(()) if method is not implemented.
Cow<Atom> is used to allow passing both references and values. First
is appropriate for collection based atomspace. Second one is more
usable if atomspace is a generator or when values cannot be extracted
easily and should be reconstructed instead.Source§impl SpaceMut for GroundingSpace
impl SpaceMut for GroundingSpace
Source§fn remove(&mut self, atom: &Atom) -> bool
fn remove(&mut self, atom: &Atom) -> bool
Removes
atom from space. Returns true if atom was found and removed,
and false otherwise. Read moreSource§fn replace(&mut self, from: &Atom, to: Atom) -> bool
fn replace(&mut self, from: &Atom, to: Atom) -> bool
Replaces
from atom to to atom inside space. Doesn’t add to when
from is not found. Returns true if atom was found and replaced, and
false otherwise. Read moreSource§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns an
&mut dyn Any for spaces where this is possibleAuto Trait Implementations§
impl<D = AllowDuplication> !Freeze for GroundingSpace<D>
impl<D = AllowDuplication> !RefUnwindSafe for GroundingSpace<D>
impl<D = AllowDuplication> !Send for GroundingSpace<D>
impl<D = AllowDuplication> !Sync for GroundingSpace<D>
impl<D> Unpin for GroundingSpace<D>where
D: Unpin,
impl<D = AllowDuplication> !UnwindSafe for GroundingSpace<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request