Module TaliaCore::ActiveSourceParts::RdfHandler
In: lib/talia_core/active_source_parts/rdf_handler.rb

Methods for the ActiveSource class to automatically create the RDF triples for a source and to access the RDF data of the source.

The RDF for a source will be automatically created through the auto_create_rdf callback when the source is set (and autosave_rdf is set)

Methods

Public Instance methods

This can be used to turn of automatic rdf creation. If set to true, create_rdf will not be called automatically after saving the source.

Attention: Improper use will compromise the integrity of the RDF data. However, it may be used in order to speed up operations that save a record several times and don‘t need the RDF data in the meantime.

[Source]

    # File lib/talia_core/active_source_parts/rdf_handler.rb, line 24
24:       def autosave_rdf=(value)
25:         @autosave_rdf = value
26:       end

Returns the value of the autosave_rdf flag, as set by autosave_rdf=

[Source]

    # File lib/talia_core/active_source_parts/rdf_handler.rb, line 12
12:       def autosave_rdf?
13:         @autosave_rdf = true unless(defined?(@autosave_rdf))
14:         @autosave_rdf
15:       end

This creates the RDF subgraph for this Source and saves it to disk. This may be an expensive operation since it removes the existing elements. (Could be optimised ;-)

Unless the force option is specified, this will ignore predicates that remain unchanged. This means that writing will be faster if a predicate will not changed, but if database objects were not added through the standard API they‘ll be missed

The force option may have three values:

false
Normal operation. This retrieves the data for each of the cached SemanticCollectionWrappers that may have been modified and rewrites the respective attribute in the RDF store. (see the PredicateHandler module for an explanation of the wrapper cache). It will ignore wrappers that are obviously "clean", but will do a "retrieve and write" for each wrapper separately.
force
Force a complete rewrite of the RDF data for this source. This will erase the RDF and write all triples for this source in one go. It will also remove any triples for this source that may have been added externally.
create
Do not check for any existing data, just write out the data that is in the cache. This is fast, but must only be used for new sources where it is certain that no data for the source exists in the RDF store.

[Source]

    # File lib/talia_core/active_source_parts/rdf_handler.rb, line 64
64:       def create_rdf(force = :false)
65:         self.class.benchmark("\033[32m\033[4m\033[1mActiveSource::RD\033[0m Creating RDF for source", Logger::DEBUG, false) do
66:           assit(!new_record?, "Record must exist here: #{self.uri}")
67:           # Get the stuff to write. This will also erase the old data
68:           
69:           s_rels = case force 
70:             when :force 
71:               prepare_all_predicates_to_write 
72:             when :create
73:               prepare_predicates_to_create
74:             else
75:               prepare_predicates_to_write
76:             end
77:           s_rels.each do |sem_ref|
78:             # We pass the object on. If it's a SemanticProperty, we need to add
79:             # the value. If not the RDF handler will detect the #uri method and
80:             # will add it as Resource.
81:             obj = sem_ref.object
82:             assit(obj, "Must have an object here. #{sem_ref.inspect}")
83:             value = obj.is_a?(SemanticProperty) ? obj.value : obj
84:             my_rdf.direct_write_predicate(N::URI.new(sem_ref.predicate_uri), value)
85:           end
86:           my_rdf.direct_write_predicate(N::RDF.type, rdf_selftype)
87:           my_rdf.save
88:         end
89:       end

Returns the RDF object to use for this ActiveSource. This will return a RdfResource, which has a similiar (but more limited API) than the ActiveSource itself. All operations and queries on that resource will go to the RDF store instead of the database

[Source]

    # File lib/talia_core/active_source_parts/rdf_handler.rb, line 33
33:       def my_rdf
34:         @rdf_resource ||= begin
35:           src = RdfResource.new(uri)
36:           src.object_class = TaliaCore::ActiveSource
37:           src
38:         end
39:       end

Creates an RDF/XML resprentation of the source. See the Xml::RdfBuilder and the Xml::SourceReader for more information.

[Source]

     # File lib/talia_core/active_source_parts/rdf_handler.rb, line 93
 93:       def to_rdf
 94:         rdf = String.new
 95: 
 96:         ActiveSourceParts::Xml::RdfBuilder.open(:target => rdf, :indent => 2) do |builder|
 97:           builder.write_source(self)
 98:         end
 99: 
100:         rdf
101:       end

[Validate]