ufu:NG(?UnitID, ufu:refersToMetric, ?MetricID) ,
ufu:NG(?UnitID, ufu:hasConversionFactor, ?Conversion) ,
ufu:NG(?UnitID, ufu:unitName, ?UnitOfMeasure) ,
[?MetricID, :metricName, ?Metric]
        :- ufrd:MetricUnits(?Metric, ?UnitOfMeasure, ?Conversion) ,
        BIND(IRI(CONCAT(STR(:), "Unit-", SHA256(?UnitOfMeasure))) AS ?UnitID) ,
        BIND(IRI(CONCAT(STR(quantitykind:), ?Metric)) AS ?MetricID) .

# If Units given instead of metrics, do conversion
[?Observation, :metric, ?Metric]
    :-
        ufu:NG(?Observation, ufu:unit, ?Unit),
        ufu:NG(?Unit, ufu:refersToMetric, ?Metric) .

[?Observation, :measurement, ?MetricVal]
    :-
        ufu:NG(?Observation, ufu:unit, ?Unit),
        ufu:NG(?Unit, ufu:refersToMetric, ?Metric) ,
        ufu:NG(?Unit, ufu:hasConversionFactor, ?Conversion),
        ufu:NG(?Observation, ufu:measurementUnit, ?Value) ,
        BIND(?Value * ?Conversion AS ?MetricVal).

[?Observation, :measurement, ?Value]
   :-
        ufu:NG(?Observation, ufu:unit, ?Unit),
        ufu:NG(?Observation, ufu:measurementUnit, ?Value) ,
        NOT EXISTS ?Metric IN (
            ufu:NG(?Unit, ufu:refersToMetric, ?Metric)
        ) .

