research_metadata_announcement 0.4.2 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -11
- data/README.md +17 -25
- data/lib/research_metadata_announcement.rb +1 -1
- data/lib/research_metadata_announcement/transformer/base.rb +17 -49
- data/lib/research_metadata_announcement/transformer/dataset.rb +1 -11
- data/lib/research_metadata_announcement/transformer/research_output.rb +20 -0
- data/lib/research_metadata_announcement/version.rb +1 -1
- data/research_metadata_announcement.gemspec +1 -1
- metadata +5 -5
- data/lib/research_metadata_announcement/transformer/publication.rb +0 -30
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4e9c9fd7ba55dbdb831bf9fc25fc4c6df3785ba
|
|
4
|
+
data.tar.gz: 280d4111796b2ea9ad96b72076891027608bbac2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0599597e515308ad7183fddb3d59791fd596c25c5d02bb9dc1c2ec0487241618f957f72765bab6cf4dd293919b4eb77f40ae22913c844e763ee461f4f46cac00
|
|
7
|
+
data.tar.gz: 4ff2e913fb3b5621226d36b5c429be46fde5e3491df8dc275df97a8fe90ef09b71b5b02bbe0c9a6422898de5a0f45ba9fb584aa1f636479659fe83c6a07ef196
|
data/CHANGELOG.md
CHANGED
|
@@ -2,20 +2,12 @@
|
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
|
5
|
-
## 0.
|
|
5
|
+
## 0.5.0 - 2018-01-11
|
|
6
6
|
### Changed
|
|
7
|
-
|
|
7
|
+
- For Pure API 59.
|
|
8
8
|
|
|
9
|
-
## 0.4.1 - 2018-01-17
|
|
10
9
|
### Added
|
|
11
|
-
- Testing
|
|
12
|
-
|
|
13
|
-
### Fixed
|
|
14
|
-
- Ellipsis after truncated title.
|
|
15
|
-
|
|
16
|
-
### Changed
|
|
17
|
-
- Handle missing resolver in DOI.
|
|
18
|
-
- Handle full stop in title.
|
|
10
|
+
- Testing against known live data.
|
|
19
11
|
|
|
20
12
|
## 0.4.0 - 2017-10-10
|
|
21
13
|
### Changed
|
data/README.md
CHANGED
|
@@ -5,8 +5,7 @@ Metadata extraction from the Pure Research Information System and transformation
|
|
|
5
5
|
## Status
|
|
6
6
|
|
|
7
7
|
[](https://badge.fury.io/rb/research_metadata_announcement)
|
|
8
|
-
[](https://codeclimate.com/github/lulibrary/research_metadata_announcement)
|
|
8
|
+
[](https://codeclimate.com/github/lulibrary/research_metadata_announcement/maintainability)
|
|
10
9
|
|
|
11
10
|
## Installation
|
|
12
11
|
|
|
@@ -29,18 +28,11 @@ Or install it yourself as:
|
|
|
29
28
|
Create a hash for passing to a transformer.
|
|
30
29
|
|
|
31
30
|
```ruby
|
|
32
|
-
# Pure host with authentication.
|
|
33
31
|
config = {
|
|
34
|
-
url:
|
|
35
|
-
username:
|
|
36
|
-
password:
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
```ruby
|
|
41
|
-
# Pure host without authentication.
|
|
42
|
-
config = {
|
|
43
|
-
url: ENV['PURE_URL']
|
|
32
|
+
url: 'https://YOUR_HOST/ws/api/59',
|
|
33
|
+
username: 'YOUR_USERNAME',
|
|
34
|
+
password: 'YOUR_PASSWORD',
|
|
35
|
+
api_key: 'YOUR_API_KEY'
|
|
44
36
|
}
|
|
45
37
|
```
|
|
46
38
|
|
|
@@ -55,7 +47,7 @@ transformer = ResearchMetadataAnnouncement::Transformer::Dataset.new config
|
|
|
55
47
|
Give it a Pure identifier and get an announcement.
|
|
56
48
|
|
|
57
49
|
```ruby
|
|
58
|
-
transformer.transform
|
|
50
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
|
59
51
|
```
|
|
60
52
|
|
|
61
53
|
Optionally, use the ```:composition``` keyword argument to pass in an array of
|
|
@@ -88,34 +80,34 @@ Each example uses a different resource for illustrative purposes.
|
|
|
88
80
|
|
|
89
81
|
```ruby
|
|
90
82
|
|
|
91
|
-
transformer.transform
|
|
83
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
|
92
84
|
#=> "New journal article. Can poly-parameter linear-free energy relationships (pp-LFERs) improve modelling bioaccumulation in fish? #partitioncoefficients #pplfer. dx.doi.org/10.1016/j.chemosphere.2017.10.007."
|
|
93
85
|
|
|
94
|
-
transformer.transform
|
|
95
|
-
#=> "New journal article. The Parting of Burroughs and
|
|
86
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', max_length: 140
|
|
87
|
+
#=> "New journal article. The Parting of Burroughs and... #americancounterculture #arthurrimbaud. dx.doi.org/10.1179/1477570013Z.00000000045."
|
|
96
88
|
|
|
97
|
-
transformer.transform
|
|
89
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:new, :title, :hashtags] # research output has no descriptors
|
|
98
90
|
#=> "New conference paper. Deductive and inductive data collection for agent-based modelling."
|
|
99
91
|
|
|
100
|
-
transformer.transform
|
|
92
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:new, :title, :keywords, :uri]
|
|
101
93
|
#=> "New journal article. Torsion pairs in a triangulated category generated by a spherical object. Auslander–Reiten theory, Calabi–Yau triangulated category. dx.doi.org/10.1016/j.jalgebra.2015.09.011."
|
|
102
94
|
|
|
103
|
-
transformer.transform
|
|
95
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:new, :title, :uri]
|
|
104
96
|
#=> "New dataset. Operating Nanobeams in a Quantum Fluid. dx.doi.org/10.17635/lancaster/researchdata/139."
|
|
105
97
|
|
|
106
|
-
transformer.transform
|
|
98
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:uri, :title]
|
|
107
99
|
#=> "dx.doi.org/10.17635/lancaster/researchdata/29. Herpes simplex virus 1 (HSV-1) evolution."
|
|
108
100
|
|
|
109
|
-
transformer.transform
|
|
101
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:keywords, :uri]
|
|
110
102
|
#=> "smart cities, sustainability. dx.doi.org/10.17635/lancaster/researchdata/35."
|
|
111
103
|
|
|
112
|
-
transformer.transform
|
|
104
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:hashtags, :uri]
|
|
113
105
|
#=> "#treatedhypertension #microvascularbloodflow. dx.doi.org/10.17635/lancaster/researchdata/148."
|
|
114
106
|
|
|
115
|
-
transformer.transform
|
|
107
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:uri, :keywords]
|
|
116
108
|
#=> "dx.doi.org/10.17635/lancaster/researchdata/134. metagenomics, deep sequencing."
|
|
117
109
|
|
|
118
|
-
transformer.transform
|
|
110
|
+
transformer.transform id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', composition: [:uri, :hashtags], max_descriptors: 4
|
|
119
111
|
#=> "dx.doi.org/10.17635/lancaster/researchdata/111. #influenza #nasopharynx #virology #virus."
|
|
120
112
|
|
|
121
113
|
```
|
|
@@ -2,7 +2,7 @@ require 'puree'
|
|
|
2
2
|
|
|
3
3
|
require 'research_metadata_announcement/transformer/base'
|
|
4
4
|
require 'research_metadata_announcement/transformer/dataset'
|
|
5
|
-
require 'research_metadata_announcement/transformer/
|
|
5
|
+
require 'research_metadata_announcement/transformer/research_output'
|
|
6
6
|
require 'research_metadata_announcement/version'
|
|
7
7
|
|
|
8
8
|
# Metadata extraction from the Pure Research Information System and
|
|
@@ -6,29 +6,30 @@ module ResearchMetadataAnnouncement
|
|
|
6
6
|
class Base
|
|
7
7
|
|
|
8
8
|
# @param config [Hash]
|
|
9
|
-
# @option config [String] :url
|
|
10
|
-
# @option config [String] :username
|
|
11
|
-
# @option config [String] :password
|
|
12
|
-
|
|
9
|
+
# @option config [String] :url URL of the Pure host
|
|
10
|
+
# @option config [String] :username Username of the Pure host account
|
|
11
|
+
# @option config [String] :password Password of the Pure host account
|
|
12
|
+
# @option config [String] :api_key API key of the Pure host account
|
|
13
13
|
def initialize(config)
|
|
14
14
|
@config = config
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
# @param id [String] Pure
|
|
18
|
-
# @param uuid [String] Pure UUID.
|
|
17
|
+
# @param id [String] Pure identifier.
|
|
19
18
|
# @param composition [Array<Symbol>] Metadata presentation sequence e.g. [:new, :title, :hashtags, :uri].
|
|
20
19
|
# @param max_length [Fixnum] Maximum length of announcement.
|
|
21
20
|
# @param max_descriptors [Fixnum] Maximum number of descriptors (common name for keywords, tags, hashtags).
|
|
22
21
|
# @return [String, nil] Announcement returned if the metadata is available and the announcement length does not exceed the max_length argument.
|
|
23
|
-
def transform(
|
|
22
|
+
def transform(id:, composition: [:new, :title, :hashtags, :uri],
|
|
24
23
|
max_length: nil, max_descriptors: 2)
|
|
25
24
|
composition.uniq!
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
@resource = @resource_extractor.find id
|
|
27
|
+
|
|
27
28
|
return nil unless @resource
|
|
28
29
|
if composition.include? :uri
|
|
29
30
|
return nil unless prepare_uri
|
|
30
31
|
end
|
|
31
|
-
title =
|
|
32
|
+
title = @resource.title
|
|
32
33
|
keywords = @resource.keywords
|
|
33
34
|
|
|
34
35
|
# sizing
|
|
@@ -38,7 +39,7 @@ module ResearchMetadataAnnouncement
|
|
|
38
39
|
composition.each do |component|
|
|
39
40
|
case component
|
|
40
41
|
when :new
|
|
41
|
-
phrase =
|
|
42
|
+
phrase = new_phrase(@resource)
|
|
42
43
|
chars_needed += phrase.size + chars_component_end
|
|
43
44
|
when :title
|
|
44
45
|
chars_needed += title.size + chars_component_end
|
|
@@ -48,16 +49,10 @@ module ResearchMetadataAnnouncement
|
|
|
48
49
|
chars_needed += build_hashtags(keywords, max_descriptors).size + chars_component_end if !keywords.empty?
|
|
49
50
|
when :uri
|
|
50
51
|
uri = prepare_uri
|
|
51
|
-
chars_needed += uri.size
|
|
52
|
+
chars_needed += uri.size if uri
|
|
52
53
|
end
|
|
53
54
|
end
|
|
54
55
|
|
|
55
|
-
# since the arrangement of the composition is unknown, after sizing
|
|
56
|
-
# chars_needed has two extra spaces allocated
|
|
57
|
-
# one is used for the terminating full stop
|
|
58
|
-
# one is not needed
|
|
59
|
-
chars_needed -= 1
|
|
60
|
-
|
|
61
56
|
# determine if title needs truncating/removing before combining
|
|
62
57
|
if chars_needed > max_length
|
|
63
58
|
# truncate title
|
|
@@ -65,7 +60,7 @@ module ResearchMetadataAnnouncement
|
|
|
65
60
|
excess_chars = chars_needed - max_length
|
|
66
61
|
truncated_title_length = title.size - excess_chars
|
|
67
62
|
truncated_title_length = 0 if truncated_title_length < 0
|
|
68
|
-
title = title[0..truncated_title_length -
|
|
63
|
+
title = title[0..truncated_title_length - 2].strip + '..'
|
|
69
64
|
composition -= [:title] if title.size <= 5 # give up on title if just too small
|
|
70
65
|
end
|
|
71
66
|
end
|
|
@@ -104,25 +99,6 @@ module ResearchMetadataAnnouncement
|
|
|
104
99
|
|
|
105
100
|
private
|
|
106
101
|
|
|
107
|
-
def handle_resolver(uri)
|
|
108
|
-
return unless uri
|
|
109
|
-
resolver = 'doi.org'
|
|
110
|
-
if uri.include? resolver
|
|
111
|
-
uri
|
|
112
|
-
else
|
|
113
|
-
File.join resolver, uri
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def remove_full_stop(str)
|
|
118
|
-
arr = str.split('')
|
|
119
|
-
if arr.pop == '.' && arr.pop != '.'
|
|
120
|
-
return str.chomp('.')
|
|
121
|
-
else
|
|
122
|
-
return str
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
102
|
def new_phrase(resource)
|
|
127
103
|
part_1 = 'New'
|
|
128
104
|
part_2 = ''
|
|
@@ -130,7 +106,7 @@ module ResearchMetadataAnnouncement
|
|
|
130
106
|
case resource.class.to_s
|
|
131
107
|
when 'Puree::Model::Dataset'
|
|
132
108
|
part_2 = 'dataset'
|
|
133
|
-
when 'Puree::Model::
|
|
109
|
+
when 'Puree::Model::ResearchOutput'
|
|
134
110
|
part_2 = resource.type.downcase
|
|
135
111
|
end
|
|
136
112
|
if part_2.empty?
|
|
@@ -140,16 +116,8 @@ module ResearchMetadataAnnouncement
|
|
|
140
116
|
end
|
|
141
117
|
end
|
|
142
118
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
# @param id [String]
|
|
146
|
-
# @param uuid [String]
|
|
147
|
-
def extract(uuid: nil, id: nil)
|
|
148
|
-
if !uuid.nil?
|
|
149
|
-
@resource = @resource_extractor.find uuid: uuid
|
|
150
|
-
else
|
|
151
|
-
@resource = @resource_extractor.find id: id
|
|
152
|
-
end
|
|
119
|
+
def prepare_uri
|
|
120
|
+
strip_uri_scheme @resource.doi if @resource && @resource.doi
|
|
153
121
|
end
|
|
154
122
|
|
|
155
123
|
def strip_uri_scheme(uri)
|
|
@@ -181,7 +149,7 @@ module ResearchMetadataAnnouncement
|
|
|
181
149
|
end
|
|
182
150
|
|
|
183
151
|
def make_extractor(resource_type)
|
|
184
|
-
resource_class = "Puree::Extractor::#{resource_type
|
|
152
|
+
resource_class = "Puree::Extractor::#{Puree::Util::String.titleize(resource_type)}"
|
|
185
153
|
@resource_extractor = Object.const_get(resource_class).new @config
|
|
186
154
|
end
|
|
187
155
|
|
|
@@ -7,22 +7,12 @@ module ResearchMetadataAnnouncement
|
|
|
7
7
|
#
|
|
8
8
|
class Dataset < ResearchMetadataAnnouncement::Transformer::Base
|
|
9
9
|
|
|
10
|
-
# @
|
|
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.
|
|
10
|
+
# @option (see ResearchMetadataAnnouncement::Transformer::Base::Resource#initialize)
|
|
14
11
|
def initialize(config)
|
|
15
12
|
super
|
|
16
13
|
make_extractor :dataset
|
|
17
14
|
end
|
|
18
15
|
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def prepare_uri
|
|
22
|
-
uri = strip_uri_scheme @resource.doi if @resource && @resource.doi
|
|
23
|
-
handle_resolver uri
|
|
24
|
-
end
|
|
25
|
-
|
|
26
16
|
end
|
|
27
17
|
|
|
28
18
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module ResearchMetadataAnnouncement
|
|
2
|
+
|
|
3
|
+
module Transformer
|
|
4
|
+
|
|
5
|
+
# Extracts research output metadata from the Pure Research Information System and
|
|
6
|
+
# converts it into an announcement
|
|
7
|
+
#
|
|
8
|
+
class ResearchOutput < ResearchMetadataAnnouncement::Transformer::Base
|
|
9
|
+
|
|
10
|
+
# @option (see ResearchMetadataAnnouncement::Transformer::Base::Resource#initialize)
|
|
11
|
+
def initialize(config)
|
|
12
|
+
super
|
|
13
|
+
make_extractor :research_output
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: research_metadata_announcement
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adrian Albin-Clark
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-01-
|
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: puree
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '2.0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '2.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: minitest-reporters
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,7 +53,7 @@ files:
|
|
|
53
53
|
- lib/research_metadata_announcement.rb
|
|
54
54
|
- lib/research_metadata_announcement/transformer/base.rb
|
|
55
55
|
- lib/research_metadata_announcement/transformer/dataset.rb
|
|
56
|
-
- lib/research_metadata_announcement/transformer/
|
|
56
|
+
- lib/research_metadata_announcement/transformer/research_output.rb
|
|
57
57
|
- lib/research_metadata_announcement/transformer/transformer.rb
|
|
58
58
|
- lib/research_metadata_announcement/version.rb
|
|
59
59
|
- research_metadata_announcement.gemspec
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module ResearchMetadataAnnouncement
|
|
2
|
-
|
|
3
|
-
module Transformer
|
|
4
|
-
|
|
5
|
-
# Extracts publication metadata from the Pure Research Information System and
|
|
6
|
-
# converts it into an announcement
|
|
7
|
-
#
|
|
8
|
-
class Publication < 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
|
-
make_extractor :publication
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def prepare_uri
|
|
22
|
-
uri = strip_uri_scheme @resource.dois[0] if @resource && @resource.dois[0]
|
|
23
|
-
handle_resolver uri
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
end
|