chinwag 0.1.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/ext/chinwag/chinwag.c +46 -41
- data/ext/chinwag/chinwag.h +20 -12
- data/ext/chinwag/config.c +6 -6
- data/ext/chinwag/dict.c +211 -107
- data/ext/chinwag/dict.h +93 -41
- data/ext/chinwag/latin.h +2 -2
- data/ext/chinwag/rb_chinwag_ext.c +255 -167
- data/ext/chinwag/seuss.h +2 -2
- data/ext/chinwag/tokenize.c +7 -5
- data/ext/chinwag/tokenize.h +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fd89d4ee2f2e3439eb95d344a7ef538911055df
|
4
|
+
data.tar.gz: 0cccb667d03b4543f09dff77de8ed74d6bd2b8f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bfd5c4396ad161bc3c2b32f10bff6922551930dca19d9fcac58b279e12b689a27aa36802d6800b5dbdec2eb7fbcd485a4fc3a5cdc7d682e6df5806ac62c2dd7
|
7
|
+
data.tar.gz: a844beae99c7f6e6fd428a8373b7b7abf9030b2830cf49dd48511a80d867d8833023293ea1a119cc814d05f8914eeaa6cffbada31c65f37b5f4b7ca10f435da8
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ Rake::ExtensionTask.new "chinwag" do |ext|
|
|
8
8
|
ext.lib_dir = "lib/chinwag"
|
9
9
|
end
|
10
10
|
|
11
|
-
s = Gem::Specification.new "chinwag", "
|
11
|
+
s = Gem::Specification.new "chinwag", "1.2.0" do |s|
|
12
12
|
s.authors = ["Chris Calo"]
|
13
13
|
s.email = ["ccalo@vulcanca.com"]
|
14
14
|
s.summary = "A text-synthesis library, for use in layout testing (and more)."
|
data/ext/chinwag/chinwag.c
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "chinwag.h"
|
2
2
|
|
3
|
-
char* chinwag
|
3
|
+
char* chinwag
|
4
|
+
(cw_t type, unsigned long min, unsigned long max, cwdict_t dict)
|
4
5
|
{
|
5
6
|
char* result = NULL;
|
6
7
|
|
@@ -27,17 +28,18 @@ char* chinwag(cw_t type, unsigned long min, unsigned long max, dict_t dict)
|
|
27
28
|
exit(EXIT_FAILURE);
|
28
29
|
}
|
29
30
|
|
30
|
-
if(type == CW_LETTERS) result =
|
31
|
-
else if(type == CW_WORDS) result =
|
32
|
-
else if(type == CW_SENTENCES) result =
|
33
|
-
else if(type == CW_PARAGRAPHS) result =
|
31
|
+
if(type == CW_LETTERS) result = cw_ltr_rng(min, max, dict);
|
32
|
+
else if(type == CW_WORDS) result = cw_wrd_rng(min, max, dict);
|
33
|
+
else if(type == CW_SENTENCES) result = cw_snt_rng(min, max, dict);
|
34
|
+
else if(type == CW_PARAGRAPHS) result = cw_pgf_rng(min, max, dict);
|
34
35
|
|
35
36
|
return result;
|
36
37
|
}
|
37
38
|
|
38
|
-
char*
|
39
|
+
char* cw_ltr_rng
|
40
|
+
(unsigned long min, unsigned long max, cwdict_t dict)
|
39
41
|
{
|
40
|
-
|
42
|
+
cwdict_t temp = cwdict_open();
|
41
43
|
I32 amount = motherr(min,max), total = 0; U32 len = 0;
|
42
44
|
char* s = (char*)malloc(SMALL_BUFFER); char* sample = NULL;
|
43
45
|
char* result = NULL; char* vowels = "aeiou";
|
@@ -54,7 +56,7 @@ char* ltr_rng(unsigned long min, unsigned long max, dict_t dict)
|
|
54
56
|
}
|
55
57
|
else
|
56
58
|
{
|
57
|
-
s = strcpy(s,
|
59
|
+
s = strcpy(s, cwdict_sample(dict));
|
58
60
|
len = strlen(s); total += len; s[len] = '\0';
|
59
61
|
if(len > amount || include(s, " ") || include(s, "-")) continue;
|
60
62
|
}
|
@@ -90,25 +92,26 @@ char* ltr_rng(unsigned long min, unsigned long max, dict_t dict)
|
|
90
92
|
amount -= 2;
|
91
93
|
}
|
92
94
|
|
93
|
-
temp =
|
95
|
+
temp = cwdict_place_word(temp, s);
|
94
96
|
if(amount > 0 && amount != 1) --amount;
|
95
97
|
}
|
96
98
|
|
97
99
|
// post-process dict (pass utility::capitalize function as parameter)
|
98
|
-
temp =
|
99
|
-
temp =
|
100
|
-
result =
|
100
|
+
temp = cwdict_prune(temp, false);
|
101
|
+
temp = cwdict_map(temp, capitalize);
|
102
|
+
result = cwdict_join(temp, " ");
|
101
103
|
|
102
|
-
|
104
|
+
cwdict_close(temp);
|
103
105
|
free(s); s = NULL;
|
104
106
|
|
105
107
|
return result;
|
106
108
|
}
|
107
109
|
|
108
|
-
char*
|
110
|
+
char* cw_wrd_rng
|
111
|
+
(unsigned long min, unsigned long max, cwdict_t dict)
|
109
112
|
{
|
110
|
-
|
111
|
-
U32 amount = motherr(min, max), total =
|
113
|
+
cwdict_t temp = cwdict_open();
|
114
|
+
U32 amount = motherr(min, max), total = cwdict_length(dict);
|
112
115
|
char* sample = NULL; char* result = NULL;
|
113
116
|
bool invalid = true;
|
114
117
|
|
@@ -117,32 +120,33 @@ char* wrd_rng(unsigned long min, unsigned long max, dict_t dict)
|
|
117
120
|
{
|
118
121
|
while(invalid)
|
119
122
|
{
|
120
|
-
sample =
|
123
|
+
sample = cwdict_sample(dict);
|
121
124
|
|
122
125
|
// valid if no space, hyphen, or duplicate (latter depends on size)
|
123
126
|
if(exclude(sample, " ") && exclude(sample, "-"))
|
124
127
|
{
|
125
128
|
if(amount > total) invalid = false;
|
126
|
-
else if(
|
129
|
+
else if(cwdict_exclude(temp, sample)) invalid = false;
|
127
130
|
}
|
128
131
|
}
|
129
132
|
|
130
|
-
temp =
|
133
|
+
temp = cwdict_place_word(temp, sample);
|
131
134
|
invalid = true;
|
132
135
|
}
|
133
136
|
|
134
137
|
// post-process dict (pass utility::capitalize function as parameter)
|
135
|
-
temp =
|
136
|
-
result =
|
138
|
+
temp = cwdict_map(temp, capitalize);
|
139
|
+
result = cwdict_join(temp, " ");
|
137
140
|
|
138
|
-
|
141
|
+
cwdict_close(temp);
|
139
142
|
|
140
143
|
return result;
|
141
144
|
}
|
142
145
|
|
143
|
-
char*
|
146
|
+
char* cw_snt_rng
|
147
|
+
(unsigned long min, unsigned long max, cwdict_t dict)
|
144
148
|
{
|
145
|
-
|
149
|
+
cwdict_t master = cwdict_open(), temp; cwdrow_t selected;
|
146
150
|
U32 word_amount = 0, last = 0, amount = motherr(min, max), now = 0,
|
147
151
|
len = 0, t_minus = 0; U8 comma = 0; I32 punct = 0;
|
148
152
|
U32* no_dice = (U32*)malloc(sizeof(U32) * SMALL_BUFFER);
|
@@ -151,7 +155,7 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
|
|
151
155
|
|
152
156
|
for(U32 i = 0; i != amount; ++i)
|
153
157
|
{
|
154
|
-
temp =
|
158
|
+
temp = cwdict_open();
|
155
159
|
word_amount = motherr(SENTENCE_MIN_WORD_LENGTH,
|
156
160
|
SENTENCE_MAX_WORD_LENGTH);
|
157
161
|
|
@@ -170,10 +174,10 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
|
|
170
174
|
else if(last > 10 || last <= 2) { now = motherr(6, 10); t_minus = 3; }
|
171
175
|
|
172
176
|
selected = dict.drows[now];
|
173
|
-
sample =
|
177
|
+
sample = cwdrow_sample(selected);
|
174
178
|
|
175
|
-
while(
|
176
|
-
{ sample =
|
179
|
+
while(cwdict_include(temp, sample) && strlen(sample) != now)
|
180
|
+
{ sample = cwdict_sample(dict); }
|
177
181
|
|
178
182
|
// add comma (if applicable)
|
179
183
|
if(comma && j == comma - 1)
|
@@ -186,18 +190,18 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
|
|
186
190
|
s[len] = '\0';
|
187
191
|
|
188
192
|
s = add_suffix(s, ",");
|
189
|
-
temp =
|
193
|
+
temp = cwdict_place_word(temp, s);
|
190
194
|
|
191
195
|
free(s);
|
192
196
|
}
|
193
|
-
else temp =
|
197
|
+
else temp = cwdict_place_word(temp, sample);
|
194
198
|
|
195
199
|
invalid = true;
|
196
200
|
last = now;
|
197
201
|
}
|
198
202
|
|
199
203
|
// join temporary dict into a sentence; capitalize first word
|
200
|
-
s =
|
204
|
+
s = cwdict_join(temp, " ");
|
201
205
|
s = capitalize(s);
|
202
206
|
|
203
207
|
// determine punctuation; 1 - period, 2 - question, 3 - exclamation
|
@@ -209,38 +213,39 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
|
|
209
213
|
else if(punct >= 85 && punct <= 99) s = add_suffix(s, "!");
|
210
214
|
|
211
215
|
// add sentence to master dict and cleanup
|
212
|
-
master =
|
216
|
+
master = cwdict_place_word(master, s);
|
213
217
|
|
214
|
-
|
218
|
+
cwdict_close(temp);
|
215
219
|
free(s);
|
216
220
|
}
|
217
221
|
|
218
|
-
result =
|
219
|
-
|
222
|
+
result = cwdict_join(master, " ");
|
223
|
+
cwdict_close(master);
|
220
224
|
free(no_dice);
|
221
225
|
|
222
226
|
return result;
|
223
227
|
}
|
224
228
|
|
225
|
-
char*
|
229
|
+
char* cw_pgf_rng
|
230
|
+
(unsigned long min, unsigned long max, cwdict_t dict)
|
226
231
|
{
|
227
232
|
char* result = NULL; char* sentences = NULL;
|
228
233
|
U32 amount = motherr(min, max), sentence_amount = 0;
|
229
|
-
|
234
|
+
cwdict_t master = cwdict_open();
|
230
235
|
|
231
236
|
for(U32 i = 0; i != amount; ++i)
|
232
237
|
{
|
233
238
|
sentence_amount = motherr(PARAGRAPH_MIN_SENTENCE_LENGTH,
|
234
239
|
PARAGRAPH_MAX_SENTENCE_LENGTH);
|
235
240
|
|
236
|
-
sentences =
|
237
|
-
master =
|
241
|
+
sentences = cw_snt(sentence_amount, dict);
|
242
|
+
master = cwdict_place_word(master, sentences);
|
238
243
|
|
239
244
|
free(sentences);
|
240
245
|
}
|
241
246
|
|
242
|
-
result =
|
243
|
-
|
247
|
+
result = cwdict_join(master, "\n\n");
|
248
|
+
cwdict_close(master);
|
244
249
|
|
245
250
|
return result;
|
246
251
|
}
|
data/ext/chinwag/chinwag.h
CHANGED
@@ -36,15 +36,15 @@ typedef struct dictionary_type {
|
|
36
36
|
unsigned long largest;
|
37
37
|
unsigned long largest_pos;
|
38
38
|
char** words;
|
39
|
-
}
|
39
|
+
} cwdrow_t;
|
40
40
|
|
41
41
|
// dictionary (row container)
|
42
42
|
typedef struct dictionary_container_type {
|
43
43
|
bool sorted;
|
44
44
|
unsigned long count;
|
45
|
-
|
45
|
+
cwdrow_t* drows;
|
46
46
|
char* name;
|
47
|
-
}
|
47
|
+
} cwdict_t;
|
48
48
|
|
49
49
|
#include "seuss.h"
|
50
50
|
#include "latin.h"
|
@@ -56,16 +56,24 @@ typedef struct dictionary_container_type {
|
|
56
56
|
#include "config.h"
|
57
57
|
#include "dict.h"
|
58
58
|
|
59
|
-
char* chinwag
|
59
|
+
char* chinwag
|
60
|
+
(cw_t type, unsigned long min, unsigned long max, cwdict_t dict);
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
#define snt(amt, dict) snt_rng(amt, amt, dict)
|
64
|
-
#define pgf(amt, dict) pgf_rng(amt, amt, dict)
|
62
|
+
char* cw_ltr_rng
|
63
|
+
(unsigned long min, unsigned long max, cwdict_t dict);
|
65
64
|
|
66
|
-
char*
|
67
|
-
|
68
|
-
|
69
|
-
char*
|
65
|
+
char* cw_wrd_rng
|
66
|
+
(unsigned long min, unsigned long max, cwdict_t dict);
|
67
|
+
|
68
|
+
char* cw_snt_rng
|
69
|
+
(unsigned long min, unsigned long max, cwdict_t dict);
|
70
|
+
|
71
|
+
char* cw_pgf_rng
|
72
|
+
(unsigned long min, unsigned long max, cwdict_t dict);
|
73
|
+
|
74
|
+
#define cw_ltr(amt, dict) cw_ltr_rng(amt, amt, dict)
|
75
|
+
#define cw_wrd(amt, dict) cw_wrd_rng(amt, amt, dict)
|
76
|
+
#define cw_snt(amt, dict) cw_snt_rng(amt, amt, dict)
|
77
|
+
#define cw_pgf(amt, dict) cw_pgf_rng(amt, amt, dict)
|
70
78
|
|
71
79
|
#endif
|
data/ext/chinwag/config.c
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#include "config.h"
|
2
2
|
|
3
3
|
const unsigned MAJOR_VERSION = 1;
|
4
|
-
const unsigned MINOR_VERSION =
|
5
|
-
const unsigned PATCH_VERSION =
|
4
|
+
const unsigned MINOR_VERSION = 2;
|
5
|
+
const unsigned PATCH_VERSION = 0;
|
6
6
|
|
7
|
-
const char* const DATE_YEAR = "
|
8
|
-
const char* const DATE_MONTH = "
|
9
|
-
const char* const DATE_DAY = "
|
10
|
-
const char* const REVISION = "
|
7
|
+
const char* const DATE_YEAR = "2015";
|
8
|
+
const char* const DATE_MONTH = "01";
|
9
|
+
const char* const DATE_DAY = "03";
|
10
|
+
const char* const REVISION = "914";
|
11
11
|
|
12
12
|
const unsigned SMALL_BUFFER = 1024;
|
13
13
|
const unsigned LARGE_BUFFER = 5120;
|