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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36ca6fa5f9ff3f90fa9d5a7e93ef297b9e7aa0a6
4
- data.tar.gz: e01564a82bab476da91d0fc192cc4a2f46d1c505
3
+ metadata.gz: 0291858b99115fa883e48381b0c99454e5383093
4
+ data.tar.gz: 4199f54a8c888b449c9f93482b32cb5c5774f187
5
5
  SHA512:
6
- metadata.gz: db222cd2987cd3fcafc65408ec6f8ba88c5c1570293faf8f0540d5c91ceef86b268ebc5a0feb22e40f9bcfaa1f42ec8aeb874f6c98d963aaf1939caac41f9774
7
- data.tar.gz: 06449ae69af4b94135a8a246123a01691aabc75bbb2ce382d088a603a060ace4082d7452bc70321e2d1629f56763dea7ca44a115feda5647f910d4b548c0cfc0
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
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'apion'
3
- s.version = '0.1.3'
4
- s.date = '2013-08-25'
3
+ s.version = '0.1.5'
4
+ s.date = '2013-09-05'
5
5
  s.summary = "Apion"
6
6
  s.description = "Easy-to-use Fr/Api translator"
7
7
  s.authors = ["Galaad Gauthier"]
data/bin/apion CHANGED
@@ -3,4 +3,4 @@
3
3
  root = File.expand_path("../..", __FILE__)
4
4
  require "#{root}/lib/apion.rb"
5
5
 
6
- puts apion(ARGV[0]).join
6
+ puts Apion.apion(ARGV[0]).join
data/lib/apion.rb CHANGED
@@ -1,31 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "json"
3
+ module Apion
4
4
 
5
- ROOT = File.expand_path("../..", __FILE__)
6
- SPE = /([(0-9)|•|—|–|\-|,|?|!|^|\r|°|“|”|...|\u00a0|«|»|…|\\|\/|!|?|\"|\'|\[|\]|\(|\)|\]|<|>|=|+|%|$|&|#|;|*|:|}|{|`])/
5
+ require "json"
6
+ require "timeout"
7
7
 
8
- def parseCSV(path)
9
- Hash[File.open("#{ROOT}/data/#{path}.csv").read.split("\n").map {|ligne| ligne.split("#")}]
10
- end
8
+ ROOT = File.expand_path("../..", __FILE__)
9
+ eval(File.read("#{ROOT}/lib/special_chars.rb"))
11
10
 
12
- def exceptions
13
- @exceptions ||= JSON.parse(File.read("#{ROOT}/data/dict.json"))
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 conversion
17
- @conversion ||= parseCSV "conversion"
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
- texte = texte.downcase
22
- texte.gsub(SPE, "").split.map do |mot|
23
- exceptions[mot] || "".tap do |result|
24
- conversion.select { |regle| mot =~ /#{regle}/ }.first.tap do |regle, api|
25
- mot.sub! /#{regle}/, ""
26
- result << api.to_s
27
- end until mot.empty?
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.3
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-08-25 00:00:00.000000000 Z
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