gallicagram 1.0.9 → 1.1.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/lib/gallicagram.rb +6 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dcee5aba79519f6fbe3e5e0061e683ae03039eabb6190a18369a5ef30232f72
|
4
|
+
data.tar.gz: f8b3a66a13656ba5ed5b704b427cf14e949481cfec2a7707bdbe8a9a79d4dc78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed8d41d5111d5a1164fac12e8706039fe430c9b73742a208a0ce7aebf116c5bed4415882b8a7cf9b2779c6616c60099b26216dde6aca6afb7a60f3413f20f67
|
7
|
+
data.tar.gz: bbc570022e015b7b9a30983963061ee64f5bb08b3986aadd028504d58cdfa095ad63cd03232856b5f5a7bef559d964834933681827a33eb3705a51b4d919ef35
|
data/lib/gallicagram.rb
CHANGED
@@ -10,25 +10,20 @@ class Gallicagram
|
|
10
10
|
def self.search(query,corpus="lemonde",start_date="1900",end_date="2000",resolution="annee",sum=false)
|
11
11
|
|
12
12
|
query = [query] unless query.kind_of?(Array)
|
13
|
-
|
13
|
+
output = ""
|
14
14
|
query.each_with_index do |word, index|
|
15
15
|
query = format_query(word, sum)
|
16
|
+
if corpus == "livres" && resolution == "mois"
|
17
|
+
resolution = "annee"
|
18
|
+
end
|
16
19
|
response = call_api(word, corpus, start_date, end_date, resolution)
|
17
20
|
unless index == 0
|
18
21
|
response = response.gsub("n,gram,annee,mois,jour,total", "\n").strip
|
19
22
|
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
if corpus == "livres" && resolution == "mois"
|
24
|
-
resolution = "annee"
|
23
|
+
output << response
|
25
24
|
end
|
26
25
|
|
27
|
-
|
28
|
-
data = group_by_resolution(data)
|
29
|
-
else
|
30
|
-
data = CSV.parse(data, :headers => true)
|
31
|
-
end
|
26
|
+
data = CSV.parse(output, :headers => true)
|
32
27
|
|
33
28
|
return data
|
34
29
|
end
|
@@ -51,17 +46,4 @@ def call_api(query, corpus, start_date, end_date, resolution)
|
|
51
46
|
response = URI.open(url)
|
52
47
|
|
53
48
|
return response.read
|
54
|
-
end
|
55
|
-
|
56
|
-
def group_by_resolution(data)
|
57
|
-
csv_parsing = CSV.parse(data, :headers => true)
|
58
|
-
clean_data_array = []
|
59
|
-
csv_parsing.group_by { |word| [word["annee"], word["mois"], word["gram"]] }.each do |cp|
|
60
|
-
sum = cp[1].sum { |word| word["total"].to_i }
|
61
|
-
new_row = cp[0]
|
62
|
-
new_row << sum
|
63
|
-
clean_data_array << new_row
|
64
|
-
end
|
65
|
-
|
66
|
-
return clean_data_array
|
67
49
|
end
|