Skip to main content

GroundingMetadata

Struct GroundingMetadata 

Source
pub struct GroundingMetadata {
    pub normalized_uri: Option<String>,
    pub normalized_label: Option<String>,
    pub normalized_prov: Option<String>,
    pub normalized_score: Option<f32>,
    pub normalized_method: Option<NormalizationMethod>,
}
Expand description

Grounding metadata for normalized terms (Dynamic Ontology)

Fields§

§normalized_uri: Option<String>

Canonical URI from ontology (NCIt, HGNC, etc.)

§normalized_label: Option<String>

Human-friendly label for display

§normalized_prov: Option<String>

Source ontology (NCIt, HGNC, custom)

§normalized_score: Option<f32>

Similarity/confidence score (0.0 - 1.0)

§normalized_method: Option<NormalizationMethod>

Method used for normalization

Implementations§

Source§

impl GroundingMetadata

Source

pub fn new( uri: String, label: String, prov: String, score: f32, method: NormalizationMethod, ) -> Self

Create new grounding metadata with URI and score

Examples found in repository?
examples/ontology_usage.rs (lines 80-86)
73fn example_coverage_signal() {
74    // Create entities with varying grounding using string-based entity_type
75    let entities = vec![
76        ExtractedEntity {
77            entity_type: "cancer_diagnosis".to_string(),
78            raw_value: "non-small cell lung cancer".to_string(),
79            normalized_value: Some("Non-Small Cell Lung Cancer".to_string()),
80            grounding: Some(GroundingMetadata::new(
81                "http://example.org/nsclc".to_string(),
82                "Non-Small Cell Lung Cancer".to_string(),
83                "NCIt".to_string(),
84                0.95,
85                terraphim_types::NormalizationMethod::Exact,
86            )),
87        },
88        ExtractedEntity {
89            entity_type: "drug".to_string(),
90            raw_value: "Osimertinib".to_string(),
91            normalized_value: Some("Osimertinib".to_string()),
92            grounding: Some(GroundingMetadata::new(
93                "http://example.org/osimertinib".to_string(),
94                "Osimertinib".to_string(),
95                "NCIt".to_string(),
96                0.98,
97                terraphim_types::NormalizationMethod::Exact,
98            )),
99        },
100        ExtractedEntity {
101            entity_type: "genomic_variant".to_string(),
102            raw_value: "Unknown mutation".to_string(),
103            normalized_value: None,
104            grounding: None,
105        },
106    ];
107
108    // Calculate categories
109    let categories: Vec<String> = entities
110        .iter()
111        .map(|e| e.normalized_value.clone().unwrap_or(e.raw_value.clone()))
112        .collect();
113
114    // Count matched (entities with grounding)
115    let matched = entities.iter().filter(|e| e.grounding.is_some()).count();
116
117    // Compute coverage with 0.7 threshold
118    let coverage = CoverageSignal::compute(&categories, matched, 0.7);
119
120    println!("  Total categories: {}", coverage.total_categories);
121    println!("  Matched categories: {}", coverage.matched_categories);
122    println!("  Coverage ratio: {:.1}%", coverage.coverage_ratio * 100.0);
123    println!("  Threshold: {:.0}%", coverage.threshold * 100.0);
124    println!("  Needs review: {}", coverage.needs_review);
125}
126
127fn example_schema_signal() {
128    // Create a schema signal from extracted oncology data using string-based types
129    let entities = vec![
130        ExtractedEntity {
131            entity_type: "cancer_diagnosis".to_string(),
132            raw_value: "lung carcinoma".to_string(),
133            normalized_value: Some("Lung Carcinoma".to_string()),
134            grounding: Some(GroundingMetadata::new(
135                "http://example.org/lung_carcinoma".to_string(),
136                "Lung Carcinoma".to_string(),
137                "NCIt".to_string(),
138                0.95,
139                terraphim_types::NormalizationMethod::Exact,
140            )),
141        },
142        ExtractedEntity {
143            entity_type: "genomic_variant".to_string(),
144            raw_value: "EGFR L858R".to_string(),
145            normalized_value: Some("EGFR L858R".to_string()),
146            grounding: None,
147        },
148    ];
149
150    let relationships = vec![];
151
152    let schema_signal = SchemaSignal {
153        entities,
154        relationships,
155        confidence: 0.5,
156    };
157
158    println!("  Entities: {}", schema_signal.entities.len());
159    println!("  Relationships: {}", schema_signal.relationships.len());
160    println!("  Confidence: {:.0}%", schema_signal.confidence * 100.0);
161}

Trait Implementations§

Source§

impl Clone for GroundingMetadata

Source§

fn clone(&self) -> GroundingMetadata

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 Debug for GroundingMetadata

Source§

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

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

impl Default for GroundingMetadata

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for GroundingMetadata

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for GroundingMetadata

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,