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
impl GroundingMetadata
Sourcepub fn new(
uri: String,
label: String,
prov: String,
score: f32,
method: NormalizationMethod,
) -> Self
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
impl Clone for GroundingMetadata
Source§fn clone(&self) -> GroundingMetadata
fn clone(&self) -> GroundingMetadata
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 Debug for GroundingMetadata
impl Debug for GroundingMetadata
Source§impl Default for GroundingMetadata
impl Default for GroundingMetadata
Source§impl<'de> Deserialize<'de> for GroundingMetadata
impl<'de> Deserialize<'de> for GroundingMetadata
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for GroundingMetadata
impl RefUnwindSafe for GroundingMetadata
impl Send for GroundingMetadata
impl Sync for GroundingMetadata
impl Unpin for GroundingMetadata
impl UnsafeUnpin for GroundingMetadata
impl UnwindSafe for GroundingMetadata
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