Module: VirtualAssembly::Semantizer::SemanticObject
- Defined in:
- lib/virtual_assembly/semantizer/semantic_object.rb
Overview
The SemanticObject module is designed to add linked data to classical objects.
A semanticObject holds semantic properties (SemanticProperty) that refers to linked data concepts.
For example, a Person object including this module could register in its initializer method a semantic property for its name like: Person.registerSemanticProperty(“xmlns.com/foaf/0.1/name”) selfself.name
Instance Attribute Summary collapse
-
#semanticId ⇒ Object
The semantic ID implements the concept of linked data ID.
-
#semanticProperties ⇒ Object
readonly
This Array stores the semantic properties of the object.
-
#semanticType ⇒ Object
The semantic type implements the concept of linked data type (also called class).
Instance Method Summary collapse
- #hasSemanticProperty?(name) ⇒ Boolean
-
#initialize(semanticId = nil, semanticType = nil) ⇒ Object
If the semanticId is nil, the object will be treated as a blank node.
- #isBlankNode? ⇒ Boolean
-
#registerSemanticProperty(name, &valueGetter) ⇒ Object
Use this method to append a semantic property to this object.
-
#semanticPropertyValue(name) ⇒ Object
Given the name of the property, it returns the value associated to a property of this object.
-
#serialize(serializer) ⇒ Object
Serialize all the semantic properties of this object to an output format.
Instance Attribute Details
#semanticId ⇒ Object
The semantic ID implements the concept of linked data ID.
This ID is an uri pointing to the location of the object on the web like “mywebsite/myobject” for instance.
If a SemanticObject doesn’t define its ID, it will be considered as a blank node.
This should be a String or nil.
40 41 42 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 40 def semanticId @semanticId end |
#semanticProperties ⇒ Object (readonly)
This Array stores the semantic properties of the object. To append a SemanticProperty, use the dedicated registerSemanticProperty method. You should pass the value of the property as a block (callback) like so: registerSemanticProperty(“xmlns.com/foaf/0.1/name”) VirtualAssembly::Semantizer::SemanticObject.selfself.name.
57 58 59 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 57 def semanticProperties @semanticProperties end |
#semanticType ⇒ Object
The semantic type implements the concept of linked data type (also called class).
This type is an uri pointing to the location of the linked data concept on the web like “xmlns.com/foaf/0.1/Person” for instance.
This should be a String or nil.
50 51 52 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 50 def semanticType @semanticType end |
Instance Method Details
#hasSemanticProperty?(name) ⇒ Boolean
75 76 77 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 75 def hasSemanticProperty?(name) return @semanticPropertiesNameIndex.include?(name) end |
#initialize(semanticId = nil, semanticType = nil) ⇒ Object
If the semanticId is nil, the object will be treated as a blank node.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 60 def initialize(semanticId = nil, semanticType = nil) @semanticId = semanticId @semanticType = semanticType @semanticProperties = Array.new # This Hash allows us to find a property using its name. # # Hash<String, Integer> # # The key store the name of a property (String). # The value store the index of the property in the # semanticProperties array (Integer). @semanticPropertiesNameIndex = Hash.new end |
#isBlankNode? ⇒ Boolean
79 80 81 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 79 def isBlankNode? return @semanticId == nil || @semanticId == "" end |
#registerSemanticProperty(name, &valueGetter) ⇒ Object
Use this method to append a semantic property to this object. The value of the property should be passed as a block so its value would be up to date when we will access it.
93 94 95 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 93 def registerSemanticProperty(name, &valueGetter) createOrUpdateSemanticProperty(name, valueGetter) end |
#semanticPropertyValue(name) ⇒ Object
Given the name of the property, it returns the value associated to a property of this object.
85 86 87 88 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 85 def semanticPropertyValue(name) index = @semanticPropertiesNameIndex.fetch(name, nil) return index != nil ? @semanticProperties[index].value : nil; end |
#serialize(serializer) ⇒ Object
Serialize all the semantic properties of this object to an output format.
You could use the HashSerializer to export as a Hash. This Hash should be then exported to JSON for instance.
135 136 137 |
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 135 def serialize(serializer) return serializer.process(self) end |