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

Make RDF and XML attribute definition syntax consistent #736

Closed
mark-dce opened this issue Mar 26, 2015 · 3 comments
Closed

Make RDF and XML attribute definition syntax consistent #736

mark-dce opened this issue Mar 26, 2015 · 3 comments
Assignees

Comments

@mark-dce
Copy link
Contributor

Maybe this is just crazy extra work that no-one will use, but I find it pretty confusing that in AF9 there are totally different syntaxes to specify how you index object attributes depending on whether the object metadata is persisted as RDF or XML. It seems like you should be able to specify how you want your object indexed independently of how it's persisted.

Currently in AF9, you define an object using RDF persistence like this:

class Book < ActiveFedora::Base
  property :title, predicate: ::RDF::DC.title, multiple: false do |index|
    index.as :stored_searchable
  end
  property :author, predicate: ::RDF::DC.creator, multiple: false do |index|
    index.as :stored_searchable
  end
end

And in AF9, you would define the same attributes persisted to XML as follows:

class Codex < ActiveFedora::Base
  contains 'descMetadata', class_name: 'CodexMetadata'

  has_attributes :title, datastream: 'descMetadata', multiple: false
  has_attributes :author, datastream: 'descMetadata', multiple: false
end

class CodexMetadata < ActiveFedora::OmDatastream
  set_terminology do |t|
    t.root(path: "fields")
    t.title
    t.author
  end

  def self.xml_template
    Nokogiri::XML.parse("<fields/>")
  end
end

It seems awkward to specify the indexing as part of the persistence for XML only. Further, it seems like historical cruft that RDF attributes are defined using property and XML attributes are defined using \has_metadata`. Would it be possible to do something more like:

# A proposed revision of XML persistence
class Codex < ActiveFedora::Base
  contains 'descMetadata', class_name: 'CodexMetadata'

  property :title, delegate_to: 'descMetadata', multiple: false do |index|
    index.as :stored_searchable
  end  

  property :author, delegate_to: 'descMetadata', multiple: false do |index|
    index.as :stored_searchable
  end  
end

class CodexMetadata < ActiveFedora::OmDatastream
  set_terminology do |t|
    t.root(path: "fields")
    t.title
    t.author
  end

  def self.xml_template
    Nokogiri::XML.parse("<fields/>")
  end
end

In this example, the XML attachment is used to specify the persistence only and the indexing is handled identically regardless of whether RDF or XML is used to persist metadata. Rather than providing a predicate to the property you specify the delegate_to to identify which XML attachment the term is persisted to.

@jcoyne jcoyne self-assigned this Mar 27, 2015
@awead
Copy link
Contributor

awead commented Mar 28, 2015

This seems like a good suggestion. I'm sure it's possible to do, but I'm not sure of the work that would be required. We'd need to pull out the indexing bits from OM. Whereas you'd usually assign indexing behaviors in OM, like:

  set_terminology do |t|
    t.root(path: "fields")
    t.title(index_as: [: stored_searchable])
    t.author(index_as: [: stored_searchable])
  end

We'd want to pass those bits from the model to the OM datastream. It also be nice we could do both so as to support both varieties.

@mark-dce
Copy link
Contributor Author

@awead I think @jcoyne has the new indexing work mostly done in https://github.com/projecthydra/active_fedora/tree/move_indexing_to_the_model . I've tested it manually and updated dive into Hydra accordingly. For now, I think we want to keep in the legacy option of specifying indexing from the OM datastream, but I'm proposing we deprecate that and remove it in Hydra 10.

Also, take a look at 31b9843 too. These two branches together make the abstractions for RDF and XML metadata much more similar, which is a big plus in training new adopters - and maybe keeping the codebase simpler overall.

@awead
Copy link
Contributor

awead commented Apr 1, 2015

👍

@jcoyne jcoyne closed this as completed in f4b287b Apr 1, 2015
mjgiarlo added a commit that referenced this issue Apr 1, 2015
Move the indexing logic to the model. Fixes #736
awead added a commit that referenced this issue Apr 2, 2015
Allow property to delegate to a datastream. Ref #736
jcoyne added a commit that referenced this issue Apr 7, 2015
You should now add indexing hints to has_attributes by passing a block
similar to how you do it with rdf properties. e.g.:

class Book < ActiveFedora::Base
  has_metadata  'descMetadata', type: MODSDatastream
  has_attributes :title, :license, datastream: 'descMetadata' do |index|
    index.as :stored_searchable, :facetable
  end
end
jcoyne added a commit that referenced this issue Apr 15, 2015
This reverts commit 2458e42.

Conflicts:
	lib/active_fedora/indexing.rb
	lib/active_fedora/indexing/map.rb
	spec/integration/attributes_spec.rb
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

3 participants