Module: Iqvoc::RDFAPI

Defined in:
lib/iqvoc/rdfapi.rb

Constant Summary collapse

FIRST_LEVEL_OBJECT_CLASSES =
[Iqvoc::Concept.base_class, Iqvoc::Collection.base_class]
SECOND_LEVEL_OBJECT_CLASSES =
Iqvoc::Concept.labeling_classes.keys +
Iqvoc::Concept.note_classes +
Iqvoc::Concept.relation_classes +
Iqvoc::Concept.match_classes +
Iqvoc::Concept.notation_classes +
Iqvoc::Concept.additional_association_classes.keys +
[Iqvoc::Collection.member_class]
OBJECT_DICTIONARY =
FIRST_LEVEL_OBJECT_CLASSES.inject({}) do |hash, klass|
  hash["#{klass.rdf_namespace}:#{klass.rdf_class}"] = klass
  hash
end
PREDICATE_DICTIONARY =
SECOND_LEVEL_OBJECT_CLASSES.inject({}) do |hash, klass|
  hash["#{klass.rdf_namespace}:#{klass.rdf_predicate}"] = klass
  hash
end
URI_REGEXP =
/^https?:\/\/[^\s]+$/
LITERAL_REGEXP =
/^"(.+)"(@(.+))?$/

Class Method Summary collapse

Class Method Details

.devour(rdf_subject, rdf_predicate, rdf_object) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/iqvoc/rdfapi.rb', line 41

def self.devour(rdf_subject, rdf_predicate, rdf_object)
  case rdf_predicate
  when 'a', 'rdf:type'
    case rdf_object
    when String
      target = OBJECT_DICTIONARY[rdf_object] || rdf_object.constantize
    else
      target = rdf_object
    end
    target.find_or_initialize_by(origin: rdf_subject)
  when String
    # dictionary lookup
    target = PREDICATE_DICTIONARY[rdf_predicate] || rdf_predicate.constantize
    target.build_from_rdf(rdf_subject, target, rdf_object)
  else # is a class
    rdf_predicate.build_from_rdf(rdf_subject, rdf_predicate, rdf_object)
  end
end