pub struct RdmCache { /* private fields */ }Expand description
Cache for RDM collections, enabling concept UUID -> label lookups
Implementations§
Source§impl RdmCache
impl RdmCache
Sourcepub fn add_collection_from_json(
&mut self,
collection_id: &str,
concepts_json: &str,
) -> Result<(), String>
pub fn add_collection_from_json( &mut self, collection_id: &str, concepts_json: &str, ) -> Result<(), String>
Add a collection from JSON
@param collection_id - The collection identifier @param concepts_json - JSON array of concepts with {id, prefLabel: {lang: label}}
Sourcepub fn add_collection(&mut self, collection: RdmCollection)
pub fn add_collection(&mut self, collection: RdmCollection)
Add a collection, merging with any existing collection that has the same ID.
When merging:
- New concepts with labels always win over existing bare stubs (no labels).
- Existing concepts with labels are kept if the incoming concept is bare.
- If both have labels, the incoming concept wins (last-writer-wins).
- New concepts that don’t exist yet are always added.
Sourcepub fn has_collection(&self, collection_id: &str) -> bool
pub fn has_collection(&self, collection_id: &str) -> bool
Check if a collection is loaded
Sourcepub fn get_collection_ids(&self) -> Vec<String>
pub fn get_collection_ids(&self) -> Vec<String>
Get all loaded collection IDs
Sourcepub fn lookup_label(
&self,
collection_id: &str,
concept_id: &str,
language: &str,
) -> Option<String>
pub fn lookup_label( &self, collection_id: &str, concept_id: &str, language: &str, ) -> Option<String>
Look up the label for a concept
@param collection_id - The collection to search in @param concept_id - The concept UUID @param language - The language code (e.g., “en”) @returns The label string, or None if not found
Sourcepub fn lookup_concept(
&self,
collection_id: &str,
concept_id: &str,
) -> Option<&RdmConcept>
pub fn lookup_concept( &self, collection_id: &str, concept_id: &str, ) -> Option<&RdmConcept>
Look up full concept info
Sourcepub fn get_parent_id(
&self,
collection_id: &str,
concept_id: &str,
) -> Option<String>
pub fn get_parent_id( &self, collection_id: &str, concept_id: &str, ) -> Option<String>
Get the first parent ID for a concept
Returns None if the collection doesn’t exist, concept doesn’t exist, or concept has no parent (top-level concept).
Sourcepub fn lookup_value(
&self,
collection_id: &str,
value_id: &str,
) -> Option<&RdmValue>
pub fn lookup_value( &self, collection_id: &str, value_id: &str, ) -> Option<&RdmValue>
Look up a value by its VALUE ID
This is the primary lookup method used by ViewModels. Returns None if the collection or value ID is not found.
Sourcepub fn get_concept_id_for_value(
&self,
collection_id: &str,
value_id: &str,
) -> Option<&str>
pub fn get_concept_id_for_value( &self, collection_id: &str, value_id: &str, ) -> Option<&str>
Get concept ID from value ID
Returns the concept ID that contains the given value ID.
Sourcepub fn validate_value(&self, collection_id: &str, value_id: &str) -> bool
pub fn validate_value(&self, collection_id: &str, value_id: &str) -> bool
Validate that a value exists in a collection
Sourcepub fn get_collection(&self, collection_id: &str) -> Option<&RdmCollection>
pub fn get_collection(&self, collection_id: &str) -> Option<&RdmCollection>
Get a collection by ID
Sourcepub fn get_collection_mut(
&mut self,
collection_id: &str,
) -> Option<&mut RdmCollection>
pub fn get_collection_mut( &mut self, collection_id: &str, ) -> Option<&mut RdmCollection>
Get a mutable reference to a collection by ID
Sourcepub fn remove_collection(&mut self, collection_id: &str) -> bool
pub fn remove_collection(&mut self, collection_id: &str) -> bool
Remove a specific collection from the cache
Sourcepub fn validate_concept(&self, collection_id: &str, concept_id: &str) -> bool
pub fn validate_concept(&self, collection_id: &str, concept_id: &str) -> bool
Validate that a concept exists in a collection
Sourcepub fn lookup_by_label(
&self,
collection_id: &str,
label: &str,
) -> Option<&RdmConcept>
pub fn lookup_by_label( &self, collection_id: &str, label: &str, ) -> Option<&RdmConcept>
Look up a concept by label in a specific collection
Returns the concept if exactly one match is found. Returns None if no match or ambiguous (multiple matches).
Sourcepub fn lookup_all_by_label(
&self,
collection_id: &str,
label: &str,
) -> Vec<&RdmConcept>
pub fn lookup_all_by_label( &self, collection_id: &str, label: &str, ) -> Vec<&RdmConcept>
Look up a concept by label, returning all matches
Sourcepub fn search_all(
&self,
query: &str,
language: Option<&str>,
) -> Vec<(&str, &RdmConcept)>
pub fn search_all( &self, query: &str, language: Option<&str>, ) -> Vec<(&str, &RdmConcept)>
Search across all collections (for autocomplete)
Source§impl RdmCache
impl RdmCache
Sourcepub fn add_from_skos_collection(&mut self, skos: &SkosCollection) -> String
pub fn add_from_skos_collection(&mut self, skos: &SkosCollection) -> String
Convert a SkosCollection to an RdmCollection and add it to the cache.
Returns the collection ID.
Sourcepub fn add_from_skos_collections(
&mut self,
collections: &[SkosCollection],
) -> Vec<String>
pub fn add_from_skos_collections( &mut self, collections: &[SkosCollection], ) -> Vec<String>
Add multiple SKOS collections to the cache.
After adding, enriches any existing collections that have bare concept stubs (concepts with no labels) if the newly-added data provides labels for those concept IDs. This handles the common Arches pattern where collections.xml and concepts.xml are separate files.
Returns the list of collection IDs added.