-
Notifications
You must be signed in to change notification settings - Fork 14
Lesson: define models with hydra works
- Start the Rails console and run code interactively in the console
- Define an ActiveFedora model class for Collection, BibliographicWork, and BibliographicFileSet objects
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.
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.
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).
object refers to an object in the Fedora repository which can represent all the models of pcdm and hydra-works.
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.
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.
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.
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"
Go on to Lesson: Create instances of Hydra-Works models or return to the Dive into Hydra-Works page.
- Dive into Hydra-Works
- Lesson: Generate a Rails Application
- Lesson: Add the Hydra Dependencies
- Lesson: Start FCRepo and Solr
- Lesson: Start the Application & Search for Results
- Lesson: Define models with Hydra-Works
- Lesson: Create instances of Hydra-Works models
- Lesson: Explore Objects in Fedora and Solr
- Lesson: Make Blacklight Return Search Results
- BONUS Lessons
- Aggregations API Documentation
- Application Profile