BrickSchema / py-brickschema

Python package for working with Brick (brickschema.org/)
Other
55 stars 15 forks source link

Brickify output empty. #74

Closed Pythonwuerger closed 3 years ago

Pythonwuerger commented 3 years ago

Hi I tried to write a few very simple operations to test it out, but I can't seem to be able to get it to run.

I created a very simple example to work on :

Building Name Heating Group Pump Valve Command
B1 HG30 HG30_PU HG30_Vlv HG30_Cmd

I want to try mapping the entries and the relations : hasEquipment, hasPart and hasPoint.

I'm using the brickify command. brickify Simplified1.csv --output bldg.ttl --input-type csv --config simple.yml

, where Simplified.csv is the name of the .csv with the info above and simple.yml is the name of the operator yml.

The only example I could find in the documentation was for the hasPoint relation so I'll start with that.

---
namespace_prefixes:
  brick: "https://brickschema.org/schema/Brick#"
operations:
  -
    data: |-
      bldg:{Heating Group} rdf:type brick:Terminal Unit ;
                      brick:hasPoint bldg:{Command} .
      bldg:{Command} rdf:type brick:Command .

I expected to get a node for Terminal Unit called HG30 with a hasPoint relation to a Command node. What I got was an empty building.ttl file.

I also tried to map hasPart relationships.

---
namespace_prefixes:
  brick: "https://brickschema.org/schema/Brick#"
operations:
  -
    data: |-
      bldg:{Heating Group} rdf:type brick:Terminal Unit ;
                      brick:hasPart bldg:{Pump} ;
                      brick:hasPart bldg:{Valve} .
      bldg:{Pump} rdf:type brick:Pump .
      bldg:{Valve} rdf:type brick:Valve .

The turtle file for this operator is completely empty as well. I expected a node for Terminal Unit called HG30 with two hasPart relations to the nodes to HG30_PU and HG30_Vlv.

Finally I'd also need the hasEquipment relationship, which I tried mapping like this.

---
namespace_prefixes:
  brick: "https://brickschema.org/schema/Brick#"
operations:
  -
    data: |-
      bldg:{Building Name} rdf:type brick:Building ;
                      brick:hasEquipment bldg:{Heating Group} .
      bldg:{Heating Group} rdf:type brick:Terminal Unit .

Same problem like the others. It runs, but the output bldg.ttl is empty. Of course in my later application I'd want to write a combined operator. From my reverse engineering I think it should look something like this:

---
namespace_prefixes:
  brick: "https://brickschema.org/schema/Brick#"
operations:
  -
    data: |-
      bldg:{Building Name} rdf:type brick:Building ;
                      brick:hasEquipment bldg:{Heating Group} .
      bldg:{Heating Group} rdf:type brick:Terminal Unit ;
                      brick:hasPart bldg:{Pump} ;
                      brick:hasPart bldg:{Valve} ;
                      brick:hasPoint bldg:{Command} .
      bldg:{Pump} rdf:type brick:Pump .
      bldg:{Valve} rdf:type brick:Valve .
      bldg:{Command} rdf:type brick:Command .

I wanted a Building (B1) main node that has the Terminal Unit (HG30) as an equipment relationship, which has a Pump and a Valve as part relationship and finally a command as a Point relationship (or should it be a is controlled by?)

My main issue is that the output is empty. How do I correct this?

Then secondly, is the operator written correctly for what I intend it to do? If not, how should I correct it?

Something else I also wondered: I'm not sure about how lines are supposed to end. I noticed that sometime they end with ";" and sometimes they end with ".". I also noticed that if there are more entries wit a relationship in the next line ";" is used. Is that correct? Please tell me when to use ";" and when ".". Finally what does the "bldg" part at the start of a brickdefinition do?

There are also some differences to the example shreyasnagare shared with me in my previous post. I also don't understand the subtle syntax differences there for example the way bricks are defined with "a brick" or the spacing with "-". What is the logic behind this? Also I noticed various relationship mappings, but with a completely different structure. Furthermore, there are various relationships like "isControlledBy" "hasLocation" "isLocationOf". Most of them are self explanatory, but is there a comprehensive list of these relationships, what they mean and how to define them?

Pythonwuerger commented 3 years ago

Thank you very much for self-assigning the issue.

Is there anything I could do to allow you to better help me solve my issue?

Pythonwuerger commented 3 years ago

The issue was probably due to all data being processes in a single operation. At some point an entry that was expected by the operation seems to have been empty, which caused the whole operation to be skipped. It was solved by splitting up the operations like this:

---
namespace_prefixes:
  brick: "https://brickschema.org/schema/Brick#"
operations:
  -
    data: |-
      bldg:{Building Name} rdf:type brick:Building .
      bldg:{Building Name} brick:hasEquipment bldg:{Heating Group} .
      bldg:{Heating Group} rdf:type brick:Terminal_Unit .
  -
    data: |-
      bldg:{Heating Group} brick:hasPart bldg:{Pump} .
      bldg:{Pump}          rdf:type brick:Pump .
  -
    data: |-
      bldg:{Heating Group} brick:hasPart bldg:{Valve} .
      bldg:{Valve}         rdf:type brick:Valve .
  -
    data: |-
      bldg:{Heating Group} brick:hasPoint bldg:{Command} .
      bldg:{Command}       rdf:type brick:Command .

Splitting this code into even smaller data operation, would reduce the chance that operations are missing even more. The other questions could be answered as well. ";" Is used when the next line has the same subject as the previous triplet, while "." doesn't affect the next line. The "bldg" is used instead of an URL, to indicate the namespace prefixes.