Skip to content

Lesson: define models with hydra works

Bess Sadler edited this page Jan 25, 2017 · 7 revisions

Goals

  • Start the Rails console and run code interactively in the console
  • Define an ActiveFedora model class for Collection, BibliographicWork, and BibliographicFileSet objects

Explanation

We are going to define models using Hydra::Works which extends the concepts of Hydra::PCDM. We will define models for a collection to hold bibliographic resource works which will hold bibliographic resource file sets. These models will have sets of RDF statements which will describe the properties of the collection, bibliographic resource work, and file representing the bibliographic resource, respectively.

Terminology

PCDM

pcdm-collection can have collections and/or objects as members. It is used for organization.

pcdm-object can have objects as members and can hold binary files.

pcdm model 2015-09-14

Hydra-Works

works-collection is a pcdm-collection that can have collections and/or works as members. It is used for organization.

work is a pcdm-object that can have works and/or file sets as members. A work does not have files representing the work. Each file of the work is added as a separate file set.

file set is a pcdm-object that can hold binary files. Each file set has one content file that is the uploaded (or primary) document. Each file set can also hold binary files representing alternate forms of the original content (i.e. derivatives).

hydra-works model 2015-12-18

Fedora

object refers to an object in the Fedora repository which can represent all the models of pcdm and hydra-works.

Steps

Step 1: Create a Collection model

Create a new file at app/models/collection.rb. We'll paste in this code:

class Collection < ActiveFedora::Base
  include Hydra::Works::CollectionBehavior
  property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
end

This class extends from ActiveFedora::Base, the abstract class from which all ActiveFedora models should descend. It includes Hydra::Works::CollectionBehavior to use the Hydra::Works behaviors for collections. The code says, create one property called title, which will be expressed in RDF using the Dublin Core RDF title predicate. Since multiple is set to false, there may only be one title on each Collection.

NOTE: The less than intuitive class name is to allow all names in the tutorial to be unique in the case where the PCDM models and Works models are all created in the same rails app.

Step 2: Create a BibliographicWork model

Create a new file at app/models/bibliographic_work.rb. We'll paste in this code:

class BibliographicWork < ActiveFedora::Base
  include Hydra::Works::WorkBehavior
  property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
  property :author, predicate: ::RDF::Vocab::DC.creator, multiple: false
  property :abstract, predicate: ::RDF::Vocab::DC.abstract, multiple: false
end

This class also extends from ActiveFedora::Base, the abstract class from which all ActiveFedora models should descend. It includes Hydra::Works::WorkBehavior to use the Hydra::Works behaviors for generic works. The code says, create one property called title, which will be expressed in RDF using the Dublin Core RDF title predicate. Since multiple is set to false, there may only be one title on each BibliographicWork. Author and abstract are similar, except they uses the Dublin Core RDF 'creator' and 'abstract' predicates, respectively.

Step 3: Create a BibliographicFileSet model

Create a new file at app/models/bibliographic_file_set.rb. We'll paste in this code:

class BibliographicFileSet < ActiveFedora::Base
  include Hydra::Works::FileSetBehavior
  property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
end

This class also extends from ActiveFedora::Base, the abstract class from which all ActiveFedora models should descend. It includes Hydra::Works::FileSetBehavior to use the Hydra::Works behaviors for file sets. The code says, create one property called title, which will be expressed in RDF using the Dublin Core RDF title predicate. Since multiple is set to false, there may only be one title on each BibliographicFileSet.

Step 4: Commit your changes

Because this Lesson is long, let's go ahead and save periodically as we go. Now that we've got our basic models defined, it's a great time to commit to git:

git status
git add .
git commit -m "Create initial collection, work, and file set models using Hydra Works"

Next Step

Go on to Lesson: Create instances of Hydra-Works models or return to the Dive into Hydra-Works page.