libil 0.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 +7 -0
- data/bin/libil +35 -0
- data/lib/libil.rb +115 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f5abf8f01f20b2ed73aa1a4f471064b38189c039
|
4
|
+
data.tar.gz: 0a149b44cc5dcff3f1f6609472156f7e3149d4a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f8b60175e39696f563104164bb294113102dc6b61c96cbbc8ade103d54b97b0e90baabaf646bc75d0de39ac4635f9103f579f458ded69429764e6cc1f74ef0d
|
7
|
+
data.tar.gz: 0ab5c71da4e813e8469d2f2c3e9a1e2466b30a5e1b6c48d10460d2c9e7802803d9ce1d6b39a9c53739bd7f7358240c533d758ebea0bae2ef0080db16eab8d652
|
data/bin/libil
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'libil'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
cmd_parser = OptionParser.new do |opts|
|
7
|
+
opts.banner = <<-USAGE
|
8
|
+
Usage: choc <word_or_sentence>
|
9
|
+
Example: choc "Ayo Bali"
|
10
|
+
USAGE
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
begin
|
15
|
+
args = cmd_parser.parse(ARGV)
|
16
|
+
|
17
|
+
if args.count < 1
|
18
|
+
puts "To Few parameters"
|
19
|
+
puts cmd_parser
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
if args.count > 1
|
24
|
+
mapped_args = args.map { |a| Libil::convert(a) }
|
25
|
+
puts mapped_args.join(' ')
|
26
|
+
else
|
27
|
+
puts Libil.convert(args[0])
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
rescue OptionParser::InvalidOption => e
|
32
|
+
puts e
|
33
|
+
puts cmd_parser
|
34
|
+
exit 1
|
35
|
+
end
|
data/lib/libil.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# This ruby gem is for converting a word to its "Basa Walikan Yogyakarta"
|
2
|
+
# It reverses the string according to very simple rules, just like an XOR encoding
|
3
|
+
# Please refer to README.md for details
|
4
|
+
|
5
|
+
require 'strscan'
|
6
|
+
|
7
|
+
module Libil
|
8
|
+
|
9
|
+
# The Consonant map of Javanese alphabet
|
10
|
+
CONSONANT_MAP = ['h', 'n', 'c', 'r', 'k', 'd', 't', 's', 'w', 'l', 'p', 'dh', 'j', 'y', 'ny', 'm', 'g', 'b', 'th', 'ng']; # 15 - 19
|
11
|
+
|
12
|
+
# This is to convert the entire sentence
|
13
|
+
def self.convert(sentence)
|
14
|
+
converted_words = sentence.split(/ /).map {|word| Libil::convert_word(word)}
|
15
|
+
return converted_words.join(' ')
|
16
|
+
end
|
17
|
+
|
18
|
+
# This function is to convert one word only
|
19
|
+
def self.convert_word(word)
|
20
|
+
vocal = ['a', 'i', 'e', 'o', 'u']
|
21
|
+
# tokenize
|
22
|
+
if (word.strip.length == 0)
|
23
|
+
return word
|
24
|
+
end
|
25
|
+
|
26
|
+
# For First Char with Vocal
|
27
|
+
first_char = word[0].downcase
|
28
|
+
if vocal.include?(first_char)
|
29
|
+
if (first_char == word[0])
|
30
|
+
word = "h" + word
|
31
|
+
else
|
32
|
+
word = "H" + first_char + word[1..-1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
tokens = self.tokenize(word)
|
37
|
+
remap_tokens = tokens.map do |t|
|
38
|
+
lowcase = t.downcase
|
39
|
+
is_low = (lowcase == t)
|
40
|
+
x = t
|
41
|
+
|
42
|
+
if (Libil::CONSONANT_MAP.include?(lowcase))
|
43
|
+
x = Libil::c_remap(lowcase)
|
44
|
+
end
|
45
|
+
|
46
|
+
if not is_low
|
47
|
+
x = x.capitalize
|
48
|
+
end
|
49
|
+
x
|
50
|
+
end
|
51
|
+
return remap_tokens.join('')
|
52
|
+
end
|
53
|
+
|
54
|
+
# This is to tokenize the word to be mapped later on when converting
|
55
|
+
def self.tokenize(word)
|
56
|
+
# scan linearly, not yet know how to tokenize fast
|
57
|
+
t = []
|
58
|
+
ss = StringScanner.new(word)
|
59
|
+
loop do
|
60
|
+
break if ss.eos?
|
61
|
+
c = ss.getch
|
62
|
+
if (c.downcase == 'n')
|
63
|
+
if not ss.eos?
|
64
|
+
cc = ss.getch
|
65
|
+
if (cc.downcase == 'y' or cc.downcase == 'g')
|
66
|
+
t << [c, cc].join('')
|
67
|
+
else
|
68
|
+
t << c; t << cc
|
69
|
+
end
|
70
|
+
else
|
71
|
+
t << c
|
72
|
+
end
|
73
|
+
elsif ( c.downcase == 'd' or c.downcase == 't')
|
74
|
+
if not ss.eos?
|
75
|
+
cc = ss.getch
|
76
|
+
if (cc.downcase == 'h')
|
77
|
+
t << [c, cc].join('')
|
78
|
+
else
|
79
|
+
t << c; t << cc
|
80
|
+
end
|
81
|
+
else
|
82
|
+
t << c
|
83
|
+
end
|
84
|
+
else
|
85
|
+
t << c
|
86
|
+
end
|
87
|
+
end
|
88
|
+
return t
|
89
|
+
end
|
90
|
+
|
91
|
+
# This function is to find a counterpart of an consonant according to the
|
92
|
+
# Walikan Yogyakarta rule
|
93
|
+
def self.c_remap(consonant)
|
94
|
+
c_index = self.find_c_index(consonant)
|
95
|
+
p_index = 0;
|
96
|
+
|
97
|
+
if c_index - 10 < 0
|
98
|
+
p_index = c_index + 10
|
99
|
+
else
|
100
|
+
p_index = c_index - 10
|
101
|
+
end
|
102
|
+
|
103
|
+
if p_index != -1
|
104
|
+
return Libil::CONSONANT_MAP[p_index]
|
105
|
+
else
|
106
|
+
return ''
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Utility Function to get the index of a consonant
|
111
|
+
def self.find_c_index(consonant)
|
112
|
+
return Libil::CONSONANT_MAP.index(consonant)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libil
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Didiet Noor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |2
|
14
|
+
Libil is a library and command line tools to implement Basa Walikan Jogja.
|
15
|
+
email: lynxluna@gmail.com
|
16
|
+
executables:
|
17
|
+
- libil
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/libil
|
22
|
+
- lib/libil.rb
|
23
|
+
homepage: http://github.com/lynxluna/libil
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.2.2
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Library for converting string to 'Basa Walikan Jogja'
|
47
|
+
test_files: []
|