Module: TaliaCore::ActiveSourceParts::Rdf
- Included in:
- TaliaCore::ActiveSource
- Defined in:
- lib/talia_core/active_source_parts/rdf.rb
Instance Method Summary collapse
-
#autosave_rdf=(value) ⇒ Object
Set the autosave property.
-
#autosave_rdf? ⇒ Boolean
This can be used to turn of automatic rdf creation.
-
#create_rdf(force = :false) ⇒ Object
This creates the RDF subgraph for this Source and saves it to disk.
-
#my_rdf ⇒ Object
Returns the RDF object to use for this ActiveSource.
-
#to_rdf ⇒ Object
Creates an RDF/XML resprentation of the source.
Instance Method Details
#autosave_rdf=(value) ⇒ Object
Set the autosave property. See autosave_rdf?
17 18 19 |
# File 'lib/talia_core/active_source_parts/rdf.rb', line 17 def autosave_rdf=(value) @autosave_rdf = value end |
#autosave_rdf? ⇒ Boolean
This can be used to turn of automatic rdf creation. Attention: Improperly used this may compromise the integrity of the RDF data. However, it may be used in order to speed up “create” operations that save a record several times and don’t need the RDF data in the meantime.
11 12 13 14 |
# File 'lib/talia_core/active_source_parts/rdf.rb', line 11 def autosave_rdf? @autosave_rdf = true unless(defined?(@autosave_rdf)) @autosave_rdf end |
#create_rdf(force = :false) ⇒ Object
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 for normal operation, :force for forcing a complete rewrite and :create - the latter will avoid the cleaning of the elements in the RDF store in case the source is completely new and no triples exist.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/talia_core/active_source_parts/rdf.rb', line 43 def create_rdf(force = :false) self.class.benchmark("\033[32m\033[4m\033[1mActiveSource::RD\033[0m Creating RDF for source", Logger::DEBUG, false) do assit(!new_record?, "Record must exist here: #{self.uri}") # Get the stuff to write. This will also erase the old data s_rels = case force when :force prepare_all_predicates_to_write when :create prepare_predicates_to_create else prepare_predicates_to_write end s_rels.each do |sem_ref| # We pass the object on. If it's a SemanticProperty, we need to add # the value. If not the RDF handler will detect the #uri method and # will add it as Resource. obj = sem_ref.object value = obj.is_a?(SemanticProperty) ? obj.value : obj my_rdf.direct_write_predicate(N::URI.new(sem_ref.predicate_uri), value) end my_rdf.direct_write_predicate(N::RDF.type, rdf_selftype) my_rdf.save end end |
#my_rdf ⇒ Object
Returns the RDF object to use for this ActiveSource
22 23 24 25 26 27 28 |
# File 'lib/talia_core/active_source_parts/rdf.rb', line 22 def my_rdf @rdf_resource ||= begin src = RdfResource.new(uri) src.object_class = TaliaCore::ActiveSource src end end |
#to_rdf ⇒ Object
Creates an RDF/XML resprentation of the source
70 71 72 73 74 75 76 77 78 |
# File 'lib/talia_core/active_source_parts/rdf.rb', line 70 def to_rdf rdf = String.new ActiveSourceParts::Xml::RdfBuilder.open(:target => rdf, :indent => 2) do |builder| builder.write_source(self) end rdf end |