diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-05 09:24:03 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-05 09:24:03 -0500 |
commit | 83920acda89b086f9484fdd2907f819451c0610f (patch) | |
tree | f1a1ae03fbf3964d3a5df9222193fe4e9d045f63 | |
parent | d0cc294174f65781c2b946d01db01b3638b48dc1 (diff) | |
download | furries-83920acda89b086f9484fdd2907f819451c0610f.tar.gz furries-83920acda89b086f9484fdd2907f819451c0610f.tar.bz2 furries-83920acda89b086f9484fdd2907f819451c0610f.zip |
Updated verbly (flattened selrestrs)
-rw-r--r-- | sentence.cpp | 299 | ||||
-rw-r--r-- | sentence.h | 7 | ||||
m--------- | vendor/verbly | 0 |
3 files changed, 128 insertions, 178 deletions
diff --git a/sentence.cpp b/sentence.cpp index fdf883e..6cfa0c3 100644 --- a/sentence.cpp +++ b/sentence.cpp | |||
@@ -29,179 +29,23 @@ std::string sentence::generate() const | |||
29 | return form.compile(); | 29 | return form.compile(); |
30 | } | 30 | } |
31 | 31 | ||
32 | verbly::filter sentence::parseSelrestrs( | 32 | bool sentence::chooseSelrestr(std::set<std::string> selrestrs, std::set<std::string> choices) const |
33 | verbly::selrestr selrestr) const | ||
34 | { | 33 | { |
35 | switch (selrestr.getType()) | 34 | int validChoices = 0; |
35 | for (const std::string& choice : choices) | ||
36 | { | 36 | { |
37 | case verbly::selrestr::type::empty: | 37 | if (selrestrs.count(choice)) |
38 | { | 38 | { |
39 | return {}; | 39 | validChoices++; |
40 | } | ||
41 | |||
42 | case verbly::selrestr::type::singleton: | ||
43 | { | ||
44 | verbly::filter result; | ||
45 | |||
46 | if (selrestr.getRestriction() == "concrete") | ||
47 | { | ||
48 | result = (verbly::notion::wnid == 100001930); // physical entity | ||
49 | } else if (selrestr.getRestriction() == "time") | ||
50 | { | ||
51 | result = (verbly::notion::wnid == 100028270); // time | ||
52 | } else if (selrestr.getRestriction() == "state") | ||
53 | { | ||
54 | result = (verbly::notion::wnid == 100024720); // state | ||
55 | } else if (selrestr.getRestriction() == "abstract") | ||
56 | { | ||
57 | result = (verbly::notion::wnid == 100002137); // abstract entity | ||
58 | } else if (selrestr.getRestriction() == "scalar") | ||
59 | { | ||
60 | result = (verbly::notion::wnid == 103835412); // number | ||
61 | } else if (selrestr.getRestriction() == "currency") | ||
62 | { | ||
63 | result = (verbly::notion::wnid == 105050379); // currency | ||
64 | } else if (selrestr.getRestriction() == "location") | ||
65 | { | ||
66 | result = (verbly::notion::wnid == 100027167); // location | ||
67 | } else if (selrestr.getRestriction() == "organization") | ||
68 | { | ||
69 | result = (verbly::notion::wnid == 100237078); // organization | ||
70 | } else if (selrestr.getRestriction() == "int_control") | ||
71 | { | ||
72 | result = (verbly::notion::wnid == 100007347); // causal agent | ||
73 | } else if (selrestr.getRestriction() == "natural") | ||
74 | { | ||
75 | result = (verbly::notion::wnid == 100019128); // natural object | ||
76 | } else if (selrestr.getRestriction() == "phys_obj") | ||
77 | { | ||
78 | result = (verbly::notion::wnid == 100002684); // physical object | ||
79 | } else if (selrestr.getRestriction() == "solid") | ||
80 | { | ||
81 | result = (verbly::notion::wnid == 113860793); // solid | ||
82 | } else if (selrestr.getRestriction() == "shape") | ||
83 | { | ||
84 | result = (verbly::notion::wnid == 100027807); // shape | ||
85 | } else if (selrestr.getRestriction() == "substance") | ||
86 | { | ||
87 | result = (verbly::notion::wnid == 100019613); // substance | ||
88 | } else if (selrestr.getRestriction() == "idea") | ||
89 | { | ||
90 | result = (verbly::notion::wnid == 105803379); // idea | ||
91 | } else if (selrestr.getRestriction() == "sound") | ||
92 | { | ||
93 | result = (verbly::notion::wnid == 107111047); // sound | ||
94 | } else if (selrestr.getRestriction() == "communication") | ||
95 | { | ||
96 | result = (verbly::notion::wnid == 100033020); // communication | ||
97 | } else if (selrestr.getRestriction() == "region") | ||
98 | { | ||
99 | result = (verbly::notion::wnid == 105221895); // region | ||
100 | } else if (selrestr.getRestriction() == "place") | ||
101 | { | ||
102 | result = (verbly::notion::wnid == 100586262); // place | ||
103 | } else if (selrestr.getRestriction() == "machine") | ||
104 | { | ||
105 | result = (verbly::notion::wnid == 102958343); // machine | ||
106 | } else if (selrestr.getRestriction() == "animate") | ||
107 | { | ||
108 | result = (verbly::notion::wnid == 100004258); // animate thing | ||
109 | } else if (selrestr.getRestriction() == "plant") | ||
110 | { | ||
111 | result = (verbly::notion::wnid == 103956922); // plant | ||
112 | } else if (selrestr.getRestriction() == "comestible") | ||
113 | { | ||
114 | result = (verbly::notion::wnid == 100021265); // food | ||
115 | } else if (selrestr.getRestriction() == "artifact") | ||
116 | { | ||
117 | result = (verbly::notion::wnid == 100021939); // artifact | ||
118 | } else if (selrestr.getRestriction() == "vehicle") | ||
119 | { | ||
120 | result = (verbly::notion::wnid == 104524313); // vehicle | ||
121 | } else if (selrestr.getRestriction() == "human") | ||
122 | { | ||
123 | result = (verbly::notion::wnid == 100007846); // person | ||
124 | } else if (selrestr.getRestriction() == "animal") | ||
125 | { | ||
126 | result = (verbly::notion::wnid == 100015388); // animal | ||
127 | } else if (selrestr.getRestriction() == "body_part") | ||
128 | { | ||
129 | result = (verbly::notion::wnid == 105220461); // body part | ||
130 | } else if (selrestr.getRestriction() == "garment") | ||
131 | { | ||
132 | result = (verbly::notion::wnid == 103051540); // clothing | ||
133 | } else if (selrestr.getRestriction() == "tool") | ||
134 | { | ||
135 | result = (verbly::notion::wnid == 104451818); // tool | ||
136 | } else { | ||
137 | return {}; | ||
138 | } | ||
139 | |||
140 | std::cout << selrestr.getRestriction() << " (" << selrestr.getPos() << ")" << std::endl; | ||
141 | |||
142 | if (selrestr.getPos()) | ||
143 | { | ||
144 | return (verbly::notion::fullHypernyms %= result); | ||
145 | } else { | ||
146 | return !(verbly::notion::fullHypernyms %= result); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | case verbly::selrestr::type::group: | ||
151 | { | ||
152 | std::cout << "or: " << selrestr.getOrlogic() << std::endl; | ||
153 | verbly::filter ret(selrestr.getOrlogic()); | ||
154 | |||
155 | for (const verbly::selrestr& child : selrestr) | ||
156 | { | ||
157 | ret += parseSelrestrs(child); | ||
158 | } | ||
159 | |||
160 | return ret; | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | |||
165 | bool sentence::requiresSelrestr( | ||
166 | std::string restriction, | ||
167 | verbly::selrestr selrestr) const | ||
168 | { | ||
169 | switch (selrestr.getType()) | ||
170 | { | ||
171 | case verbly::selrestr::type::empty: | ||
172 | { | ||
173 | return false; | ||
174 | } | ||
175 | |||
176 | case verbly::selrestr::type::singleton: | ||
177 | { | ||
178 | if (selrestr.getRestriction() == restriction) | ||
179 | { | ||
180 | return selrestr.getPos(); | ||
181 | } else { | ||
182 | return false; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | case verbly::selrestr::type::group: | ||
187 | { | ||
188 | if (selrestr.getOrlogic()) | ||
189 | { | ||
190 | return std::all_of(std::begin(selrestr), std::end(selrestr), [=] (const verbly::selrestr& s) { | ||
191 | return requiresSelrestr(restriction, s); | ||
192 | }); | ||
193 | } else { | ||
194 | return std::any_of(std::begin(selrestr), std::end(selrestr), [=] (const verbly::selrestr& s) { | ||
195 | return requiresSelrestr(restriction, s); | ||
196 | }); | ||
197 | } | ||
198 | } | 40 | } |
199 | } | 41 | } |
42 | |||
43 | return std::bernoulli_distribution(static_cast<double>(validChoices)/static_cast<double>(selrestrs.size()))(rng_); | ||
200 | } | 44 | } |
201 | 45 | ||
202 | verbly::word sentence::generateStandardNoun( | 46 | verbly::word sentence::generateStandardNoun( |
203 | std::string role, | 47 | std::string role, |
204 | verbly::selrestr selrestrs) const | 48 | std::set<std::string> selrestrs) const |
205 | { | 49 | { |
206 | std::geometric_distribution<int> tagdist(0.5); // 0.06 | 50 | std::geometric_distribution<int> tagdist(0.5); // 0.06 |
207 | std::vector<verbly::word> result; | 51 | std::vector<verbly::word> result; |
@@ -218,11 +62,122 @@ verbly::word sentence::generateStandardNoun( | |||
218 | // Only use selection restrictions for a first attempt. | 62 | // Only use selection restrictions for a first attempt. |
219 | if (trySelection) | 63 | if (trySelection) |
220 | { | 64 | { |
221 | verbly::filter selrestrCondition = parseSelrestrs(selrestrs).compact(); | 65 | verbly::filter selection(true); |
222 | 66 | ||
223 | if (selrestrCondition.getType() != verbly::filter::type::empty) | 67 | for (const std::string& selrestr : selrestrs) |
68 | { | ||
69 | if (selrestr == "concrete") | ||
70 | { | ||
71 | selection += (verbly::notion::wnid == 100001930); // physical entity | ||
72 | } else if (selrestr == "time") | ||
73 | { | ||
74 | selection += (verbly::notion::wnid == 100028270); // time | ||
75 | } else if (selrestr == "state") | ||
76 | { | ||
77 | selection += (verbly::notion::wnid == 100024720); // state | ||
78 | } else if (selrestr == "abstract") | ||
79 | { | ||
80 | selection += (verbly::notion::wnid == 100002137); // abstract entity | ||
81 | } else if (selrestr == "scalar") | ||
82 | { | ||
83 | selection += (verbly::notion::wnid == 103835412); // number | ||
84 | } else if (selrestr == "currency") | ||
85 | { | ||
86 | selection += (verbly::notion::wnid == 105050379); // currency | ||
87 | } else if (selrestr == "location") | ||
88 | { | ||
89 | selection += (verbly::notion::wnid == 100027167); // location | ||
90 | } else if (selrestr == "organization") | ||
91 | { | ||
92 | selection += (verbly::notion::wnid == 100237078); // organization | ||
93 | } else if (selrestr == "int_control") | ||
94 | { | ||
95 | selection += (verbly::notion::wnid == 100007347); // causal agent | ||
96 | } else if (selrestr == "natural") | ||
97 | { | ||
98 | selection += (verbly::notion::wnid == 100019128); // natural object | ||
99 | } else if (selrestr == "phys_obj") | ||
100 | { | ||
101 | selection += (verbly::notion::wnid == 100002684); // physical object | ||
102 | } else if (selrestr == "solid") | ||
103 | { | ||
104 | selection += (verbly::notion::wnid == 113860793); // solid | ||
105 | } else if (selrestr == "shape") | ||
106 | { | ||
107 | selection += (verbly::notion::wnid == 100027807); // shape | ||
108 | } else if (selrestr == "substance") | ||
109 | { | ||
110 | selection += (verbly::notion::wnid == 100019613); // substance | ||
111 | } else if (selrestr == "idea") | ||
112 | { | ||
113 | selection += (verbly::notion::wnid == 105803379); // idea | ||
114 | } else if (selrestr == "sound") | ||
115 | { | ||
116 | selection += (verbly::notion::wnid == 107111047); // sound | ||
117 | } else if (selrestr == "communication") | ||
118 | { | ||
119 | selection += (verbly::notion::wnid == 100033020); // communication | ||
120 | } else if (selrestr == "region") | ||
121 | { | ||
122 | selection += (verbly::notion::wnid == 105221895); // region | ||
123 | } else if (selrestr == "place") | ||
124 | { | ||
125 | selection += (verbly::notion::wnid == 100586262); // place | ||
126 | } else if (selrestr == "machine") | ||
127 | { | ||
128 | selection += (verbly::notion::wnid == 102958343); // machine | ||
129 | } else if (selrestr == "animate") | ||
130 | { | ||
131 | selection += (verbly::notion::wnid == 100004258); // animate thing | ||
132 | } else if (selrestr == "plant") | ||
133 | { | ||
134 | selection += (verbly::notion::wnid == 103956922); // plant | ||
135 | } else if (selrestr == "comestible") | ||
136 | { | ||
137 | selection += (verbly::notion::wnid == 100021265); // food | ||
138 | } else if (selrestr == "artifact") | ||
139 | { | ||
140 | selection += (verbly::notion::wnid == 100021939); // artifact | ||
141 | } else if (selrestr == "vehicle") | ||
142 | { | ||
143 | selection += (verbly::notion::wnid == 104524313); // vehicle | ||
144 | } else if (selrestr == "human") | ||
145 | { | ||
146 | selection += (verbly::notion::wnid == 100007846); // person | ||
147 | } else if (selrestr == "animal") | ||
148 | { | ||
149 | selection += (verbly::notion::wnid == 100015388); // animal | ||
150 | } else if (selrestr == "body_part") | ||
151 | { | ||
152 | selection += (verbly::notion::wnid == 105220461); // body part | ||
153 | } else if (selrestr == "garment") | ||
154 | { | ||
155 | selection += (verbly::notion::wnid == 103051540); // clothing | ||
156 | } else if (selrestr == "tool") | ||
157 | { | ||
158 | selection += (verbly::notion::wnid == 104451818); // tool | ||
159 | } else if ((selrestr == "concrete_inanimate") || (selrestr == "inanimate")) | ||
160 | { | ||
161 | selection += (verbly::notion::wnid == 100021939); // artifact | ||
162 | selection += (verbly::notion::wnid == 100019128); // natural object | ||
163 | } else if (selrestr == "non_region_location") | ||
164 | { | ||
165 | selection += (verbly::notion::wnid == 102913152); // building | ||
166 | } else if (selrestr == "non_solid_food") | ||
167 | { | ||
168 | selection += (verbly::notion::wnid == 107881800); // beverage | ||
169 | } else if (selrestr == "solid_food") | ||
170 | { | ||
171 | selection += (verbly::notion::wnid == 107555863); // solid food | ||
172 | } else if (selrestr == "slinky") | ||
173 | { | ||
174 | selection += (verbly::notion::wnid == 103670849); // line | ||
175 | } | ||
176 | } | ||
177 | |||
178 | if (selection.compact().getType() != verbly::filter::type::empty) | ||
224 | { | 179 | { |
225 | condition &= std::move(selrestrCondition); | 180 | condition &= std::move(selection); |
226 | } else if (role == "Attribute") | 181 | } else if (role == "Attribute") |
227 | { | 182 | { |
228 | condition &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100024264)); // attribute | 183 | condition &= (verbly::notion::fullHypernyms %= (verbly::notion::wnid == 100024264)); // attribute |
@@ -383,7 +338,7 @@ verbly::token sentence::generateClause( | |||
383 | } | 338 | } |
384 | std::cout << std::endl; | 339 | std::cout << std::endl; |
385 | 340 | ||
386 | if (requiresSelrestr("currency", part.getNounSelrestrs())) | 341 | if (chooseSelrestr(part.getNounSelrestrs(), {"currency"})) |
387 | { | 342 | { |
388 | int lead = std::uniform_int_distribution<int>(1,9)(rng_); | 343 | int lead = std::uniform_int_distribution<int>(1,9)(rng_); |
389 | int tail = std::uniform_int_distribution<int>(0,6)(rng_); | 344 | int tail = std::uniform_int_distribution<int>(0,6)(rng_); |
@@ -485,12 +440,8 @@ verbly::token sentence::generateClause( | |||
485 | } else { | 440 | } else { |
486 | verbly::word noun = generateStandardNoun(part.getNounRole(), part.getNounSelrestrs()); | 441 | verbly::word noun = generateStandardNoun(part.getNounRole(), part.getNounSelrestrs()); |
487 | 442 | ||
488 | bool plural = part.nounHasSynrestr("plural"); | 443 | bool plural = part.nounHasSynrestr("plural") || chooseSelrestr(part.getNounSelrestrs(), {"plural", "group"}); |
489 | if (!plural) | 444 | |
490 | { | ||
491 | plural = requiresSelrestr("plural", part.getNounSelrestrs()); | ||
492 | } | ||
493 | |||
494 | utter << generateStandardNounPhrase( | 445 | utter << generateStandardNounPhrase( |
495 | noun, | 446 | noun, |
496 | part.getNounRole(), | 447 | part.getNounRole(), |
diff --git a/sentence.h b/sentence.h index abf6860..02674cf 100644 --- a/sentence.h +++ b/sentence.h | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <verbly.h> | 4 | #include <verbly.h> |
5 | #include <random> | 5 | #include <random> |
6 | #include <string> | 6 | #include <string> |
7 | #include <set> | ||
7 | 8 | ||
8 | class sentence { | 9 | class sentence { |
9 | public: | 10 | public: |
@@ -16,11 +17,9 @@ public: | |||
16 | 17 | ||
17 | private: | 18 | private: |
18 | 19 | ||
19 | verbly::filter parseSelrestrs(verbly::selrestr selrestr) const; | 20 | bool chooseSelrestr(std::set<std::string> selrestrs, std::set<std::string> choices) const; |
20 | 21 | ||
21 | bool requiresSelrestr(std::string restriction, verbly::selrestr selrestr) const; | 22 | verbly::word generateStandardNoun(std::string role, std::set<std::string> selrestrs) const; |
22 | |||
23 | verbly::word generateStandardNoun(std::string role, verbly::selrestr selrestrs) const; | ||
24 | 23 | ||
25 | verbly::token generateStandardNounPhrase( | 24 | verbly::token generateStandardNounPhrase( |
26 | const verbly::word& noun, | 25 | const verbly::word& noun, |
diff --git a/vendor/verbly b/vendor/verbly | |||
Subproject bea3673ae1b3d19585dec56e96dbcd8a56b96e6 | Subproject a3a033c730a2eb4242076f5b34823190aa441cd | ||