#measurement #ontology

om2

A set of classes generated from the OM2 RDF schema (mainly Unit)

9 releases

0.1.9 Sep 21, 2020
0.1.8 Jun 4, 2020
0.1.7 May 29, 2020

#1643 in Data structures

Download history 5/week @ 2023-11-06 15/week @ 2023-11-13 16/week @ 2023-11-20 32/week @ 2023-11-27 3/week @ 2023-12-04 4/week @ 2023-12-11 13/week @ 2023-12-18 31/week @ 2023-12-25 2/week @ 2024-01-01 6/week @ 2024-01-08 17/week @ 2024-01-15 6/week @ 2024-01-22 20/week @ 2024-01-29 8/week @ 2024-02-05 43/week @ 2024-02-12 256/week @ 2024-02-19

327 downloads per month
Used in vf-rs

Custom license

135KB
639 lines

OM2

This crate is a loose attempt at creating a Unit struct based off of the units available in the OM2 ontology. It also exports Measure and NumericUnion classes.

All structs/enums exported are (de)serializable via Serde.

use om2::{Unit, Measure, NumericUnion};
let measure = Measure::builder()
    .has_unit(Unit::Hour)
    .has_numerical_value(NumericUnion::Integer(7))
    .build().unwrap();
assert_eq!(measure.has_unit(), &Unit::Hour);
assert_eq!(measure.has_numerical_value(), &NumericUnion::Integer(7));

lib.rs:

This is an auto-generated wrapper around the om2:Unit class, with a few supporting structs/enums/utils.

The idea here is to map Unit into a big (de)serializable rust enum, so you don't need to know the label/symbol up front but can just grab it from the Unit enum:

use om2::Unit;

let wh = Unit::WattHour;
assert_eq!(wh.symbol(), Some("W h".to_string()));
assert_eq!(wh.label(), Some("watt hour".to_string()));

Note that the symbol() and label() methods return Option because not all the enum values have those fields defined int he schema.

This crate also exports om2:Measure, useful for holding full measurements. It also has getters by default, with the option to include setters as well:

use om2::{Unit, Measure, NumericUnion};
let measure = Measure::new(7.3 as f64, Unit::Hour);
assert_eq!(measure.has_unit(), &Unit::Hour);
assert_eq!(measure.has_numerical_value(), &NumericUnion::Double(7.3));

Note that none of the available RDF/XML rust libs were able to parse the om2 RDF schema, so this library requires conversion to .ttl first (this is done via the make schema command, which uses the rapper command line util under the hood).

Features:

  • getset_setters - implements setters on the generated structs so they can be mutated in-place via setter methods
  • getset_getmut - implements mutable getters on the generated structs so they can be mutated in-place via &mut getters

Note that all features are enabled when building the docs to give a sense of the library's full abilities.

Dependencies

~1.8–2.4MB
~53K SLoC