philologic-client 0.0.13 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +4 -0
- data/PhiloLogicResponseDocumentation.txt +30 -8
- data/README.rdoc +12 -4
- data/Rakefile +7 -7
- data/lib/philologic-client.rb +33 -10
- data/lib/philologic-client/collocation.rb +48 -23
- data/lib/philologic-client/document.rb +1 -1
- data/lib/philologic-client/occurrence.rb +7 -6
- data/lib/philologic-client/version.rb +1 -1
- data/test/data/bibliography.html +351 -89
- data/test/data/collocation.html +717 -2359
- data/test/data/concordance.html +355 -196
- data/test/data/frequency.html +197 -37
- data/test/data/navigation.html +196 -37
- data/test/data/object.html +173 -12
- data/test/helper.rb +9 -0
- data/test/test_bibliography.rb +6 -10
- data/test/test_client.rb +125 -499
- data/test/test_collocation.rb +22 -23
- data/test/test_concordance.rb +4 -10
- data/test/test_document.rb +7 -11
- data/test/test_frequency.rb +10 -14
- data/test/test_occurrence.rb +13 -9
- data/test/test_response.rb +1 -5
- metadata +48 -21
data/test/data/object.html
CHANGED
@@ -1,20 +1,181 @@
|
|
1
|
+
<html>
|
1
2
|
<head>
|
2
|
-
<title>
|
3
|
+
<title>shakespeare_bamboo</title>
|
3
4
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
|
6
|
+
<link rel="stylesheet" href="http://lafayette.uchicago.edu/philo4/shakespeare_bamboo/css/style.css" type="text/css" media="screen, projection">
|
7
|
+
<link type="text/css" href="http://lafayette.uchicago.edu/philo4/shakespeare_bamboo/css/ui-lightness/jquery-ui-1.8.17.custom.css" rel="stylesheet" />
|
8
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript"></script>
|
9
|
+
<script type="text/javascript" src="http://lafayette.uchicago.edu/philo4/shakespeare_bamboo/js/jquery-ui-1.8.17.custom.min.js"></script>
|
10
|
+
<script type="text/javascript">
|
11
|
+
function monkeyPatchAutocomplete() {
|
12
|
+
//taken from http://stackoverflow.com/questions/2435964/jqueryui-how-can-i-custom-format-the-autocomplete-plug-in-results
|
13
|
+
|
14
|
+
// don't really need this, but in case I did, I could store it and chain
|
15
|
+
var oldFn = $.ui.autocomplete.prototype._renderItem;
|
16
|
+
|
17
|
+
$.ui.autocomplete.prototype._renderItem = function( ul, item) {
|
18
|
+
// This regex took some fiddling but should match beginning of string and
|
19
|
+
// any match preceded by a string: this is useful for sql matches.
|
20
|
+
var re = new RegExp('((^' + this.term + ')|( ' + this.term + '))', "gi") ;
|
21
|
+
var t = item.label.replace(re,"<span style='font-weight:bold;color:Red;'>" +
|
22
|
+
"$&" +
|
23
|
+
"</span>");
|
24
|
+
return $( "<li></li>" )
|
25
|
+
.data( "item.autocomplete", item )
|
26
|
+
.append( "<a>" + t + "</a>" )
|
27
|
+
.appendTo( ul );
|
28
|
+
};
|
29
|
+
}
|
30
|
+
|
31
|
+
function autocomplete_metadata(metadata, field) {
|
32
|
+
$("#" + field).autocomplete({
|
33
|
+
source: "/philo4/shakespeare_bamboo/scripts/metadata_list.py?field=" + field,
|
34
|
+
minLength: 2,
|
35
|
+
dataType: "json"
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
var fields = ['author', 'title', 'date', 'volume', 'id', 'head', 'n', 'who']
|
40
|
+
$(document).ready(function(){
|
41
|
+
|
42
|
+
monkeyPatchAutocomplete();
|
43
|
+
|
44
|
+
$("#q").autocomplete({
|
45
|
+
source: "/philo4/shakespeare_bamboo/scripts/term_list.py",
|
46
|
+
minLength: 2,
|
47
|
+
"dataType": "json"
|
48
|
+
});
|
49
|
+
for (i in fields) {
|
50
|
+
var metadata = $("#" + fields[i]).val();
|
51
|
+
var field = fields[i];
|
52
|
+
autocomplete_metadata(metadata, field)
|
53
|
+
}
|
54
|
+
// The following is to display the right options when using the back button
|
55
|
+
if ($("#report option[value='concordance']").attr('selected')) {
|
56
|
+
$("#frequency").hide()
|
57
|
+
$("#collocation").hide()
|
58
|
+
$("#theme_rheme").hide()
|
59
|
+
$("#results_per_page").show()
|
60
|
+
}
|
61
|
+
if ($("#report option[value='kwic']").attr('selected')) {
|
62
|
+
$("#frequency").hide()
|
63
|
+
$("#collocation").hide()
|
64
|
+
$("#theme_rheme").hide()
|
65
|
+
$("#results_per_page").show()
|
66
|
+
}
|
67
|
+
if ($("#report option[value='collocation']").attr('selected')) {
|
68
|
+
$("#frequency").hide()
|
69
|
+
$("#results_per_page").hide()
|
70
|
+
$("#theme_rheme").hide()
|
71
|
+
$("#collocation").show()
|
72
|
+
}
|
73
|
+
if ($("#report option[value='frequency']").attr('selected')) {
|
74
|
+
$("#collocation").hide()
|
75
|
+
$("#results_per_page").hide()
|
76
|
+
$("#theme_rheme").hide()
|
77
|
+
$("#frequency").show()
|
78
|
+
}
|
79
|
+
if ($("#report option[value='relevance']").attr('selected')) {
|
80
|
+
$("#frequency").hide()
|
81
|
+
$("#collocation").hide()
|
82
|
+
$("#theme_rheme").hide()
|
83
|
+
$("#results_per_page").show()
|
84
|
+
}
|
85
|
+
if ($("#report option[value='theme_rheme']").attr('selected')) {
|
86
|
+
$("#frequency").hide()
|
87
|
+
$("#collocation").hide()
|
88
|
+
$("#theme_rheme").show()
|
89
|
+
$("#results_per_page").show()
|
90
|
+
}
|
91
|
+
});
|
92
|
+
|
93
|
+
function showHide(value) {
|
94
|
+
if (value == 'frequency') {
|
95
|
+
$("#collocation").hide()
|
96
|
+
$("#results_per_page").hide()
|
97
|
+
$("#theme_rheme").hide()
|
98
|
+
$("#frequency").show()
|
99
|
+
}
|
100
|
+
if (value == 'collocation') {
|
101
|
+
$("#frequency").hide()
|
102
|
+
$("#results_per_page").hide()
|
103
|
+
$("#theme_rheme").hide()
|
104
|
+
$("#collocation").show()
|
105
|
+
}
|
106
|
+
if (value == 'concordance' || value == 'kwic' || value == 'relevance') {
|
107
|
+
$("#frequency").hide()
|
108
|
+
$("#collocation").hide()
|
109
|
+
$("#theme_rheme").hide()
|
110
|
+
$("#results_per_page").show()
|
111
|
+
}
|
112
|
+
if (value == 'theme_rheme') {
|
113
|
+
$("#frequency").hide()
|
114
|
+
$("#collocation").hide()
|
115
|
+
$("#theme_rheme").show()
|
116
|
+
$("#results_per_page").show()
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
</script>
|
4
121
|
</head>
|
5
|
-
<body
|
122
|
+
<body>
|
123
|
+
<div id="container">
|
124
|
+
<div id="wrapper">
|
125
|
+
<div id="header">
|
126
|
+
<div id="top-bar">
|
127
|
+
<div class="region-content">
|
128
|
+
<ul class="links secondary-links">
|
129
|
+
<li class="menu-121 first"><a href="http://humanities.uchicago.edu/orgs/ARTFL/" title="The ARTFL Project">THE ARTFL PROJECT</a></li>
|
130
|
+
<li class="menu-120"><a href="http://philologic.uchicago.edu/manual.php" title="How to use the PhiloLogic Search Engine">PHILOLOGIC USER MANUAL</a></li>
|
131
|
+
<li class="menu-119"><a href="http://www.lib.uchicago.edu/efts/ARTFL/newhome/subscribe/" title="Subscribe to the ARTFL Project">SUBSCRIPTION INFORMATION</a></li>
|
132
|
+
<li class="menu-118"><a href="http://www.uchicago.edu/" title="University of Chicago">UNIVERSITY OF CHICAGO</a></li>
|
133
|
+
<li class="menu-117 last"><a href="http://www.atilf.fr/" title="Analyse et Traitment Informatique de la Langue Française">ATILF - CNRS</a></li>
|
134
|
+
</ul>
|
135
|
+
</div>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
<div class="region-content">
|
139
|
+
<h1><a href="/philo4/shakespeare_bamboo/" title="ARTFL Encyclopédie Project - Robert Morrissey,General Editor"><span class="site-name">shakespeare_bamboo</span></a></h1>
|
140
|
+
</div>
|
141
|
+
</div>
|
142
|
+
<div class="main_body">
|
6
143
|
|
7
|
-
<div class='philologic_response'>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
144
|
+
<div class='philologic_response'>
|
145
|
+
<div class='philologic_cite'>
|
146
|
+
<span class='philologic_property' title='author'>William Shakespeare</span>, <span class='philologic_property' title='title'>The First Part of King Henry the Fourth</span>
|
147
|
+
</div>
|
148
|
+
<div class='philologic_object'>
|
149
|
+
The First Part of King Henry the Fourth William Shakespeare Craig A. Berry, Martin Mueller, and Clifford Wulfman editors Jeffrey Cousens and Bill Parod technical editors Lawrence Berland, Hilary Bina, Katherine Gould, Kreg Segal, Nicholas Terrell editorial assistants
|
12
150
|
<p/> The WordHoard Shakespeare is a joint project of the Perseus Project at Tufts University, The Northwestern University Library, and Northwestern University Academic Technologies. It is derived from The Globe Shakespeare , the one-volume version of the Cambridge Shakespeare , edited by W. G. Clark, J. Glover, and W. A. Wright (1891-3). The Internet Shakespeare editions of the quartos and folios have been consulted to create a modern text that observes as closely as possible the morphological and prosodic practices of the earliest editions. Spellings, especially of contracted and hyphenated forms, have been standardized across the corpus. The text has been fully lemmatized and morphosyntactically tagged.
|
13
151
|
<p/> © 2003. The copyright to The WordHoard Shakespeare is owned jointly by Northwestern University and Tufts University. The WordHoard Shakespeare is provided for free solely for non-commercial use by students, scholars, and the public. Any commercial use or publication of it, in whole or in part, without prior written authorization of the copyright holders is strictly prohibited.
|
14
152
|
<p/> The Wordhoard Shakespeare is derived from, but not identical with, The Globe Shakespeare , the one-volume version of the Cambridge Shakespeare (1891-3) edited by W. G. Clark, J. Glover, and W. A. Wright.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
153
|
+
</div>
|
154
|
+
<div class='more'>
|
155
|
+
|
156
|
+
<a href='http://lafayette.uchicago.edu/philo4/shakespeare_bamboo/dispatcher.py/1/2/0/0/0/0/0' class='next'>Next</a>
|
157
|
+
<div style='clear:both;'></div>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
</div>
|
161
|
+
<div id="footer">
|
162
|
+
<div class="bottom-border">
|
163
|
+
<div class="region-content">
|
164
|
+
<div class="footer-nav" style="float:left;">
|
165
|
+
<ul class="links primary-links"><li class="menu-204 first"><a href="/content/about-artfl" title="General Information about the ARTFL Project">about artfl</a></li>
|
166
|
+
<li class="menu-139"><a href="/content/subscription-information-0" title="Information concerning ARTFL Subscription">subscription info</a></li>
|
167
|
+
<li class="menu-140"><a href="/content/whats-new-artfl" title="New Developments at the ARTFL Project">what's new</a></li>
|
168
|
+
<li class="menu-143"><a href="http://sites.google.com/site/philologic3/home" title="Philologic 3: Open Source ARTFL Search and Retrieval Engine">philologic</a></li>
|
169
|
+
<li class="menu-197 last"><a href="/content/contact-us" title="Contact information for the ARTFL Project">contact us</a></li>
|
170
|
+
</ul>
|
171
|
+
<br />
|
172
|
+
<br />
|
173
|
+
<img src="http://humanities.uchicago.edu/images/wordmarks/hum-wordmark-black-small.png" style="display:block;margin-left:-5px;" />
|
174
|
+
</div>
|
175
|
+
<p id="footer-message">The ARTFL Project<br>Department of Romance Languages and Literatures<br>Division of the Humanities<br>University of Chicago<br>1115 East 58th Street Chicago, IL 60637<br>tel: 773-702-8488 | email: artfl[at]artfl[dot]uchicago[dot]edu<br></p> <span class="clear"></span>
|
176
|
+
</div>
|
177
|
+
</div>
|
178
|
+
</div> <!-- /footer -->
|
179
|
+
</div> <!-- /container -->
|
180
|
+
</body>
|
19
181
|
</html>
|
20
|
-
|
data/test/helper.rb
ADDED
data/test/test_bibliography.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require 'philologic-client'
|
7
|
-
require 'test_response'
|
8
|
-
require 'test/unit'
|
3
|
+
require_relative 'helper'
|
4
|
+
require_relative 'test_response'
|
9
5
|
|
10
6
|
|
11
7
|
class TestBibliography < TestResponse
|
@@ -61,17 +57,17 @@ class TestBibliography < TestResponse
|
|
61
57
|
assert_not_nil first
|
62
58
|
assert_kind_of Philologic::Client::Occurrence, first
|
63
59
|
assert_equal 'William Shakespeare', first['author']
|
64
|
-
assert_equal './1
|
60
|
+
assert_equal './1?', first['href']
|
65
61
|
assert_equal 'The First Part of King Henry the Fourth', first['title']
|
66
|
-
assert_equal
|
62
|
+
assert_equal nil, first['who']
|
67
63
|
|
68
64
|
last = r.titles.last
|
69
65
|
assert_not_nil last
|
70
66
|
assert_kind_of Philologic::Client::Occurrence, last
|
71
67
|
assert_equal 'William Shakespeare', last['author']
|
72
|
-
assert_equal './42
|
68
|
+
assert_equal './42?', last['href']
|
73
69
|
assert_equal "The Winter's Tale", last['title']
|
74
|
-
assert_equal
|
70
|
+
assert_equal nil, last['who']
|
75
71
|
end
|
76
72
|
|
77
73
|
end
|
data/test/test_client.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
SimpleCov.start
|
5
|
-
|
6
|
-
require 'philologic-client'
|
7
|
-
require 'test/unit'
|
8
|
-
require 'mocha'
|
3
|
+
require_relative 'helper'
|
9
4
|
|
10
5
|
|
11
6
|
class TestClient < Test::Unit::TestCase
|
@@ -18,6 +13,9 @@ class TestClient < Test::Unit::TestCase
|
|
18
13
|
@biblio_path = 'bibliography.html' # XXX
|
19
14
|
@biblio_file = File.join( @data_dir, @biblio_path ) # XXX
|
20
15
|
|
16
|
+
@col_path = 'collocation.html' # XXX
|
17
|
+
@col_file = File.join( @data_dir, @col_path ) # XXX
|
18
|
+
|
21
19
|
@con_path = 'concordance.html' # XXX
|
22
20
|
@con_file = File.join( @data_dir, @con_path ) # XXX
|
23
21
|
|
@@ -92,7 +90,7 @@ class TestClient < Test::Unit::TestCase
|
|
92
90
|
h = Nokogiri::HTML( open(@biblio_file) )
|
93
91
|
r = client.send( :_parse, Nokogiri::HTML( open(@biblio_file) ) )
|
94
92
|
|
95
|
-
client.stubs(:_get).with('?
|
93
|
+
client.stubs(:_get).with('?method=proxy&q=').returns(r)
|
96
94
|
assert_not_nil r
|
97
95
|
|
98
96
|
b = client.bibliography
|
@@ -107,17 +105,17 @@ class TestClient < Test::Unit::TestCase
|
|
107
105
|
assert_not_nil first
|
108
106
|
assert_kind_of Philologic::Client::Occurrence, first
|
109
107
|
assert_equal 'William Shakespeare', first['author']
|
110
|
-
assert_equal './1
|
108
|
+
assert_equal './1?', first['href']
|
111
109
|
assert_equal 'The First Part of King Henry the Fourth', first['title']
|
112
|
-
assert_equal
|
110
|
+
assert_equal nil, first['who']
|
113
111
|
|
114
112
|
last = b.titles.last
|
115
113
|
assert_not_nil last
|
116
114
|
assert_kind_of Philologic::Client::Occurrence, last
|
117
115
|
assert_equal 'William Shakespeare', last['author']
|
118
|
-
assert_equal './42
|
116
|
+
assert_equal './42?', last['href']
|
119
117
|
assert_equal "The Winter's Tale", last['title']
|
120
|
-
assert_equal
|
118
|
+
assert_equal nil, last['who']
|
121
119
|
end
|
122
120
|
end
|
123
121
|
|
@@ -167,10 +165,10 @@ class TestClient < Test::Unit::TestCase
|
|
167
165
|
assert_kind_of Array, r.links
|
168
166
|
assert_equal 26, r.links.size
|
169
167
|
assert_kind_of Philologic::Client::Link, r.links.first
|
170
|
-
|
171
|
-
assert_equal '',
|
168
|
+
assert r.links.first.url =~ %r{/dispatcher.py/1/2/0/0/0/0/0$}
|
169
|
+
assert_equal '[div1]', r.links.first.text
|
172
170
|
assert_kind_of Philologic::Client::Link, r.links.last
|
173
|
-
|
171
|
+
assert r.links.last.url =~ %r{/dispatcher.py/1/7/6/0/0/0/0$}
|
174
172
|
assert_equal 'Act 5, Scene 5', r.links.last.text
|
175
173
|
|
176
174
|
assert !r.text?
|
@@ -180,7 +178,6 @@ class TestClient < Test::Unit::TestCase
|
|
180
178
|
end
|
181
179
|
|
182
180
|
def test_get_document_that_is_text
|
183
|
-
|
184
181
|
Philologic::Client.new do |client|
|
185
182
|
doc = client.send( :_parse, Nokogiri::HTML( open(@obj_file) ) )
|
186
183
|
client.expects(:_get).with(@obj_path).returns(doc)
|
@@ -224,6 +221,88 @@ class TestClient < Test::Unit::TestCase
|
|
224
221
|
end
|
225
222
|
end
|
226
223
|
|
224
|
+
def test_get_collocation_without_endpoint
|
225
|
+
Philologic::Client.new do |client|
|
226
|
+
assert_raise(RuntimeError, 'nil endpoint') { client.collocation('lion') }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_get_collocation
|
231
|
+
Philologic::Client.new do |client|
|
232
|
+
doc = client.send( :_parse, Nokogiri::HTML( open(@col_file) ) )
|
233
|
+
client.expects(:_get).with('?method=proxy&q=lion&report=collocation').returns(doc)
|
234
|
+
r = client.collocation('lion')
|
235
|
+
|
236
|
+
assert_not_nil doc
|
237
|
+
assert_not_nil r
|
238
|
+
assert_equal doc, r
|
239
|
+
assert_kind_of Philologic::Client::Response, r
|
240
|
+
assert_kind_of Philologic::Client::Collocation, r
|
241
|
+
|
242
|
+
assert r.results?
|
243
|
+
assert_kind_of Array, r.results
|
244
|
+
assert_equal 110, r.results.size
|
245
|
+
|
246
|
+
first = r.results.first
|
247
|
+
assert_not_nil first
|
248
|
+
assert_kind_of Philologic::Client::Collocation::Row, first
|
249
|
+
assert_equal 4, first.value
|
250
|
+
assert_equal 'whose', first.word
|
251
|
+
assert_equal 3, first.left_value
|
252
|
+
assert_equal 'whose', first.left_word
|
253
|
+
assert_equal 4, first.right_value
|
254
|
+
assert_equal 'roar', first.right_word
|
255
|
+
|
256
|
+
last = r.results.last
|
257
|
+
assert_not_nil last
|
258
|
+
assert_kind_of Philologic::Client::Collocation::Row, last
|
259
|
+
assert_equal 1, last.value
|
260
|
+
assert_equal 'still', last.word
|
261
|
+
assert_equal 1, last.left_value
|
262
|
+
assert_equal 'shade', last.left_word
|
263
|
+
assert_equal 1, last.right_value
|
264
|
+
assert_equal 'top', last.right_word
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_get_collocation_with_query_parameters
|
269
|
+
Philologic::Client.new do |client|
|
270
|
+
doc = client.send( :_parse, Nokogiri::HTML( open(@col_file) ) )
|
271
|
+
client.expects(:_get).with('?foo=bar&method=proxy&q=lion&report=collocation').returns(doc)
|
272
|
+
r = client.collocation( :foo => 'bar', :q => 'lion' )
|
273
|
+
|
274
|
+
assert_not_nil doc
|
275
|
+
assert_not_nil r
|
276
|
+
assert_equal doc, r
|
277
|
+
assert_kind_of Philologic::Client::Response, r
|
278
|
+
assert_kind_of Philologic::Client::Collocation, r
|
279
|
+
|
280
|
+
assert r.results?
|
281
|
+
assert_kind_of Array, r.results
|
282
|
+
assert_equal 110, r.results.size
|
283
|
+
|
284
|
+
first = r.results.first
|
285
|
+
assert_not_nil first
|
286
|
+
assert_kind_of Philologic::Client::Collocation::Row, first
|
287
|
+
assert_equal 4, first.value
|
288
|
+
assert_equal 'whose', first.word
|
289
|
+
assert_equal 3, first.left_value
|
290
|
+
assert_equal 'whose', first.left_word
|
291
|
+
assert_equal 4, first.right_value
|
292
|
+
assert_equal 'roar', first.right_word
|
293
|
+
|
294
|
+
last = r.results.last
|
295
|
+
assert_not_nil last
|
296
|
+
assert_kind_of Philologic::Client::Collocation::Row, last
|
297
|
+
assert_equal 1, last.value
|
298
|
+
assert_equal 'still', last.word
|
299
|
+
assert_equal 1, last.left_value
|
300
|
+
assert_equal 'shade', last.left_word
|
301
|
+
assert_equal 1, last.right_value
|
302
|
+
assert_equal 'top', last.right_word
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
227
306
|
def test_get_concordance_without_endpoint
|
228
307
|
Philologic::Client.new do |client|
|
229
308
|
assert_raise(RuntimeError, 'nil endpoint') { client.concordance('lion') }
|
@@ -233,7 +312,7 @@ class TestClient < Test::Unit::TestCase
|
|
233
312
|
def test_get_concordance
|
234
313
|
Philologic::Client.new do |client|
|
235
314
|
doc = client.send( :_parse, Nokogiri::HTML( open(@con_file) ) )
|
236
|
-
client.expects(:_get).with('?q=lion').returns(doc)
|
315
|
+
client.expects(:_get).with('?method=proxy&q=lion&report=concordance').returns(doc)
|
237
316
|
r = client.concordance('lion')
|
238
317
|
|
239
318
|
assert_not_nil doc
|
@@ -251,14 +330,13 @@ class TestClient < Test::Unit::TestCase
|
|
251
330
|
assert_equal 1, first['hit_n']
|
252
331
|
assert_equal 'William Shakespeare', first['author']
|
253
332
|
assert_equal 'The First Part of King Henry the Fourth', first['title']
|
254
|
-
assert_equal 'Prince', first['who']
|
255
333
|
assert first.text?
|
256
334
|
assert_not_nil first.text
|
257
335
|
assert_match /^ cat or a lugged bear/, first.text
|
258
|
-
assert_match /
|
336
|
+
assert_match /Falstaff$/, first.text
|
259
337
|
assert_not_nil first.html
|
260
338
|
assert_match /^ cat or a lugged bear/, first.html
|
261
|
-
assert_match /
|
339
|
+
assert_match /Falstaff$/, first.html
|
262
340
|
|
263
341
|
last = r.results.last
|
264
342
|
assert_not_nil last
|
@@ -266,7 +344,6 @@ class TestClient < Test::Unit::TestCase
|
|
266
344
|
assert_equal 50, last['hit_n']
|
267
345
|
assert_equal 'William Shakespeare', last['author']
|
268
346
|
assert_equal "A Midsummer Night's Dream", last['title']
|
269
|
-
assert_equal 'Bottom', last['who']
|
270
347
|
|
271
348
|
assert last.text?
|
272
349
|
assert_not_nil last.text
|
@@ -281,7 +358,7 @@ class TestClient < Test::Unit::TestCase
|
|
281
358
|
def test_get_concordance_with_query_parameters
|
282
359
|
Philologic::Client.new do |client|
|
283
360
|
doc = client.send( :_parse, Nokogiri::HTML( open(@con_file) ) )
|
284
|
-
client.expects(:_get).with('?foo=bar&q=lion').returns(doc)
|
361
|
+
client.expects(:_get).with('?foo=bar&method=proxy&q=lion&report=concordance').returns(doc)
|
285
362
|
r = client.concordance( :foo => 'bar', :q => 'lion' )
|
286
363
|
|
287
364
|
assert_not_nil doc
|
@@ -299,14 +376,13 @@ class TestClient < Test::Unit::TestCase
|
|
299
376
|
assert_equal 1, first['hit_n']
|
300
377
|
assert_equal 'William Shakespeare', first['author']
|
301
378
|
assert_equal 'The First Part of King Henry the Fourth', first['title']
|
302
|
-
assert_equal 'Prince', first['who']
|
303
379
|
assert first.text?
|
304
380
|
assert_not_nil first.text
|
305
381
|
assert_match /^ cat or a lugged bear/, first.text
|
306
|
-
assert_match /
|
382
|
+
assert_match /Falstaff$/, first.text
|
307
383
|
assert_not_nil first.html
|
308
384
|
assert_match /^ cat or a lugged bear/, first.html
|
309
|
-
assert_match /
|
385
|
+
assert_match /Falstaff$/, first.html
|
310
386
|
|
311
387
|
last = r.results.last
|
312
388
|
assert_not_nil last
|
@@ -314,7 +390,6 @@ class TestClient < Test::Unit::TestCase
|
|
314
390
|
assert_equal 50, last['hit_n']
|
315
391
|
assert_equal 'William Shakespeare', last['author']
|
316
392
|
assert_equal "A Midsummer Night's Dream", last['title']
|
317
|
-
assert_equal 'Bottom', last['who']
|
318
393
|
|
319
394
|
assert last.text?
|
320
395
|
assert_not_nil last.text
|
@@ -325,6 +400,7 @@ class TestClient < Test::Unit::TestCase
|
|
325
400
|
assert_match /for there is not a more$/, last.html.strip
|
326
401
|
end
|
327
402
|
end
|
403
|
+
|
328
404
|
def test_underscore_build_query_with_invalid_queries
|
329
405
|
Philologic::Client.new(@endpoint) do |client|
|
330
406
|
assert_raise(RuntimeError, 'no query specified') { client.send(:_build_query, nil) }
|
@@ -344,518 +420,68 @@ class TestClient < Test::Unit::TestCase
|
|
344
420
|
def test_get_frequency
|
345
421
|
Philologic::Client.new do |client|
|
346
422
|
doc = client.send( :_parse, Nokogiri::HTML( open( File.join( @data_dir, 'frequency.html' ) ) ) )
|
347
|
-
client.expects(:_get).with('?q=lion&report=frequency').returns(doc)
|
423
|
+
client.expects(:_get).with('?method=proxy&q=lion&report=frequency').returns(doc)
|
348
424
|
r = client.frequency('lion')
|
349
425
|
|
350
426
|
assert_not_nil doc
|
427
|
+
assert_not_nil r
|
351
428
|
assert_equal doc, r
|
352
429
|
assert_kind_of Philologic::Client::Response, r
|
353
430
|
assert_kind_of Philologic::Client::Frequency, r
|
354
431
|
|
355
432
|
assert r.results?
|
356
433
|
assert_not_nil r.results
|
357
|
-
assert_kind_of Array,
|
358
|
-
assert_equal 29,
|
434
|
+
assert_kind_of Array, r.results
|
435
|
+
assert_equal 29, r.results.size
|
359
436
|
|
360
437
|
first = r.results.first
|
361
438
|
assert_not_nil first
|
362
|
-
assert_kind_of Philologic::Client::FrequencyRow,
|
363
|
-
assert_equal "A Midsummer Night's Dream",
|
364
|
-
assert_equal './?q=lion&title
|
365
|
-
assert_equal '30',
|
439
|
+
assert_kind_of Philologic::Client::FrequencyRow, first
|
440
|
+
assert_equal "A Midsummer Night's Dream", first.label
|
441
|
+
assert_equal './?q=lion&method=proxy&title=%22A+Midsummer+Night%27s+Dream%22', first.link
|
442
|
+
assert_equal '30', first.value
|
366
443
|
|
367
444
|
last = r.results.last
|
368
445
|
assert_not_nil last
|
369
|
-
assert_kind_of Philologic::Client::FrequencyRow,
|
370
|
-
assert_equal 'As You Like It',
|
371
|
-
assert_equal './?q=lion&title
|
372
|
-
assert_equal '1',
|
446
|
+
assert_kind_of Philologic::Client::FrequencyRow, last
|
447
|
+
assert_equal 'As You Like It', last.label
|
448
|
+
assert_equal './?q=lion&method=proxy&title=%22As+You+Like+It%22', last.link
|
449
|
+
assert_equal '1', last.value
|
373
450
|
end
|
374
451
|
end
|
375
452
|
|
376
453
|
def test_get_frequency_with_query_parameters
|
377
454
|
Philologic::Client.new do |client|
|
378
455
|
doc = client.send( :_parse, Nokogiri::HTML( open( File.join( @data_dir, 'frequency.html' ) ) ) )
|
379
|
-
client.expects(:_get).with('?foo=bar&q=lion&report=frequency').returns(doc)
|
456
|
+
client.expects(:_get).with('?foo=bar&method=proxy&q=lion&report=frequency').returns(doc)
|
380
457
|
r = client.frequency( :q => 'lion', :foo => 'bar' )
|
381
458
|
|
382
459
|
assert_not_nil doc
|
460
|
+
assert_not_nil r
|
383
461
|
assert_equal doc, r
|
384
462
|
assert_kind_of Philologic::Client::Response, r
|
385
463
|
assert_kind_of Philologic::Client::Frequency, r
|
386
464
|
|
387
465
|
assert r.results?
|
388
466
|
assert_not_nil r.results
|
389
|
-
assert_kind_of Array,
|
390
|
-
assert_equal 29,
|
467
|
+
assert_kind_of Array, r.results
|
468
|
+
assert_equal 29, r.results.size
|
391
469
|
|
392
470
|
first = r.results.first
|
393
471
|
assert_not_nil first
|
394
|
-
assert_kind_of Philologic::Client::FrequencyRow,
|
395
|
-
assert_equal "A Midsummer Night's Dream",
|
396
|
-
assert_equal './?q=lion&title
|
397
|
-
assert_equal '30',
|
472
|
+
assert_kind_of Philologic::Client::FrequencyRow, first
|
473
|
+
assert_equal "A Midsummer Night's Dream", first.label
|
474
|
+
assert_equal './?q=lion&method=proxy&title=%22A+Midsummer+Night%27s+Dream%22', first.link
|
475
|
+
assert_equal '30', first.value
|
398
476
|
|
399
477
|
last = r.results.last
|
400
478
|
assert_not_nil last
|
401
|
-
assert_kind_of Philologic::Client::FrequencyRow,
|
402
|
-
assert_equal 'As You Like It',
|
403
|
-
assert_equal './?q=lion&title
|
404
|
-
assert_equal '1',
|
479
|
+
assert_kind_of Philologic::Client::FrequencyRow, last
|
480
|
+
assert_equal 'As You Like It', last.label
|
481
|
+
assert_equal './?q=lion&method=proxy&title=%22As+You+Like+It%22', last.link
|
482
|
+
assert_equal '1', last.value
|
405
483
|
end
|
406
484
|
end
|
407
|
-
# def test_get_children_without_an_endpoint
|
408
|
-
# Philologic::Client.new do |client|
|
409
|
-
# assert_raises(RuntimeError) { client.children }
|
410
|
-
# end
|
411
|
-
# end
|
412
|
-
|
413
|
-
|
414
|
-
# # TODO What are we actually testing here?
|
415
|
-
# def test_get_children
|
416
|
-
# Philologic::Client.new do |client|
|
417
|
-
# h = Nokogiri::HTML( open(@root_file) )
|
418
|
-
# children = client.send( :_parse, Nokogiri::HTML( open(@root_file) ) )
|
419
|
-
# client.stubs(:_get).with('/?title=').returns(children)
|
420
|
-
# assert_not_nil children
|
421
|
-
# assert_equal children, client.children
|
422
|
-
# end
|
423
|
-
# end
|
424
|
-
|
425
|
-
# def test_parse_children
|
426
|
-
# Philologic::Client.new do |client|
|
427
|
-
# client.endpoint = @endpoint
|
428
|
-
# children = client.children(@root_path)
|
429
|
-
# assert_not_nil children
|
430
|
-
# assert_kind_of Array, children
|
431
|
-
# assert_equal 1845, children.size
|
432
|
-
# children.each do |child|
|
433
|
-
# assert_kind_of Philologic::Link, child
|
434
|
-
# assert_equal 'philologic_cite', child['class']
|
435
|
-
# assert_not_nil child['href']
|
436
|
-
# assert_nil child['some random attribute']
|
437
|
-
# assert_not_nil child['author']
|
438
|
-
# assert_not_nil child['filename']
|
439
|
-
# assert_not_nil child['title']
|
440
|
-
# assert_not_nil child.text
|
441
|
-
# end
|
442
|
-
#
|
443
|
-
# assert_equal './1/0/0/0/0/0/0', children.first['href']
|
444
|
-
# assert_equal 'Conon, de Béthune, ca. 1160-1219 or 20.', children.first['author']
|
445
|
-
# assert_equal 'Les Chansons', children.first['title']
|
446
|
-
# assert_equal 'TLF.0.tei', children.first['filename']
|
447
|
-
# assert_match /^Conon, de Béthune, ca. 1160-1219 or 20./, children.first.text
|
448
|
-
# assert_equal './1/0/0/0/0/0/0', children.first.to_s
|
449
|
-
#
|
450
|
-
# assert_equal './1845/0/0/0/0/0/0', children.last['href']
|
451
|
-
# assert_equal 'Sartre J.-P.', children.last['author']
|
452
|
-
# assert_equal 'Les Mots', children.last['title']
|
453
|
-
# assert_equal 'TLF.1879.tei', children.last['filename']
|
454
|
-
# assert_equal "Sartre J.-P., Les Mots: TLF.1879.tei", children.last.text
|
455
|
-
# assert_equal './1845/0/0/0/0/0/0', children.last.to_s
|
456
|
-
#
|
457
|
-
# end
|
458
|
-
# end
|
459
|
-
|
460
|
-
# def test_parse_document
|
461
|
-
# Philologic::Client.new do |client|
|
462
|
-
# client.endpoint = @endpoint
|
463
|
-
# doc = client.document(@doc_path)
|
464
|
-
# assert_not_nil doc
|
465
|
-
#
|
466
|
-
# assert_kind_of Philologic::Document, doc
|
467
|
-
# assert_equal 'philologic_object', doc['class']
|
468
|
-
# assert_nil doc['some random attribute']
|
469
|
-
# assert_kind_of String, doc.html
|
470
|
-
# assert_match /^<div class="context_container" id="1">/, doc.html
|
471
|
-
# assert_match %r{par tans la verité." </div>}, doc.html
|
472
|
-
# assert_kind_of String, doc.text
|
473
|
-
# assert_match /^Conon, de Béthune/, doc.text
|
474
|
-
# assert_match /verité." $/, doc.text
|
475
|
-
# end
|
476
|
-
# end
|
477
|
-
|
478
|
-
# def test_get_document_from_cite_through_client
|
479
|
-
# Philologic::Client.new do |client|
|
480
|
-
# client.endpoint = @endpoint
|
481
|
-
# child = client.children(@root_path).first
|
482
|
-
# assert_not_nil child
|
483
|
-
# assert_kind_of Philologic::Link, child
|
484
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@doc_file) ) )
|
485
|
-
# client.stubs(:_get).with('./1/0/0/0/0/0/0').returns(doc) # TODO Improve
|
486
|
-
# assert_equal doc, client.document( child['href'] )
|
487
|
-
# end
|
488
|
-
# end
|
489
|
-
|
490
|
-
# def test_get_document_from_cite
|
491
|
-
# Philologic::Client.new do |client|
|
492
|
-
# client.endpoint = @endpoint
|
493
|
-
# child = client.children(@root_path).first
|
494
|
-
# assert_not_nil child
|
495
|
-
# assert_kind_of Philologic::Link, child
|
496
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@doc_file) ) )
|
497
|
-
# client.stubs(:_get).with('./1/0/0/0/0/0/0').returns(doc) # TODO Improve
|
498
|
-
# assert_equal doc, child.document
|
499
|
-
# end
|
500
|
-
# end
|
501
|
-
|
502
|
-
# def test_underscore_query
|
503
|
-
# Philologic::Client.new(@endpoint) do |client|
|
504
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@query_file) ) )
|
505
|
-
# client.stubs(:_get).with('?q=lion').returns(doc)
|
506
|
-
# assert_equal doc, client.send( :_query, :q => 'lion' )
|
507
|
-
# end
|
508
|
-
# end
|
509
|
-
|
510
|
-
# Philologic::Client.new(@endpoint) do |client|
|
511
|
-
# assert_equal '?q=lion', client.send( :_build_query, :q => 'lion' )
|
512
|
-
# assert_equal '?foo=bar&q=lion', client.send( :_build_query, :q => 'lion', :foo => 'bar' )
|
513
|
-
# end
|
514
|
-
# end
|
515
|
-
|
516
|
-
# def test_search_with_invalid_queries
|
517
|
-
# Philologic::Client.new(@endpoint) do |client|
|
518
|
-
# [ nil, [], {}, '', [ '' ], [ nil ], Object.new ].each do |q|
|
519
|
-
# assert_raise(RuntimeError, 'invalid query') { client.search(q) }
|
520
|
-
# end
|
521
|
-
# end
|
522
|
-
# end
|
523
|
-
|
524
|
-
# def test_search
|
525
|
-
# Philologic::Client.new(@endpoint) do |client|
|
526
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@query_file) ) )
|
527
|
-
# client.stubs(:_get).with('?q=lion').returns(doc)
|
528
|
-
|
529
|
-
# results = client.search('lion')
|
530
|
-
|
531
|
-
# assert_not_nil results
|
532
|
-
# assert_kind_of Array, results
|
533
|
-
# assert_equal 50, results.size
|
534
|
-
# results.each do |result|
|
535
|
-
# assert_kind_of Philologic::Link, result
|
536
|
-
# assert_equal 'philologic_occurrence', result['class']
|
537
|
-
# assert_not_nil result['href']
|
538
|
-
# assert_nil result['some random attribute']
|
539
|
-
# assert_not_nil result['author']
|
540
|
-
# assert_not_nil result['hit_n']
|
541
|
-
# assert_nil result['filename']
|
542
|
-
# assert_not_nil result['title']
|
543
|
-
# assert_not_nil result.text
|
544
|
-
# end
|
545
|
-
|
546
|
-
# assert_equal './1/3/3/1/25/?byte=33845', results.first['href']
|
547
|
-
# assert_equal 'William Shakespeare', results.first['author']
|
548
|
-
# assert_equal 'The First Part of King Henry the Fourth', results.first['title']
|
549
|
-
# assert_equal '1', results.first['hit_n']
|
550
|
-
# assert_match /^1\. William Shakespeare, The First Part/, results.first.text
|
551
|
-
# assert_match './1/3/3/1/25/?byte=33845', results.first.to_s
|
552
|
-
|
553
|
-
# assert_equal './24/5/2/1/14/?byte=124024', results.last['href']
|
554
|
-
# assert_equal 'William Shakespeare', results.last['author']
|
555
|
-
# assert_equal "A Midsummer Night's Dream", results.last['title']
|
556
|
-
# assert_equal '50', results.last['hit_n']
|
557
|
-
# assert_match /^50\. William Shakespeare,/, results.last.text
|
558
|
-
# assert_equal './24/5/2/1/14/?byte=124024', results.last.to_s
|
559
|
-
|
560
|
-
# end
|
561
|
-
# end
|
562
|
-
|
563
|
-
# def test_search_with_key_value_pairs
|
564
|
-
# Philologic::Client.new(@endpoint) do |client|
|
565
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@query_file) ) )
|
566
|
-
# client.stubs(:_get).with('?q=lion').returns(doc)
|
567
|
-
|
568
|
-
# results = client.search( :q => 'lion' )
|
569
|
-
|
570
|
-
# assert_not_nil results
|
571
|
-
# assert_kind_of Array, results
|
572
|
-
# assert_equal 50, results.size
|
573
|
-
# results.each do |result|
|
574
|
-
# assert_kind_of Philologic::Link, result
|
575
|
-
# assert_equal 'philologic_occurrence', result['class']
|
576
|
-
# assert_not_nil result['href']
|
577
|
-
# assert_nil result['some random attribute']
|
578
|
-
# assert_not_nil result['author']
|
579
|
-
# assert_nil result['filename']
|
580
|
-
# assert_not_nil result['hit_n']
|
581
|
-
# assert_not_nil result['title']
|
582
|
-
# assert_not_nil result.text
|
583
|
-
# end
|
584
|
-
|
585
|
-
# assert_equal './1/3/3/1/25/?byte=33845', results.first['href']
|
586
|
-
# assert_equal 'William Shakespeare', results.first['author']
|
587
|
-
# assert_equal 'The First Part of King Henry the Fourth', results.first['title']
|
588
|
-
# assert_equal '1', results.first['hit_n']
|
589
|
-
# assert_match /^1\. William Shakespeare, The First Part/, results.first.text
|
590
|
-
# assert_match './1/3/3/1/25/?byte=33845', results.first.to_s
|
591
|
-
|
592
|
-
# assert_equal './24/5/2/1/14/?byte=124024', results.last['href']
|
593
|
-
# assert_equal 'William Shakespeare', results.last['author']
|
594
|
-
# assert_equal '50', results.last['hit_n']
|
595
|
-
# assert_equal "A Midsummer Night's Dream", results.last['title']
|
596
|
-
# assert_match /^50\. William Shakespeare,/, results.last.text
|
597
|
-
# assert_equal './24/5/2/1/14/?byte=124024', results.last.to_s
|
598
|
-
|
599
|
-
# end
|
600
|
-
# end
|
601
|
-
|
602
|
-
# def test_frequency_search_with_invalid_queries
|
603
|
-
# Philologic::Client.new(@endpoint) do |client|
|
604
|
-
# [ nil, [], {}, '', [ '' ], [ nil ], Object.new ].each do |q|
|
605
|
-
# assert_raise(RuntimeError, 'invalid query') { client.frequency(q) }
|
606
|
-
# end
|
607
|
-
# end
|
608
|
-
# end
|
609
|
-
|
610
|
-
# def test_frequency_search
|
611
|
-
# Philologic::Client.new(@endpoint) do |client|
|
612
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@freq_file) ) )
|
613
|
-
# client.stubs(:_get).with('?q=lion&report=frequency').returns(doc)
|
614
|
-
#
|
615
|
-
# results = client.frequency('lion')
|
616
|
-
#
|
617
|
-
# assert_not_nil results
|
618
|
-
# assert_kind_of Array, results
|
619
|
-
# assert_equal 15, results.size
|
620
|
-
# results.each do |result|
|
621
|
-
# assert_kind_of Philologic::TableRow, result
|
622
|
-
# assert_equal 'philologic_frequency_row', result['class']
|
623
|
-
# assert_nil result['href']
|
624
|
-
# assert_nil result['some random attribute']
|
625
|
-
# assert_nil result['author']
|
626
|
-
# assert_nil result['filename']
|
627
|
-
# assert_nil result['title']
|
628
|
-
# assert_not_nil result.count
|
629
|
-
# assert_not_nil result.field
|
630
|
-
# assert_not_nil result.href
|
631
|
-
# assert_not_nil result.text
|
632
|
-
# end
|
633
|
-
#
|
634
|
-
# assert_equal 'author', results.first.field
|
635
|
-
# assert_equal 48, results.first.count
|
636
|
-
# assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
|
637
|
-
# assert_equal 'Beauvoir S. de', results.first.text
|
638
|
-
# assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
|
639
|
-
#
|
640
|
-
# assert_equal 'author', results.last.field
|
641
|
-
# assert_equal 1, results.last.count
|
642
|
-
# assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
|
643
|
-
# assert_equal 'Schaeffer P.', results.last.text
|
644
|
-
# assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
|
645
|
-
# end
|
646
|
-
# end
|
647
|
-
|
648
|
-
# def test_frequency_search_with_key_value_pairs
|
649
|
-
# Philologic::Client.new(@endpoint) do |client|
|
650
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@freq_file) ) )
|
651
|
-
# client.stubs(:_get).with('?q=lion&report=frequency').returns(doc)
|
652
|
-
#
|
653
|
-
# results = client.frequency( :q => 'lion' )
|
654
|
-
#
|
655
|
-
# assert_not_nil results
|
656
|
-
# assert_kind_of Array, results
|
657
|
-
# assert_equal 15, results.size
|
658
|
-
# results.each do |result|
|
659
|
-
# assert_kind_of Philologic::TableRow, result
|
660
|
-
# assert_equal 'philologic_frequency_row', result['class']
|
661
|
-
# assert_nil result['href']
|
662
|
-
# assert_nil result['some random attribute']
|
663
|
-
# assert_nil result['author']
|
664
|
-
# assert_nil result['filename']
|
665
|
-
# assert_nil result['title']
|
666
|
-
# assert_not_nil result.count
|
667
|
-
# assert_not_nil result.field
|
668
|
-
# assert_not_nil result.href
|
669
|
-
# assert_not_nil result.text
|
670
|
-
# end
|
671
|
-
#
|
672
|
-
# assert_equal 'author', results.first.field
|
673
|
-
# assert_equal 48, results.first.count
|
674
|
-
# assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
|
675
|
-
# assert_equal 'Beauvoir S. de', results.first.text
|
676
|
-
# assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
|
677
|
-
#
|
678
|
-
# assert_equal 'author', results.last.field
|
679
|
-
# assert_equal 1, results.last.count
|
680
|
-
# assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
|
681
|
-
# assert_equal 'Schaeffer P.', results.last.text
|
682
|
-
# assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
|
683
|
-
#
|
684
|
-
# end
|
685
|
-
# end
|
686
|
-
|
687
|
-
# def test_philologic_frequency_tablerow_links
|
688
|
-
# Philologic::Client.new(@endpoint) do |client|
|
689
|
-
# freq_doc = client.send( :_parse, Nokogiri::HTML( open(@freq_file) ) )
|
690
|
-
# freq_links_doc = client.send( :_parse, Nokogiri::HTML( open(@freq_links_file) ) )
|
691
|
-
# client.stubs(:_get).with('?q=lion&report=frequency').returns(freq_doc)
|
692
|
-
# client.stubs(:_get).with('?author=Beauvoir+S.+de&q=lion&title=').returns(freq_links_doc)
|
693
|
-
#
|
694
|
-
# results = client.frequency( :q => 'lion' )
|
695
|
-
# assert_not_nil results
|
696
|
-
#
|
697
|
-
# links = results.first.links
|
698
|
-
#
|
699
|
-
# assert_not_nil links
|
700
|
-
# assert_kind_of Array, links
|
701
|
-
# assert_equal 48, links.size
|
702
|
-
#
|
703
|
-
# links.each do |link|
|
704
|
-
# assert_kind_of Philologic::Link, link
|
705
|
-
# assert_equal 'philologic_occurence', link['class']
|
706
|
-
# assert_not_nil link['href']
|
707
|
-
# assert_nil link['some random attribute']
|
708
|
-
# assert_not_nil link['author']
|
709
|
-
# assert_nil link['filename']
|
710
|
-
# assert_not_nil link['title']
|
711
|
-
# assert_not_nil link.text
|
712
|
-
# end
|
713
|
-
#
|
714
|
-
# assert_equal './1839/3/0/0', links.first['href']
|
715
|
-
# assert_equal 'Beauvoir S. de', links.first['author']
|
716
|
-
# assert_equal 'Memoires Jeune Fille Rangee', links.first['title']
|
717
|
-
# assert_nil links.first['filename']
|
718
|
-
# assert_match /^Beauvoir S. de/, links.first.text
|
719
|
-
# assert_equal './1839/3/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.first.to_s
|
720
|
-
#
|
721
|
-
# assert_equal './1839/4/0/0', links.last['href']
|
722
|
-
# assert_equal 'Beauvoir S. de', links.last['author']
|
723
|
-
# assert_equal 'Memoires Jeune Fille Rangee', links.last['title']
|
724
|
-
# assert_nil links.last['filename']
|
725
|
-
# assert_match /^Beauvoir S. de,/, links.last.text
|
726
|
-
# assert_equal './1839/4/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.last.to_s
|
727
|
-
#
|
728
|
-
# end
|
729
|
-
# end
|
730
|
-
|
731
|
-
# def test_collocation_search_with_invalid_queries
|
732
|
-
# Philologic::Client.new(@endpoint) do |client|
|
733
|
-
# [ nil, [], {}, '', [ '' ], [ nil ], Object.new ].each do |q|
|
734
|
-
# assert_raise(RuntimeError, 'invalid query') { client.collocation(q) }
|
735
|
-
# end
|
736
|
-
# end
|
737
|
-
# end
|
738
|
-
|
739
|
-
# def test_collocation_search
|
740
|
-
# Philologic::Client.new(@endpoint) do |client|
|
741
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@coll_file) ) )
|
742
|
-
# client.stubs(:_get).with('?field=collocates&q=lion&report=frequency').returns(doc)
|
743
|
-
#
|
744
|
-
# results = client.collocation('lion')
|
745
|
-
#
|
746
|
-
# assert_not_nil results
|
747
|
-
# assert_kind_of Array, results
|
748
|
-
# assert_equal 15, results.size
|
749
|
-
# results.each do |result|
|
750
|
-
# assert_kind_of Philologic::TableRow, result
|
751
|
-
# assert_equal 'philologic_frequency_row', result['class']
|
752
|
-
# assert_nil result['href']
|
753
|
-
# assert_nil result['some random attribute']
|
754
|
-
# assert_nil result['author']
|
755
|
-
# assert_nil result['filename']
|
756
|
-
# assert_nil result['title']
|
757
|
-
# assert_not_nil result.count
|
758
|
-
# assert_not_nil result.field
|
759
|
-
# assert_not_nil result.href
|
760
|
-
# assert_not_nil result.text
|
761
|
-
# end
|
762
|
-
#
|
763
|
-
# assert_equal 'author', results.first.field
|
764
|
-
# assert_equal 48, results.first.count
|
765
|
-
# assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
|
766
|
-
# assert_equal 'Beauvoir S. de', results.first.text
|
767
|
-
# assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
|
768
|
-
#
|
769
|
-
# assert_equal 'author', results.last.field
|
770
|
-
# assert_equal 1, results.last.count
|
771
|
-
# assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
|
772
|
-
# assert_equal 'Schaeffer P.', results.last.text
|
773
|
-
# assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
|
774
|
-
# end
|
775
|
-
# end
|
776
|
-
|
777
|
-
# def test_collocation_search_with_key_value_pairs
|
778
|
-
# Philologic::Client.new(@endpoint) do |client|
|
779
|
-
# doc = client.send( :_parse, Nokogiri::HTML( open(@coll_file) ) )
|
780
|
-
# client.stubs(:_get).with('?field=collocates&q=lion&report=frequency').returns(doc)
|
781
|
-
#
|
782
|
-
# results = client.collocation( :q => 'lion' )
|
783
|
-
#
|
784
|
-
# assert_not_nil results
|
785
|
-
# assert_kind_of Array, results
|
786
|
-
# assert_equal 15, results.size
|
787
|
-
# results.each do |result|
|
788
|
-
# assert_kind_of Philologic::TableRow, result
|
789
|
-
# assert_equal 'philologic_frequency_row', result['class']
|
790
|
-
# assert_nil result['href']
|
791
|
-
# assert_nil result['some random attribute']
|
792
|
-
# assert_nil result['author']
|
793
|
-
# assert_nil result['filename']
|
794
|
-
# assert_nil result['title']
|
795
|
-
# assert_not_nil result.count
|
796
|
-
# assert_not_nil result.field
|
797
|
-
# assert_not_nil result.href
|
798
|
-
# assert_not_nil result.text
|
799
|
-
# end
|
800
|
-
#
|
801
|
-
# assert_equal 'author', results.first.field
|
802
|
-
# assert_equal 48, results.first.count
|
803
|
-
# assert_equal './?q=lion&author=Beauvoir+S.+de&title=', results.first.href
|
804
|
-
# assert_equal 'Beauvoir S. de', results.first.text
|
805
|
-
# assert_equal 'author | 48 | Beauvoir S. de', results.first.to_s
|
806
|
-
#
|
807
|
-
# assert_equal 'author', results.last.field
|
808
|
-
# assert_equal 1, results.last.count
|
809
|
-
# assert_equal './?q=lion&author=Schaeffer+P.&title=', results.last.href
|
810
|
-
# assert_equal 'Schaeffer P.', results.last.text
|
811
|
-
# assert_equal 'author | 1 | Schaeffer P.', results.last.to_s
|
812
|
-
#
|
813
|
-
# end
|
814
|
-
# end
|
815
|
-
|
816
|
-
# def test_philologic_collocation_tablerow_links
|
817
|
-
# Philologic::Client.new(@endpoint) do |client|
|
818
|
-
# coll_doc = client.send( :_parse, Nokogiri::HTML( open(@coll_file) ) )
|
819
|
-
# coll_links_doc = client.send( :_parse, Nokogiri::HTML( open(@coll_links_file) ) )
|
820
|
-
# client.stubs(:_get).with('?field=collocates&q=lion&report=frequency').returns(coll_doc)
|
821
|
-
# client.stubs(:_get).with('?author=Beauvoir+S.+de&q=lion&title=').returns(coll_links_doc)
|
822
|
-
#
|
823
|
-
# results = client.collocation( :q => 'lion' )
|
824
|
-
# assert_not_nil results
|
825
|
-
#
|
826
|
-
# links = results.first.links
|
827
|
-
#
|
828
|
-
# assert_not_nil links
|
829
|
-
# assert_kind_of Array, links
|
830
|
-
# assert_equal 48, links.size
|
831
|
-
#
|
832
|
-
# links.each do |link|
|
833
|
-
# assert_kind_of Philologic::Link, link
|
834
|
-
# assert_equal 'philologic_occurence', link['class']
|
835
|
-
# assert_not_nil link['href']
|
836
|
-
# assert_nil link['some random attribute']
|
837
|
-
# assert_not_nil link['author']
|
838
|
-
# assert_nil link['filename']
|
839
|
-
# assert_not_nil link['title']
|
840
|
-
# assert_not_nil link.text
|
841
|
-
# end
|
842
|
-
#
|
843
|
-
# assert_equal './1839/3/0/0', links.first['href']
|
844
|
-
# assert_equal 'Beauvoir S. de', links.first['author']
|
845
|
-
# assert_equal 'Memoires Jeune Fille Rangee', links.first['title']
|
846
|
-
# assert_nil links.first['filename']
|
847
|
-
# assert_match /^Beauvoir S. de/, links.first.text
|
848
|
-
# assert_equal './1839/3/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.first.to_s
|
849
|
-
#
|
850
|
-
# assert_equal './1839/4/0/0', links.last['href']
|
851
|
-
# assert_equal 'Beauvoir S. de', links.last['author']
|
852
|
-
# assert_equal 'Memoires Jeune Fille Rangee', links.last['title']
|
853
|
-
# assert_nil links.last['filename']
|
854
|
-
# assert_match /^Beauvoir S. de/, links.last.text
|
855
|
-
# assert_equal './1839/4/0/0 | Memoires Jeune Fille Rangee | Beauvoir S. de', links.last.to_s
|
856
|
-
#
|
857
|
-
# end
|
858
|
-
# end
|
859
485
|
|
860
486
|
end
|
861
487
|
|