conlang 0.3.0 → 0.3.1
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/LANG_FILES_DOC.md +15 -0
- data/README.md +2 -3
- data/lib/conlang/symbolset.rb +4 -1
- data/lib/conlang/version.rb +1 -1
- data/lib/conlang/wordgenerator.rb +34 -10
- data/test/test_file_replacements.lang +19 -0
- data/test/test_wordgenerator.rb +10 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c3fa9530fea0396261592ac22612c07dd94ad7
|
4
|
+
data.tar.gz: f325285e8db5859dc36ad9015c59e6b943f71a2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10ece298a14025c4e2d4ca094eaf9cc0c30c2f08b1f44e1b7b09299cc9e51ea652c376599c0da3db646fc44eca34908be4133ec3b7e0336c6ce3ab7decc28897
|
7
|
+
data.tar.gz: 00e1fe61645036d72e3b9609688605527cac8dc14a1c9239b58c233a6e4861c8bd7360da960edf8155ef2d4480412f816602b3b8a90c77097870b52463a24dda
|
data/LANG_FILES_DOC.md
CHANGED
@@ -41,6 +41,21 @@ A phoneme's statistical weight gives
|
|
41
41
|
a priority to the symbol. It must be an
|
42
42
|
integer greater than 0 and less than 100.
|
43
43
|
|
44
|
+
Replacements
|
45
|
+
------------
|
46
|
+
Replacements are a way to add exceptions, so they are
|
47
|
+
simple ways to avoid complicated expressions.
|
48
|
+
|
49
|
+
All replacements are applied at the level of each word
|
50
|
+
in order.
|
51
|
+
|
52
|
+
replacements:
|
53
|
+
a: aj
|
54
|
+
ew: ej
|
55
|
+
|
56
|
+
The previous replacements would convert
|
57
|
+
words like `vakew` to `vajkej`.
|
58
|
+
|
44
59
|
Expression and operators
|
45
60
|
------------------------
|
46
61
|
Each LANG file has an expression at the end.
|
data/README.md
CHANGED
@@ -36,7 +36,6 @@ Usage as a **gem**:
|
|
36
36
|
# an array of strings.
|
37
37
|
p x.get_words(10)
|
38
38
|
|
39
|
-
|
40
39
|
There are `*.lang` files as examples at `lang-examples`
|
41
40
|
directory of this [project's source](https://github.com/fluorine/ConlangWordGenerator).
|
42
41
|
|
@@ -46,8 +45,8 @@ You must create your own .lang files to generate random
|
|
46
45
|
words for your constructed languages.
|
47
46
|
|
48
47
|
There files include a simple lightweight markup language
|
49
|
-
to describe sets of phonemes, their probability,
|
50
|
-
simple regular grammatical expression.
|
48
|
+
to describe sets of phonemes, their probability, replacements
|
49
|
+
(for exceptions) and a simple regular grammatical expression.
|
51
50
|
|
52
51
|
You can learn how to create LANG files [**here**](LANG_FILES_DOC.md).
|
53
52
|
Again, examples at `lang-examples` directory can help you a lot.
|
data/lib/conlang/symbolset.rb
CHANGED
data/lib/conlang/version.rb
CHANGED
@@ -31,6 +31,9 @@ class WordGenerator
|
|
31
31
|
@bindings = {}
|
32
32
|
@full_expression = ""
|
33
33
|
|
34
|
+
# Bindings for replacements
|
35
|
+
@replacements = {}
|
36
|
+
|
34
37
|
# Parse .lang file
|
35
38
|
parse_lang_file
|
36
39
|
|
@@ -46,7 +49,7 @@ class WordGenerator
|
|
46
49
|
# its full grammatical expression.
|
47
50
|
File.open(@lang_file, "r:UTF-8") do |file|
|
48
51
|
lines_count = 1
|
49
|
-
|
52
|
+
current = :none
|
50
53
|
|
51
54
|
# Evaluating lines
|
52
55
|
while (line = file.gets)
|
@@ -60,18 +63,30 @@ class WordGenerator
|
|
60
63
|
captured = line.scan(/\s*(\w+)\s*:/)
|
61
64
|
current_binding = captured[0][0]
|
62
65
|
@bindings[current_binding] = ConlangWordGenerator::SymbolSet.new
|
66
|
+
current = :symbols
|
63
67
|
|
64
68
|
when /^\s*expression\s*:\s*(#.*)?$/
|
65
69
|
# Start of grammatical expression
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
current = :expression
|
71
|
+
|
72
|
+
when /^\s*replacements\s*:\s*(#.*)?$/
|
73
|
+
# Start of list of replacements
|
74
|
+
current = :replacements
|
75
|
+
|
76
|
+
when /^\s*(\S+)\s*[:=]\s*(\S+)\s*(#.*)?$/
|
77
|
+
# Add bindings
|
78
|
+
case current
|
79
|
+
when :symbols
|
80
|
+
#Add a symbol to the current SymbolSet's binding
|
81
|
+
@bindings[current_binding].add_pair($1, $2.to_i)
|
82
|
+
when :replacements
|
83
|
+
@replacements[$1] = $2
|
84
|
+
else
|
85
|
+
raise LangSyntaxError, "Runtime error when evaluating " +
|
86
|
+
"\"#{@lang_file}\" at binding line #{lines_count}."
|
87
|
+
end
|
73
88
|
else
|
74
|
-
if
|
89
|
+
if current == :expression
|
75
90
|
# Copying expression
|
76
91
|
@full_expression += line.strip
|
77
92
|
else
|
@@ -100,9 +115,18 @@ class WordGenerator
|
|
100
115
|
words = []
|
101
116
|
|
102
117
|
qty.times do
|
103
|
-
words += [@evaluated_expression.sample]
|
118
|
+
words += [apply_replacements(@evaluated_expression.sample)]
|
104
119
|
end
|
105
120
|
|
106
121
|
words
|
107
122
|
end
|
123
|
+
|
124
|
+
# Apply replacements to words
|
125
|
+
def apply_replacements(word)
|
126
|
+
@replacements.each do |pattern, target|
|
127
|
+
word.gsub!(pattern, target)
|
128
|
+
end
|
129
|
+
|
130
|
+
word
|
131
|
+
end
|
108
132
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Thest LANG file for OR operators.
|
2
|
+
|
3
|
+
symbols for a vowel:
|
4
|
+
a: 50
|
5
|
+
o: 50
|
6
|
+
|
7
|
+
symbols for any constant:
|
8
|
+
p: 33
|
9
|
+
t: 33
|
10
|
+
k: 33
|
11
|
+
|
12
|
+
replacements:
|
13
|
+
p: b
|
14
|
+
t: d
|
15
|
+
k: g
|
16
|
+
|
17
|
+
expression:
|
18
|
+
# Pattern: /[aobdg][ao]/
|
19
|
+
or(constant, vowel) + or(10, vowel, vowel)
|
data/test/test_wordgenerator.rb
CHANGED
@@ -43,4 +43,14 @@ class TestWordGenerator < Test::Unit::TestCase
|
|
43
43
|
assert_match(/^[ptk]*[ao]*$/, word)
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Test replacements
|
49
|
+
#
|
50
|
+
def test_replacements
|
51
|
+
words = WordGenerator.new(Dir.pwd + "/test/test_file_replacements.lang").get_words(10)
|
52
|
+
words.each do |word|
|
53
|
+
assert_match(/^[aobdg][ao]$/, word)
|
54
|
+
end
|
55
|
+
end
|
46
56
|
end
|
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conlang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: 'This gem
|
14
|
-
|
15
|
-
files, at this project''s source
|
13
|
+
description: 'This gem allow users to generate random words. The user must provide
|
14
|
+
a LANG file with defined phonemes and a regular grammatical expression. You can
|
15
|
+
learn how to create LANG files, or explore some examples, at this project''s source
|
16
|
+
repository on Github: https://github.com/fluorine/ConlangWordGenerator'
|
16
17
|
email: fluorine@github.com
|
17
18
|
executables:
|
18
19
|
- conlang
|
@@ -34,6 +35,7 @@ files:
|
|
34
35
|
- test/not_lang.gaga
|
35
36
|
- test/test_file_maybe.lang
|
36
37
|
- test/test_file_or.lang
|
38
|
+
- test/test_file_replacements.lang
|
37
39
|
- test/test_symbolset.rb
|
38
40
|
- test/test_syntax_error.lang
|
39
41
|
- test/test_wordgenerator.rb
|
@@ -62,6 +64,5 @@ rubyforge_project:
|
|
62
64
|
rubygems_version: 2.0.3
|
63
65
|
signing_key:
|
64
66
|
specification_version: 4
|
65
|
-
summary:
|
66
|
-
constructed languages.'
|
67
|
+
summary: ConlangWordGenerator. A statistical random word generator for regular grammars.
|
67
68
|
test_files: []
|