Class: Match::SKOS::Base

Inherits:
Base
  • Object
show all
Defined in:
app/models/match/skos/base.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Direct Known Subclasses

MappingRelation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_from_rdf(rdf_subject, rdf_predicate, rdf_object) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'app/models/match/skos/base.rb', line 20

def self.build_from_rdf(rdf_subject, rdf_predicate, rdf_object)
  raise "#{self.class}#build_from_rdf: Subject (#{rdf_subject}) must be able to receive this kind of match (#{self.name} => #{self.name.to_relation_name})." unless rdf_subject.class.reflections.include?(self.name.to_relation_name.to_s)
  raise "#{self.class}#build_from_rdf: Object (#{rdf_object}) must be a URI" unless rdf_object =~ /^<(.+)>$/ # XXX: this assumes nt-format, right?
  uri = $1

  match_class = RDFAPI::PREDICATE_DICTIONARY[rdf_predicate] || self
  match_class.new(value: uri).tap do |match|
    rdf_subject.send(self.name.to_relation_name) << match
  end
end

Instance Method Details

#build_rdf(document, subject) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'app/models/match/skos/base.rb', line 31

def build_rdf(document, subject)
  raise "Match::SKOS::Base#build_rdf: Class #{self.name} needs to define self.rdf_namespace and self.rdf_predicate." unless self.rdf_namespace && self.rdf_predicate

  if (IqRdf::Namespace.find_namespace_class(self.rdf_namespace.camelcase))
    subject.send(self.rdf_namespace.camelcase).send(self.rdf_predicate, URI.parse(value))
  else
    raise "#{self.class}#build_rdf: couldn't find Namespace '#{self.rdf_namespace.camelcase}'."
  end
end