bib_card 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ module BibCard
2
+ module DBPedia
3
+ class Resource < Spira::Base
4
+
5
+ configure base_uri: "http://dbpedia.org/resource/"
6
+
7
+ property :given_name, predicate: FOAF_GIVEN_NAME, type: XSD.string
8
+ property :surname, predicate: FOAF_SURNAME, type: XSD.string
9
+ property :rdfs_label, predicate: RDF::RDFS.label, type: XSD.string
10
+ property :abstract, predicate: BibCard::DBO_ABSTRACT, type: XSD.string
11
+ property :founded, predicate: DBP_FOUNDED, type: XSD.string
12
+ property :location, predicate: DBP_LOCATION, type: XSD.string
13
+ property :thumbnail, predicate: DBO_THUMBNAIL, type: RDF::URI
14
+ property :depiction, predicate: FOAF_DEPICTION, type: RDF::URI
15
+ has_many :influences, predicate: DBO_INFLUENCED_BY, type: 'DBPedia::Resource'
16
+ has_many :influencees, predicate: DBO_INFLUENCED, type: 'DBPedia::Resource'
17
+
18
+ def name
19
+ if self.given_name and self.surname
20
+ self.given_name + ' ' + self.surname
21
+ else
22
+ self.rdfs_label
23
+ end
24
+ end
25
+
26
+ def film_appearances
27
+ Spira.repository.query({predicate: DBO_STARRING, object: self.subject}).map do |film|
28
+ film.subject.as(DBPedia::Resource)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module BibCard
2
+ class EntityNotFoundException < RuntimeError
3
+
4
+ MESSAGE = 'Entity not found.'
5
+
6
+ def initialize(custom_msg = nil)
7
+ custom_msg.nil? ? super(MESSAGE) : super(custom_msg)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module BibCard
2
+ module Getty
3
+ class ScopeNote < Spira::Base
4
+
5
+ configure base_uri: "http://vocab.getty.edu/ulan/scopeNote/"
6
+
7
+ property :value, predicate: RDF.value, type: XSD.string
8
+
9
+ def sources
10
+ Spira.repository.query({subject: self.subject, predicate: DC_SOURCE}).map do |stmt|
11
+ source = stmt.object.as(Source)
12
+ source.type == BIBO_DOCUMENT_PART ? source.parent : source
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module BibCard
2
+ module Getty
3
+ class Source < Spira::Base
4
+
5
+ property :type, :predicate => RDF.type, :type => RDF::URI
6
+ property :short_title, predicate: BIBO_SHORT_TITLE, type: XSD.string
7
+
8
+ def parent
9
+ stmt = Spira.repository.query({subject: self.subject, predicate: DC_IS_PART_OF}).first
10
+ stmt.nil? ? nil : stmt.object.as(Source)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module BibCard
2
+ module Getty
3
+ class Subject < Spira::Base
4
+
5
+ configure base_uri: "http://vocab.getty.edu/ulan/"
6
+
7
+ property :scope_note, predicate: SKOS_SCOPE_NOTE, type: 'ScopeNote'
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module BibCard
2
+ class InvalidURIException < RuntimeError
3
+
4
+ MESSAGE = 'Invalid URI. BibCard requires a valid VIAF or LCNAF URI.'
5
+
6
+ def initialize
7
+ super MESSAGE
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,65 @@
1
+ module BibCard
2
+ class Person < Spira::Base
3
+
4
+ property :birth_date, predicate: SCHEMA_BIRTHDATE, type: XSD.string
5
+ property :death_date, predicate: SCHEMA_DEATHDATE, type: XSD.string
6
+ has_many :types, predicate: RDF.type, type: RDF::URI
7
+
8
+ def uri
9
+ self.subject
10
+ end
11
+
12
+ def name(preferred_languages = nil)
13
+ if preferred_languages
14
+ matches = Spira.repository.query({subject: @subject, predicate: SCHEMA_NAME}).reduce(Array.new) do |matches, stmt|
15
+ language = stmt.object.language.to_s
16
+ matches << stmt if preferred_languages.include?(language)
17
+ matches
18
+ end
19
+ else
20
+ matches = Spira.repository.query({subject: @subject, predicate: SCHEMA_NAME})
21
+ end
22
+ matches.first.nil? ? nil : matches.first.object.to_s
23
+ end
24
+
25
+ def loc_uri
26
+ stmt = related_entity_by_uri_prefix("http://id.loc.gov/authorities/names/")
27
+ stmt.nil? ? nil : stmt.object
28
+ end
29
+
30
+ def dbpedia_uri
31
+ stmt = related_entity_by_uri_prefix("http://dbpedia.org/resource")
32
+ stmt.nil? ? nil : stmt.object
33
+ end
34
+
35
+ def getty_uri
36
+ stmt = related_entity_by_uri_prefix("http://vocab.getty.edu/ulan")
37
+ # Note that we are modifying the URI to get the RWO URI
38
+ stmt.nil? ? nil : RDF::URI.new( stmt.object.to_s.gsub('-agent', '') )
39
+ end
40
+
41
+ def wikidata_uri
42
+ stmt = related_entity_by_uri_prefix("http://www.wikidata.org/entity")
43
+ stmt.nil? ? nil : stmt.object
44
+ end
45
+
46
+ def dbpedia_resource
47
+ self.dbpedia_uri.as(BibCard::DBPedia::Resource) if self.dbpedia_uri
48
+ end
49
+
50
+ def getty_subject
51
+ self.getty_uri.as(BibCard::Getty::Subject) if self.getty_uri
52
+ end
53
+
54
+ def wikidata_entity
55
+ self.wikidata_uri.as(BibCard::Wikidata::Entity) if self.wikidata_uri
56
+ end
57
+
58
+ protected
59
+
60
+ def related_entity_by_uri_prefix(domain)
61
+ Spira.repository.query({subject: @subject, predicate: SCHEMA_SAME_AS}).select {|s| s.object.to_s.match(domain)}.first
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,8 @@
1
+ module BibCard
2
+ # Add support for rails logging
3
+ class Railtie < Rails::Railtie
4
+ initializer 'Rails logger' do
5
+ BibCard.logger = Rails.logger
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,76 @@
1
+ module BibCard
2
+ # SHOULD BE LOADED VIA RDF::Vocab, but not working
3
+ FOAF_GIVEN_NAME = RDF::URI.new('http://xmlns.com/foaf/0.1/givenName')
4
+ FOAF_SURNAME = RDF::URI.new('http://xmlns.com/foaf/0.1/surname')
5
+ FOAF_DEPICTION = RDF::URI.new('http://xmlns.com/foaf/0.1/depiction')
6
+ SKOS_SCOPE_NOTE = RDF::URI.new('http://www.w3.org/2004/02/skos/core#scopeNote')
7
+ DC_SOURCE = RDF::URI.new('http://purl.org/dc/terms/source')
8
+ DC_IS_PART_OF = RDF::URI.new('http://purl.org/dc/terms/isPartOf')
9
+ RDFS_COMMENT = RDF::URI.new('http://www.w3.org/2000/01/rdf-schema#comment')
10
+ RDFS_LABEL = RDF::URI.new('http://www.w3.org/2000/01/rdf-schema#label')
11
+ SCHEMA_PERSON = RDF::URI.new('http://schema.org/Person')
12
+ SCHEMA_ORGANIZATION = RDF::URI.new('http://schema.org/Organization')
13
+ SCHEMA_SAME_AS = RDF::URI.new('http://schema.org/sameAs')
14
+ SCHEMA_NAME = RDF::URI.new('http://schema.org/name')
15
+ SCHEMA_BIRTHDATE = RDF::URI.new('http://schema.org/birthDate')
16
+ SCHEMA_DEATHDATE = RDF::URI.new('http://schema.org/deathDate')
17
+ SCHEMA_DESCRIPTION = RDF::URI.new('http://schema.org/description')
18
+ SCOPE_NOTE = RDF::URI.new('http://vocab.getty.edu/ontology#ScopeNote')
19
+ SKOS_NOTE = RDF::URI.new('http://www.w3.org/2004/02/skos/core#note')
20
+ SKOS_SCOPENOTE = RDF::URI.new('http://www.w3.org/2004/02/skos/core#scopeNote')
21
+ DCT_SOURCE = RDF::URI.new('http://purl.org/dc/terms/source')
22
+ DCT_IS_PART_OF = RDF::URI.new('http://purl.org/dc/terms/isPartOf')
23
+ BIBO_DOCUMENT_PART = RDF::URI.new('http://purl.org/ontology/bibo/DocumentPart')
24
+ BIBO_SHORT_TITLE = RDF::URI.new('http://purl.org/ontology/bibo/shortTitle')
25
+ WDT_WORK_LOCATION = RDF::URI.new('http://www.wikidata.org/prop/direct/P937')
26
+ WDT_NOTABLE_WORKS = RDF::URI.new('http://www.wikidata.org/prop/direct/P800')
27
+ WDT_ISBN = RDF::URI.new('http://www.wikidata.org/prop/direct/P212')
28
+ WDT_OCLC_NUMBER = RDF::URI.new('http://www.wikidata.org/prop/direct/P243')
29
+ WDT_EDUCATED_AT = RDF::URI.new('http://www.wikidata.org/prop/direct/P69')
30
+ WDP_EDUCATED_AT = RDF::URI.new('http://www.wikidata.org/prop/P69')
31
+ WDPS_STMT_EDU_AT = RDF::URI.new('http://www.wikidata.org/prop/statement/P69')
32
+ PROV_DERIVED_FROM = RDF::URI.new('http://www.w3.org/ns/prov#wasDerivedFrom')
33
+ WDR_STATED_IN = RDF::URI.new('http://www.wikidata.org/prop/reference/P248')
34
+ DBO_INFLUENCED_BY = RDF::URI.new('http://dbpedia.org/ontology/influencedBy')
35
+ DBO_INFLUENCED = RDF::URI.new('http://dbpedia.org/ontology/influenced')
36
+ DBO_STARRING = RDF::URI.new('http://dbpedia.org/ontology/starring')
37
+ DBO_ABSTRACT = RDF::URI.new('http://dbpedia.org/ontology/abstract')
38
+ DBO_THUMBNAIL = RDF::URI.new('http://dbpedia.org/ontology/thumbnail')
39
+ DBP_FOUNDED = RDF::URI.new('http://dbpedia.org/ontology/foundedDate')
40
+ DBP_LOCATION = RDF::URI.new('http://dbpedia.org/ontology/location')
41
+
42
+ VOCAB_PREFIXES = {
43
+ schema: RDF::URI.new("http://schema.org/"),
44
+ foaf: RDF::URI.new("http://xmlns.com/foaf/0.1/"),
45
+ owl: RDF::URI.new("http://www.w3.org/2002/07/owl#"),
46
+ skos: RDF::URI.new("http://www.w3.org/2004/02/skos/core#"),
47
+ dcterms: RDF::URI.new("http://purl.org/dc/terms/"),
48
+ bibo: RDF::URI.new("http://purl.org/ontology/bibo/"),
49
+ wdpd: RDF::URI.new("http://www.wikidata.org/prop/direct/"),
50
+ wdpr: RDF::URI.new("http://www.wikidata.org/prop/reference/"),
51
+ wdps: RDF::URI.new("http://www.wikidata.org/prop/statement/"),
52
+ wdp: RDF::URI.new("http://www.wikidata.org/prop/"),
53
+ rdfs: RDF::URI.new("http://www.w3.org/2000/01/rdf-schema#"),
54
+ dbo: RDF::URI.new("http://dbpedia.org/ontology/"),
55
+ rdf: RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
56
+ }
57
+
58
+ JSON_LD_CONTEXT = {
59
+ schema: "http://schema.org/",
60
+ foaf: "http://xmlns.com/foaf/0.1/",
61
+ owl: "http://www.w3.org/2002/07/owl#",
62
+ skos: "http://www.w3.org/2004/02/skos/core#",
63
+ dcterms: "http://purl.org/dc/terms/",
64
+ bibo: "http://purl.org/ontology/bibo/",
65
+ wdpd: "http://www.wikidata.org/prop/direct/",
66
+ wdp: "http://www.wikidata.org/prop/",
67
+ rdfs: "http://www.w3.org/2000/01/rdf-schema#",
68
+ dbo: "http://dbpedia.org/ontology/",
69
+ rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
70
+ }
71
+
72
+ JSON_LD_FRAME = {
73
+ "@context" => JSON_LD_CONTEXT,
74
+ "@type" => ["schema:Person", "schema:Organization"]
75
+ }
76
+ end
@@ -0,0 +1,3 @@
1
+ module BibCard
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ module BibCard
2
+ module Wikidata
3
+ class Entity < Spira::Base
4
+
5
+ configure base_uri: "http://www.wikidata.org/entity/"
6
+
7
+ property :schema_name, predicate: SCHEMA_NAME, localized: true
8
+ property :rdfs_label, predicate: RDF::RDFS.label, type: XSD.string
9
+ property :description, predicate: SCHEMA_DESCRIPTION, type: XSD.string
10
+ property :work_location, predicate: WDT_WORK_LOCATION, type: 'Wikidata::Entity'
11
+ has_many :alma_maters, predicate: WDT_EDUCATED_AT, type: 'Wikidata::Entity'
12
+ has_many :notable_works, predicate: WDT_NOTABLE_WORKS, type: 'Wikidata::Entity'
13
+
14
+ def name
15
+ self.schema_name.nil? ? self.rdfs_label : self.schema_name
16
+ end
17
+
18
+ def source
19
+ edu_assertion = Spira.repository.query({predicate: WDPS_STMT_EDU_AT, object: self.subject}).first.subject
20
+ reference_stmt = Spira.repository.query({subject: edu_assertion, predicate: PROV_DERIVED_FROM}).first if edu_assertion
21
+ reference = reference_stmt.object if reference_stmt
22
+ source = Spira.repository.query({subject: reference, predicate: WDR_STATED_IN}).first.object if reference
23
+ source.nil? ? nil : source.as(Wikidata::Entity)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bib_card
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Meyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdf
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rdf-rdfxml
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 3.1.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 3.1.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: spira
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rest-client
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 2.0.2
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 2.0.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: nokogiri
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 1.11.1
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 1.11.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: equivalent-xml
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.6'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.6'
103
+ - !ruby/object:Gem::Dependency
104
+ name: bundler
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 2.2.5
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 2.2.5
117
+ - !ruby/object:Gem::Dependency
118
+ name: rake
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 13.0.1
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 13.0.1
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.4'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.4'
145
+ - !ruby/object:Gem::Dependency
146
+ name: simplecov
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.11'
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 0.11.2
155
+ type: :development
156
+ prerelease: false
157
+ version_requirements: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '0.11'
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 0.11.2
165
+ - !ruby/object:Gem::Dependency
166
+ name: webmock
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '2.0'
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 2.0.3
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '2.0'
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: 2.0.3
185
+ description: Given a URI for a bibliographic author entity, assemble useful information
186
+ for producing a knowledge card.
187
+ email:
188
+ - stephen.meyer@wisc.edu
189
+ executables: []
190
+ extensions: []
191
+ extra_rdoc_files: []
192
+ files:
193
+ - ".gitignore"
194
+ - ".rspec"
195
+ - ".travis.yml"
196
+ - CODE_OF_CONDUCT.md
197
+ - Gemfile
198
+ - LICENSE.txt
199
+ - README.md
200
+ - Rakefile
201
+ - bib_card.gemspec
202
+ - bin/console
203
+ - bin/setup
204
+ - lib/bib_card.rb
205
+ - lib/bib_card/author.rb
206
+ - lib/bib_card/crawl_exception.rb
207
+ - lib/bib_card/crawler.rb
208
+ - lib/bib_card/db_pedia/resource.rb
209
+ - lib/bib_card/entity_not_found_exception.rb
210
+ - lib/bib_card/getty/scope_note.rb
211
+ - lib/bib_card/getty/source.rb
212
+ - lib/bib_card/getty/subject.rb
213
+ - lib/bib_card/invalid_uri_exception.rb
214
+ - lib/bib_card/person.rb
215
+ - lib/bib_card/railtie.rb
216
+ - lib/bib_card/uris.rb
217
+ - lib/bib_card/version.rb
218
+ - lib/bib_card/wikidata/entity.rb
219
+ homepage: https://github.com/UW-Madison-Library/bibcard.git
220
+ licenses:
221
+ - MIT
222
+ metadata: {}
223
+ post_install_message:
224
+ rdoc_options: []
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ required_rubygems_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ requirements: []
238
+ rubygems_version: 3.1.2
239
+ signing_key:
240
+ specification_version: 4
241
+ summary: Library Linked Data for building knowledge cards.
242
+ test_files: []