Class: ActiveFedora::RDFDatastream

Inherits:
Datastream
  • Object
show all
Includes:
RdfNode, Solrizer::Common
Defined in:
lib/active_fedora/rdf_datastream.rb

Direct Known Subclasses

NtriplesRDFDatastream, RdfxmlRDFDatastream

Instance Attribute Summary collapse

Attributes inherited from Datastream

#digital_object, #last_modified

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RdfNode

#append, #config_for_term_or_uri, #delete_predicate, #find_predicate, #get_values, #method_missing, #query, #rdf_subject, #reset_rdf_subject!, #set_value, #target_class

Methods inherited from Datastream

#create, #dirty, #dirty=, #dirty?, from_xml, #initialize, #inspect, #new_object?, #profile_from_hash, #save, #serialize!, #solrize_profile, #to_param, #validate_content_present

Constructor Details

This class inherits a constructor from ActiveFedora::Datastream

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveFedora::RdfNode

Instance Attribute Details

#loadedObject

Returns the value of attribute loaded.



34
35
36
# File 'lib/active_fedora/rdf_datastream.rb', line 34

def loaded
  @loaded
end

Class Method Details

.rdf_subject {|ds| ... } ⇒ Object

Register a ruby block that evaluates to the subject of the graph By default, the block returns the current object’s pid This should override the method in RdfObject, which just creates a b-node by default

Yields:

  • (ds)

    ‘ds’ is the datastream instance



20
21
22
23
24
25
26
# File 'lib/active_fedora/rdf_datastream.rb', line 20

def rdf_subject &block
  if block_given?
     return @subject_block = block
  end

  @subject_block ||= lambda { |ds| RDF::URI.new("info:fedora/#{ds.pid}") }
end

.register_vocabularies(*vocabs) ⇒ Object



28
29
30
# File 'lib/active_fedora/rdf_datastream.rb', line 28

def register_vocabularies(*vocabs)
  Deprecation.warn(RDFDatastream, "register_vocabularies no longer has any effect and will be removed in active-fedora 6.0", caller)
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/active_fedora/rdf_datastream.rb', line 59

def changed?
  super || content_changed?
end

#contentObject



45
46
47
# File 'lib/active_fedora/rdf_datastream.rb', line 45

def content
  serialize
end

#content=(content) ⇒ Object



49
50
51
52
# File 'lib/active_fedora/rdf_datastream.rb', line 49

def content=(content)
  self.loaded = true
  @graph = deserialize(content)
end

#content_changed?Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/active_fedora/rdf_datastream.rb', line 54

def content_changed?
  return false if new? and !loaded
  super
end

#deserialize(data = nil) ⇒ Object

Populate a RDFDatastream object based on the “datastream” content Assumes that the datastream contains RDF content

Parameters:

  • data (String) (defaults to: nil)

    the “rdf” node



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/active_fedora/rdf_datastream.rb', line 82

def deserialize(data = nil)
  repository = RDF::Repository.new
  return repository if new? and data.nil?

  data ||= datastream_content

  RDF::Reader.for(serialization_format).new(data) do |reader|
    reader.each_statement do |statement|
      repository << statement
    end
  end

  repository
end

#graphObject



97
98
99
100
101
102
# File 'lib/active_fedora/rdf_datastream.rb', line 97

def graph
  @graph ||= begin
    self.loaded = true
    deserialize
  end      
end

#metadata?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_fedora/rdf_datastream.rb', line 35

def metadata?
  true
end

#prefix(name) ⇒ Object



39
40
41
42
43
# File 'lib/active_fedora/rdf_datastream.rb', line 39

def prefix(name)
  name = name.to_s unless name.is_a? String
  pre = dsid.underscore
  return "#{pre}__#{name}".to_sym
end

#serialization_formatObject



104
105
106
# File 'lib/active_fedora/rdf_datastream.rb', line 104

def serialization_format
  raise "you must override the `serialization_format' method in a subclass"
end

#serializeObject

Creates a RDF datastream for insertion into a Fedora Object Note: This method is implemented on SemanticNode instead of RelsExtDatastream because SemanticNode contains the relationships array



110
111
112
113
# File 'lib/active_fedora/rdf_datastream.rb', line 110

def serialize
  update_subjects_to_use_a_real_pid!
  RDF::Writer.for(serialization_format).dump(graph)
end

#to_solr(solr_doc = Hash.new) ⇒ Object

:nodoc:



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/active_fedora/rdf_datastream.rb', line 64

def to_solr(solr_doc = Hash.new) # :nodoc:
  fields.each do |field_key, field_info|
    values = get_values(rdf_subject, field_key)
    directive = Solrizer::Directive.new(field_info[:type], field_info[:behaviors])
    if values
      Array(values).each do |val|    
        val = val.to_s if val.kind_of? RDF::URI
        self.class.create_and_insert_terms(prefix(field_key), val, directive, solr_doc)
      end
    end
  end
  solr_doc
end