Module: VirtualAssembly::Semantizer::SemanticObject

Defined in:
lib/virtual_assembly/semantizer/semantic_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#semanticIdObject

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.



43
44
45
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 43

def semanticId
  @semanticId
end

#semanticTypeObject

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.



53
54
55
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 53

def semanticType
  @semanticType
end

Instance Method Details

#==(other) ⇒ Object



144
145
146
147
148
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 144

def ==(other)
  return false unless other.respond_to?(:semanticProperties)

  semanticProperties == other.semanticProperties
end

#hasSemanticProperty?(name) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 73

def hasSemanticProperty?(name)
  @semanticPropertiesMap.key?(name)
end

#initialize(semanticId = nil, semanticType = nil) ⇒ Object

If the semanticId is nil, the object will be treated as a blank node.



56
57
58
59
60
61
62
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 56

def initialize(semanticId = nil, semanticType = nil)
  @semanticPropertiesMap = {}

  # Ensure to call the setter methods
  self.semanticId = semanticId
  self.semanticType = semanticType
end

#isBlankNode?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 77

def isBlankNode?
  @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.



96
97
98
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 96

def registerSemanticProperty(name, &valueGetter)
  createOrUpdateSemanticProperty(name, valueGetter)
end

#semanticPropertiesObject

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.



69
70
71
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 69

def semanticProperties
  @semanticPropertiesMap.values
end

#semanticProperty(name) ⇒ Object

Given its name, returns the corresponding SemanticProperty stored by this object or nil if the property does not exist.



89
90
91
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 89

def semanticProperty(name)
  @semanticPropertiesMap[name]
end

#semanticPropertyValue(name) ⇒ Object

Given the name of the property, it returns the value associated to a property of this object.



83
84
85
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 83

def semanticPropertyValue(name)
  semanticProperty(name)&.value
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.



140
141
142
# File 'lib/virtual_assembly/semantizer/semantic_object.rb', line 140

def serialize(serializer)
  serializer.process(self)
end