qa 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +15 -0
- data/README.md +174 -0
- data/Rakefile +10 -0
- data/app/assets/javascripts/qa/application.js +13 -0
- data/app/assets/stylesheets/qa/application.css +13 -0
- data/app/controllers/qa/application_controller.rb +4 -0
- data/app/controllers/qa/terms_controller.rb +76 -0
- data/app/helpers/qa/application_helper.rb +2 -0
- data/app/models/qa/mesh_tree.rb +37 -0
- data/app/models/qa/subject_mesh_term.rb +45 -0
- data/app/views/layouts/qa/application.html.erb +14 -0
- data/config/authorities.yml +1 -0
- data/config/authorities/states.yml +101 -0
- data/config/initializers/authorities.rb +1 -0
- data/config/oclcts-authorities.yml +24 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20130917200611_create_qa_subject_mesh_terms.rb +11 -0
- data/db/migrate/20130917201026_create_qa_mesh_tree.rb +10 -0
- data/db/migrate/20130918141523_add_term_lower_to_qa_subject_mesh_terms.rb +7 -0
- data/lib/qa.rb +9 -0
- data/lib/qa/authorities.rb +12 -0
- data/lib/qa/authorities/base.rb +50 -0
- data/lib/qa/authorities/lcsh.rb +46 -0
- data/lib/qa/authorities/loc.rb +200 -0
- data/lib/qa/authorities/local.rb +69 -0
- data/lib/qa/authorities/mesh.rb +20 -0
- data/lib/qa/authorities/mesh_tools.rb +6 -0
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +65 -0
- data/lib/qa/authorities/mesh_tools/mesh_importer.rb +41 -0
- data/lib/qa/authorities/oclcts.rb +63 -0
- data/lib/qa/authorities/tgnlang.rb +40 -0
- data/lib/qa/data/TGN_LANGUAGES.xml +7435 -0
- data/lib/qa/engine.rb +5 -0
- data/lib/qa/version.rb +3 -0
- data/lib/tasks/qa_tasks.rake +4 -0
- data/spec/controllers/terms_controller_spec.rb +70 -0
- data/spec/fixtures/authorities/authority_A.yml +10 -0
- data/spec/fixtures/authorities/authority_B.yml +7 -0
- data/spec/fixtures/authorities/authority_C.yml +4 -0
- data/spec/fixtures/lcsh-response.txt +1 -0
- data/spec/fixtures/loc-response.txt +147 -0
- data/spec/fixtures/mesh.txt +334 -0
- data/spec/fixtures/oclcts-response-mesh-1.txt +28 -0
- data/spec/fixtures/oclcts-response-mesh-2.txt +253 -0
- data/spec/fixtures/oclcts-response-mesh-3.txt +28 -0
- data/spec/internal/Gemfile +48 -0
- data/spec/internal/Gemfile.lock +156 -0
- data/spec/internal/README.rdoc +28 -0
- data/spec/internal/Rakefile +6 -0
- data/spec/internal/app/assets/javascripts/application.js +16 -0
- data/spec/internal/app/assets/stylesheets/application.css +13 -0
- data/spec/internal/app/controllers/application_controller.rb +5 -0
- data/spec/internal/app/helpers/application_helper.rb +2 -0
- data/spec/internal/app/views/layouts/application.html.erb +14 -0
- data/spec/internal/bin/bundle +3 -0
- data/spec/internal/bin/rails +4 -0
- data/spec/internal/bin/rake +4 -0
- data/spec/internal/config.ru +4 -0
- data/spec/internal/config/application.rb +23 -0
- data/spec/internal/config/boot.rb +4 -0
- data/spec/internal/config/database.yml +25 -0
- data/spec/internal/config/environment.rb +5 -0
- data/spec/internal/config/environments/development.rb +29 -0
- data/spec/internal/config/environments/production.rb +80 -0
- data/spec/internal/config/environments/test.rb +36 -0
- data/spec/internal/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/internal/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/internal/config/initializers/inflections.rb +16 -0
- data/spec/internal/config/initializers/mime_types.rb +5 -0
- data/spec/internal/config/initializers/secret_token.rb +12 -0
- data/spec/internal/config/initializers/session_store.rb +3 -0
- data/spec/internal/config/initializers/wrap_parameters.rb +14 -0
- data/spec/internal/config/locales/en.yml +23 -0
- data/spec/internal/config/oclcts-authorities.yml +24 -0
- data/spec/internal/config/routes.rb +60 -0
- data/spec/internal/db/development.sqlite3 +0 -0
- data/spec/internal/db/migrate/20130930151844_create_qa_subject_mesh_terms.qa.rb +12 -0
- data/spec/internal/db/migrate/20130930151845_create_qa_mesh_tree.qa.rb +11 -0
- data/spec/internal/db/migrate/20130930151846_add_term_lower_to_qa_subject_mesh_terms.qa.rb +8 -0
- data/spec/internal/db/schema.rb +34 -0
- data/spec/internal/db/seeds.rb +7 -0
- data/spec/internal/db/test.sqlite3 +0 -0
- data/spec/internal/lib/generators/test_app_generator.rb +20 -0
- data/spec/internal/log/development.log +193 -0
- data/spec/internal/public/404.html +58 -0
- data/spec/internal/public/422.html +58 -0
- data/spec/internal/public/500.html +57 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/internal/public/robots.txt +5 -0
- data/spec/internal/test/test_helper.rb +15 -0
- data/spec/lib/authorities_lcsh_spec.rb +61 -0
- data/spec/lib/authorities_loc_spec.rb +35 -0
- data/spec/lib/authorities_local_spec.rb +89 -0
- data/spec/lib/authorities_mesh_spec.rb +38 -0
- data/spec/lib/authorities_oclcts_spec.rb +49 -0
- data/spec/lib/authorities_tgnlang_spec.rb +22 -0
- data/spec/lib/mesh_data_parser_spec.rb +125 -0
- data/spec/models/subject_mesh_term_spec.rb +49 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/lib/generators/test_app_generator.rb +20 -0
- metadata +396 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
ActiveRecord::Migration.check_pending!
|
7
|
+
|
8
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
9
|
+
#
|
10
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
11
|
+
# -- they do not yet inherit this setting
|
12
|
+
fixtures :all
|
13
|
+
|
14
|
+
# Add more helper methods to be used by all tests here...
|
15
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Lcsh do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
stub_request(:get, "http://id.loc.gov/authorities/suggest/?q=ABBA").
|
7
|
+
to_return(:body => webmock_fixture("lcsh-response.txt"), :status => 200)
|
8
|
+
@terms = Qa::Authorities::Lcsh.new "ABBA"
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "response from LOC" do
|
12
|
+
it "should have the query term for its first element" do
|
13
|
+
@terms.raw_response[0].should be_kind_of String
|
14
|
+
@terms.raw_response[0].should == "ABBA"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have an array of results that match the query" do
|
18
|
+
@terms.raw_response[1].should be_kind_of Array
|
19
|
+
@terms.raw_response[1].should include "ABBA (Musical group)"
|
20
|
+
@terms.raw_response[1].length.should == 10
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have an array of strings that appear to have no use" do
|
24
|
+
@terms.raw_response[2].should be_kind_of Array
|
25
|
+
@terms.raw_response[2].collect { |v| v.should == "1 result" }
|
26
|
+
@terms.raw_response[2].length.should == 10
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have an array of the urls for each term" do
|
30
|
+
@terms.raw_response[3].should be_kind_of Array
|
31
|
+
@terms.raw_response[3].should include "http://id.loc.gov/authorities/names/n98029154"
|
32
|
+
@terms.raw_response[3].length.should == 10
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "presenting the results from LOC" do
|
37
|
+
it "should give us the query term" do
|
38
|
+
@terms.query.should == "ABBA"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should give us an array of suggestions" do
|
42
|
+
@terms.suggestions.should be_kind_of Array
|
43
|
+
@terms.suggestions.should include "ABBA (Musical group)"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should give us an array of urls for each suggestion" do
|
47
|
+
@terms.urls_for_suggestions.should be_kind_of Array
|
48
|
+
@terms.urls_for_suggestions.should include "http://id.loc.gov/authorities/names/n98029154"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#parse_authority_response" do
|
53
|
+
it "should set .response to be an array of hashes in the id/label structure" do
|
54
|
+
sample = { "id"=>"n92117993", "label"=>"Abba (Nigeria)" }
|
55
|
+
@terms.parse_authority_response
|
56
|
+
@terms.response.should be_kind_of Array
|
57
|
+
@terms.response.should include sample
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Loc do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
stub_request(:get, "http://id.loc.gov/search/?format=json&q=haw*&q=cs:http://id.loc.gov/vocabulary/geographicAreas").
|
7
|
+
with(:headers => {'Accept'=>'application/json'}).
|
8
|
+
to_return(:body => webmock_fixture("loc-response.txt"), :status => 200)
|
9
|
+
@authority = Qa::Authorities::Loc.new("haw*", "geographicAreas")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should instantiate with a query and return data" do
|
13
|
+
expect(@authority).not_to be_nil
|
14
|
+
@authority.raw_response.to_s.should include("id")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a sub_authority url" do
|
18
|
+
@authority.should_not be_nil
|
19
|
+
url = @authority.sub_authorityURL("geographicAreas")
|
20
|
+
expect(url).not_to be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not return a url for an invalid sub_authority" do
|
24
|
+
@authority.should_not be_nil
|
25
|
+
url = @authority.sub_authorityURL("invalid sub_authority")
|
26
|
+
expect(url).to eq("")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return JSON" do
|
30
|
+
@authority.should_not be_nil
|
31
|
+
json = @authority.parse_authority_response
|
32
|
+
expect(json).not_to be_empty
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Local do
|
4
|
+
|
5
|
+
before do
|
6
|
+
AUTHORITIES_CONFIG[:local_path] = local_authorities_path
|
7
|
+
end
|
8
|
+
|
9
|
+
context "valid local sub_authorities" do
|
10
|
+
it "should validate the sub_authority" do
|
11
|
+
Qa::Authorities::Local.sub_authorities.should include "authority_A"
|
12
|
+
Qa::Authorities::Local.sub_authorities.should include "authority_B"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "retrieve all entries for a local sub_authority" do
|
17
|
+
let(:expected) { [ { :id => "A1", :label => "Abc Term A1" }, { :id => "A2", :label => "Term A2" }, { :id => "A3", :label => "Abc Term A3" } ] }
|
18
|
+
it "should return all the entries" do
|
19
|
+
authorities = Qa::Authorities::Local.new("", "authority_A")
|
20
|
+
expect(authorities.parse_authority_response).to eq(expected)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "retrieve a subset of entries for a local sub_authority" do
|
25
|
+
|
26
|
+
context "at least one matching entry" do
|
27
|
+
let(:expected) { [ { :id => "A1", :label => "Abc Term A1" }, { :id => "A3", :label => "Abc Term A3" } ] }
|
28
|
+
it "should return only entries matching the query term" do
|
29
|
+
authorities = Qa::Authorities::Local.new("Abc", "authority_A")
|
30
|
+
expect(authorities.parse_authority_response).to eq(expected)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "no matching entries" do
|
35
|
+
let(:expected) { [] }
|
36
|
+
it "should return an empty array" do
|
37
|
+
authorities = Qa::Authorities::Local.new("def", "authority_A")
|
38
|
+
expect(authorities.parse_authority_response).to eq(expected)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "search not case-sensitive" do
|
43
|
+
let(:expected) { [ { :id => "A1", :label => "Abc Term A1" }, { :id => "A3", :label => "Abc Term A3" } ] }
|
44
|
+
it "should return entries matching the query term without regard to case" do
|
45
|
+
authorities = Qa::Authorities::Local.new("aBc", "authority_A")
|
46
|
+
expect(authorities.parse_authority_response).to eq(expected)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
context "retrieve full record for term" do
|
53
|
+
|
54
|
+
let(:authorities) { Qa::Authorities::Local.new("", "authority_A") }
|
55
|
+
|
56
|
+
context "term exists" do
|
57
|
+
let(:id) { "A2" }
|
58
|
+
let(:expected) { { :id => "A2", :term => "Term A2", :active => false }.to_json }
|
59
|
+
it "should return the full term record" do
|
60
|
+
expect(authorities.get_full_record(id)).to eq(expected)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "term does not exist" do
|
65
|
+
let(:id) { "NonID" }
|
66
|
+
let(:expected) { {}.to_json }
|
67
|
+
it "should return an empty hash" do
|
68
|
+
expect(authorities.get_full_record(id)).to eq(expected)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "term does not an id" do
|
74
|
+
let(:authorities) { Qa::Authorities::Local.new("", "authority_B") }
|
75
|
+
let(:expected) { [ { :id => "Term B1", :label => "Term B1" }, { :id => "Term B2", :label => "Term B2" }, { :id => "Term B3", :label => "Term B3" } ] }
|
76
|
+
it "should set the id to be same as the label" do
|
77
|
+
expect(authorities.parse_authority_response).to eq(expected)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "authority YAML is a list of terms" do
|
82
|
+
let(:authorities) { Qa::Authorities::Local.new("", "authority_C") }
|
83
|
+
let(:expected) { [ { :id => "Term C1", :label => "Term C1" }, { :id => "Term C2", :label => "Term C2" }, { :id => "Term C3", :label => "Term C3" } ] }
|
84
|
+
it "should use the terms as labels" do
|
85
|
+
expect(authorities.parse_authority_response).to eq(expected)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Mesh do
|
4
|
+
def where_unique_record(klass, q)
|
5
|
+
klass.where(q).length.should == 1
|
6
|
+
end
|
7
|
+
|
8
|
+
it "imports a mesh dump file" do
|
9
|
+
m = Qa::Authorities::MeshTools::MeshImporter.new
|
10
|
+
File.open(webmock_fixture('mesh.txt').path) do |f|
|
11
|
+
m.import_from_file(f)
|
12
|
+
end
|
13
|
+
where_unique_record(Qa::SubjectMeshTerm, {term_lower: "malaria"})
|
14
|
+
where_unique_record(Qa::SubjectMeshTerm, {term: "Malaria"})
|
15
|
+
where_unique_record(Qa::SubjectMeshTerm, {term_id: "D008288"})
|
16
|
+
Qa::SubjectMeshTerm.all.length.should == 11
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#results" do
|
20
|
+
before(:all) do
|
21
|
+
Qa::SubjectMeshTerm.create(term_id: '1', term: 'Mr Plow', term_lower: 'mr plow')
|
22
|
+
Qa::SubjectMeshTerm.create(term_id: '2', term: 'Mr Snow', term_lower: 'mr snow')
|
23
|
+
Qa::SubjectMeshTerm.create(term_id: '3', term: 'Mrs Fields', term_lower: 'mrs fields')
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:all) do
|
27
|
+
Qa::SubjectMeshTerm.delete_all
|
28
|
+
end
|
29
|
+
|
30
|
+
it "handles queries" do
|
31
|
+
pending "Re-enable this test once Mesh#results is changed to return a hash of results instead of a single json string"
|
32
|
+
m = Authorities::Mesh.new('mr')
|
33
|
+
results = m.results
|
34
|
+
results.should include( {id: '1', label: 'Mr Plow'} )
|
35
|
+
results.length.should == 3
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Oclcts do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts.rootHeading%20exact%20%22ball*%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1").
|
7
|
+
to_return(:body => webmock_fixture("oclcts-response-mesh-1.txt"), :status => 200)
|
8
|
+
stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=oclcts.rootHeading%20exact%20%22alph*%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1").
|
9
|
+
to_return(:body => webmock_fixture("oclcts-response-mesh-2.txt"), :status => 200)
|
10
|
+
stub_request(:get, "http://tspilot.oclc.org/mesh/?maximumRecords=10&operation=searchRetrieve&query=dc.identifier%20exact%20%22D031329Q000821%22&recordPacking=xml&recordSchema=http://zthes.z3950.org/xml/1.0/&recordXPath=&resultSetTTL=300&sortKeys=&startRecord=1&version=1.1").
|
11
|
+
to_return(:body => webmock_fixture("oclcts-response-mesh-3.txt"), :status => 200)
|
12
|
+
|
13
|
+
@first_query = Qa::Authorities::Oclcts.new("ball", "mesh")
|
14
|
+
@terms = @first_query.parse_authority_response
|
15
|
+
@term_record = @first_query.get_full_record @terms.first["id"]
|
16
|
+
@second_query = Qa::Authorities::Oclcts.new("alph", "mesh")
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "a query for terms" do
|
20
|
+
|
21
|
+
it "should have an array of hashes that match the query" do
|
22
|
+
@terms.should be_kind_of Array
|
23
|
+
@terms.first.should be_kind_of Hash
|
24
|
+
@terms.first["label"].should be_kind_of String
|
25
|
+
@terms.first["label"].should include "Ballota"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have an array of hashes containing unique id and label" do
|
29
|
+
@terms.first.should have_key("id")
|
30
|
+
@terms.first.should have_key("label")
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "a query for a single item" do
|
36
|
+
it "should have a hash of values that represent the item requested" do
|
37
|
+
@term_record.should be_kind_of Hash
|
38
|
+
@term_record.values.should include @terms.first["id"]
|
39
|
+
@term_record.values.should include @terms.first["label"]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should succeed for valid ids, even if the id is not in the initial list of responses" do
|
43
|
+
record = @second_query.get_full_record @terms.first["id"]
|
44
|
+
record.values.should include @terms.first["id"]
|
45
|
+
record.values.should include @terms.first["label"]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Tgnlang do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
@terms = Qa::Authorities::Tgnlang.new("Tibetan")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "response from dataset" do
|
10
|
+
it "should return size 34 with query of Tibetan" do
|
11
|
+
@terms.results.size.should == 34
|
12
|
+
end
|
13
|
+
it "should return type string" do
|
14
|
+
@terms.results.class.name.should == "String"
|
15
|
+
end
|
16
|
+
it "should return a string it contains" do
|
17
|
+
@terms.results["Tibetan"].should == "Tibetan"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::MeshTools::MeshDataParser do
|
4
|
+
|
5
|
+
it "parses a record correctly" do
|
6
|
+
data = <<-EOS
|
7
|
+
*NEWRECORD
|
8
|
+
A = 45
|
9
|
+
B = a = b = c = d
|
10
|
+
B = more than one
|
11
|
+
EOS
|
12
|
+
mesh = Qa::Authorities::MeshTools::MeshDataParser.new(StringIO.new(data))
|
13
|
+
records = mesh.all_records
|
14
|
+
records.length.should == 1
|
15
|
+
records[0].should == {'A'=>['45'],'B'=>['a = b = c = d','more than one']}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "handles two records" do
|
19
|
+
data = <<-EOS
|
20
|
+
*NEWRECORD
|
21
|
+
A = 45
|
22
|
+
B = a = b = c = d
|
23
|
+
|
24
|
+
*NEWRECORD
|
25
|
+
A = another field
|
26
|
+
print entry = test
|
27
|
+
|
28
|
+
EOS
|
29
|
+
mesh = Qa::Authorities::MeshTools::MeshDataParser.new(StringIO.new(data))
|
30
|
+
records = mesh.all_records
|
31
|
+
records.length.should == 2
|
32
|
+
records[0].should == {'A'=>['45'],'B'=>['a = b = c = d']}
|
33
|
+
records[1].should == {'A'=>['another field'], 'print entry'=>['test']}
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'ignores bad input' do
|
37
|
+
data = <<-EOS
|
38
|
+
*NEWRECORD
|
39
|
+
A = 45
|
40
|
+
B=no space
|
41
|
+
space at beginning of line and no =
|
42
|
+
*NEWRECORD
|
43
|
+
EOS
|
44
|
+
mesh = Qa::Authorities::MeshTools::MeshDataParser.new(StringIO.new(data))
|
45
|
+
records = mesh.all_records
|
46
|
+
records.length.should == 2
|
47
|
+
records[0].should == {'A'=>['45']}
|
48
|
+
records[1].should == {}
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'parses a sample mesh file' do
|
52
|
+
mesh = Qa::Authorities::MeshTools::MeshDataParser.new(webmock_fixture('mesh.txt'))
|
53
|
+
records = mesh.all_records
|
54
|
+
records.length.should == 11
|
55
|
+
records[0].should == {
|
56
|
+
"RECTYPE" => ["D"],
|
57
|
+
"MH" => ["Malaria"],
|
58
|
+
"AQ" => ["BL CF CI CL CN CO DH DI DT EC EH EM EN EP ET GE HI IM ME MI MO NU PA PC PP PS PX RA RH RI RT SU TH TM UR US VE VI"],
|
59
|
+
"PRINT ENTRY" => ["Marsh Fever|T047|NON|EQV|NLM (2006)|050114|abcdef",
|
60
|
+
"Plasmodium Infections|T047|NON|EQV|UNK (19XX)|740330|PLASMODIUM INFECT|abcdefv",
|
61
|
+
"Remittent Fever|T047|NON|EQV|NLM (2006)|050114|abcdef"],
|
62
|
+
"ENTRY" => ["Infections, Plasmodium|T047|NON|EQV|NLM (1992)|911126|INFECT PLASMODIUM|abcdefv",
|
63
|
+
"Paludism|T047|NON|EQV|NLM (2005)|040220|abcdef",
|
64
|
+
"Fever, Marsh",
|
65
|
+
"Fever, Remittent",
|
66
|
+
"Infection, Plasmodium",
|
67
|
+
"Plasmodium Infection"],
|
68
|
+
"MN" => ["C03.752.530", "C23.996.660"],
|
69
|
+
"FX" => ["Antimalarials"],
|
70
|
+
"MH_TH" => ["NLM (1986)", "ORD (2010)"],
|
71
|
+
"ST" => ["T047"],
|
72
|
+
"AN" => ["GEN or unspecified; specify Plasmodium species IM if possible but note P. falciparum malaria = MALARIA, FALCIPARUM; P. vivax malaria = MALARIA, VIVAX; tertian malaria = MALARIA, VIVAX, quartan malaria: coord IM with PLASMODIUM MALARIAE (IM); malariotherapy = HYPERTHERMIA, INDUCED: do not confuse with MALARIA /ther; /drug ther: consider also ANTIMALARIALS"],
|
73
|
+
"MS" => ["A protozoan disease caused in humans by four species of the PLASMODIUM genus: PLASMODIUM FALCIPARUM; PLASMODIUM VIVAX; PLASMODIUM OVALE; and PLASMODIUM MALARIAE; and transmitted by the bite of an infected female mosquito of the genus ANOPHELES. Malaria is endemic in parts of Asia, Africa, Central and South America, Oceania, and certain Caribbean islands. It is characterized by extreme exhaustion associated with paroxysms of high FEVER; SWEATING; shaking CHILLS; and ANEMIA. Malaria in ANIMALS is caused by other species of plasmodia."],
|
74
|
+
"OL" => ["use MALARIA to search MALARIA CONTROL 1966"],
|
75
|
+
"PM" => ["MALARIA CONTROL was heading 1963-66"],
|
76
|
+
"HN" => ["MALARIA CONTROL was heading 1963-66"],
|
77
|
+
"MED" => ["*1141", "1541"],
|
78
|
+
"M90" => ["*2010", "2428"],
|
79
|
+
"M85" => ["*2929", "3509"],
|
80
|
+
"M80" => ["*2008", "2567"],
|
81
|
+
"M75" => ["*1414", "1928"],
|
82
|
+
"M66" => ["*2561", "3568"],
|
83
|
+
"M94" => ["*1272", "1646"],
|
84
|
+
"CATSH" => ["CAT LIST"],
|
85
|
+
"MR" => ["20120703"],
|
86
|
+
"DA" => ["19990101"],
|
87
|
+
"DC" => ["1"],
|
88
|
+
"UI" => ["D008288"]
|
89
|
+
}
|
90
|
+
records[1].should == {
|
91
|
+
"RECTYPE" => ["D"],
|
92
|
+
"MH" => ["Calcimycin"],
|
93
|
+
"AQ" => ["AA AD AE AG AI AN BI BL CF CH CL CS CT DU EC HI IM IP ME PD PK PO RE SD ST TO TU UR"],
|
94
|
+
"ENTRY" => ["A-23187|T109|T195|LAB|NRW|NLM (1991)|900308|abbcdef",
|
95
|
+
"A23187|T109|T195|LAB|NRW|UNK (19XX)|741111|abbcdef",
|
96
|
+
"Antibiotic A23187|T109|T195|NON|NRW|NLM (1991)|900308|abbcdef",
|
97
|
+
"A 23187",
|
98
|
+
"A23187, Antibiotic"],
|
99
|
+
"MN" => ["D03.438.221.173"],
|
100
|
+
"PA" => ["Anti-Bacterial Agents", "Calcium Ionophores"],
|
101
|
+
"MH_TH" => ["NLM (1975)"],
|
102
|
+
"ST" => ["T109", "T195"],
|
103
|
+
"N1" => ["4-Benzoxazolecarboxylic acid, 5-(methylamino)-2-((3,9,11-trimethyl-8-(1-methyl-2-oxo-2-(1H-pyrrol-2-yl)ethyl)-1,7-dioxaspiro(5.5)undec-2-yl)methyl)-, (6S-(6alpha(2S*,3S*),8beta(R*),9beta,11alpha))-"],
|
104
|
+
"RN" => ["52665-69-7"],
|
105
|
+
"PI" => ["Antibiotics (1973-1974)", "Carboxylic Acids (1973-1974)"],
|
106
|
+
"MS" => ["An ionophorous, polyether antibiotic from Streptomyces chartreusensis. It binds and transports CALCIUM and other divalent cations across membranes and uncouples oxidative phosphorylation while inhibiting ATPase of rat liver mitochondria. The substance is used mostly as a biochemical tool to study the role of divalent cations in various biological systems."],
|
107
|
+
"OL" => ["use CALCIMYCIN to search A 23187 1975-90"],
|
108
|
+
"PM" => ["91; was A 23187 1975-90 (see under ANTIBIOTICS 1975-83)"],
|
109
|
+
"HN" => ["91(75); was A 23187 1975-90 (see under ANTIBIOTICS 1975-83)"],
|
110
|
+
"MED" => ["*62", "847"],
|
111
|
+
"M90" => ["*299", "2405"],
|
112
|
+
"M85" => ["*454", "2878"],
|
113
|
+
"M80" => ["*316", "1601"],
|
114
|
+
"M75" => ["*300", "823"],
|
115
|
+
"M66" => ["*1", "3"],
|
116
|
+
"M94" => ["*153", "1606"],
|
117
|
+
"MR" => ["20110624"],
|
118
|
+
"DA" => ["19741119"],
|
119
|
+
"DC" => ["1"],
|
120
|
+
"DX" => ["19840101"],
|
121
|
+
"UI" => ["D000001"]
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|