Skip to content

Instantly share code, notes, and snippets.

@no-reply
Last active August 29, 2015 14:10
Show Gist options
  • Save no-reply/9a88d71c4495b4e943ec to your computer and use it in GitHub Desktop.
Save no-reply/9a88d71c4495b4e943ec to your computer and use it in GitHub Desktop.
A Dummy Mapping for Harvard in OAI DC
Krikri::Mapper.define(:harvard) do
provider :class => DPLA::MAP::Agent do
name 'Harvard'
# uri # how to handle provider URIs?
end
isShownAt :class => DPLA::MAP::WebResource do
uri(record do |rec|
rec['dc:identifier'].map(&:value).select do |v|
v.include? 'nrs.harvard.edu/urn'
end
end)
end
aggregatedCHO :class => DPLA::MAP::SourceResource do
title record { |rec| rec['dc:title'].map(&:value) }
description record { |rec| rec['dc:description'].map(&:value) }
creator :class => DPLA::MAP::Agent do
providedLabel record { |rec| rec['dc:creator'].map(&:value) }
end
publisher :class => DPLA::MAP::Agent do
providedLabel record { |rec| rec['dc:publisher'].map(&:value) }
end
subject :class => DPLA::MAP::Concept do
providedLabel record { |rec| rec['dc:subject'].map(&:value) }
end
# format record { |rec|
# require 'pry'
# binding.pry
# rec['dc:format'].map(&:value) }
language :class => DPLA::MAP::Controlled::Language do
prefLabel record { |rec| rec['dc:language'].map(&:value) }
uri(record { |rec| rec['dc:language'].map(&:value) }) do |val|
"http://www.lexvo.org/page/iso639-3/#{val}"
end
end
dctype :class => DPLA::MAP::Controlled::DCMIType do
providedLabel record { |rec| rec['dc:type'].map(&:value) }
end
end
end
require '../../harvard_mapping.rb'
# => true
harvester = Krikri::Harvesters::OAIHarvester.new(:endpoint => 'http://vcoai.lib.harvard.edu/vcoai/vc')
# => #<Krikri::Harvesters::OAIHarvester:0x007fb372f932d8 ... >
res = Krikri::Mapper.map(:harvard, Krikri::OaiDcParser.new(harvester.records.first))
# => [#<DPLA::MAP::Aggregation:0x3fd9b9cfd258(default)>]
puts res.first.dump :ttl
# _:g70204354453860 a <http://www.w3.org/2000/01/rdf-schema#Class>;
# <http://dp.la/about/map/providedLabel> "Text" .
#
# <http://nrs.harvard.edu/urn-3:FHCL.Loeb:505968> a <http://www.europeana.eu/schemas/edm/WebResource> .
#
# <http://www.lexvo.org/page/iso639-3/ger> <http://www.w3.org/2004/02/skos/core#prefLabel> "ger" .
#
# [
# a <http://www.openarchives.org/ore/terms/Aggregation>;
# <http://www.europeana.eu/schemas/edm/aggregatedCHO> [
# a <http://dp.la/about/map/SourceResource>;
# <http://purl.org/dc/terms/title> "Johann Sebastian Bach's Saemtliche Werke : thematisch verzeichnet mit Ausgabe der bisher im Druck erschienenen und ihrer Verleger, der Besitzer der Autografa und gleichzeitiger Abschriften",
# "Thematisch verzeichnet";
# <http://purl.org/dc/terms/creator> [
# a <http://www.europeana.eu/schemas/edm/Agent>;
# <http://dp.la/about/map/providedLabel> "Hauser, Franz , 1794-1870"
# ];
# <http://purl.org/dc/terms/description> "von Franz Hauser.",
# "Pencil annotations in different hand.";
# <http://purl.org/dc/terms/language> <http://www.lexvo.org/page/iso639-3/ger>;
# <http://purl.org/dc/terms/publisher> [
# a <http://www.europeana.eu/schemas/edm/Agent>;
# <http://dp.la/about/map/providedLabel> "Loeb Music"
# ];
# <http://purl.org/dc/terms/subject> [
# a <http://www.w3.org/2004/02/skos/core#Concept>;
# <http://dp.la/about/map/providedLabel> "Bach, Johann Sebastian--1685-1750--Thematic catalogs",
# "Music--Manuscripts"
# ];
# <http://purl.org/dc/terms/type> _:g70204354453860
# ];
# <http://www.europeana.eu/schemas/edm/isShownAt> <http://nrs.harvard.edu/urn-3:FHCL.Loeb:505968>;
# <http://www.europeana.eu/schemas/edm/provider> []
# ] .
# => nil
# Some ActiveTriples examples from results...
agg.aggregatedCHO.first.title
# => ["Johann Sebastian Bach's Saemtliche Werke : thematisch verzeichnet mit Ausgabe der bisher im Druck erschienenen und ihrer Verleger, der Besitzer der Autografa und gleichzeitiger Abschriften", "Thematisch verzeichnet"]
agg.aggregatedCHO.first.language.first.prefLabel
# => ["ger"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment