Class: BibframeRuby::GraphBuilder
- Inherits:
-
Object
- Object
- BibframeRuby::GraphBuilder
- Defined in:
- lib/bibframe_ruby/graph_builder.rb
Overview
Walks an RDF::Graph to instantiate typed model objects, populate their properties, and link relationships.
Constant Summary collapse
- BF =
"http://id.loc.gov/ontologies/bibframe/"- BFLC =
"http://id.loc.gov/ontologies/bflc/"- RDF_TYPE =
RDF.type.to_s
- RDFS_LABEL =
RDF::RDFS.label.to_s
- TYPE_MAP =
{ "#{BF}Hub" => Hub, "#{BF}Work" => Work, "#{BF}Instance" => Instance, "#{BF}Item" => Item, "#{BF}Contribution" => Contribution, "#{BF}PrimaryContribution" => Contribution, "#{BF}Title" => Title, "#{BF}Person" => Person, "#{BF}Organization" => Organization, "#{BF}Subject" => Subject }.freeze
- PROPERTY_MAP =
Maps BIBFRAME predicates to Ruby property names
{ "#{BF}title" => "title", "#{BF}mainTitle" => "main_title", "#{BF}subtitle" => "subtitle", "#{BFLC}nonSortNum" => "non_sort_num", "#{BF}contribution" => "contributions", "#{BF}hasInstance" => "instances", "#{BF}instanceOf" => "work", "#{BF}hasItem" => "items", "#{BF}itemOf" => "instance", "#{BF}language" => "language", "#{BF}summary" => "summary", "#{BF}genreForm" => "genre_forms", "#{BF}classification" => "classifications", "#{BF}relation" => "relations", "#{BF}identifiedBy" => "identifiers", "#{BF}extent" => "extent", "#{BF}carrier" => "carrier", "#{BF}media" => "media", "#{BF}provisionActivity" => "provision_activity", "#{BF}editionStatement" => "edition_statement", "#{BF}dimensions" => "dimensions", "#{BF}publicationStatement" => "publication_statement", "#{BF}responsibilityStatement" => "responsibility_statement", "#{BF}issuance" => "issuance", "#{BF}agent" => "agent", "#{BF}role" => "role", "#{BF}heldBy" => "held_by", "#{BF}shelfMark" => "shelf_mark", "#{BF}content" => "content", "#{BF}subject" => "subjects", RDFS_LABEL => "label", "#{BF}code" => "code", "#{BF}source" => "source", "#{BF}status" => "status", "#{BF}date" => "date", "#{BF}seriesEnumeration" => "series_enumeration", "#{BF}associatedResource" => "associated_resource", "#{BF}relationship" => "relationship", "#{BF}adminMetadata" => "admin_metadata", "#{BF}derivedFrom" => "derived_from", "#{BF}assigner" => "assigner", "#{BF}classificationPortion" => "classification_portion", "#{BF}itemPortion" => "item_portion", "#{BF}edition" => "edition", "#{BF}descriptionLevel" => "description_level", "#{BF}descriptionLanguage" => "description_language", "#{BF}descriptionAuthentication" => "description_authentication", "#{BFLC}catalogerId" => "cataloger_id", "#{BFLC}aap" => "Authorized Access Point", "#{BFLC}aap-normalized" => "aap_normalized", "#{BFLC}simpleDate" => "simple_date", "#{BFLC}simpleAgent" => "simple_agent", "#{BFLC}simplePlace" => "simple_place" }.freeze
- ARRAY_PROPERTIES =
Properties that always hold arrays
%w[ contributions instances items genre_forms classifications relations identifiers subjects admin_metadata ].freeze
- LABEL_COLLAPSE_PROPERTIES =
Properties whose blank-node value should be collapsed to its rdfs:label string
%w[summary extent].freeze
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(rdf_graph) ⇒ GraphBuilder
constructor
A new instance of GraphBuilder.
Constructor Details
#initialize(rdf_graph) ⇒ GraphBuilder
Returns a new instance of GraphBuilder.
91 92 93 94 95 |
# File 'lib/bibframe_ruby/graph_builder.rb', line 91 def initialize(rdf_graph) @rdf_graph = rdf_graph @resources = {} @stubs = {} end |
Instance Method Details
#build ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/bibframe_ruby/graph_builder.rb', line 97 def build grouped = group_by_subject extract_resources(grouped) link_relationships { resources: @resources, works: @resources.values.grep(Work), instances: @resources.values.grep(Instance), items: @resources.values.grep(Item), hubs: @resources.values.grep(Hub) } end |