Skip to main content

ProvenanceSet

Struct ProvenanceSet 

Source
pub struct ProvenanceSet<P: Ord> { /* private fields */ }
Expand description

Deterministic provenance tokens attached to one stored fact.

ProvenanceSet<P> is the user-visible witness for a fact in this first G3 slice. It is an exact BTreeSet-backed set of tokens or labels, not a derivation DAG.

§Examples

use relmath::provenance::{ProvenanceRelation, ProvenanceSet};

let empty = ProvenanceSet::<&str>::default();
assert!(empty.is_empty());

let evidence = ProvenanceRelation::from_facts([
    (("BRCA1", "BreastCancer"), "paper_12"),
    (("BRCA1", "BreastCancer"), "curated_panel"),
]);
let witness = evidence
    .why(&("BRCA1", "BreastCancer"))
    .expect("expected explanation");

assert_eq!(witness.len(), 2);
assert!(witness.contains(&"paper_12"));
assert!(witness.contains_token(&"curated_panel"));
assert_eq!(
    witness.iter().copied().collect::<Vec<_>>(),
    vec!["curated_panel", "paper_12"]
);
assert_eq!(witness.to_vec(), vec!["curated_panel", "paper_12"]);

Implementations§

Source§

impl<P: Ord> ProvenanceSet<P>

Source

pub fn len(&self) -> usize

Returns the number of provenance tokens in the set.

Source

pub fn is_empty(&self) -> bool

Returns true when the provenance set contains no tokens.

Source

pub fn contains(&self, token: &P) -> bool

Returns true when the set contains the given token.

Source

pub fn contains_token(&self, token: &P) -> bool

Returns true when the set contains the given provenance token.

Examples found in repository?
examples/provenance.rs (line 29)
5fn main() {
6    let gene_disease = ProvenanceRelation::from_facts([
7        (("BRCA1", "BreastCancer"), "curated_panel"),
8        (("BRCA1", "BreastCancer"), "paper_12"),
9        (("TP53", "BreastCancer"), "paper_77"),
10    ]);
11
12    let disease_drug = relmath::BinaryRelation::from_pairs([
13        ("BreastCancer", "Olaparib"),
14        ("BreastCancer", "Tamoxifen"),
15    ]);
16
17    let supported_gene_disease = gene_disease.to_binary_relation();
18    let gene_drug = supported_gene_disease.compose(&disease_drug);
19    let brca1 = UnaryRelation::singleton("BRCA1");
20    let brca1_witness = gene_disease
21        .why(&("BRCA1", "BreastCancer"))
22        .expect("expected explanation");
23
24    assert_eq!(
25        gene_drug.image(&brca1).to_vec(),
26        vec!["Olaparib", "Tamoxifen"]
27    );
28    assert_eq!(brca1_witness.to_vec(), vec!["curated_panel", "paper_12"]);
29    assert!(brca1_witness.contains_token(&"paper_12"));
30    assert_eq!(
31        gene_disease
32            .provenance_of(&("BRCA1", "BreastCancer"))
33            .expect("expected explanation")
34            .to_vec(),
35        brca1_witness.to_vec()
36    );
37    assert_eq!(
38        gene_disease.support().to_vec(),
39        vec![("BRCA1", "BreastCancer"), ("TP53", "BreastCancer")]
40    );
41    assert!(gene_disease.why(&("BRCA1", "Olaparib")).is_none());
42
43    println!(
44        "why BRCA1 links to BreastCancer in the base evidence: {:?}",
45        brca1_witness.to_vec()
46    );
47}
Source

pub fn iter(&self) -> impl Iterator<Item = &P>

Returns an iterator over provenance tokens in deterministic order.

Source

pub fn to_vec(&self) -> Vec<P>
where P: Clone,

Converts the provenance set into a sorted vector of tokens.

Examples found in repository?
examples/provenance.rs (line 28)
5fn main() {
6    let gene_disease = ProvenanceRelation::from_facts([
7        (("BRCA1", "BreastCancer"), "curated_panel"),
8        (("BRCA1", "BreastCancer"), "paper_12"),
9        (("TP53", "BreastCancer"), "paper_77"),
10    ]);
11
12    let disease_drug = relmath::BinaryRelation::from_pairs([
13        ("BreastCancer", "Olaparib"),
14        ("BreastCancer", "Tamoxifen"),
15    ]);
16
17    let supported_gene_disease = gene_disease.to_binary_relation();
18    let gene_drug = supported_gene_disease.compose(&disease_drug);
19    let brca1 = UnaryRelation::singleton("BRCA1");
20    let brca1_witness = gene_disease
21        .why(&("BRCA1", "BreastCancer"))
22        .expect("expected explanation");
23
24    assert_eq!(
25        gene_drug.image(&brca1).to_vec(),
26        vec!["Olaparib", "Tamoxifen"]
27    );
28    assert_eq!(brca1_witness.to_vec(), vec!["curated_panel", "paper_12"]);
29    assert!(brca1_witness.contains_token(&"paper_12"));
30    assert_eq!(
31        gene_disease
32            .provenance_of(&("BRCA1", "BreastCancer"))
33            .expect("expected explanation")
34            .to_vec(),
35        brca1_witness.to_vec()
36    );
37    assert_eq!(
38        gene_disease.support().to_vec(),
39        vec![("BRCA1", "BreastCancer"), ("TP53", "BreastCancer")]
40    );
41    assert!(gene_disease.why(&("BRCA1", "Olaparib")).is_none());
42
43    println!(
44        "why BRCA1 links to BreastCancer in the base evidence: {:?}",
45        brca1_witness.to_vec()
46    );
47}
More examples
Hide additional examples
examples/capability_boundaries.rs (line 57)
22fn main() {
23    let evidence = ProvenanceRelation::from_facts([
24        (("alice", "review"), "directory"),
25        (("bob", "approve"), "policy"),
26    ]);
27    let permissions = AnnotatedRelation::from_facts([
28        (("alice", "review"), BooleanSemiring::TRUE),
29        (("bob", "approve"), BooleanSemiring::TRUE),
30    ]);
31    let schedule = ValidTimeRelation::from_facts([
32        (
33            ("alice", "review"),
34            Interval::new(1, 3).expect("expected valid interval"),
35        ),
36        (
37            ("bob", "approve"),
38            Interval::new(2, 4).expect("expected valid interval"),
39        ),
40    ]);
41
42    let exact_evidence = exact_pairs(&evidence);
43    let exact_permissions = exact_pairs(&permissions);
44    let exact_schedule = exact_pairs(&schedule);
45
46    assert_eq!(
47        exact_evidence.to_vec(),
48        vec![("alice", "review"), ("bob", "approve")]
49    );
50    assert_eq!(exact_permissions.to_vec(), exact_evidence.to_vec());
51    assert_eq!(exact_schedule.to_vec(), exact_evidence.to_vec());
52
53    assert_eq!(
54        evidence
55            .why(&("alice", "review"))
56            .expect("expected witness")
57            .to_vec(),
58        vec!["directory"]
59    );
60    assert_eq!(
61        permissions.annotation_of(&("alice", "review")),
62        Some(&BooleanSemiring::TRUE)
63    );
64    assert_eq!(
65        schedule
66            .valid_time_of(&("alice", "review"))
67            .expect("expected interval support")
68            .to_vec(),
69        vec![Interval::new(1, 3).expect("expected valid interval")]
70    );
71
72    println!(
73        "witness={:?}, annotation={:?}, interval_support={:?}, exact_support={:?}",
74        evidence
75            .why(&("alice", "review"))
76            .expect("expected witness")
77            .to_vec(),
78        permissions.annotation_of(&("alice", "review")),
79        schedule
80            .valid_time_of(&("alice", "review"))
81            .expect("expected interval support")
82            .to_vec(),
83        exact_schedule.to_vec()
84    );
85}

Trait Implementations§

Source§

impl<P: Clone + Ord> Clone for ProvenanceSet<P>

Source§

fn clone(&self) -> ProvenanceSet<P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + Ord> Debug for ProvenanceSet<P>

Source§

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

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

impl<P: Ord> Default for ProvenanceSet<P>

Source§

fn default() -> Self

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

impl<P: PartialEq + Ord> PartialEq for ProvenanceSet<P>

Source§

fn eq(&self, other: &ProvenanceSet<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Eq + Ord> Eq for ProvenanceSet<P>

Source§

impl<P: Ord> StructuralPartialEq for ProvenanceSet<P>

Auto Trait Implementations§

§

impl<P> Freeze for ProvenanceSet<P>

§

impl<P> RefUnwindSafe for ProvenanceSet<P>
where P: RefUnwindSafe,

§

impl<P> Send for ProvenanceSet<P>
where P: Send,

§

impl<P> Sync for ProvenanceSet<P>
where P: Sync,

§

impl<P> Unpin for ProvenanceSet<P>

§

impl<P> UnsafeUnpin for ProvenanceSet<P>

§

impl<P> UnwindSafe for ProvenanceSet<P>
where P: RefUnwindSafe,

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.