Skip to main content

GraphIndex

Struct GraphIndex 

Source
pub struct GraphIndex { /* private fields */ }
Expand description

An in-memory default graph with distinct facts and authored assertions.

use morphir_core::metadata::{Assertion, AssertionKey, Carrier, DocumentId,
    Fact, GraphIndex, GraphName, ObjectTerm};
use morphir_core::node_address::NodeUri;
use serde_json::json;

let subject = NodeUri::parse(
    "morphir://ir/pkg/acme/orders?format=4.0.0#/module/api/value/submit-order"
).unwrap();
let predicate = NodeUri::parse(
    "morphir://ir/pkg/acme/metadata?format=4.0.0#/module/naming/value/aliases"
).unwrap();
let fact = Fact::new(subject.clone(), predicate, ObjectTerm::value(json!("placeOrder")),
    GraphName::Default);
let owner = DocumentId::new("orders/spec.json").unwrap();
let key = AssertionKey::new(owner, Carrier::AttributesFacts(subject.clone()), fact).unwrap();
let mut graph = GraphIndex::new();
graph.insert(Assertion::new(key)).unwrap();
assert_eq!(graph.outgoing(&subject).len(), 1);

Implementations§

Source§

impl GraphIndex

Source

pub fn new() -> Self

Create an empty default graph.

Source

pub fn insert(&mut self, assertion: Assertion) -> Result<(), MetadataError>

Insert one assertion, coalescing equal facts and repeated same-carrier assertions.

A duplicate key with mixed explicit and implicit source knowledge is rejected because merging it could hide an unknown contributor. Named graphs remain representable in Fact but are rejected here.

Source

pub fn facts(&self) -> &[Fact]

Distinct facts in first-insertion order.

Source

pub fn assertions(&self) -> &[Assertion]

Distinct document-and-carrier assertions in first-insertion order.

Source

pub fn try_map_node_uris<E>( &self, map: impl FnMut(&NodeUri) -> Result<NodeUri, E>, ) -> Result<Self, GraphMapError<E>>

Rebind every addressed term and carrier in one transaction. Source detail travels with its assertion, so a published selector cannot be left referring to the authoring identity. Literal data is never scanned for URI-looking strings.

Source

pub fn apply_source_records( &mut self, owner: &DocumentId, records: &[SourceRecord], ) -> Result<(), MetadataError>

Apply one document’s optional detailed source table after all selectors validate.

Selectors use the already-expanded assertion identity. Any invalid row rejects the entire table without changing source ownership.

Source

pub fn rewrite_assertion( &mut self, old: &AssertionKey, replacement: Fact, ) -> Result<(), MetadataError>

Replace one authored fact and its selector in one graph update.

Existing explicit sources move with the assertion. A failed replacement leaves both the graph and its source table association untouched.

Source

pub fn remove_source_from_owner( &mut self, owner: &DocumentId, source: &AssertionSource, ) -> Result<usize, MetadataError>

Remove a known source’s contribution to one document’s assertions.

An assertion with only the implicit document source has unknown detailed ownership, so source-dependent removal fails before changing anything. Assertions without remaining sources are removed from the graph.

Source

pub fn assertions_for_fact(&self, fact: &Fact) -> Vec<&Assertion>

All document-and-carrier assertions for one expanded fact.

Source

pub fn outgoing(&self, subject: &NodeUri) -> Vec<&Fact>

All distinct default-graph facts whose subject is this node.

Source

pub fn outgoing_with_predicate( &self, subject: &NodeUri, predicate: &NodeUri, ) -> Vec<&Fact>

Outgoing facts for one expanded predicate declaration.

Source

pub fn incoming(&self, object: &NodeUri) -> Vec<&Fact>

All distinct default-graph facts that link to this node.

Strings inside typed data are never interpreted as incoming links.

Trait Implementations§

Source§

impl Debug for GraphIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GraphIndex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.