-
-
Save flyingzumwalt/5861758 to your computer and use it in GitHub Desktop.
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 'rails', '3.2.13' | |
gem "active-fedora", :git => "git://github.com/projecthydra/active_fedora.git", :branch => "rdf_nested_attributes" |
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 | |
require "active-fedora" | |
class MADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#") | |
property :MADSScheme | |
property :isMemberOfMADSScheme | |
property :authoritativeLabel | |
property :elementList | |
property :elementValue | |
property :Topic | |
property :TopicElement | |
property :hasExactExternalAuthority | |
end | |
class TopicElement | |
include ActiveFedora::RdfObject | |
rdf_type MADS.TopicElement | |
map_predicates do |map| | |
map.elementValue(:in=> MADS) | |
end | |
end | |
class ElementList | |
# include ActiveFedora::RdfList | |
include ActiveFedora::RdfObject | |
map_predicates do |map| | |
map.topicElement(:in=> MADS, :to =>"TopicElement", :class_name => "TopicElement") | |
end | |
accepts_nested_attributes_for :topicElement | |
end | |
class Topic | |
include ActiveFedora::RdfObject | |
rdf_type MADS.Topic | |
rdf_subject { |ds| RDF::URI.new(Rails.configuration.id_namespace + ds.pid)} | |
map_predicates do |map| | |
map.name(:in => MADS, :to => 'authoritativeLabel') | |
map.elementList(:in => MADS, :class_name=>'ElementList') | |
map.externalAuthority(:in => MADS, :to => 'hasExactExternalAuthority') | |
end | |
accepts_nested_attributes_for :elementList | |
end | |
params = { | |
topic: { | |
name: "Baseball", | |
externalAuthority: "http://id.loc.gov/authorities/subjects/sh85012026", | |
elementList_attributes: [ | |
topicElement_attributes: { elementValue: "Baseball" } | |
] | |
} | |
} | |
topic = Topic.new(RDF::Graph.new) | |
topic.attributes = params[:topic] | |
puts topic.graph.dump(:ntriples) |
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 | |
require "active-fedora" | |
class MADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#") | |
property :MADSScheme | |
property :isMemberOfMADSScheme | |
property :authoritativeLabel | |
property :elementList | |
property :elementValue | |
property :Topic | |
property :TopicElement | |
property :hasExactExternalAuthority | |
end | |
class TopicElement | |
include ActiveFedora::RdfObject | |
rdf_type MADS.TopicElement | |
map_predicates do |map| | |
map.elementValue(:in=> MADS) | |
end | |
end | |
class ElementList | |
include ActiveFedora::RdfList | |
end | |
class Topic | |
include ActiveFedora::RdfObject | |
rdf_type MADS.Topic | |
rdf_subject { |ds| RDF::URI.new(Rails.configuration.id_namespace + ds.pid)} | |
map_predicates do |map| | |
map.name(:in => MADS, :to => 'authoritativeLabel') | |
map.elementList(:in => MADS, :class_name=>'ElementList') | |
map.externalAuthority(:in => MADS, :to => 'hasExactExternalAuthority') | |
end | |
accepts_nested_attributes_for :elementList | |
end | |
params = { | |
topic: { | |
name: "Baseball", | |
externalAuthority: "http://id.loc.gov/authorities/subjects/sh85012026", | |
}, | |
topicElement: { | |
elementValue: "Baseball" | |
} | |
} | |
topic = Topic.new(RDF::Graph.new) | |
topic.attributes = params[:topic] | |
topicElement = TopicElement.new(RDF::Graph.new) | |
topic.attributes = params[:topicElement] | |
elementList = ElementList.new(RDF::Graph.new,RDF::Node.new) | |
elementList[0] = topicElement | |
topic.elementList = elementList | |
puts topic.graph.dump(:ntriples) |
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
output from "bundle exec ./nested_element_list.rb": | |
_:bn1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Topic> . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#authoritativeLabel> "Baseball" . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#hasExactExternalAuthority> "http://id.loc.gov/authorities/subjects/sh85012026" . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#elementList> "{:topicElement_attributes=>{:elementValue=>\"Baseball\"}}" . | |
output from "bundle exec ./nested_element_list2.rb": | |
_:bn1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Topic> . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#authoritativeLabel> "Baseball" . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#hasExactExternalAuthority> "http://id.loc.gov/authorities/subjects/sh85012026" . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#elementList> "#<ElementList:0x007f84d229db88>" . | |
expected: | |
_:bn1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#Topic> . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#authoritativeLabel> "Baseball" . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#hasExactExternalAuthority> "http://id.loc.gov/authorities/subjects/sh85012026" . | |
_:bn1 <http://www.loc.gov/mads/rdf/v1#elementList> _:bn2 . | |
_:bn2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:bn3 . | |
_:bn2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> . | |
_:bn3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.loc.gov/mads/rdf/v1#TopicElement> . | |
_:bn3 <http://www.loc.gov/mads/rdf/v1#elementValue> "Baseball" . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment