string_language 0.0.7 → 0.0.8
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/google_translator.rb +3 -3
- data/lib/string_helpers.rb +20 -36
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7f79d274fd5b4e0c819b7390b8aa6f29fa0cdd6
|
|
4
|
+
data.tar.gz: 61b51ec3f63a8ac7b9ee1b49718ca300f5e06c41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7001e8ced170b53e154b3054203d36aea7aea5112311e2fbbc6d2d409e7a4b93cc654c63740d1f8fc040ea87057b331e5c04e7c72d12151f2ed5432132a580f
|
|
7
|
+
data.tar.gz: e80b05c84923311e90992767cac8982d34b33db9113b3373c1a5cba8079667afe99b53ebf0fa3f021b21fcc9503520aca83373894d16c2a0252c6bcbfd49984d
|
data/lib/google_translator.rb
CHANGED
|
@@ -24,7 +24,7 @@ class GoogleTranslator
|
|
|
24
24
|
ask_google
|
|
25
25
|
|
|
26
26
|
# return the untranslated input when it is translated to white space only
|
|
27
|
-
self.output = translation.match( /^\s*$/ ) ? input : StringHelpers::
|
|
27
|
+
self.output = translation.match( /^\s*$/ ) ? input : StringHelpers::equalize( translation, input )
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def language input
|
|
@@ -75,9 +75,9 @@ class GoogleTranslator
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
# Quick Testing
|
|
78
|
-
begin
|
|
78
|
+
=begin
|
|
79
79
|
english = "'none' and 'ad' Articles"
|
|
80
80
|
translator = GoogleTranslator.new
|
|
81
81
|
translation = translator.translate english, 'en', 'nl'
|
|
82
82
|
puts translation
|
|
83
|
-
end
|
|
83
|
+
=end
|
data/lib/string_helpers.rb
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
module StringHelpers
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# the i-th bracket/quote in stringB
|
|
5
|
-
def self.space_equally stringA, stringB
|
|
3
|
+
def self.equalize stringA, stringB
|
|
6
4
|
|
|
7
|
-
intermediateA =
|
|
5
|
+
intermediateA = equalize_interpunction( stringA, stringB )
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
equalize_surrounding_space( intermediateA, stringB )
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
private
|
|
@@ -15,7 +13,7 @@ module StringHelpers
|
|
|
15
13
|
# @example
|
|
16
14
|
# space_equally_surrounding( "gnu ", " gnat " ) => " gnu "
|
|
17
15
|
#
|
|
18
|
-
def self.
|
|
16
|
+
def self.equalize_surrounding_space stringA, stringB
|
|
19
17
|
|
|
20
18
|
prefix = stringB.match( /^\s*/ )[0]
|
|
21
19
|
suffix = stringB.match( /\s*$/ )[0]
|
|
@@ -24,49 +22,35 @@ module StringHelpers
|
|
|
24
22
|
prefix + middle + suffix
|
|
25
23
|
end
|
|
26
24
|
|
|
27
|
-
def self.
|
|
25
|
+
def self.equalize_interpunction stringA, stringB
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
regex = /(\s*[#{
|
|
27
|
+
interpunction = ".,:;'@|$%^&*-+={()}\/\\\\\#\"\\\[\\\]"
|
|
28
|
+
regex = /(\s*[#{interpunction}]\s*)/
|
|
31
29
|
|
|
32
30
|
splitA = stringA.split( regex ) # "'a' ( bla ) (c )" => ["", "'", "a", "' ", "", "( ", "bla )", " (", "c )"]
|
|
33
31
|
splitB = stringB.split( regex )
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
splitA.each_with_index do |item,index|
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def self.space_ith_match listA, listB, regex, i
|
|
35
|
+
a = splitA[ index ] ; b = splitB[ index ]
|
|
36
|
+
|
|
37
|
+
if a != nil and b != nil and a.match( regex ) and b.match( regex )
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
splitA[ index ] = b
|
|
40
|
+
end
|
|
41
|
+
end
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
listA[ indexA ] = space_equally_surrounding( listA[ indexA ], listB[ indexB ] )
|
|
43
|
+
splitA.join('')
|
|
48
44
|
end
|
|
49
45
|
|
|
50
|
-
def self.ith_match list, regex, i
|
|
51
|
-
|
|
52
|
-
count = 0
|
|
53
|
-
|
|
54
|
-
list.each_with_index do |item,index|
|
|
55
|
-
|
|
56
|
-
count+=1 if item.match( regex )
|
|
57
|
-
return [item,index] if count == i
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
return [nil,nil]
|
|
61
|
-
end
|
|
62
46
|
end
|
|
63
47
|
|
|
64
48
|
# Quick Testing
|
|
65
|
-
|
|
66
|
-
a = "(Dit is een (test) 'van' de spacing)"
|
|
67
|
-
b = "( Deze was niet goed gespaced, zoals ( test) ' van ' dittum)"
|
|
49
|
+
begin
|
|
50
|
+
a = "(Dit is een, enigzins, wel (test) 'van' de spacing)"
|
|
51
|
+
b = " ( Deze was niet goed gespaced, en zelfs , zoals ( test) ' van ' dittum) "
|
|
68
52
|
|
|
69
53
|
puts "correct: >#{a}<"
|
|
70
54
|
puts "wrong: >#{b}<"
|
|
71
|
-
puts "test: >#{StringHelpers::
|
|
72
|
-
|
|
55
|
+
puts "test: >#{StringHelpers::equalize( b, a )}<"
|
|
56
|
+
end
|