Class: OpenStudio::Metadata::BrickGraph
- Inherits:
-
Object
- Object
- OpenStudio::Metadata::BrickGraph
- Defined in:
- lib/openstudio/metadata/serializer.rb
Overview
Class to serialize entities into Brick Graph
Instance Method Summary collapse
-
#create_from_entities(entities) ⇒ Object
Creates graph from list of entities.
-
#dump(format = :ttl) ⇒ String
Outputs Brick graph in desired ‘format`.
-
#initialize(building_namespace: 'http://example.com/mybuilding#') ⇒ BrickGraph
constructor
Returns new instance of BrickGraph.
Constructor Details
#initialize(building_namespace: 'http://example.com/mybuilding#') ⇒ BrickGraph
Returns new instance of BrickGraph
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/openstudio/metadata/serializer.rb', line 52 def initialize(building_namespace: 'http://example.com/mybuilding#') @brick = RDF::Vocabulary.new('https://brickschema.org/schema/1.1/Brick#') @bldg = RDF::Vocabulary.new(building_namespace) @prefixes = { rdf: RDF.to_uri, rdfs: RDF::RDFS.to_uri, brick: @brick, bldg: @bldg } @g = nil end |
Instance Method Details
#create_from_entities(entities) ⇒ Object
Creates graph from list of entities
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/openstudio/metadata/serializer.rb', line 68 def create_from_entities(entities) @g = RDF::Repository.new entities.each do |entity| @g << RDF::Statement.new(@bldg[entity['id']], RDF.type, @brick[entity['type']]) @g << RDF::Statement.new(@bldg[entity['id']], RDF::RDFS.label, entity['dis']) if entity.key? 'relationships' entity['relationships'].each do |relationship, reference| @g << RDF::Statement.new(@bldg[entity['id']], @brick[relationship], @bldg[reference]) end end end end |
#dump(format = :ttl) ⇒ String
Outputs Brick graph in desired ‘format`
89 90 91 |
# File 'lib/openstudio/metadata/serializer.rb', line 89 def dump(format = :ttl) return @g.dump(format, prefixes: @prefixes) end |