mw_dictionary_api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80f489f6fae5b0f1b982015d98eca2fe4ebb4a2c
4
- data.tar.gz: b7d1b0ac8af7932169d75b7ba5a40c6b0ff63605
3
+ metadata.gz: fde666fe3da63ac495854526b7290e75c88139d0
4
+ data.tar.gz: 8c495dedbdec5aea75ded362b8286ad615744daf
5
5
  SHA512:
6
- metadata.gz: efb2c50f4c1d612e36b1077c0455bde9bfd4df2c3b0e1b8225d8536c8a613557ae5aa12f9b35001262d86cc38c5aae17f5fe3999574616d69bef9f36b354c803
7
- data.tar.gz: 2a72daf3bcbf6a2e2e4471cb6ca7c528b0193e616d07ecd91adceadd70bde7fb1403c4cf6fe5f1bb782de55148d5c30f789a3eabfbd21d24ce83c6adc7db71c7
6
+ metadata.gz: be5bfd04c8bc8a3d16317ee28fa398efcf0f6a45a200c0c0eacceb8ffe66f907ff84a32a8b42258477f4ecab276c05f0e240481e16d714adc48eab0fe3974631
7
+ data.tar.gz: 17e34ff4252c94e7c927bba6cf22212a21ade65ee34edf4cf88958dbb54584c6aa8024362e7ecbc26af221be956185103aa7e1496e90208c11363c651676b67c
@@ -49,15 +49,28 @@ module MWDictionaryAPI
49
49
  end
50
50
 
51
51
  rule :inflections do |data, opts|
52
- data.xpath("in//il | in//if").each_slice(2).inject([]) do |hashes, nodes|
53
- hash = Hash[nodes.map {|n| n.name.to_sym}.zip(nodes.map {|n| n.content})]
54
- hash[:il] = hashes[-1][:il] if hashes[-1] and hash[:il] == "or"
55
- hashes << hash
56
- end.inject({}) do |inflections, hash|
57
- inflections[hash[:il].to_sym] ||= []
58
- inflections[hash[:il].to_sym] << hash[:if].gsub(/\W/, "")
52
+ inflections = data.xpath("in").inject([]) do |inflections, in_node|
53
+ hash = {}
54
+ in_node.xpath("il | if").each do |node|
55
+ if node.name == "il"
56
+ hash[:inflection_label] = node.content
57
+ else
58
+ hash[:inflected_form] = node.content.gsub(/\W/, "").force_encoding("UTF-8")
59
+ end
60
+
61
+ if hash.has_key? :inflected_form
62
+ inflections << hash
63
+ hash = {}
64
+ end
65
+ end
59
66
  inflections
60
67
  end
68
+ inflections.each_index do |index|
69
+ if inflections[index][:inflection_label] == "or"
70
+ inflections[index][:inflection_label] = inflections[index-1][:inflection_label] if index > 0
71
+ end
72
+ end
73
+ inflections
61
74
  end
62
75
 
63
76
  rule_helpers do
@@ -13,7 +13,7 @@ module MWDictionaryAPI
13
13
  @api_type = api_type
14
14
  @response_format = response_format
15
15
  @parser_class = parser_class
16
-
16
+
17
17
  parse!
18
18
  end
19
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mw_dictionary_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Liu