pub struct Schema {
pub vintage: &'static str,
pub namespaces: &'static [NamespaceDef],
pub profiles: &'static [ProfileDef],
pub classes: &'static [ClassDef],
pub attributes: &'static [AttrDef],
pub enums: &'static [EnumDef],
pub enum_values: &'static [EnumValueDef],
pub datatypes: &'static [DatatypeDef],
pub class_index: &'static [(u16, &'static str, ClassId)],
pub attr_index: &'static [(u16, &'static str, AttrId)],
pub enum_value_index: &'static [(u16, &'static str, EnumValueId)],
}Expand description
A complete CIM schema vintage.
Fields§
§vintage: &'static strVintage key, e.g. cgmes3.
namespaces: &'static [NamespaceDef]§profiles: &'static [ProfileDef]§classes: &'static [ClassDef]§attributes: &'static [AttrDef]§enums: &'static [EnumDef]§enum_values: &'static [EnumValueDef]§datatypes: &'static [DatatypeDef]§class_index: &'static [(u16, &'static str, ClassId)](ns index, local name) sorted, for binary-search lookup of classes.
attr_index: &'static [(u16, &'static str, AttrId)](ns index, qualified name) sorted, for attribute lookup.
enum_value_index: &'static [(u16, &'static str, EnumValueId)](ns index, qualified name) sorted, for enum literal lookup.
Implementations§
Source§impl Schema
impl Schema
pub fn class(&self, id: ClassId) -> &'static ClassDef
pub fn attr(&self, id: AttrId) -> &'static AttrDef
pub fn enumeration(&self, id: EnumId) -> &'static EnumDef
pub fn enum_value(&self, id: EnumValueId) -> &'static EnumValueDef
pub fn datatype(&self, id: DatatypeId) -> &'static DatatypeDef
pub fn profile(&self, id: ProfileId) -> &'static ProfileDef
pub fn namespace(&self, id: NsId) -> &'static NamespaceDef
pub fn ns_id(&self, iri: &str) -> Option<NsId>
pub fn profile_by_keyword(&self, keyword: &str) -> Option<ProfileId>
Sourcepub fn profile_by_iri(&self, iri: &str) -> Option<ProfileId>
pub fn profile_by_iri(&self, iri: &str) -> Option<ProfileId>
Resolve the md:Model.profile IRI written in an instance file header.
The trailing version segment is ignored so that, for example, a file declaring
.../CoreEquipment-EU/3.0 still resolves when the schema knows /3.0.
Sourcepub fn find_class(&self, ns: &str, local: &str) -> Option<ClassId>
pub fn find_class(&self, ns: &str, local: &str) -> Option<ClassId>
Look up a class by namespace IRI and local name.
Sourcepub fn class_by_name(&self, local: &str) -> Option<ClassId>
pub fn class_by_name(&self, local: &str) -> Option<ClassId>
Look up a class by local name in whichever namespace declares it.
For tooling that must work across vintages without knowing their namespaces:
Substation lives in CIM100 in CGMES 3.0 and in cim16 in CGMES 2.4.15, and a
program that only wants to count substations should not have to spell either. Where
two namespaces declare the same local name — an extension shadowing a core class —
the first in namespace order wins, so Schema::find_class is the call to reach
for when the distinction matters.
Sourcepub fn find_attr(&self, ns: &str, qualified: &str) -> Option<AttrId>
pub fn find_attr(&self, ns: &str, qualified: &str) -> Option<AttrId>
Look up an attribute by namespace IRI and qualified name (Class.attr).
Sourcepub fn find_enum_value(&self, ns: &str, qualified: &str) -> Option<EnumValueId>
pub fn find_enum_value(&self, ns: &str, qualified: &str) -> Option<EnumValueId>
Look up an enumeration literal by namespace IRI and qualified name.
Sourcepub fn find_enum_value_any_ns(&self, qualified: &str) -> Option<EnumValueId>
pub fn find_enum_value_any_ns(&self, qualified: &str) -> Option<EnumValueId>
Look up an enumeration literal by qualified name in any namespace.
Exporters do misplace these: published CGMES 2.4.15 test models write the
ENTSO-E extension literal LimitTypeKind.patl under the cim namespace. The
qualified name is unambiguous on its own, so the value can still be recovered —
callers should report the namespace mismatch rather than accept it silently.
Sourcepub fn is_a(&self, class: ClassId, ancestor: ClassId) -> bool
pub fn is_a(&self, class: ClassId, ancestor: ClassId) -> bool
Whether class is ancestor or inherits from it.
Sourcepub fn attr_by_label(&self, class: ClassId, label: &str) -> Option<AttrId>
pub fn attr_by_label(&self, class: ClassId, label: &str) -> Option<AttrId>
Find an attribute visible on class by its short label.
Searches the class and its ancestors, most-derived first.
Sourcepub fn effective_profiles(
&self,
attr: AttrId,
provenance: ProfileMask,
) -> ProfileMask
pub fn effective_profiles( &self, attr: AttrId, provenance: ProfileMask, ) -> ProfileMask
The profiles a stored value belongs in — the single rule the writer and the per-profile coverage report share, so the report cannot drift from the export.
provenance is the profile mask recorded on the value when it was read (zero for
values set programmatically). It is intersected with the profiles that actually
declare the attribute, because one instance file routinely declares several
profiles: a CGMES 3.0 Equipment file commonly declares both CoreEquipment and
ShortCircuit, and without the intersection every value in it would be written to
both exports, duplicating the whole file.
The intersection can be empty, because published files do set attributes their own
header does not declare — a CGMES 2.4.15 boundary file writes
Terminal.ConnectivityNode, which only the Equipment profile declares. When that
happens the value goes back where it came from: the data is evidence, the
vocabulary is a claim about it, and re-filing the value under a profile its source
does not serve would drop it from every export. validate
reports the discrepancy as Rule::AttributeNotInProfile.
Only a value with no provenance at all — one set programmatically — falls back to the attribute’s declaration, which is then the sole available answer.
Sourcepub fn declaration_covers(&self, attr: AttrId, provenance: ProfileMask) -> bool
pub fn declaration_covers(&self, attr: AttrId, provenance: ProfileMask) -> bool
Whether a value’s source file declared a profile that declares its attribute.
False means the file under-declares its own content: it carries data belonging to
a profile its md:Model.profile does not name. Published models do this — the
RealGrid Equipment file carries ShortCircuit attributes while declaring only
CoreEquipment — so it is a warning about the header, not a reason to lose data.
Sourcepub fn match_score<'a>(
&self,
namespaces: impl IntoIterator<Item = &'a str>,
) -> usize
pub fn match_score<'a>( &self, namespaces: impl IntoIterator<Item = &'a str>, ) -> usize
How strongly a document declaring namespaces looks like this vintage.
The number of this vintage’s classes that live in namespaces the document declares.
Weighted by class count rather than by namespace, because every namespace a schema
knows holds at least one class — the 61970-552 header vocabulary puts classes in
md, dm and even rdf — so presence alone discriminates nothing. Bulk does:
CIM100# holds 436 classes against rdf’s one, so a CGMES 2.4.15 document scores
400 for 2.4.15 and 3 for 3.0.
Sourcepub fn detect<'a>(
namespaces: impl IntoIterator<Item = &'a str>,
) -> Option<&'static Schema>
pub fn detect<'a>( namespaces: impl IntoIterator<Item = &'a str>, ) -> Option<&'static Schema>
The compiled-in vintage a document declaring namespaces belongs to.
CIM/XML names its vocabulary in the document — xmlns:cim="…/CIM100#" for CGMES 3.0,
"…/CIM-schema-cim16#" for 2.4.15 — so the caller never has to guess, and guessing
wrong is expensive: reading a 2.4.15 file against the CGMES 3.0 tables resolves no
class at all and yields an empty model with one “unknown class” warning per element.
Returns None when nothing in the document points at any compiled-in vintage, which
is the honest answer for a build without the matching feature.
See reader::sniff, which answers this from a document’s
root element without parsing the rest.
Sourcepub fn concrete_classes(&self) -> impl Iterator<Item = ClassId> + '_
pub fn concrete_classes(&self) -> impl Iterator<Item = ClassId> + '_
Every concrete class, useful for tooling that enumerates the model.