Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph.validate() fails when Brick ontology is preloaded to the graph #106

Open
emesar opened this issue Dec 19, 2023 · 6 comments
Open

Graph.validate() fails when Brick ontology is preloaded to the graph #106

emesar opened this issue Dec 19, 2023 · 6 comments

Comments

@emesar
Copy link

emesar commented Dec 19, 2023

For a simple graph that only includes the Brick ontology, validation appears to fail.

from brickschema import Graph

g = Graph(load_brick=True)
_, _, report = g.validate()
print(report)

The resulting report:

Validation Report
Conforms: False
Results (38):
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Power_Factor
        Value Node: qudtqk:PowerFactor
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Speed
        Value Node: qudtqk:Speed
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Capacity
        Value Node: qudtqk:Capacity
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Active_Power
        Value Node: qudtqk:ActivePower
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Luminous_Intensity
        Value Node: qudtqk:LuminousIntensity
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Time
        Value Node: qudtqk:Time
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Flow
        Value Node: qudtqk:VolumeFlowRate
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Conductivity
        Value Node: qudtqk:Conductivity
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Voltage
        Value Node: qudtqk:Voltage
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Atmospheric_Pressure
        Value Node: qudtqk:AtmosphericPressure
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Luminance
        Value Node: qudtqk:Luminance
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Torque
        Value Node: qudtqk:Torque
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Radiance
        Value Node: qudtqk:Radiance
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Temperature
        Value Node: qudtqk:Temperature
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Angle
        Value Node: qudtqk:Angle
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Differential_Dynamic_Pressure
        Value Node: qudtqk:DynamicPressure
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Frequency
        Value Node: qudtqk:Frequency
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Absolute_Humidity
        Value Node: qudtqk:AbsoluteHumidity
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Relative_Humidity
        Value Node: qudtqk:RelativeHumidity
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Mass
        Value Node: qudtqk:Mass
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Complex_Power
        Value Node: qudtqk:ComplexPower
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Volume
        Value Node: qudtqk:Volume
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Electric_Power
        Value Node: qudtqk:ElectricPower
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Pressure
        Value Node: qudtqk:Pressure
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Static_Pressure
        Value Node: qudtqk:StaticPressure
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Dewpoint
        Value Node: qudtqk:DewPointTemperature
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Luminous_Flux
        Value Node: qudtqk:LuminousFlux
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Apparent_Power
        Value Node: qudtqk:ApparentPower
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Real_Power
        Value Node: qudtqk:ActivePower
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Enthalpy
        Value Node: qudtqk:Enthalpy
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Illuminance
        Value Node: qudtqk:Illuminance
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Reactive_Power
        Value Node: qudtqk:ReactivePower
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Differential_Temperature
        Value Node: qudtqk:Temperature
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Electric_Current
        Value Node: qudtqk:ElectricCurrent
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Thermal_Energy
        Value Node: qudtqk:ThermalEnergy
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Differential_Static_Pressure
        Value Node: qudtqk:StaticPressure
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Power
        Value Node: qudtqk:Power
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: bsh:hasQUDTReferenceShape
        Focus Node: brick:Velocity_Pressure
        Value Node: qudtqk:DynamicPressure
        Result Path: brick:hasQUDTReference
        Message: Value does not have class qudt:QuantityKind
@gtfierro
Copy link
Member

This is due to recent changes in QUDT, which caught some insufficient extensions of QUDT we were doing in Brick. As long as you just have these QUDT results in your validation result, you should be ok. We are working on fixing these validation issues in the main Brick repo

@Maghnie
Copy link

Maghnie commented Dec 11, 2024

Is there a recommended workaround?

Currently, I'm using this hard-coded if condition

...

valid, _, results_text = g.validate()

qudt_errors = True if results_text.count("Result Path: brick:hasQUDTReference") == 38 else False

if valid or qudt_errors:
    print("Graph is valid")
else:    
    print("Graph is not valid")
    print(results_text)

...

@gtfierro
Copy link
Member

Hi @Maghnie the reason this is failing is because you do not have the QUDT ontology loaded in. You can use https://github.com/gtfierro/ontoenv-rs?tab=readme-ov-file#python-library to load the dependency ontologies into the same graph before you validate, and that should address the issues.

I will also make a note to update the tutorial and address these issues for future users! Please let me know if this addresses your issue and if you ahve any other questions

@Maghnie
Copy link

Maghnie commented Dec 17, 2024

Thanks for the quick reply!

Can the pyontoenv package work on Windows?

When I try to run the example from the pyontoenv readme, I get this error

Creating new OntoEnv
Traceback (most recent call last):
File "[...]\pyontoenv_example.py", line 7, in
env = OntoEnv(cfg)
^^^^^^^^^^^^
ValueError: IO error for operation on brick: Das System kann die angegebene Datei nicht finden. (os error 2)

And sure enough, my virtual environment doesn't have any source files for pyontoenv, even though I tried to install the package with pip install pyontoenv. I also tried pip install ontoenv, since there was a pip entry for that, but it didn't work either.

@gtfierro
Copy link
Member

Yes, it should work on Windows. If you update to pyontoenv==0.1.10a2, then you should be able to change the line of the xample to cfg = Config(strict=False, offline=True). The current code is failing because you don't have a "brick" directory locally.

@Maghnie
Copy link

Maghnie commented Dec 19, 2024

Still won't work - I'm not sure if I'm missing something 😅.

I updated the pyontoenv version and the Config arguments as you mentioned above. Also copied the "brick" directory from the ontoenv-rs repo locally. For good measure, I deleted the automatically created .ontoenv directory from previous runs. Now I get a different error:

Config path: Some(".\\.ontoenv\\ontoenv.json")
Creating new OntoEnv with provided config     
thread '<unnamed>' panicked at lib\src\ontology.rs:167:57:
called `Result::unwrap()` on an `Err` value: IriParseError { kind: InvalidIriCodePoint('\\') }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "[...]\pyontoenv_example.py", line 8, in <module>
    env = OntoEnv(cfg)
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: IriParseError { kind: InvalidIriCodePoint('\\') }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants