Skip to main content

Module diff

Module diff 

Source
Expand description

Computing a difference model from two model states.

IEC 61970-552’s dm:DifferenceModel exchanges an update as statements to retract and statements to assert. reader::read_difference, Dataset::apply_difference and writer::write_difference read, apply and write one; this module produces one from a before and an after.

use cim_kit::prelude::*;
use cim_kit::cgmes3::SCHEMA;
use cim_kit::diff::DiffOptions;

let base = Dataset::load(SCHEMA, ["base_EQ.xml", "base_SSH.xml"])?;
let updated = Dataset::load(SCHEMA, ["updated_EQ.xml", "updated_SSH.xml"])?;

let change = base.difference_to(&updated, &DiffOptions::default());
let out = std::fs::File::create("change_DIFF.xml")?;
cim_kit::writer::write_difference(SCHEMA, &change.model, out, &Default::default())?;

§What the result guarantees

Applying the result to the base reproduces the target: base.apply_difference(&base.difference_to(&target, o).model) leaves base holding every value target holds, and none it does not (tested in tests/difference.rs).

§What a statement-level difference cannot say

Two limits of the standard, both reported:

  • An object cannot be deleted, only emptied. rdf:parseType="Statements" retracts statements; there is no statement that says “this identifier no longer denotes anything”. An object absent from the target becomes a subject with no properties; Dataset::prune_empty removes such shells.
  • A compound has no statement form. Location.mainAddress holds a StreetAddress inline, which the statement syntax cannot carry. A changed compound is reported as Rule::Structure and left out.

Structs§

DiffOptions
Options controlling how a difference is computed.
DiffReport
A computed change set, together with what could not be expressed.