Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: In RDF update, delete all old triples #29

Open
demery opened this issue Sep 22, 2020 · 0 comments
Open

Bug fix: In RDF update, delete all old triples #29

demery opened this issue Sep 22, 2020 · 0 comments

Comments

@demery
Copy link
Member

demery commented Sep 22, 2020

The change to not send empty values to RDF when objects are updated has meant that old triples are not getting deleted.

In order to prevent triples without objects being added to the store, a change was made to only send to the interface those values that a present on objects. Thus:

  def to_rdf
    map = {
      model_class: "names",
      id: id,
      fields: {}
    }

    map[:fields][:name]       = "'''#{name.to_s.gsub("'", "")}'''"       if name.present?
    map[:fields][:viaf_id]    = "'''#{viaf_id}'''"                       if viaf_id.present?
    map[:fields][:subtype]    = "'''#{subtype}'''"                       if subtype.present?
    map[:fields][:startdate]  = "'''#{startdate}'''"                     if startdate.present?
    map[:fields][:enddate]    = "'''#{enddate}'''"                       if enddate.present?
    map[:fields][:other_info] = "'''#{other_info.to_s.gsub("'", "")}'''" if other_info.present?
    map[:fields][:deleted]    = "'#{deleted}'^^xsd:boolean"              unless deleted.nil?

    map
  end

However, the RDF update process deletes each triple before inserting the updated one. interface.rb deletes only those triples given in the message hash:

      message['fields'].each do |field, new_value|
        query += %Q(
          DELETE { ?subject #{predicate} ?object }
          INSERT { ?subject #{predicate} #{new_value} }
          WHERE {
            BIND (<https://sdbm.library.upenn.edu/#{message['model_class']}/#{message['id']}> as ?subject) .
            OPTIONAL { ?subject #{predicate} ?object }
          };
        )
      # etc.
      end

Since empty values are not sent in the message hash, the delete clause isn't created. To fix this, the empty fields should be sent in the message hash, and -- in the update code in interface.rb -- added to the DELETE clause, but no INSERT clause should be created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant