research_metadata_announcement 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/.gitignore +18 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -0
- data/README.md +89 -0
- data/Rakefile +2 -0
- data/lib/research_metadata_announcement.rb +11 -0
- data/lib/research_metadata_announcement/transformer/base.rb +56 -0
- data/lib/research_metadata_announcement/transformer/dataset.rb +222 -0
- data/lib/research_metadata_announcement/transformer/transformer.rb +7 -0
- data/lib/research_metadata_announcement/version.rb +5 -0
- data/research_metadata_announcement.gemspec +29 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9cc9974c6b361bb579f8454ffcf2602d78a62746
|
4
|
+
data.tar.gz: 33da4d070192919b91c45317d7a026f6c8f19f20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5db2978940ff75facb1fba4cf2d53f9a3abd462c3131b78cb1c518bbf77335f61116f7d993c213af663c7e7598c4baa4292fa8bfee4f4d2d9fbf4bb00e9142f0
|
7
|
+
data.tar.gz: bd79b981ed25b340755a255f609789415c695afbdea235d1e75cb9f9da6650ee39204e235273d0053e4fe6de9a7504501c5830655adecc59128bf4577c088875
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# ResearchMetadataAnnouncement
|
2
|
+
|
3
|
+
Metadata extraction from the Pure Research Information System and transformation of the metadata into an announcement.
|
4
|
+
|
5
|
+
## Status
|
6
|
+
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/research_metadata_announcement.svg)](https://badge.fury.io/rb/research_metadata_announcement)
|
8
|
+
[![Build Status](https://semaphoreci.com/api/v1/aalbinclark/research_metadata_announcement/branches/master/badge.svg)](https://semaphoreci.com/aalbinclark/research_metadata_announcement)
|
9
|
+
[![Code Climate](https://codeclimate.com/github/lulibrary/research_metadata_announcement/badges/gpa.svg)](https://codeclimate.com/github/lulibrary/research_metadata_announcement)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'research_metadata_announcement'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install research_metadata_announcement
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Configuration
|
28
|
+
|
29
|
+
Create a hash for passing to a transformer.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# Pure host with authentication.
|
33
|
+
config = {
|
34
|
+
url: ENV['PURE_URL'],
|
35
|
+
username: ENV['PURE_USERNAME'],
|
36
|
+
password: ENV['PURE_PASSWORD'],
|
37
|
+
}
|
38
|
+
```
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# Pure host without authentication.
|
42
|
+
config = {
|
43
|
+
url: ENV['PURE_URL']
|
44
|
+
}
|
45
|
+
```
|
46
|
+
|
47
|
+
### Transformation
|
48
|
+
|
49
|
+
Create a metadata transformer for a Pure dataset.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
transformer = ResearchMetadataAnnouncement::Transformer::Dataset.new config
|
53
|
+
```
|
54
|
+
|
55
|
+
Give it a Pure identifier and extract the metadata.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
transformer.extract uuid: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
59
|
+
```
|
60
|
+
|
61
|
+
An announcement can be obtained in various formats, assuming the metadata is
|
62
|
+
available and the announcement length does not exceed the optional max_length
|
63
|
+
argument. Each example uses a different dataset for illustrative purposes.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
|
67
|
+
transformer.title_uri
|
68
|
+
#=> "Operating Nanobeams in a Quantum Fluid. dx.doi.org/10.17635/lancaster/researchdata/139."
|
69
|
+
|
70
|
+
transformer.title_uri max_length: 140
|
71
|
+
#=> "Ruthenium Volatilisation from Reprocessed Spent Nuclear Fuel – Studying the Baseline Therm... dx.doi.org/10.17635/lancaster/researchdata/14."
|
72
|
+
|
73
|
+
transformer.uri_title
|
74
|
+
#=> "dx.doi.org/10.17635/lancaster/researchdata/29. Herpes simplex virus 1 (HSV-1) evolution."
|
75
|
+
|
76
|
+
transformer.keywords_uri
|
77
|
+
#=> "smart cities, sustainability. dx.doi.org/10.17635/lancaster/researchdata/35."
|
78
|
+
|
79
|
+
transformer.hashtags_uri
|
80
|
+
#=> "#treatedhypertension #microvascularbloodflow. dx.doi.org/10.17635/lancaster/researchdata/148."
|
81
|
+
|
82
|
+
transformer.uri_keywords
|
83
|
+
#=> "dx.doi.org/10.17635/lancaster/researchdata/134. metagenomics, deep sequencing."
|
84
|
+
|
85
|
+
transformer.uri_hashtags max_descriptors: 4
|
86
|
+
#=> "dx.doi.org/10.17635/lancaster/researchdata/111. #influenza #nasopharynx #virology #virus."
|
87
|
+
|
88
|
+
```
|
89
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'puree'
|
2
|
+
|
3
|
+
require 'research_metadata_announcement/transformer/base'
|
4
|
+
require 'research_metadata_announcement/transformer/dataset'
|
5
|
+
require 'research_metadata_announcement/version'
|
6
|
+
|
7
|
+
# Metadata extraction from the Pure Research Information System and
|
8
|
+
# transformation of the metadata into an announcement
|
9
|
+
#
|
10
|
+
module ResearchMetadataAnnouncement
|
11
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module ResearchMetadataAnnouncement
|
2
|
+
module Transformer
|
3
|
+
|
4
|
+
# Base transformer
|
5
|
+
#
|
6
|
+
class Base
|
7
|
+
|
8
|
+
# @param config [Hash]
|
9
|
+
# @option config [String] :url The URL of the Pure host.
|
10
|
+
# @option config [String] :username The username of the Pure host account.
|
11
|
+
# @option config [String] :password The password of the Pure host account.
|
12
|
+
|
13
|
+
def initialize(config)
|
14
|
+
@config = config
|
15
|
+
end
|
16
|
+
|
17
|
+
# Extract metadata from Pure
|
18
|
+
#
|
19
|
+
# @param id [String]
|
20
|
+
# @param uuid [String]
|
21
|
+
def extract(uuid: nil, id: nil)
|
22
|
+
if !uuid.nil?
|
23
|
+
@resource = @resource_extractor.find uuid: uuid
|
24
|
+
else
|
25
|
+
@resource = @resource_extractor.find id: id
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def append_sentence(str, str_to_append)
|
32
|
+
if str_to_append && str_to_append.size > 0
|
33
|
+
if str
|
34
|
+
if str.size > 0
|
35
|
+
"#{str}. #{str_to_append}."
|
36
|
+
else
|
37
|
+
"#{str_to_append}."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
str
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def strip_uri_scheme(uri)
|
46
|
+
uri.sub /^.+\/\//, ''
|
47
|
+
end
|
48
|
+
|
49
|
+
def length_constrained?(max_length)
|
50
|
+
max_length && max_length > 0
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
module ResearchMetadataAnnouncement
|
2
|
+
|
3
|
+
module Transformer
|
4
|
+
|
5
|
+
# Extracts dataset metadata from the Pure Research Information System and
|
6
|
+
# converts it into an announcement
|
7
|
+
#
|
8
|
+
class Dataset < ResearchMetadataAnnouncement::Transformer::Base
|
9
|
+
|
10
|
+
# @param config [Hash]
|
11
|
+
# @option config [String] :url The URL of the Pure host.
|
12
|
+
# @option config [String] :username The username of the Pure host account.
|
13
|
+
# @option config [String] :password The password of the Pure host account.
|
14
|
+
def initialize(config)
|
15
|
+
super
|
16
|
+
@resource_extractor = Puree::Extractor::Dataset.new config
|
17
|
+
end
|
18
|
+
|
19
|
+
# Keywords followed by uri format
|
20
|
+
#
|
21
|
+
# @param max_length [Fixnum] Maximum length of announcement.
|
22
|
+
# @param max_descriptors [Fixnum] Maximum number of descriptors (common name for keywords, tags, hashtags).
|
23
|
+
# @return [String, nil] Announcement returned if the metadata is available and the announcement length does not exceed the max_length argument.
|
24
|
+
def keywords_uri(max_length: nil, max_descriptors: 2)
|
25
|
+
return nil if !@resource
|
26
|
+
keywords = @resource.keywords
|
27
|
+
uri = prepare_uri
|
28
|
+
if uri
|
29
|
+
return build_keywords_uri(keywords: keywords,
|
30
|
+
uri: uri,
|
31
|
+
max_length: max_length,
|
32
|
+
max_descriptors: max_descriptors)
|
33
|
+
end
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# Uri followed by keywords format
|
38
|
+
#
|
39
|
+
# @see #keywords_uri
|
40
|
+
def uri_keywords(max_length: nil, max_descriptors: 2)
|
41
|
+
return nil if !@resource
|
42
|
+
keywords = @resource.keywords
|
43
|
+
uri = prepare_uri
|
44
|
+
if uri
|
45
|
+
return build_uri_keywords(keywords: keywords,
|
46
|
+
uri: uri,
|
47
|
+
max_length: max_length,
|
48
|
+
max_descriptors: max_descriptors)
|
49
|
+
end
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# Uri followed by hashtags format
|
54
|
+
#
|
55
|
+
# @see #keywords_uri
|
56
|
+
def uri_hashtags(max_length: nil, max_descriptors: 2)
|
57
|
+
return nil if !@resource
|
58
|
+
keywords = @resource.keywords
|
59
|
+
uri = prepare_uri
|
60
|
+
if uri
|
61
|
+
return build_uri_hashtags(keywords: keywords,
|
62
|
+
uri: uri,
|
63
|
+
max_length: max_length,
|
64
|
+
max_descriptors: max_descriptors)
|
65
|
+
end
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
|
69
|
+
# Hashtags followed by uri format
|
70
|
+
#
|
71
|
+
# @see #keywords_uri
|
72
|
+
def hashtags_uri(max_length: nil, max_descriptors: 2)
|
73
|
+
return nil if !@resource
|
74
|
+
keywords = @resource.keywords
|
75
|
+
uri = prepare_uri
|
76
|
+
if uri
|
77
|
+
return build_hashtags_uri(keywords: keywords,
|
78
|
+
uri: uri,
|
79
|
+
max_length: max_length,
|
80
|
+
max_descriptors: max_descriptors)
|
81
|
+
end
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
85
|
+
# Title followed by uri format
|
86
|
+
#
|
87
|
+
# @param max_length [Fixnum]
|
88
|
+
# @return [String, nil] Announcement returned if the metadata is available and the announcement length does not exceed the max_length argument.
|
89
|
+
def title_uri(max_length: nil)
|
90
|
+
return nil if !@resource
|
91
|
+
title = @resource.title
|
92
|
+
uri = prepare_uri
|
93
|
+
if uri
|
94
|
+
return build_title_uri(uri: uri, title: title, max_length: max_length)
|
95
|
+
end
|
96
|
+
nil
|
97
|
+
end
|
98
|
+
|
99
|
+
# Uri followed by title format
|
100
|
+
#
|
101
|
+
# @see #title_uri
|
102
|
+
def uri_title(max_length: nil)
|
103
|
+
return nil if !@resource
|
104
|
+
title = @resource.title
|
105
|
+
uri = prepare_uri
|
106
|
+
if uri
|
107
|
+
return build_uri_title(uri: uri, title: title, max_length: max_length)
|
108
|
+
end
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def prepare_uri
|
115
|
+
if @resource && @resource.doi
|
116
|
+
return strip_uri_scheme @resource.doi
|
117
|
+
end
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_keywords_uri(keywords:, uri:, max_length:, max_descriptors:)
|
122
|
+
if !keywords.empty?
|
123
|
+
str = append_sentence(build_keywords(keywords, max_descriptors), uri)
|
124
|
+
if length_constrained? max_length
|
125
|
+
return str if str.size <= max_length
|
126
|
+
else
|
127
|
+
return str
|
128
|
+
end
|
129
|
+
end
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
|
133
|
+
def build_uri_keywords(keywords:, uri:, max_length:, max_descriptors:)
|
134
|
+
if !keywords.empty?
|
135
|
+
str = append_sentence(uri, build_keywords(keywords, max_descriptors))
|
136
|
+
if length_constrained? max_length
|
137
|
+
return str if str.size <= max_length
|
138
|
+
else
|
139
|
+
return str
|
140
|
+
end
|
141
|
+
end
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
|
145
|
+
def build_uri_hashtags(keywords:, uri:, max_length:, max_descriptors:)
|
146
|
+
if !keywords.empty?
|
147
|
+
str = append_sentence(uri, build_hashtags(keywords, max_descriptors))
|
148
|
+
if length_constrained? max_length
|
149
|
+
return str if str.size <= max_length
|
150
|
+
else
|
151
|
+
return str
|
152
|
+
end
|
153
|
+
end
|
154
|
+
nil
|
155
|
+
end
|
156
|
+
|
157
|
+
def build_hashtags_uri(keywords:, uri:, max_length:, max_descriptors:)
|
158
|
+
if !keywords.empty?
|
159
|
+
str = append_sentence(build_hashtags(keywords, max_descriptors), uri)
|
160
|
+
if length_constrained? max_length
|
161
|
+
return str if str.size <= max_length
|
162
|
+
else
|
163
|
+
return str
|
164
|
+
end
|
165
|
+
end
|
166
|
+
nil
|
167
|
+
end
|
168
|
+
|
169
|
+
def build_title_uri(title:, uri:, max_length:)
|
170
|
+
if length_constrained? max_length
|
171
|
+
available_chars = max_length - (uri.size + 3)
|
172
|
+
available_chars = 0 if available_chars < 0
|
173
|
+
if title.size <= available_chars
|
174
|
+
return append_sentence title, uri
|
175
|
+
end
|
176
|
+
if available_chars-3 > 0
|
177
|
+
truncated_title = title[0..available_chars-3].strip + '...'
|
178
|
+
return "#{truncated_title} #{uri}."
|
179
|
+
end
|
180
|
+
else
|
181
|
+
return append_sentence title, uri
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def build_uri_title(uri:, title:, max_length:)
|
186
|
+
if length_constrained? max_length
|
187
|
+
available_chars = max_length - (uri.size + 3)
|
188
|
+
available_chars = 0 if available_chars < 0
|
189
|
+
if title.size <= available_chars
|
190
|
+
return append_sentence uri, title
|
191
|
+
end
|
192
|
+
if available_chars-3 > 0
|
193
|
+
truncated_title = title[0..available_chars-3].strip + '...'
|
194
|
+
return "#{uri}. #{truncated_title}"
|
195
|
+
end
|
196
|
+
else
|
197
|
+
return append_sentence uri, title
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def build_keywords(keywords, max)
|
202
|
+
return keywords[0..max-1].join ', ' if keywords
|
203
|
+
nil
|
204
|
+
end
|
205
|
+
|
206
|
+
def build_hashtags(keywords, max)
|
207
|
+
a = keywords[0..max-1].map { |i| i.downcase }
|
208
|
+
a = a.map { |i| i.gsub(/[^a-zA-Z0-9]/,'') }
|
209
|
+
a = a.map { |i| i.gsub(/\s+/, '') }
|
210
|
+
a = a.map { |i| "##{i}" }
|
211
|
+
if a.size > 0
|
212
|
+
return a.join ' '
|
213
|
+
else
|
214
|
+
return nil
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "research_metadata_announcement/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "research_metadata_announcement"
|
8
|
+
spec.version = ResearchMetadataAnnouncement::VERSION
|
9
|
+
spec.authors = ["Adrian Albin-Clark"]
|
10
|
+
spec.email = ["a.albin-clark@lancaster.ac.uk"]
|
11
|
+
|
12
|
+
spec.summary = %q{Metadata extraction from the Pure Research Information System and transformation of the metadata into an announcement.}
|
13
|
+
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.homepage = "https://github.com/lulibrary/research_metadata_announcement"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.required_ruby_version = '~> 2.1'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "puree", "~> 1.4"
|
27
|
+
|
28
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: research_metadata_announcement
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Albin-Clark
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: puree
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest-reporters
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- a.albin-clark@lancaster.ac.uk
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CHANGELOG.md
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/research_metadata_announcement.rb
|
54
|
+
- lib/research_metadata_announcement/transformer/base.rb
|
55
|
+
- lib/research_metadata_announcement/transformer/dataset.rb
|
56
|
+
- lib/research_metadata_announcement/transformer/transformer.rb
|
57
|
+
- lib/research_metadata_announcement/version.rb
|
58
|
+
- research_metadata_announcement.gemspec
|
59
|
+
homepage: https://github.com/lulibrary/research_metadata_announcement
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '2.1'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Metadata extraction from the Pure Research Information System and transformation
|
83
|
+
of the metadata into an announcement.
|
84
|
+
test_files: []
|