aboutsummaryrefslogtreecommitdiff
path: root/lib/jdtalk/core.d
diff options
context:
space:
mode:
Diffstat (limited to 'lib/jdtalk/core.d')
-rw-r--r--lib/jdtalk/core.d45
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/jdtalk/core.d b/lib/jdtalk/core.d
index aafe64a..c6a2c6b 100644
--- a/lib/jdtalk/core.d
+++ b/lib/jdtalk/core.d
@@ -140,18 +140,39 @@ bool hasWord(string match, string str) {
}
+bool wordStartsWith(ref string[] words, char ch) {
+ foreach (word; words) {
+ if (word.startsWith(ch.to!string)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
bool searchDict(dict_t dict, string pattern) {
bool has_pattern = false;
foreach (wordList; [dict.noun, dict.verb, dict.adverb, dict.adjective]) {
foreach (word; wordList) {
has_pattern = wordList.canFind(pattern);
- break;
+ if (has_pattern) break;
}
if (has_pattern) break;
}
return has_pattern;
}
+char acronymSafe(ref dict_t dict, string acronym) {
+ string[] words;
+ words = dict.noun ~ dict.verb ~ dict.adverb ~ dict.adjective;
+ for (int i = 0; i < acronym.length; i++) {
+ if (!wordStartsWith(words, acronym[i])) {
+ return acronym[i];
+ }
+ }
+ return 0;
+}
+
dict_t getData(string root) {
// override data root with environment variable
@@ -178,6 +199,7 @@ string talk(ref dict_t dict) {
return output;
}
+
string talkSalad(ref dict_t dict, int words) {
string[] salad;
for (int i = 0; i < words; i++) {
@@ -187,6 +209,7 @@ string talkSalad(ref dict_t dict, int words) {
return salad.join(" ");
}
+
string talkf(ref dict_t dict, string fmt) {
string[] output;
for (int i = 0; i < fmt.length; i++) {
@@ -211,3 +234,23 @@ string talkf(ref dict_t dict, string fmt) {
}
return output.join(" ");
}
+
+
+string talkAcronym(ref dict_t dict, string abbrev) {
+ string[] words;
+ string[] output;
+
+ words = dict.noun ~ dict.verb ~ dict.adverb ~ dict.adjective;
+
+ for (int i = 0; i < abbrev.length; i++) {
+ string word = "";
+ while ((word = words.choice) !is null) {
+ if (word.startsWith(abbrev[i].to!char)) {
+ break;
+ }
+ }
+
+ output ~= word;
+ }
+ return output.join(" ");
+}