ld4l-works_rdf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +25 -0
- data/.travis.yml +14 -0
- data/CHANGES.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +170 -0
- data/Rakefile +2 -0
- data/ld4l-works_rdf.gemspec +42 -0
- data/lib/ld4l/works_rdf.rb +131 -0
- data/lib/ld4l/works_rdf/configuration.rb +41 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_identifier.rb +17 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_instance.rb +23 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_organization.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_person.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_place.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_provider.rb +18 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_title.rb +18 -0
- data/lib/ld4l/works_rdf/models/bibframe/bibframe_work.rb +16 -0
- data/lib/ld4l/works_rdf/models/bibo/bibo_book.rb +19 -0
- data/lib/ld4l/works_rdf/models/bibo/bibo_document.rb +14 -0
- data/lib/ld4l/works_rdf/models/bibo/vivo_authorship.rb +15 -0
- data/lib/ld4l/works_rdf/models/bibo/vivo_book.rb +18 -0
- data/lib/ld4l/works_rdf/models/generic_work.rb +13 -0
- data/lib/ld4l/works_rdf/models/schema/oclc_schema_book.rb +16 -0
- data/lib/ld4l/works_rdf/models/schema/schema_book.rb +23 -0
- data/lib/ld4l/works_rdf/models/schema/schema_person.rb +17 -0
- data/lib/ld4l/works_rdf/models/schema/schema_publisher.rb +15 -0
- data/lib/ld4l/works_rdf/models/work_metadata.rb +212 -0
- data/lib/ld4l/works_rdf/services/attempt_generic_metadata_extraction.rb +41 -0
- data/lib/ld4l/works_rdf/services/conversion_services/get_rdfxml_from_marcxml.rb +44 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.ErrorCodes.xqy +56 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXML-2-MADSRDF.xqy +1702 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXML-2-RecordInfoRDF.xqy +216 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXMLBIB-2-BIBFRAME.xqy +140 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MARCXMLBIB-BFUtils.xqy +3287 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-2-BIBFRAME-Shared.xqy +4112 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-Default-2-BF.xqy +61 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.MBIB-NotatedMusic-2-BF.xqy +105 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-ExhibitJSON.xqy +119 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-JSON.xqy +193 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXML-2-Ntriples.xqy +276 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/modules/module.RDFXMLnested-2-flat.xqy +380 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/ml.xqy +239 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/saxon.xqy +134 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba.xqy +359 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba2-0.xqy +249 -0
- data/lib/ld4l/works_rdf/services/conversion_services/marc2bibframe/xbin/zorba3-0.xqy +362 -0
- data/lib/ld4l/works_rdf/services/conversion_services/saxon/saxon9he.jar +0 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_marcxml_uri.rb +43 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_oclc_uri.rb +25 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_solr_query.rb +29 -0
- data/lib/ld4l/works_rdf/services/get_metadata_from_vivo_uri.rb +25 -0
- data/lib/ld4l/works_rdf/services/get_model_from_uri.rb +62 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_bibframe_models.rb +60 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_bibo_model.rb +42 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_generic_model.rb +41 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_oclc_model.rb +42 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_solr_doc.rb +67 -0
- data/lib/ld4l/works_rdf/services/metadata_services/get_metadata_from_vivo_model.rb +45 -0
- data/lib/ld4l/works_rdf/services/metadata_services/set_error_in_metadata.rb +27 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_bibframe_models_from_repository.rb +46 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_generic_model_from_repository.rb +30 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_oclc_model_from_repository.rb +27 -0
- data/lib/ld4l/works_rdf/services/model_services/populate_vivo_model_from_repository.rb +27 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_marcxml_from_uri.rb +35 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_rdfxml_from_uri.rb +37 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_solr_results_from_solr_query.rb +35 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/get_turtle_from_uri.rb +37 -0
- data/lib/ld4l/works_rdf/services/negotiation_services/response_header.rb +51 -0
- data/lib/ld4l/works_rdf/services/repository_services/populate_graph_from_rdfxml.rb +22 -0
- data/lib/ld4l/works_rdf/services/repository_services/populate_graph_from_turtle.rb +21 -0
- data/lib/ld4l/works_rdf/services/repository_services/populate_repository_from_graph.rb +25 -0
- data/lib/ld4l/works_rdf/version.rb +5 -0
- data/lib/ld4l/works_rdf/vocab/bf.rb +29 -0
- data/lib/ld4l/works_rdf/vocab/bgn.rb +5 -0
- data/lib/ld4l/works_rdf/vocab/bibo.rb +10 -0
- data/lib/ld4l/works_rdf/vocab/library.rb +6 -0
- data/lib/ld4l/works_rdf/vocab/vitro.rb +5 -0
- data/lib/ld4l/works_rdf/vocab/vivo.rb +11 -0
- data/spec/ld4l/works_rdf/configuration_spec.rb +166 -0
- data/spec/ld4l/works_rdf/models/books/vivo_book_rdf_spec.rb +267 -0
- data/spec/ld4l/works_rdf/services/get_metadata_from_uri_spec.rb +39 -0
- data/spec/ld4l/works_rdf/services/get_model_from_uri_spec.rb +34 -0
- data/spec/ld4l/works_rdf_spec.rb +53 -0
- data/spec/spec_helper.rb +26 -0
- metadata +321 -0
Binary file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromMarcxmlURI
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get display metadata via content negotiation from an URI known to return MARCXML
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
#
|
10
|
+
# @returns an instance of LD4L::WorksRDF::WorkMetadata populated with display metadata for the work located at the URI
|
11
|
+
def self.call( uri, localname_prefix="" )
|
12
|
+
raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
|
13
|
+
uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
|
14
|
+
|
15
|
+
baseuri = LD4L::WorksRDF.configuration.base_uri
|
16
|
+
baseuri = "#{baseuri}/" unless baseuri.end_with?("/")
|
17
|
+
|
18
|
+
document_id = URI.parse(uri).path.split('/').last
|
19
|
+
|
20
|
+
bibframe_work_uri = "#{baseuri}#{localname_prefix}#{document_id}"
|
21
|
+
|
22
|
+
marcxml = LD4L::WorksRDF::GetMarcxmlFromURI.call(uri)
|
23
|
+
metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to retrieve MARCXML from URI') unless marcxml && marcxml.size > 0
|
24
|
+
|
25
|
+
rdfxml = LD4L::WorksRDF::GetRdfxmlFromMarcxml.call(marcxml,baseuri) if marcxml && marcxml.size > 0
|
26
|
+
metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to convert MARCXML into RDFXMl') unless rdfxml && rdfxml.size > 0
|
27
|
+
|
28
|
+
graph = LD4L::WorksRDF::PopulateGraphFromRdfxml.call(rdfxml) if rdfxml && rdfxml.size > 0
|
29
|
+
metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to populate graph from RDFXML') unless graph
|
30
|
+
|
31
|
+
repository = LD4L::WorksRDF::PopulateRepositoryFromGraph.call(graph) if graph
|
32
|
+
metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to populate repository from graph') unless repository
|
33
|
+
|
34
|
+
models = LD4L::WorksRDF::PopulateBibframeModelsFromRepository.call(bibframe_work_uri,repository) if repository
|
35
|
+
metadata = LD4L::WorksRDF::SetErrorInMetadata.call(uri,'ERROR: Unable to populate models from repository') unless models
|
36
|
+
|
37
|
+
metadata = LD4L::WorksRDF::GetMetadataFromBibframeModels.call(uri, models) if models
|
38
|
+
metadata
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromOclcURI
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get display metadata via content negotiation from an URI known to return OCLC produced triples
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
#
|
10
|
+
# @returns an instance of LD4L::WorksRDF::WorkMetadata populated with display metadata for the work located at the URI
|
11
|
+
def self.call( uri )
|
12
|
+
raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
|
13
|
+
uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
|
14
|
+
|
15
|
+
turtle = LD4L::WorksRDF::GetTurtleFromURI.call(uri)
|
16
|
+
graph = LD4L::WorksRDF::PopulateGraphFromTurtle.call(turtle)
|
17
|
+
repository = LD4L::WorksRDF::PopulateRepositoryFromGraph.call(graph)
|
18
|
+
model = LD4L::WorksRDF::PopulateOclcModelFromRepository.call(uri,repository)
|
19
|
+
metadata = LD4L::WorksRDF::GetMetadataFromOclcModel.call(uri,model)
|
20
|
+
metadata
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromSolrQuery
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get display metadata via content negotiation from an Cornell Solr
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
#
|
10
|
+
# @returns an instance of LD4L::WorksRDF::WorkMetadata populated with display metadata for the work located at the URI
|
11
|
+
def self.call( solr_query_url, solr_field_translations, localname_prefix="" )
|
12
|
+
raise ArgumentError, 'solr_query_url argument must be a uri string' unless solr_query_url.kind_of?(String)
|
13
|
+
|
14
|
+
results = LD4L::WorksRDF::GetSolrResultsFromSolrQuery.call(solr_query_url)
|
15
|
+
return LD4L::WorksRDF::SetErrorInMetadata.call(solr_query_url,'ERROR: Unable to retrieve SOLR documents from URI') unless results && results.size > 0
|
16
|
+
|
17
|
+
results_hash = Hash.from_xml(results)
|
18
|
+
solr_docs = results_hash["response"]["result"]["doc"]
|
19
|
+
solr_docs = [ solr_docs ] unless solr_docs.is_a? Array
|
20
|
+
|
21
|
+
metadata = []
|
22
|
+
solr_docs.each do |solr_doc|
|
23
|
+
metadata << LD4L::WorksRDF::GetMetadataFromSolrDoc.call(solr_doc, solr_field_translations)
|
24
|
+
end
|
25
|
+
metadata
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromVivoURI
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get display metadata via content negotiation from an URI known to return VIVO produced triples
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
#
|
10
|
+
# @returns an instance of LD4L::WorksRDF::WorkMetadata populated with display metadata for the work located at the URI
|
11
|
+
def self.call( uri )
|
12
|
+
raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
|
13
|
+
uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
|
14
|
+
|
15
|
+
turtle = LD4L::WorksRDF::GetTurtleFromURI.call(uri)
|
16
|
+
graph = LD4L::WorksRDF::PopulateGraphFromTurtle.call(turtle)
|
17
|
+
repository = LD4L::WorksRDF::PopulateRepositoryFromGraph.call(graph)
|
18
|
+
model = LD4L::WorksRDF::PopulateVivoModelFromRepository.call(uri,repository)
|
19
|
+
metadata = LD4L::WorksRDF::GetMetadataFromVivoModel.call(uri,model)
|
20
|
+
metadata
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetModelFromURI
|
4
|
+
|
5
|
+
##
|
6
|
+
# Attempt to get metadata from the source of the URI via content negotiation.
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
#
|
10
|
+
# @returns an instance of one of the generic work models
|
11
|
+
def self.call( uri )
|
12
|
+
uri = uri.to_s if uri.kind_of?(RDF::URI)
|
13
|
+
|
14
|
+
# curl -L -D - -H "Accept: text/turtle" http://vivo.cornell.edu/individual/n56611
|
15
|
+
http = Curl.get(uri) do |curl|
|
16
|
+
curl.headers['Accept'] = 'text/turtle'
|
17
|
+
curl.headers['Content-Type'] = 'text/turtle'
|
18
|
+
curl.headers['Api-Version'] = '2.2'
|
19
|
+
curl.follow_location = true
|
20
|
+
curl.max_redirects = 3
|
21
|
+
curl.connect_timeout = 30
|
22
|
+
curl.useragent = "curb"
|
23
|
+
end
|
24
|
+
result = http.body_str
|
25
|
+
header = http.header_str
|
26
|
+
|
27
|
+
work_graph = RDF::Graph.new.from_ttl result
|
28
|
+
repo_name = SecureRandom.uuid.to_sym
|
29
|
+
# r = RDF::Repository.new
|
30
|
+
r = ActiveTriples::Repositories.add_repository repo_name, RDF::Repository.new
|
31
|
+
r << work_graph
|
32
|
+
|
33
|
+
# Get work as a generic work
|
34
|
+
the_work = self.get_generic_work( r, uri )
|
35
|
+
types = []
|
36
|
+
the_work.type.each do |t|
|
37
|
+
types << t.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
# Try to get more specific work
|
41
|
+
the_work = self.get_vivo_book( r, uri ) if types.include? RDFVocabularies::BIBO.Book.to_s
|
42
|
+
the_work = self.get_schema_book( r, uri ) if types.include? RDF::SCHEMA.Book.to_s
|
43
|
+
the_work
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_generic_work( repo, uri )
|
47
|
+
LD4L::WorksRDF::GenericWork.new(uri, :data => repo)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.get_vivo_book( repo, uri )
|
51
|
+
LD4L::WorksRDF::VivoBook.new(uri, :data => repo)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.get_schema_book( repo, uri )
|
55
|
+
LD4L::WorksRDF::SchemaBook.new(uri, :data => repo)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromBibframeModels
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get standard display metadata from a oclc model
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
# @param [Model] a oclc model
|
10
|
+
#
|
11
|
+
# @returns an instance of LD4L::WorksRDF::WorkMetadata
|
12
|
+
def self.call( uri, models )
|
13
|
+
raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
|
14
|
+
uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
|
15
|
+
|
16
|
+
uri = uri.to_s if uri.kind_of?(RDF::URI)
|
17
|
+
|
18
|
+
# TODO: Determine type of work from the model. Right now, only processing books.
|
19
|
+
metadata = self.populate_with_bibframe_book( models ) # if model.type.include? RDF::SCHEMA.Book.to_s
|
20
|
+
metadata.uri = uri
|
21
|
+
metadata.local_id = URI.parse(uri).path.split('/').last
|
22
|
+
metadata
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.populate_with_bibframe_book( models )
|
26
|
+
work = models[:work]
|
27
|
+
instance = models[:instance]
|
28
|
+
|
29
|
+
metadata = LD4L::WorksRDF::WorkMetadata.new(instance)
|
30
|
+
metadata.set_type_to_book # TODO Hardcoding to book for now
|
31
|
+
metadata.title = instance.title.first.label.first if instance.title && instance.title.first && instance.title.first.label
|
32
|
+
metadata.title = instance.title.first.title_value.first if instance.title && instance.title.first && instance.title.first.title_value
|
33
|
+
metadata.subtitle = instance.title.first.subtitle.first if instance.title && instance.title.first && instance.title.first.subtitle
|
34
|
+
metadata.title = "#{metadata.title} : #{metadata.subtitle}" if metadata.subtitle && metadata.subtitle.size > 0
|
35
|
+
metadata.title = instance.title_statement.first if instance.title_statement && instance.title_statement.first
|
36
|
+
metadata.author = work.contributor.first.label.first if work.contributor && work.contributor.first && work.contributor.first.label
|
37
|
+
metadata.author = work.creator.first.label.first if work.creator && work.creator.first && work.creator.first.label
|
38
|
+
metadata.pub_date = instance.publication.first.provider_date.first
|
39
|
+
metadata.pub_info = instance.provider_statement.first
|
40
|
+
# metadata.language = model.in_language.first
|
41
|
+
metadata.edition = instance.book_edition.first
|
42
|
+
|
43
|
+
system_numbers = instance.system_number
|
44
|
+
system_numbers.each do |sysnum|
|
45
|
+
uri = sysnum.rdf_subject.to_s
|
46
|
+
if uri.match('.*\/oclc\/(.*)')
|
47
|
+
parts = URI.parse(uri).path.split('/')
|
48
|
+
metadata.oclc_id = parts.last if parts.include?("oclc")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
metadata.source = "Bibframe"
|
54
|
+
# metadata.set_source_to_bibframe
|
55
|
+
metadata
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromBiboModel
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get standard display metadata from an bibo model
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
# @param [Model] an bibo model
|
10
|
+
#
|
11
|
+
# @returns an instance of LD4L::WorksRDF::WorkMetadata
|
12
|
+
def self.call( uri, model )
|
13
|
+
raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
|
14
|
+
uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
|
15
|
+
|
16
|
+
uri = uri.to_s if uri.kind_of?(RDF::URI)
|
17
|
+
|
18
|
+
# TODO: Determine type of work from the model. Right now, only processing books.
|
19
|
+
metadata = self.populate_with_bibo_book( model ) if
|
20
|
+
model.type.include?(RDFVocabularies::BIBO.Book.to_s) || model.type.include?(RDFVocabularies::BIBO.Document.to_s)
|
21
|
+
metadata.uri = uri
|
22
|
+
metadata.local_id = URI.parse(uri).path.split('/').last
|
23
|
+
metadata
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.populate_with_bibo_book( model )
|
27
|
+
# TODO: Could reach out to OCLC and get more info OR could make multiple calls to VIVO to get more info
|
28
|
+
metadata = LD4L::WorksRDF::WorkMetadata.new(model)
|
29
|
+
metadata.set_type_to_book
|
30
|
+
if model.title && model.title.size > 0
|
31
|
+
metadata.title = model.title.first
|
32
|
+
elsif model.label && model.label.size > 0
|
33
|
+
metadata.title = model.label.first
|
34
|
+
end
|
35
|
+
metadata.oclc_id = model.oclcnum.first if model.oclcnum && model.oclcnum.size > 0
|
36
|
+
# metadata.source = "BIBO"
|
37
|
+
metadata.set_source_to_unknown
|
38
|
+
metadata
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromGenericModel
|
4
|
+
|
5
|
+
##
|
6
|
+
# Attempt to get standard display metadata from a various models.
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
# @param [Model] one of the supported models
|
10
|
+
#
|
11
|
+
# @returns an instance of one of the OCLC work models
|
12
|
+
def self.call( uri, model )
|
13
|
+
raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
|
14
|
+
uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
|
15
|
+
|
16
|
+
uri = uri.to_s if uri.kind_of?(RDF::URI)
|
17
|
+
|
18
|
+
work = model[:work] if model.kind_of? Hash
|
19
|
+
work = model unless model.kind_of? Hash
|
20
|
+
|
21
|
+
# TODO: Move to common place because this code is repeated in each model_from_repository file
|
22
|
+
# Get work as a generic work
|
23
|
+
types = []
|
24
|
+
work.type.each do |t|
|
25
|
+
types << t.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
# TODO: Need to support multiple types (e.g. book, music, video). Currently only supporting books.
|
29
|
+
metadata = LD4L::WorksRDF::GetMetadataFromBiboModel.call(uri,model) if types.include? RDFVocabularies::BIBO.Book.to_s
|
30
|
+
metadata = LD4L::WorksRDF::GetMetadataFromBiboModel.call(uri,model) if types.include? RDFVocabularies::BIBO.Document.to_s
|
31
|
+
metadata = LD4L::WorksRDF::PopulateBibframeModelsFromRepository.call(uri,model) if types.include? RDFVocabularies::BF.Work.to_s
|
32
|
+
metadata = LD4L::WorksRDF::GetMetadataFromOclcModel.new(uri,model) if types.include? RDF::SCHEMA.Book.to_s
|
33
|
+
|
34
|
+
metadata.source = URI.parse(uri).host
|
35
|
+
metadata.set_source_to_unknown
|
36
|
+
|
37
|
+
metadata
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromOclcModel
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get standard display metadata from a oclc model
|
7
|
+
#
|
8
|
+
# @param [String, RDF::URI] uri for the work
|
9
|
+
# @param [Model] a oclc model
|
10
|
+
#
|
11
|
+
# @returns an instance of LD4L::WorksRDF::WorkMetadata
|
12
|
+
def self.call( uri, model )
|
13
|
+
raise ArgumentError, 'uri argument must be a uri string or an instance of RDF::URI' unless
|
14
|
+
uri.kind_of?(String) && uri.size > 0 || uri.kind_of?(RDF::URI)
|
15
|
+
|
16
|
+
uri = uri.to_s if uri.kind_of?(RDF::URI)
|
17
|
+
|
18
|
+
# TODO: Determine type of work from the model. Right now, only processing books.
|
19
|
+
metadata = self.populate_with_schema_book( model ) if model.type.include? RDF::SCHEMA.Book.to_s
|
20
|
+
metadata.uri = uri
|
21
|
+
metadata.local_id = URI.parse(uri).path.split('/').last
|
22
|
+
metadata
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.populate_with_schema_book( model )
|
26
|
+
metadata = LD4L::WorksRDF::WorkMetadata.new(model)
|
27
|
+
metadata.set_type_to_book
|
28
|
+
metadata.title = model.title.first if model.title && model.title.size > 0
|
29
|
+
metadata.author = model.creator.first.full_name.first if model.creator && model.creator.size > 0 && model.creator.first.full_name
|
30
|
+
metadata.pub_date = model.date_published.first if model.date_published && model.date_published.size > 0
|
31
|
+
metadata.pub_info = "#{model.place_of_publication.first} : #{model.publisher.first}, #{model.date_published.first}"
|
32
|
+
metadata.language = model.in_language.first if model.in_language && model.in_language.size > 0
|
33
|
+
metadata.edition = model.book_edition.first if model.book_edition && model.book_edition.size > 0
|
34
|
+
metadata.oclc_id = model.oclcnum.first
|
35
|
+
metadata.source = "OCLC Worldcat"
|
36
|
+
metadata.set_source_to_oclc
|
37
|
+
metadata
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module LD4L
|
2
|
+
module WorksRDF
|
3
|
+
class GetMetadataFromSolrDoc
|
4
|
+
|
5
|
+
# TODO This is Cornell specific. Need a general processor of solr OR a callback to an institution specific processor.
|
6
|
+
##
|
7
|
+
# Get metadata from solr document.
|
8
|
+
#
|
9
|
+
# @param [Hash] solr document
|
10
|
+
# @param [Hash] translations identifying location in solr doc for metadata fields
|
11
|
+
#
|
12
|
+
# @returns an instance of one of the OCLC work models
|
13
|
+
def self.call( solr_doc, solr_field_translations )
|
14
|
+
flat_doc = flatten(solr_doc["arr"])
|
15
|
+
flat_doc.merge! interpret_str(solr_doc["str"])
|
16
|
+
metadata = self.populate_with_solr_values(flat_doc, solr_field_translations)
|
17
|
+
metadata
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.populate_with_solr_values( solr_doc, solr_field_translations )
|
21
|
+
metadata = LD4L::WorksRDF::WorkMetadata.new()
|
22
|
+
|
23
|
+
metadata.source = "Cornell Library"
|
24
|
+
metadata.set_source_to_cornell_library
|
25
|
+
|
26
|
+
# metadata.format = solr_doc["format"].upcase.to_sym
|
27
|
+
metadata.set_type(solr_doc["format"])
|
28
|
+
metadata.local_id = solr_doc["id"]
|
29
|
+
metadata.uri = "https://newcatalog.library.cornell.edu/catalog/"+metadata.local_id
|
30
|
+
metadata.title = solr_doc["title"]
|
31
|
+
metadata.author = solr_doc["author"]
|
32
|
+
metadata.pub_date = solr_doc["pub_date_display"]
|
33
|
+
metadata.pub_info = solr_doc["pub_info_display"]
|
34
|
+
metadata.language = solr_doc["language_display"]
|
35
|
+
metadata.edition = solr_doc["edition_display"]
|
36
|
+
|
37
|
+
other_ids = solr_doc["other_id_display"]
|
38
|
+
oclc_id = nil
|
39
|
+
oclc_id = other_ids.select { |id| id.start_with? "(OCoLC)" } if other_ids.is_a? Array
|
40
|
+
oclc_id = oclc_id.first if (oclc_id.is_a? Array) && (oclc_id.size > 0)
|
41
|
+
oclc_id = other_ids if (other_ids.is_a? String) && (other_ids.start_with? "(OCoLC)")
|
42
|
+
metadata.oclc_id = oclc_id[7..-1] unless (oclc_id.nil?) || (!oclc_id.is_a? String)
|
43
|
+
|
44
|
+
metadata
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.flatten( solr_doc )
|
48
|
+
flat_hash = {}
|
49
|
+
solr_doc.each do |h|
|
50
|
+
name = h["name"]
|
51
|
+
value = h["str"]
|
52
|
+
flat_hash[name] = value
|
53
|
+
end
|
54
|
+
flat_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.interpret_str( str_field )
|
58
|
+
flat_hash = {}
|
59
|
+
flat_hash["id"] = str_field.first
|
60
|
+
flat_hash["author"] = str_field[1] if str_field.size > 3
|
61
|
+
flat_hash["title"] = str_field.last
|
62
|
+
flat_hash
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|