Created
April 4, 2014 14:04
-
-
Save escowles/9975373 to your computer and use it in GitHub Desktop.
MADS linkage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'active-fedora', github: 'projecthydra/active_fedora', branch: 'master' | |
gem 'linkeddata' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# mads demo using AF 7.0 rc3 | |
require 'active-fedora' | |
require 'linkeddata' | |
# vocabulary | |
class MADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#") | |
# MADS classes | |
property :ComplexSubject | |
property :Topic | |
property :MADSScheme | |
# MADS properties | |
property :isMemberOfMADSScheme | |
# elementList and elementList values | |
property :componentList | |
property :elementList | |
property :elementValue | |
property :TopicElement | |
end | |
# scheme | |
class MadsScheme < ActiveFedora::Rdf::Resource | |
configure type: MADS.MADSScheme | |
configure base_uri: "http://library.ucsd.edu/ark:/20775/" | |
property :name, predicate: RDF::RDFS.label | |
end | |
# topic | |
class MadsTopic < ActiveFedora::Rdf::Resource | |
configure type: MADS.Topic | |
property :name, predicate: MADS.authoritativeLabel | |
property :scheme, predicate: MADS.isMemberOfMADSScheme, class_name: "MadsScheme" | |
property :elementList, predicate: MADS.elementList, class_name: "MadsElementList" | |
accepts_nested_attributes_for :scheme, :elementList | |
end | |
class MadsElementList < ActiveFedora::Rdf::List | |
configure type: MADS.elementList | |
property :topicElement, predicate: MADS.TopicElement, class_name: "MadsTopicElement" | |
accepts_nested_attributes_for :topicElement | |
end | |
class MadsTopicElement < ActiveFedora::Rdf::Resource | |
property :elementValue, predicate: MADS.elementValue | |
configure :type => MADS.TopicElement | |
end | |
# complex subject | |
class MadsComplexSubjectDatastream < ActiveFedora::RdfxmlRDFDatastream | |
resource_class.configure type: MADS.ComplexSubject | |
resource_class.configure base_uri: "http://library.ucsd.edu/ark:/20775/" | |
property :name, predicate: MADS.authoritativeLabel | |
property :scheme, predicate: MADS.isMemberOfMADSScheme | |
property :componentList, predicate: MADS.componentList, class_name: "MadsComponentList" | |
accepts_nested_attributes_for :componentList, :topic, :scheme | |
delegate :topic_attributes=, to: :componentList | |
alias_method :topic, :componentList | |
end | |
class MadsComplexSubject < ActiveFedora::Base | |
has_metadata :name => "damsMetadata", :type => MadsComplexSubjectDatastream | |
has_attributes :name, :componentList, :scheme, datastream: "damsMetadata", multiple: false | |
delegate :componentList_attributes=, to: :damsMetadata | |
delegate :topic_attributes=, to: :damsMetadata | |
delegate :scheme_attributes=, to: :damsMetadata | |
end | |
class MadsComponentList < ActiveFedora::Rdf::List | |
configure type: MADS.componentList | |
property :topic, predicate: MADS.Topic, class_name: "MadsTopic" | |
accepts_nested_attributes_for :topic | |
end | |
# complex subject | |
complex_subject_params = { | |
name: 'Civilization, Modern', | |
scheme_attributes: [{ | |
id: 'http://library.ucsd.edu/ark:/20775/bb3333333x', | |
name: 'Library of Congress Subject Headings' | |
}], | |
componentList_attributes: [{ | |
topic_attributes: [{ | |
id: 'http://library.ucsd.edu/ark:20775/bb2222222x', | |
name: 'Civilization, Modern', | |
elementList_attributes: [{ | |
topicElement_attributes: [{elementValue:"Civilization, Modern"}] | |
}], | |
scheme_attributes: [{ | |
id: 'http://library.ucsd.edu/ark:20775/bb4444444x', | |
name: 'Library of Congress Subject Headings' | |
}] | |
} | |
] | |
}] | |
} | |
sub = MadsComplexSubject.new(pid:'bb1111111x') | |
sub.attributes = complex_subject_params | |
puts sub.damsMetadata.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.0' encoding='utf-8' ?> | |
<rdf:RDF xmlns:ns0='http://www.loc.gov/mads/rdf/v1#' | |
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' | |
xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'> | |
<ns0:MADSScheme rdf:about='http://library.ucsd.edu/ark:20775/bb4444444x'> | |
<rdfs:label>Library of Congress Subject Headings</rdfs:label> | |
</ns0:MADSScheme> | |
<ns0:ComplexSubject rdf:about='http://library.ucsd.edu/ark:/20775/bb1111111x'> | |
<ns0:authoritativeLabel>Civilization, Modern</ns0:authoritativeLabel> | |
<ns0:componentList rdf:parseType='Collection'> | |
<ns0:Topic rdf:nodeID='g70290732937020'> | |
<ns0:authoritativeLabel>Civilization, Modern</ns0:authoritativeLabel> | |
<ns0:elementList rdf:parseType='Collection'> | |
<ns0:TopicElement rdf:nodeID='g70290732966240'> | |
<ns0:elementValue>Civilization, Modern</ns0:elementValue> | |
</ns0:TopicElement> | |
</ns0:elementList> | |
<ns0:isMemberOfMADSScheme rdf:resource='http://library.ucsd.edu/ark:20775/bb4444444x' /> | |
</ns0:Topic> | |
</ns0:componentList> | |
<ns0:isMemberOfMADSScheme rdf:resource='http://library.ucsd.edu/ark:/20775/bb3333333x' /> | |
</ns0:ComplexSubject> | |
</rdf:RDF> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's now a PR in for error messages in #attributes=. With that, your gist should fail at L97 with
ArgumentError: No association found for name
name'. Has it been defined yet?`.Hopefully this resolves both issues.