apion 0.1.3 → 0.1.5
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/README.md +4 -4
- data/apion.gemspec +2 -2
- data/bin/apion +1 -1
- data/lib/apion.rb +29 -20
- data/lib/special_chars.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0291858b99115fa883e48381b0c99454e5383093
|
4
|
+
data.tar.gz: 4199f54a8c888b449c9f93482b32cb5c5774f187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb85aa8d165f26ee1da9fae375b20ba9f6f503fa0e4395031abc6066ec8a8307094b9e8c4e16c532d782b97681f2296ea3979c2f3a8c866369d3342337d86632
|
7
|
+
data.tar.gz: 19cb88d655fec743350fa0f28ca6039c4457e40840ab9b06f9eb4e94fea76a75cce424436c2b074923467713275b7882d262676abd1470e8f2ee64cc1a98e507
|
data/README.md
CHANGED
@@ -14,24 +14,24 @@ require "apion"
|
|
14
14
|
*Examples* :
|
15
15
|
|
16
16
|
~~~
|
17
|
-
irb(main):002:0> apion("Le chat dodu et roux mange une quiche aux lardons")
|
17
|
+
irb(main):002:0> Apion.apion("Le chat dodu et roux mange une quiche aux lardons")
|
18
18
|
=> ["lœ", "ʃa", "dɔdy", "e", "ru", "mɑ̃ʒ", "yn", "kiʃ", "o", "lardɔ̃"]
|
19
19
|
~~~
|
20
20
|
|
21
21
|
*Automatic ponctuation removal* :
|
22
22
|
|
23
23
|
~~~
|
24
|
-
irb(main):003:0> apion("Le chat dodu et roux mange ? Oh ! C'est une belle quiche aux lardons !!!")
|
24
|
+
irb(main):003:0> Apion.apion("Le chat dodu et roux mange ? Oh ! C'est une belle quiche aux lardons !!!")
|
25
25
|
=> ["lœ", "ʃa", "dɔdy", "e", "ru", "mɑ̃ʒ", "o", "sɛ", "yn", "bɛl", "kiʃ", "o", "lardɔ̃"]
|
26
26
|
~~~
|
27
27
|
|
28
28
|
*Handles both existing and non-existing words*
|
29
29
|
|
30
30
|
~~~
|
31
|
-
irb(main):004:0> apion("Un chat dodu")
|
31
|
+
irb(main):004:0> Apion.apion("Un chat dodu")
|
32
32
|
=> ["œ̃", "ʃa", "dɔdy"]
|
33
33
|
|
34
|
-
irb(main):005:0> apion("Un chat toudouchoubidou")
|
34
|
+
irb(main):005:0> Apion.apion("Un chat toudouchoubidou")
|
35
35
|
=> ["œ̃", "ʃa", "tuduʃubidu"]
|
36
36
|
~~~
|
37
37
|
|
data/apion.gemspec
CHANGED
data/bin/apion
CHANGED
data/lib/apion.rb
CHANGED
@@ -1,31 +1,40 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
module Apion
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
require "json"
|
6
|
+
require "timeout"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
ROOT = File.expand_path("../..", __FILE__)
|
9
|
+
eval(File.read("#{ROOT}/lib/special_chars.rb"))
|
11
10
|
|
12
|
-
def
|
13
|
-
|
14
|
-
end
|
11
|
+
def Apion.parseCSV(path)
|
12
|
+
Hash[File.open("#{ROOT}/data/#{path}.csv").read.split("\n").map {|ligne| ligne.split("#")}]
|
13
|
+
end
|
15
14
|
|
16
|
-
def
|
17
|
-
|
18
|
-
end
|
15
|
+
def Apion.exceptions
|
16
|
+
@exceptions ||= JSON.parse(File.read("#{ROOT}/data/dict.json"))
|
17
|
+
end
|
18
|
+
|
19
|
+
def Apion.conversion
|
20
|
+
@conversion ||= parseCSV "conversion"
|
21
|
+
end
|
19
22
|
|
20
|
-
def apion(texte)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def Apion.apion(texte)
|
24
|
+
texte = texte.downcase
|
25
|
+
texte.gsub(SPE, "").split.map do |mot|
|
26
|
+
exceptions[mot] || "".tap do |result|
|
27
|
+
Timeout::timeout(1) do
|
28
|
+
conversion.select { |regle| mot =~ /#{regle}/ }.first.tap do |regle, api|
|
29
|
+
mot.sub! /#{regle}/, ""
|
30
|
+
result << api.to_s
|
31
|
+
end until mot.empty?
|
32
|
+
end
|
33
|
+
end
|
28
34
|
end
|
35
|
+
rescue Timeout::Error
|
36
|
+
return []
|
29
37
|
end
|
38
|
+
|
30
39
|
end
|
31
40
|
|
@@ -0,0 +1 @@
|
|
1
|
+
SPE = /([(0-9)|•|—|–|\-|,|?|!|^|\r|°|“|”|...|\u00a0|«|»|…|\\|\/|!|?|\"|\'|\[|\]|\(|\)|\]|<|>|=|+|%|$|&|#|;|*|:|}|{|`])/
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Galaad Gauthier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- Gemfile
|
35
35
|
- apion.gemspec
|
36
|
+
- lib/special_chars.rb
|
36
37
|
- lib/apion.rb
|
37
38
|
- data/dict.json
|
38
39
|
- data/conversion.csv
|