praat_gram.cpp 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  1. /* praat_gram.cpp
  2. *
  3. * Copyright (C) 1997-2018 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "Network.h"
  19. #include "OTGrammar.h"
  20. #include "OTMulti.h"
  21. #include "OTGrammarEditor.h"
  22. #include "OTMultiEditor.h"
  23. #include "Net.h"
  24. #include "NoulliGridEditor.h"
  25. #include "praat_TableOfReal.h"
  26. #undef iam
  27. #define iam iam_LOOP
  28. // MARK: - NETWORK
  29. // MARK: New
  30. #define UiForm_addNetworkFields \
  31. LABEL (U"Activity spreading settings:") \
  32. REAL (spreadingRate, U"Spreading rate", U"0.01") \
  33. OPTIONMENU_ENUM (kNetwork_activityClippingRule, activityClippingRule, \
  34. U"Activity clipping rule", kNetwork_activityClippingRule::DEFAULT) \
  35. REAL (minimumActivity, U"left Activity range", U"0.0") \
  36. REAL (maximumActivity, U"right Activity range", U"1.0") \
  37. REAL (activityLeak, U"Activity leak", U"1.0") \
  38. LABEL (U"Weight update settings:") \
  39. REAL (learningRate, U"Learning rate", U"0.1") \
  40. REAL (minimumWeight, U"left Weight range", U"-1.0") \
  41. REAL (maximumWeight, U"right Weight range", U"1.0") \
  42. REAL (weightLeak, U"Weight leak", U"0.0")
  43. FORM (NEW1_Create_empty_Network, U"Create empty Network", nullptr) {
  44. WORD (name, U"Name", U"network")
  45. UiForm_addNetworkFields
  46. LABEL (U"World coordinates:")
  47. REAL (fromX, U"left x range", U"0.0")
  48. REAL (toX, U"right x range", U"10.0")
  49. REAL (fromY, U"left y range", U"0.0")
  50. REAL (toY, U"right y range", U"10.0")
  51. OK
  52. DO
  53. CREATE_ONE
  54. autoNetwork result = Network_create (spreadingRate, activityClippingRule,
  55. minimumActivity, maximumActivity, activityLeak, learningRate, minimumWeight, maximumWeight, weightLeak,
  56. fromX, toX, fromY, toY, 0, 0
  57. );
  58. CREATE_ONE_END (name)
  59. }
  60. FORM (NEW1_Create_rectangular_Network, U"Create rectangular Network", nullptr) {
  61. UiForm_addNetworkFields
  62. LABEL (U"Structure settings:")
  63. NATURAL (numberOfRows, U"Number of rows", U"10")
  64. NATURAL (numberOfColumns, U"Number of columns", U"10")
  65. BOOLEAN (bottomRowClamped, U"Bottom row clamped", 1)
  66. LABEL (U"Initial state settings:")
  67. REAL (minimumInitialWeight, U"left Initial weight range", U"-0.1")
  68. REAL (maximumInitialWeight, U"right Initial weight range", U"0.1")
  69. OK
  70. DO
  71. CREATE_ONE
  72. autoNetwork result = Network_create_rectangle (spreadingRate, activityClippingRule,
  73. minimumActivity, maximumActivity, activityLeak, learningRate, minimumWeight, maximumWeight, weightLeak,
  74. numberOfRows, numberOfColumns, bottomRowClamped, minimumInitialWeight, maximumInitialWeight
  75. );
  76. CREATE_ONE_END (U"rectangle_", numberOfRows, U"_", numberOfColumns)
  77. }
  78. FORM (NEW1_Create_rectangular_Network_vertical, U"Create rectangular Network (vertical)", nullptr) {
  79. UiForm_addNetworkFields
  80. LABEL (U"Structure settings:")
  81. NATURAL (numberOfRows, U"Number of rows", U"10")
  82. NATURAL (numberOfColumns, U"Number of columns", U"10")
  83. BOOLEAN (bottomRowClamped, U"Bottom row clamped", 1)
  84. LABEL (U"Initial state settings:")
  85. REAL (minimumInitialWeight, U"left Initial weight range", U"-0.1")
  86. REAL (maximumInitialWeight, U"right Initial weight range", U"0.1")
  87. OK
  88. DO
  89. CREATE_ONE
  90. autoNetwork result = Network_create_rectangle_vertical (spreadingRate,
  91. (kNetwork_activityClippingRule) activityClippingRule,
  92. minimumActivity, maximumActivity, activityLeak, learningRate, minimumWeight, maximumWeight, weightLeak,
  93. numberOfRows, numberOfColumns, bottomRowClamped, minimumInitialWeight, maximumInitialWeight
  94. );
  95. CREATE_ONE_END (U"rectangle_", numberOfRows, U"_", numberOfColumns)
  96. }
  97. // MARK: Draw
  98. FORM (GRAPHICS_Network_draw, U"Draw Network", nullptr) {
  99. BOOLEAN (useColour, U"Use colour", true)
  100. OK
  101. DO
  102. GRAPHICS_EACH (Network)
  103. Network_draw (me, GRAPHICS, useColour);
  104. GRAPHICS_EACH_END
  105. }
  106. // MARK: Tabulate
  107. FORM (LIST_Network_listNodes, U"Network: List nodes", nullptr) {
  108. INTEGER (fromNodeNumber, U"From node number", U"1")
  109. INTEGER (toNodeNumber, U"To node number", U"1000")
  110. BOOLEAN (includeNodeNumbers, U"Include node numbers", true)
  111. BOOLEAN (includeX, U"Include x", false)
  112. BOOLEAN (includeY, U"Include y", false)
  113. INTEGER (positionDecimals, U"Position decimals", U"6")
  114. BOOLEAN (includeClamped, U"Include clamped", false)
  115. BOOLEAN (includeActivity, U"Include activity", true)
  116. BOOLEAN (includeExcitation, U"Include excitation", false)
  117. INTEGER (activityDecimals, U"Activity decimals", U"6")
  118. OK
  119. DO
  120. INFO_ONE (Network)
  121. Network_listNodes (me, fromNodeNumber, toNodeNumber,
  122. includeNodeNumbers, includeX, includeY, positionDecimals,
  123. includeClamped, includeActivity, includeExcitation, activityDecimals
  124. );
  125. INFO_ONE_END
  126. }
  127. FORM (NEW_Network_nodes_downto_Table, U"Network: Nodes down to Table", nullptr) {
  128. INTEGER (fromNodeNumber, U"From node number", U"1")
  129. INTEGER (toNodeNumber, U"To node number", U"1000")
  130. BOOLEAN (includeNodeNumbers, U"Include node numbers", true)
  131. BOOLEAN (includeX, U"Include x", false)
  132. BOOLEAN (includeY, U"Include y", false)
  133. INTEGER (positionDecimals, U"Position decimals", U"6")
  134. BOOLEAN (includeClamped, U"Include clamped", false)
  135. BOOLEAN (includeActivity, U"Include activity", true)
  136. BOOLEAN (includeExcitation, U"Include excitation", false)
  137. INTEGER (activityDecimals, U"Activity decimals", U"6")
  138. OK
  139. DO
  140. CONVERT_EACH (Network)
  141. autoTable result = Network_nodes_downto_Table (me, fromNodeNumber, toNodeNumber,
  142. includeNodeNumbers, includeX, includeY, positionDecimals,
  143. includeClamped, includeActivity, includeExcitation, activityDecimals
  144. );
  145. CONVERT_EACH_END (my name.get())
  146. }
  147. // MARK: Query
  148. FORM (REAL_Network_getActivity, U"Network: Get activity", nullptr) {
  149. NATURAL (node, U"Node", U"1")
  150. OK
  151. DO
  152. NUMBER_ONE (Network)
  153. double result = Network_getActivity (me, node);
  154. NUMBER_ONE_END (U" (activity of node ", node, U")")
  155. }
  156. FORM (REAL_Network_getWeight, U"Network: Get weight", nullptr) {
  157. NATURAL (connection, U"Connection", U"1")
  158. OK
  159. DO
  160. NUMBER_ONE (Network)
  161. double result = Network_getWeight (me, connection);
  162. NUMBER_ONE_END (U" (weight of connection ", connection, U")")
  163. }
  164. // MARK: Modify
  165. FORM (MODIFY_Network_addConnection, U"Network: Add connection", nullptr) {
  166. NATURAL (fromNode, U"From node", U"1")
  167. NATURAL (toNode, U"To node", U"2")
  168. REAL (weight, U"Weight", U"0.0")
  169. REAL (plasticity, U"Plasticity", U"1.0")
  170. OK
  171. DO
  172. MODIFY_EACH (Network)
  173. Network_addConnection (me, fromNode, toNode, weight, plasticity);
  174. MODIFY_EACH_END
  175. }
  176. FORM (MODIFY_Network_addNode, U"Network: Add node", nullptr) {
  177. REAL (x, U"x", U"5.0")
  178. REAL (y, U"y", U"5.0")
  179. REAL (activity, U"Activity", U"0.0")
  180. BOOLEAN (clamping, U"Clamping", false)
  181. OK
  182. DO
  183. MODIFY_EACH (Network)
  184. Network_addNode (me, x, y, activity, clamping);
  185. MODIFY_EACH_END
  186. }
  187. FORM (MODIFY_Network_normalizeActivities, U"Network: Normalize activities", nullptr) {
  188. INTEGER (fromNode, U"From node", U"1")
  189. INTEGER (toNode, U"To node", U"0 (= all)")
  190. OK
  191. DO
  192. MODIFY_EACH (Network)
  193. Network_normalizeActivities (me, fromNode, toNode);
  194. MODIFY_EACH_END
  195. }
  196. FORM (MODIFY_Network_normalizeWeights, U"Network: Normalize weights", nullptr) {
  197. INTEGER (fromNode, U"From node", U"1")
  198. INTEGER (toNode, U"To node", U"0 (= all)")
  199. INTEGER (fromIncomingNode, U"From incoming node", U"1")
  200. INTEGER (toIncomingNode, U"To incoming node", U"10")
  201. REAL (newSum, U"New sum", U"1.0")
  202. OK
  203. DO
  204. MODIFY_EACH (Network)
  205. Network_normalizeWeights (me, fromNode, toNode, fromIncomingNode, toIncomingNode, newSum);
  206. MODIFY_EACH_END
  207. }
  208. FORM (MODIFY_Network_setActivity, U"Network: Set activity", nullptr) {
  209. NATURAL (node, U"Node", U"1")
  210. REAL (activity, U"Activity", U"1.0")
  211. OK
  212. DO
  213. MODIFY_EACH (Network)
  214. Network_setActivity (me, node, activity);
  215. MODIFY_EACH_END
  216. }
  217. FORM (MODIFY_Network_setActivityClippingRule, U"Network: Set activity clipping rule", nullptr) {
  218. RADIO_ENUM (kNetwork_activityClippingRule, activityClippingRule,
  219. U"Activity clipping rule", kNetwork_activityClippingRule::DEFAULT)
  220. OK
  221. DO
  222. MODIFY_EACH (Network)
  223. Network_setActivityClippingRule (me, activityClippingRule);
  224. MODIFY_EACH_END
  225. }
  226. FORM (MODIFY_Network_setActivityLeak, U"Network: Set activity leak", nullptr) {
  227. REAL (activityLeak, U"Activity leak", U"1.0")
  228. OK
  229. DO
  230. MODIFY_EACH (Network)
  231. Network_setActivityLeak (me, activityLeak);
  232. MODIFY_EACH_END
  233. }
  234. FORM (MODIFY_Network_setClamping, U"Network: Set clamping", nullptr) {
  235. NATURAL (node, U"Node", U"1")
  236. BOOLEAN (clamping, U"Clamping", true)
  237. OK
  238. DO
  239. MODIFY_EACH (Network)
  240. Network_setClamping (me, node, clamping);
  241. MODIFY_EACH_END
  242. }
  243. FORM (MODIFY_Network_setInstar, U"Network: Set instar", nullptr) {
  244. REAL (instar, U"Instar", U"0.0")
  245. OK
  246. DO
  247. MODIFY_EACH (Network)
  248. Network_setInstar (me, instar);
  249. MODIFY_EACH_END
  250. }
  251. FORM (MODIFY_Network_setWeightLeak, U"Network: Set weight leak", nullptr) {
  252. REAL (weightLeak, U"Weight leak", U"0.0")
  253. OK
  254. DO
  255. MODIFY_EACH (Network)
  256. Network_setWeightLeak (me, weightLeak);
  257. MODIFY_EACH_END
  258. }
  259. FORM (MODIFY_Network_setOutstar, U"Network: Set outstar", nullptr) {
  260. REAL (outstar, U"Outstar", U"0.0")
  261. OK
  262. DO
  263. MODIFY_EACH (Network)
  264. Network_setOutstar (me, outstar);
  265. MODIFY_EACH_END
  266. }
  267. FORM (MODIFY_Network_setShunting, U"Network: Set shunting", nullptr) {
  268. REAL (shunting, U"Shunting", U"1.0")
  269. OK
  270. DO
  271. MODIFY_EACH (Network)
  272. Network_setShunting (me, shunting);
  273. MODIFY_EACH_END
  274. }
  275. FORM (MODIFY_Network_setWeight, U"Network: Set weight", nullptr) {
  276. NATURAL (connection, U"Connection", U"1")
  277. REAL (weight, U"Weight", U"1.0")
  278. OK
  279. DO
  280. MODIFY_EACH (Network)
  281. Network_setWeight (me, connection, weight);
  282. MODIFY_EACH_END
  283. }
  284. FORM (MODIFY_Network_spreadActivities, U"Network: Spread activities", nullptr) {
  285. NATURAL (numberOfSteps, U"Number of steps", U"20")
  286. OK
  287. DO
  288. MODIFY_EACH (Network)
  289. Network_spreadActivities (me, numberOfSteps);
  290. MODIFY_EACH_END
  291. }
  292. DIRECT (MODIFY_Network_updateWeights) {
  293. MODIFY_EACH (Network)
  294. Network_updateWeights (me);
  295. MODIFY_EACH_END
  296. }
  297. FORM (MODIFY_Network_zeroActivities, U"Network: Zero activities", nullptr) {
  298. INTEGER (fromNode, U"From node", U"1")
  299. INTEGER (toNode, U"To node", U"0 (= all)")
  300. OK
  301. DO
  302. MODIFY_EACH (Network)
  303. Network_zeroActivities (me, fromNode, toNode);
  304. MODIFY_EACH_END
  305. }
  306. // MARK: - OTGRAMMAR
  307. // MARK: New
  308. DIRECT (HELP_OT_learning_tutorial) {
  309. HELP (U"OT learning")
  310. }
  311. DIRECT (NEW1_Create_NoCoda_grammar) {
  312. CREATE_ONE
  313. autoOTGrammar result = OTGrammar_create_NoCoda_grammar ();
  314. CREATE_ONE_END (U"NoCoda")
  315. }
  316. DIRECT (NEW1_Create_NPA_grammar) {
  317. CREATE_ONE
  318. autoOTGrammar result = OTGrammar_create_NPA_grammar ();
  319. CREATE_ONE_END (U"assimilation")
  320. }
  321. DIRECT (NEW1_Create_NPA_distribution) {
  322. CREATE_ONE
  323. autoPairDistribution result = OTGrammar_create_NPA_distribution ();
  324. CREATE_ONE_END (U"assimilation")
  325. }
  326. FORM (NEW1_Create_tongue_root_grammar, U"Create tongue-root grammar", U"Create tongue-root grammar...") {
  327. RADIO_ENUM (kOTGrammar_createTongueRootGrammar_constraintSet, constraintSet,
  328. U"Constraint set", kOTGrammar_createTongueRootGrammar_constraintSet::DEFAULT)
  329. RADIO_ENUM (kOTGrammar_createTongueRootGrammar_ranking, ranking,
  330. U"Ranking", kOTGrammar_createTongueRootGrammar_ranking::DEFAULT)
  331. OK
  332. DO
  333. CREATE_ONE
  334. autoOTGrammar result = OTGrammar_create_tongueRoot_grammar (constraintSet, ranking);
  335. CREATE_ONE_END (kOTGrammar_createTongueRootGrammar_ranking_getText (ranking))
  336. }
  337. FORM (NEW1_Create_metrics_grammar, U"Create metrics grammar", nullptr) {
  338. OPTIONMENU_ENUM (kOTGrammar_createMetricsGrammar_initialRanking, initialRanking,
  339. U"Initial ranking", kOTGrammar_createMetricsGrammar_initialRanking::DEFAULT)
  340. OPTIONMENU (trochaicityConstraint, U"Trochaicity constraint", 1)
  341. OPTION (U"FtNonfinal")
  342. OPTION (U"Trochaic")
  343. BOOLEAN (includeFootBimoraic, U"Include FootBimoraic", false)
  344. BOOLEAN (includeFootBisyllabic, U"Include FootBisyllabic", false)
  345. BOOLEAN (includePeripheral, U"Include Peripheral", false)
  346. OPTIONMENU (nonfinalityConstraint, U"Nonfinality constraint", 1)
  347. OPTION (U"Nonfinal")
  348. OPTION (U"MainNonfinal")
  349. OPTION (U"HeadNonfinal")
  350. BOOLEAN (overtFormsHaveSecondaryStress, U"Overt forms have secondary stress", true)
  351. BOOLEAN (includeClashAndLapse, U"Include *Clash and *Lapse", false)
  352. BOOLEAN (includeCodas, U"Include codas", false)
  353. OK
  354. DO
  355. CREATE_ONE
  356. autoOTGrammar result = OTGrammar_create_metrics (initialRanking, trochaicityConstraint,
  357. includeFootBimoraic, includeFootBisyllabic, includePeripheral, nonfinalityConstraint,
  358. overtFormsHaveSecondaryStress, includeClashAndLapse, includeCodas);
  359. CREATE_ONE_END (kOTGrammar_createMetricsGrammar_initialRanking_getText (initialRanking))
  360. }
  361. // MARK: Save
  362. FORM_SAVE (SAVE_OTGrammar_writeToHeaderlessSpreadsheetFile, U"Write OTGrammar to spreadsheet", 0, U"txt") {
  363. SAVE_ONE (OTGrammar)
  364. OTGrammar_writeToHeaderlessSpreadsheetFile (me, file);
  365. SAVE_ONE_END
  366. }
  367. // MARK: Help
  368. DIRECT (HELP_OTGrammar_help) {
  369. HELP (U"OTGrammar")
  370. }
  371. // MARK: View & Edit
  372. DIRECT (WINDOW_OTGrammar_viewAndEdit) {
  373. if (theCurrentPraatApplication -> batch) Melder_throw (U"Cannot edit from batch.");
  374. FIND_ONE_WITH_IOBJECT (OTGrammar)
  375. autoOTGrammarEditor editor = OTGrammarEditor_create (ID_AND_FULL_NAME, me);
  376. praat_installEditor (editor.get(), IOBJECT);
  377. editor.releaseToUser();
  378. END
  379. }
  380. // MARK: Draw
  381. FORM (GRAPHICS_OTGrammar_drawTableau, U"Draw tableau", U"OT learning") {
  382. SENTENCE (inputString, U"Input string", U"")
  383. OK
  384. DO
  385. GRAPHICS_EACH (OTGrammar)
  386. OTGrammar_drawTableau (me, GRAPHICS, false, inputString);
  387. GRAPHICS_EACH_END
  388. }
  389. FORM (GRAPHICS_OTGrammar_drawTableau_narrowly, U"Draw tableau (narrowly)", U"OT learning") {
  390. SENTENCE (inputString, U"Input string", U"")
  391. OK
  392. DO
  393. GRAPHICS_EACH (OTGrammar)
  394. OTGrammar_drawTableau (me, GRAPHICS, true, inputString);
  395. GRAPHICS_EACH_END
  396. }
  397. // MARK: Query
  398. DIRECT (INTEGER_OTGrammar_getNumberOfConstraints) {
  399. INTEGER_ONE (OTGrammar)
  400. integer result = my numberOfConstraints;
  401. INTEGER_ONE_END (U" constraints")
  402. }
  403. FORM (STRING_OTGrammar_getConstraint, U"Get constraint name", nullptr) {
  404. NATURAL (constraintNumber, U"Constraint number", U"1")
  405. OK
  406. DO
  407. STRING_ONE (OTGrammar)
  408. if (constraintNumber > my numberOfConstraints)
  409. Melder_throw (U"The specified constraint number should not exceed the number of constraints.");
  410. const conststring32 result = my constraints [constraintNumber]. name.get();
  411. STRING_ONE_END
  412. }
  413. FORM (REAL_OTGrammar_getRankingValue, U"Get ranking value", nullptr) {
  414. NATURAL (constraintNumber, U"Constraint number", U"1")
  415. OK
  416. DO
  417. NUMBER_ONE (OTGrammar)
  418. if (constraintNumber > my numberOfConstraints)
  419. Melder_throw (U"The specified constraint number should not exceed the number of constraints.");
  420. double result = my constraints [constraintNumber]. ranking;
  421. NUMBER_ONE_END (U" (ranking of constraint ", constraintNumber, U")")
  422. }
  423. FORM (REAL_OTGrammar_getDisharmony, U"Get disharmony", nullptr) {
  424. NATURAL (constraintNumber, U"Constraint number", U"1")
  425. OK
  426. DO
  427. NUMBER_ONE (OTGrammar)
  428. if (constraintNumber > my numberOfConstraints)
  429. Melder_throw (U"The specified constraint number should not exceed the number of constraints.");
  430. double result = my constraints [constraintNumber]. disharmony;
  431. NUMBER_ONE_END (U" (disharmony of constraint ", constraintNumber, U")")
  432. }
  433. DIRECT (INTEGER_OTGrammar_getNumberOfTableaus) {
  434. INTEGER_ONE (OTGrammar)
  435. integer result = my numberOfTableaus;
  436. INTEGER_ONE_END (U" tableaus")
  437. }
  438. FORM (STRING_OTGrammar_getInput, U"Get input", nullptr) {
  439. NATURAL (tableauNumber, U"Tableau number", U"1")
  440. OK
  441. DO
  442. STRING_ONE (OTGrammar)
  443. if (tableauNumber > my numberOfTableaus)
  444. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  445. const conststring32 result = my tableaus [tableauNumber]. input.get();
  446. STRING_ONE_END
  447. }
  448. FORM (INTEGER_OTGrammar_getNumberOfCandidates, U"Get number of candidates", nullptr) {
  449. NATURAL (tableauNumber, U"Tableau number", U"1")
  450. OK
  451. DO
  452. NUMBER_ONE (OTGrammar)
  453. if (tableauNumber > my numberOfTableaus)
  454. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  455. integer result = my tableaus [tableauNumber]. numberOfCandidates;
  456. NUMBER_ONE_END (U" candidates in tableau ", tableauNumber)
  457. }
  458. FORM (STRING_OTGrammar_getCandidate, U"Get candidate", nullptr) {
  459. NATURAL (tableauNumber, U"Tableau number", U"1")
  460. NATURAL (candidateNumber, U"Candidate number", U"1")
  461. OK
  462. DO
  463. STRING_ONE (OTGrammar)
  464. if (tableauNumber > my numberOfTableaus)
  465. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  466. OTGrammarTableau tableau = & my tableaus [tableauNumber];
  467. if (candidateNumber > tableau -> numberOfCandidates)
  468. Melder_throw (U"The specified candidate should not exceed the number of candidates.");
  469. const conststring32 result = tableau -> candidates [candidateNumber]. output.get();
  470. STRING_ONE_END
  471. }
  472. FORM (INTEGER_OTGrammar_getNumberOfViolations, U"Get number of violations", nullptr) {
  473. NATURAL (tableauNumber, U"Tableau number", U"1")
  474. NATURAL (candidateNumber, U"Candidate number", U"1")
  475. NATURAL (constraintNumber, U"Constraint number", U"1")
  476. OK
  477. DO
  478. NUMBER_ONE (OTGrammar)
  479. if (tableauNumber > my numberOfTableaus)
  480. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  481. if (candidateNumber > my tableaus [tableauNumber]. numberOfCandidates)
  482. Melder_throw (U"The specified candidate should not exceed the number of candidates.");
  483. if (constraintNumber > my numberOfConstraints)
  484. Melder_throw (U"The specified constraint number should not exceed the number of constraints.");
  485. integer result = my tableaus [tableauNumber]. candidates [candidateNumber]. marks [constraintNumber];
  486. NUMBER_ONE_END (U" violations")
  487. }
  488. // MARK: Query (parse)
  489. FORM (INTEGER_OTGrammar_getWinner, U"Get winner", nullptr) {
  490. NATURAL (tableauNumber, U"Tableau number", U"1")
  491. OK
  492. DO
  493. NUMBER_ONE (OTGrammar)
  494. if (tableauNumber > my numberOfTableaus)
  495. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  496. integer result = OTGrammar_getWinner (me, tableauNumber);
  497. NUMBER_ONE_END (U" (winner in tableau ", tableauNumber, U")")
  498. }
  499. FORM (INTEGER_OTGrammar_compareCandidates, U"Compare candidates", nullptr) {
  500. NATURAL (tableauNumber1, U"Tableau number 1", U"1")
  501. NATURAL (candidateNumber1, U"Candidate number 1", U"1")
  502. NATURAL (tableauNumber2, U"Tableau number 2", U"1")
  503. NATURAL (candidateNumber2, U"Candidate number 2", U"2")
  504. OK
  505. DO
  506. NUMBER_ONE (OTGrammar)
  507. if (tableauNumber1 > my numberOfTableaus)
  508. Melder_throw (U"The specified tableau (number 1) should not exceed the number of tableaus.");
  509. if (candidateNumber1 > my tableaus [tableauNumber1]. numberOfCandidates)
  510. Melder_throw (U"The specified candidate (number 1) should not exceed the number of candidates for this tableau.");
  511. if (tableauNumber2 > my numberOfTableaus)
  512. Melder_throw (U"The specified tableau (number 2) should not exceed the number of tableaus.");
  513. if (candidateNumber2 > my tableaus [tableauNumber2]. numberOfCandidates)
  514. Melder_throw (U"The specified candidate (number 2) should not exceed the number of candidates for this tableau.");
  515. integer result = OTGrammar_compareCandidates (me, tableauNumber1, candidateNumber1, tableauNumber2, candidateNumber2);
  516. NUMBER_ONE_END (result == -1 ? U" (candidate 1 is better)" :
  517. result == +1 ? U" (candidate 2 is better)" : U" (candidates are equally good)")
  518. }
  519. FORM (INTEGER_OTGrammar_getNumberOfOptimalCandidates, U"Get number of optimal candidates", nullptr) {
  520. NATURAL (tableauNumber, U"Tableau number", U"1")
  521. OK
  522. DO
  523. NUMBER_ONE (OTGrammar)
  524. if (tableauNumber > my numberOfTableaus)
  525. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  526. integer result = OTGrammar_getNumberOfOptimalCandidates (me, tableauNumber);
  527. NUMBER_ONE_END (U" optimal candidates in tableau ", tableauNumber)
  528. }
  529. FORM (BOOLEAN_OTGrammar_isCandidateGrammatical, U"Is candidate grammatical?", nullptr) {
  530. NATURAL (tableauNumber, U"Tableau number", U"1")
  531. NATURAL (candidateNumber, U"Candidate number", U"1")
  532. OK
  533. DO
  534. NUMBER_ONE (OTGrammar)
  535. if (tableauNumber > my numberOfTableaus)
  536. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  537. if (candidateNumber > my tableaus [tableauNumber]. numberOfCandidates)
  538. Melder_throw (U"The specified candidate should not exceed the number of candidates.");
  539. integer result = OTGrammar_isCandidateGrammatical (me, tableauNumber, candidateNumber);
  540. NUMBER_ONE_END (result ? U" (grammatical)" : U" (ungrammatical)")
  541. }
  542. FORM (BOOLEAN_OTGrammar_isCandidateSinglyGrammatical, U"Is candidate singly grammatical?", nullptr) {
  543. NATURAL (tableauNumber, U"Tableau number", U"1")
  544. NATURAL (candidateNumber, U"Candidate number", U"1")
  545. OK
  546. DO
  547. NUMBER_ONE (OTGrammar)
  548. if (tableauNumber > my numberOfTableaus)
  549. Melder_throw (U"The specified tableau number should not exceed the number of tableaus.");
  550. if (candidateNumber > my tableaus [tableauNumber]. numberOfCandidates)
  551. Melder_throw (U"The specified candidate should not exceed the number of candidates.");
  552. integer result = OTGrammar_isCandidateSinglyGrammatical (me, tableauNumber, candidateNumber);
  553. NUMBER_ONE_END (result ? U" (singly grammatical)" : U" (not singly grammatical)")
  554. }
  555. FORM (STRING_OTGrammar_getInterpretiveParse, U"OTGrammar: Interpretive parse", nullptr) {
  556. SENTENCE (partialOutput, U"Partial output", U"")
  557. OK
  558. DO
  559. FIND_ONE (OTGrammar)
  560. integer bestInput, bestOutput;
  561. OTGrammar_getInterpretiveParse (me, partialOutput, & bestInput, & bestOutput);
  562. Melder_information (U"Best input = ", bestInput, U": ", my tableaus [bestInput]. input.get(),
  563. U"\nBest output = ", bestOutput, U": ", my tableaus [bestInput]. candidates [bestOutput]. output.get());
  564. END
  565. }
  566. FORM (BOOLEAN_OTGrammar_isPartialOutputGrammatical, U"Is partial output grammatical?", nullptr) {
  567. SENTENCE (partialOutput, U"Partial output", U"")
  568. OK
  569. DO
  570. NUMBER_ONE (OTGrammar)
  571. integer result = OTGrammar_isPartialOutputGrammatical (me, partialOutput);
  572. NUMBER_ONE_END (result ? U" (grammatical)" : U" (ungrammatical)")
  573. }
  574. FORM (BOOLEAN_OTGrammar_isPartialOutputSinglyGrammatical, U"Is partial output singly grammatical?", nullptr) {
  575. SENTENCE (partialOutput, U"Partial output", U"")
  576. OK
  577. DO
  578. NUMBER_ONE (OTGrammar)
  579. integer result = OTGrammar_isPartialOutputSinglyGrammatical (me, partialOutput);
  580. NUMBER_ONE_END (result ? U" (singly grammatical)" : U" (not singly grammatical)")
  581. }
  582. // MARK: -
  583. FORM (NEW_OTGrammar_generateInputs, U"Generate inputs", U"OTGrammar: Generate inputs...") {
  584. NATURAL (numberOfTrials, U"Number of trials", U"1000")
  585. OK
  586. DO
  587. CONVERT_EACH (OTGrammar)
  588. autoStrings result = OTGrammar_generateInputs (me, numberOfTrials);
  589. CONVERT_EACH_END (my name.get(), U"_in")
  590. }
  591. DIRECT (NEW_OTGrammar_getInputs) {
  592. CONVERT_EACH (OTGrammar)
  593. autoStrings result = OTGrammar_getInputs (me);
  594. CONVERT_EACH_END (my name.get(), U"_in")
  595. }
  596. DIRECT (NEW_MODIFY_OTGrammar_measureTypology) {
  597. LOOP try {
  598. iam (OTGrammar);
  599. autoDistributions thee = OTGrammar_measureTypology_WEAK (me);
  600. praat_new (std::move (thee), my name.get(), U"_out");
  601. praat_dataChanged (me);
  602. } catch (MelderError) {
  603. praat_dataChanged (OBJECT);
  604. throw;
  605. }
  606. END }
  607. // MARK: Evaluate
  608. FORM (MODIFY_OTGrammar_evaluate, U"OTGrammar: Evaluate", nullptr) {
  609. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  610. OK
  611. DO
  612. MODIFY_EACH (OTGrammar)
  613. OTGrammar_newDisharmonies (me, evaluationNoise);
  614. MODIFY_EACH_END
  615. }
  616. FORM (STRING_MODIFY_OTGrammar_inputToOutput, U"OTGrammar: Input to output", U"OTGrammar: Input to output...") {
  617. SENTENCE (inputForm, U"Input form", U"")
  618. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  619. OK
  620. DO
  621. FIND_ONE (OTGrammar)
  622. autostring32 output = OTGrammar_inputToOutput (me, inputForm, evaluationNoise);
  623. Melder_information (output.get());
  624. praat_dataChanged (me);
  625. END
  626. }
  627. FORM (NEW1_MODIFY_OTGrammar_inputToOutputs, U"OTGrammar: Input to outputs", U"OTGrammar: Input to outputs...") {
  628. NATURAL (trials, U"Trials", U"1000")
  629. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  630. SENTENCE (inputForm, U"Input form", U"")
  631. OK
  632. DO
  633. FIND_ONE (OTGrammar)
  634. autoStrings thee = OTGrammar_inputToOutputs (me, inputForm, trials, evaluationNoise);
  635. praat_new (thee.move(), my name.get(), U"_out");
  636. praat_dataChanged (me);
  637. END
  638. }
  639. FORM (NEW_MODIFY_OTGrammar_to_Distributions, U"OTGrammar: Compute output distributions", U"OTGrammar: To output Distributions...") {
  640. NATURAL (trialsPerInput, U"Trials per input", U"100000")
  641. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  642. OK
  643. DO
  644. LOOP {
  645. iam (OTGrammar);
  646. try {
  647. autoDistributions thee = OTGrammar_to_Distribution (me, trialsPerInput, evaluationNoise);
  648. praat_new (thee.move(), my name.get(), U"_out");
  649. praat_dataChanged (me);
  650. } catch (MelderError) {
  651. praat_dataChanged (me);
  652. throw;
  653. }
  654. }
  655. END }
  656. FORM (NEW_MODIFY_OTGrammar_to_PairDistribution, U"OTGrammar: Compute output distributions", nullptr) {
  657. NATURAL (trialsPerInput, U"Trials per input", U"100000")
  658. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  659. OK
  660. DO
  661. LOOP try {
  662. iam (OTGrammar);
  663. autoPairDistribution thee = OTGrammar_to_PairDistribution (me, trialsPerInput, evaluationNoise);
  664. praat_new (thee.move(), my name.get(), U"_out");
  665. praat_dataChanged (me);
  666. } catch (MelderError) {
  667. praat_dataChanged (OBJECT);
  668. throw;
  669. }
  670. END }
  671. // MARK: Modify ranking
  672. FORM (MODIFY_OTGrammar_setRanking, U"OTGrammar: Set ranking", nullptr) {
  673. NATURAL (constraintNumber, U"Constraint number", U"1")
  674. REAL (ranking, U"Ranking", U"100.0")
  675. REAL (disharmony, U"Disharmony", U"100.0")
  676. OK
  677. DO
  678. MODIFY_EACH (OTGrammar)
  679. OTGrammar_setRanking (me, constraintNumber, ranking, disharmony);
  680. MODIFY_EACH_END
  681. }
  682. FORM (MODIFY_OTGrammar_resetAllRankings, U"OTGrammar: Reset all rankings", nullptr) {
  683. REAL (ranking, U"Ranking", U"100.0")
  684. OK
  685. DO
  686. MODIFY_EACH (OTGrammar)
  687. OTGrammar_reset (me, ranking);
  688. MODIFY_EACH_END
  689. }
  690. FORM (MODIFY_OTGrammar_resetToRandomRanking, U"OTGrammar: Reset to random ranking", nullptr) {
  691. REAL (mean, U"Mean", U"10.0")
  692. POSITIVE (standardDeviation, U"Standard deviation", U"1e-4")
  693. OK
  694. DO
  695. MODIFY_EACH (OTGrammar)
  696. OTGrammar_resetToRandomRanking (me, mean, standardDeviation);
  697. MODIFY_EACH_END
  698. }
  699. FORM (MODIFY_OTGrammar_resetToRandomTotalRanking, U"OTGrammar: Reset to random total ranking", nullptr) {
  700. REAL (maximumRanking, U"Maximum ranking", U"100.0")
  701. POSITIVE (rankingDistance, U"Ranking distance", U"1.0")
  702. OK
  703. DO
  704. MODIFY_EACH (OTGrammar)
  705. OTGrammar_resetToRandomTotalRanking (me, maximumRanking, rankingDistance);
  706. MODIFY_EACH_END
  707. }
  708. FORM (MODIFY_OTGrammar_learnOne, U"OTGrammar: Learn one", U"OTGrammar: Learn one...") {
  709. SENTENCE (inputString, U"Input string", U"")
  710. SENTENCE (outputString, U"Output string", U"")
  711. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  712. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  713. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  714. REAL (plasticity, U"Plasticity", U"0.1")
  715. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  716. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  717. OK
  718. DO
  719. MODIFY_EACH_WEAK (OTGrammar)
  720. OTGrammar_learnOne (me, inputString, outputString, evaluationNoise, updateRule, honourLocalRankings,
  721. plasticity, relativePlasticitySpreading, true, true, nullptr);
  722. MODIFY_EACH_WEAK_END
  723. }
  724. FORM (MODIFY_OTGrammar_learnOneFromPartialOutput, U"OTGrammar: Learn one from partial adult output", nullptr) {
  725. LABEL (U"Partial adult surface form (e.g. overt form):")
  726. SENTENCE (partialOutput, U"Partial output", U"")
  727. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  728. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  729. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  730. REAL (plasticity, U"Plasticity", U"0.1")
  731. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  732. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  733. NATURAL (numberOfChews, U"Number of chews", U"1")
  734. OK
  735. DO
  736. MODIFY_EACH_WEAK (OTGrammar)
  737. OTGrammar_learnOneFromPartialOutput (me, partialOutput, evaluationNoise, updateRule, honourLocalRankings,
  738. plasticity, relativePlasticitySpreading, numberOfChews, true);
  739. MODIFY_EACH_WEAK_END
  740. }
  741. // MARK: Modify behaviour
  742. FORM (MODIFY_OTGrammar_setDecisionStrategy, U"OTGrammar: Set decision strategy", nullptr) {
  743. RADIO_ENUM (kOTGrammar_decisionStrategy, decisionStrategy,
  744. U"Decision strategy", kOTGrammar_decisionStrategy::DEFAULT)
  745. OK
  746. FIND_ONE (OTGrammar)
  747. SET_ENUM (decisionStrategy, kOTGrammar_decisionStrategy, my decisionStrategy);
  748. DO
  749. MODIFY_EACH (OTGrammar)
  750. my decisionStrategy = decisionStrategy;
  751. MODIFY_EACH_END
  752. }
  753. FORM (MODIFY_OTGrammar_setLeak, U"OTGrammar: Set leak", nullptr) {
  754. REAL (leak, U"Leak", U"0.0")
  755. OK
  756. FIND_ONE (OTGrammar)
  757. SET_REAL (leak, my leak)
  758. DO
  759. MODIFY_EACH (OTGrammar)
  760. my leak = leak;
  761. MODIFY_EACH_END
  762. }
  763. FORM (MODIFY_OTGrammar_setConstraintPlasticity, U"OTGrammar: Set constraint plasticity", nullptr) {
  764. NATURAL (constraint, U"Constraint", U"1")
  765. REAL (plasticity, U"Plasticity", U"1.0")
  766. OK
  767. DO
  768. MODIFY_EACH (OTGrammar)
  769. OTGrammar_setConstraintPlasticity (me, constraint, plasticity);
  770. MODIFY_EACH_END
  771. }
  772. // MARK: Modify structure
  773. FORM (MODIFY_OTGrammar_removeConstraint, U"OTGrammar: Remove constraint", nullptr) {
  774. SENTENCE (constraintName, U"Constraint name", U"")
  775. OK
  776. DO
  777. MODIFY_EACH (OTGrammar)
  778. OTGrammar_removeConstraint (me, constraintName);
  779. MODIFY_EACH_END
  780. }
  781. FORM (MODIFY_OTGrammar_removeHarmonicallyBoundedCandidates, U"OTGrammar: Remove harmonically bounded candidates", nullptr) {
  782. BOOLEAN (singly, U"Singly", false)
  783. OK
  784. DO
  785. MODIFY_EACH (OTGrammar)
  786. OTGrammar_removeHarmonicallyBoundedCandidates (me, singly);
  787. MODIFY_EACH_END
  788. }
  789. // MARK: OTGRAMMAR & STRINGS
  790. FORM (NEW1_MODIFY_OTGrammar_Strings_inputsToOutputs, U"OTGrammar: Inputs to outputs", U"OTGrammar: Inputs to outputs...") {
  791. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  792. OK
  793. DO
  794. FIND_TWO (OTGrammar, Strings)
  795. autoStrings result = OTGrammar_inputsToOutputs (me, you, evaluationNoise);
  796. praat_new (result.move(), my name.get(), U"_out");
  797. praat_dataChanged (me);
  798. END
  799. }
  800. DIRECT (BOOLEAN_OTGrammar_Strings_areAllPartialOutputsGrammatical) {
  801. NUMBER_TWO (OTGrammar, Strings)
  802. integer result = OTGrammar_areAllPartialOutputsGrammatical (me, you);
  803. NUMBER_TWO_END (result ? U" (all grammatical)" : U" (not all grammatical)")
  804. }
  805. DIRECT (BOOLEAN_OTGrammar_Strings_areAllPartialOutputsSinglyGrammatical) {
  806. NUMBER_TWO (OTGrammar, Strings)
  807. integer result = OTGrammar_areAllPartialOutputsSinglyGrammatical (me, you);
  808. NUMBER_TWO_END (result ? U" (all singly grammatical)" : U" (not all singly grammatical)")
  809. }
  810. FORM (MODIFY_OTGrammar_Stringses_learn, U"OTGrammar: Learn", U"OTGrammar & 2 Strings: Learn...") {
  811. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  812. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  813. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  814. REAL (plasticity, U"Plasticity", U"0.1")
  815. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  816. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  817. NATURAL (numberOfChews, U"Number of chews", U"1")
  818. OK
  819. DO
  820. MODIFY_FIRST_OF_ONE_AND_COUPLE_WEAK (OTGrammar, Strings)
  821. OTGrammar_learn (me, you, him, evaluationNoise, updateRule, honourLocalRankings,
  822. plasticity, relativePlasticitySpreading, numberOfChews);
  823. MODIFY_FIRST_OF_ONE_AND_COUPLE_WEAK_END
  824. }
  825. FORM (MODIFY_OTGrammar_Strings_learnFromPartialOutputs, U"OTGrammar: Learn from partial adult outputs", nullptr) {
  826. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  827. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  828. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  829. REAL (plasticity, U"Plasticity", U"0.1")
  830. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  831. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  832. NATURAL (numberOfChews, U"Number of chews", U"1")
  833. INTEGER (storeHistoryEvery, U"Store history every", U"0")
  834. OK
  835. DO
  836. FIND_TWO (OTGrammar, Strings)
  837. autoOTHistory history;
  838. try {
  839. OTGrammar_learnFromPartialOutputs (me, you, evaluationNoise, updateRule, honourLocalRankings,
  840. plasticity, relativePlasticitySpreading, numberOfChews, storeHistoryEvery, & history);
  841. praat_dataChanged (me);
  842. } catch (MelderError) {
  843. praat_dataChanged (me); // e.g. in case of partial learning
  844. Melder_flushError ();
  845. // trickle down to save history
  846. }
  847. if (history) praat_new (history.move(), my name.get());
  848. END
  849. }
  850. // MARK: OTGRAMMAR & DISTRIBUTIONS
  851. FORM (REAL_MODIFY_OTGrammar_Distributions_getFractionCorrect, U"OTGrammar & Distributions: Get fraction correct...", nullptr) {
  852. NATURAL (columnNumber, U"Column number", U"1")
  853. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  854. INTEGER (replications, U"Replications", U"100000")
  855. OK
  856. DO
  857. FIND_TWO (OTGrammar, Distributions)
  858. double result = OTGrammar_Distributions_getFractionCorrect (me, you, columnNumber,
  859. evaluationNoise, replications);
  860. praat_dataChanged (me);
  861. Melder_informationReal (result, nullptr);
  862. END
  863. }
  864. FORM (MODIFY_OTGrammar_Distributions_learnFromPartialOutputs, U"OTGrammar & Distributions: Learn from partial outputs", U"OT learning 6. Shortcut to grammar learning") {
  865. NATURAL (columnNumber, U"Column number", U"1")
  866. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  867. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  868. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  869. REAL (initialPlasticity, U"Initial plasticity", U"1.0")
  870. NATURAL (replicationsPerPlasticity, U"Replications per plasticity", U"100000")
  871. REAL (plasticityDecrement, U"Plasticity decrement", U"0.1")
  872. NATURAL (numberOfPlasticities, U"Number of plasticities", U"4")
  873. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  874. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  875. NATURAL (numberOfChews, U"Number of chews", U"1")
  876. INTEGER (storeHistoryEvery, U"Store history every", U"0")
  877. OK
  878. DO
  879. FIND_TWO (OTGrammar, Distributions)
  880. autoOTHistory history;
  881. try {
  882. OTGrammar_Distributions_learnFromPartialOutputs (me, you, columnNumber, evaluationNoise,
  883. updateRule, honourLocalRankings,
  884. initialPlasticity, replicationsPerPlasticity, plasticityDecrement, numberOfPlasticities,
  885. relativePlasticitySpreading, numberOfChews, storeHistoryEvery, & history, false, false, 0
  886. );
  887. praat_dataChanged (me);
  888. } catch (MelderError) {
  889. praat_dataChanged (me);
  890. Melder_flushError ();
  891. }
  892. if (history)
  893. praat_new (history.move(), my name.get());
  894. END
  895. }
  896. FORM (MODIFY_OTGrammar_Distributions_learnFromPartialOutputs_rrip, U"OTGrammar & Distributions: Learn from partial outputs (rrip)", U"OT learning 6. Shortcut to grammar learning") {
  897. NATURAL (columnNumber, U"Column number", U"1")
  898. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  899. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  900. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  901. REAL (initialPlasticity, U"Initial plasticity", U"1.0")
  902. NATURAL (replicationsPerPlasticity, U"Replications per plasticity", U"100000")
  903. REAL (plasticityDecrement, U"Plasticity decrement", U"0.1")
  904. NATURAL (numberOfPlasticities, U"Number of plasticities", U"4")
  905. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  906. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  907. NATURAL (numberOfChews, U"Number of chews", U"1")
  908. INTEGER (storeHistoryEvery, U"Store history every", U"0")
  909. OK
  910. DO
  911. FIND_TWO (OTGrammar, Distributions)
  912. autoOTHistory history;
  913. try {
  914. OTGrammar_Distributions_learnFromPartialOutputs (me, you, columnNumber, evaluationNoise,
  915. updateRule, honourLocalRankings,
  916. initialPlasticity, replicationsPerPlasticity, plasticityDecrement, numberOfPlasticities,
  917. relativePlasticitySpreading, numberOfChews, storeHistoryEvery, & history, true, true, 0
  918. );
  919. praat_dataChanged (me);
  920. } catch (MelderError) {
  921. praat_dataChanged (me);
  922. Melder_flushError ();
  923. }
  924. if (history)
  925. praat_new (history.move(), my name.get());
  926. END
  927. }
  928. FORM (MODIFY_OTGrammar_Distributions_learnFromPartialOutputs_eip, U"OTGrammar & Distributions: Learn from partial outputs (eip)", U"OT learning 6. Shortcut to grammar learning") {
  929. NATURAL (columnNumber, U"Column number", U"1")
  930. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  931. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  932. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  933. REAL (initialPlasticity, U"Initial plasticity", U"1.0")
  934. NATURAL (replicationsPerPlasticity, U"Replications per plasticity", U"100000")
  935. REAL (plasticityDecrement, U"Plasticity decrement", U"0.1")
  936. NATURAL (numberOfPlasticities, U"Number of plasticities", U"4")
  937. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  938. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  939. NATURAL (numberOfChews, U"Number of chews", U"1")
  940. INTEGER (storeHistoryEvery, U"Store history every", U"0")
  941. OK
  942. DO
  943. FIND_TWO (OTGrammar, Distributions)
  944. autoOTHistory history;
  945. try {
  946. OTGrammar_Distributions_learnFromPartialOutputs (me, you, columnNumber, evaluationNoise,
  947. updateRule, honourLocalRankings,
  948. initialPlasticity, replicationsPerPlasticity, plasticityDecrement, numberOfPlasticities,
  949. relativePlasticitySpreading, numberOfChews, storeHistoryEvery, & history, true, true, 1000
  950. );
  951. praat_dataChanged (me);
  952. } catch (MelderError) {
  953. praat_dataChanged (me);
  954. Melder_flushError ();
  955. }
  956. if (history)
  957. praat_new (history.move(), my name.get());
  958. END
  959. }
  960. FORM (MODIFY_OTGrammar_Distributions_learnFromPartialOutputs_wrip, U"OTGrammar & Distributions: Learn from partial outputs (wrip)", U"OT learning 6. Shortcut to grammar learning") {
  961. NATURAL (columnNumber, U"Column number", U"1")
  962. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  963. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  964. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  965. REAL (initialPlasticity, U"Initial plasticity", U"1.0")
  966. NATURAL (replicationsPerPlasticity, U"Replications per plasticity", U"100000")
  967. REAL (plasticityDecrement, U"Plasticity decrement", U"0.1")
  968. NATURAL (numberOfPlasticities, U"Number of plasticities", U"4")
  969. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  970. BOOLEAN (honourLocalRankings, U"Honour local rankings", 1)
  971. NATURAL (numberOfChews, U"Number of chews", U"1")
  972. INTEGER (storeHistoryEvery, U"Store history every", U"0")
  973. OK
  974. DO
  975. FIND_TWO (OTGrammar, Distributions)
  976. autoOTHistory history;
  977. try {
  978. OTGrammar_Distributions_learnFromPartialOutputs (me, you, columnNumber, evaluationNoise,
  979. updateRule, honourLocalRankings,
  980. initialPlasticity, replicationsPerPlasticity, plasticityDecrement, numberOfPlasticities,
  981. relativePlasticitySpreading, numberOfChews, storeHistoryEvery, & history, true, true, 1
  982. );
  983. praat_dataChanged (me);
  984. } catch (MelderError) {
  985. praat_dataChanged (me);
  986. Melder_flushError ();
  987. }
  988. if (history)
  989. praat_new (history.move(), my name.get());
  990. END
  991. }
  992. FORM (LIST_OTGrammar_Distributions_listObligatoryRankings, U"OTGrammar & Distributions: Get fraction correct...", nullptr) {
  993. NATURAL (columnNumber, U"Column number", U"1")
  994. OK
  995. DO
  996. INFO_TWO (OTGrammar, Distributions)
  997. OTGrammar_Distributions_listObligatoryRankings (me, you, columnNumber);
  998. INFO_TWO_END
  999. }
  1000. // MARK: OTGRAMMAR & PAIRDISTRIBUTION
  1001. FORM (MODIFY_OTGrammar_PairDistribution_findPositiveWeights, U"OTGrammar & PairDistribution: Find positive weights", U"OTGrammar & PairDistribution: Find positive weights...") {
  1002. POSITIVE (weightFloor, U"Weight floor", U"1.0")
  1003. POSITIVE (marginOfSeparation, U"Margin of separation", U"1.0")
  1004. OK
  1005. DO
  1006. MODIFY_FIRST_OF_TWO (OTGrammar, PairDistribution)
  1007. OTGrammar_PairDistribution_findPositiveWeights (me, you, weightFloor, marginOfSeparation);
  1008. MODIFY_FIRST_OF_TWO_END
  1009. }
  1010. FORM (REAL_MODIFY_OTGrammar_PairDistribution_getFractionCorrect, U"OTGrammar & PairDistribution: Get fraction correct...", nullptr) {
  1011. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1012. INTEGER (replications, U"Replications", U"100000")
  1013. OK
  1014. DO
  1015. FIND_TWO (OTGrammar, PairDistribution)
  1016. double result;
  1017. try {
  1018. result = OTGrammar_PairDistribution_getFractionCorrect (me, you, evaluationNoise, replications);
  1019. praat_dataChanged (me);
  1020. } catch (MelderError) {
  1021. praat_dataChanged (me);
  1022. throw;
  1023. }
  1024. Melder_information (result, U" correct");
  1025. END
  1026. }
  1027. FORM (INTEGER_MODIFY_OTGrammar_PairDistribution_getMinimumNumberCorrect, U"OTGrammar & PairDistribution: Get minimum number correct...", nullptr) {
  1028. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1029. INTEGER (replicationsPerInput, U"Replications per input", U"1000")
  1030. OK
  1031. DO
  1032. FIND_TWO (OTGrammar, PairDistribution)
  1033. integer result;
  1034. try {
  1035. result = OTGrammar_PairDistribution_getMinimumNumberCorrect (me, you,
  1036. evaluationNoise, replicationsPerInput);
  1037. praat_dataChanged (me);
  1038. } catch (MelderError) {
  1039. praat_dataChanged (me);
  1040. throw;
  1041. }
  1042. Melder_information (result, U" (minimally correct)");
  1043. END
  1044. }
  1045. FORM (MODIFY_OTGrammar_PairDistribution_learn, U"OTGrammar & PairDistribution: Learn", U"OT learning 6. Shortcut to grammar learning") {
  1046. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1047. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  1048. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  1049. POSITIVE (initialPlasticity, U"Initial plasticity", U"1.0")
  1050. NATURAL (replicationsPerPlasticity, U"Replications per plasticity", U"100000")
  1051. REAL (plasticityDecrement, U"Plasticity decrement", U"0.1")
  1052. NATURAL (numberOfPlasticities, U"Number of plasticities", U"4")
  1053. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  1054. BOOLEAN (honourLocalRankings, U"Honour local rankings", true)
  1055. NATURAL (numberOfChews, U"Number of chews", U"1")
  1056. OK
  1057. DO
  1058. MODIFY_FIRST_OF_TWO_WEAK (OTGrammar, PairDistribution)
  1059. OTGrammar_PairDistribution_learn (me, you,
  1060. evaluationNoise, updateRule, honourLocalRankings,
  1061. initialPlasticity, replicationsPerPlasticity,
  1062. plasticityDecrement, numberOfPlasticities, relativePlasticitySpreading, numberOfChews);
  1063. MODIFY_FIRST_OF_TWO_WEAK_END
  1064. }
  1065. DIRECT (LIST_OTGrammar_PairDistribution_listObligatoryRankings) {
  1066. FIND_TWO (OTGrammar, PairDistribution)
  1067. OTGrammar_PairDistribution_listObligatoryRankings (me, you);
  1068. END
  1069. }
  1070. // MARK: - OTMULTI
  1071. // MARK: New
  1072. FORM (NEW1_Create_multi_level_metrics_grammar, U"Create multi-level metrics grammar", nullptr) {
  1073. OPTIONMENU_ENUM (kOTGrammar_createMetricsGrammar_initialRanking, initialRanking,
  1074. U"Initial ranking", kOTGrammar_createMetricsGrammar_initialRanking::DEFAULT)
  1075. OPTIONMENU (trochaicityConstraint, U"Trochaicity constraint", 1)
  1076. OPTION (U"FtNonfinal")
  1077. OPTION (U"Trochaic")
  1078. BOOLEAN (includeFootBimoraic, U"Include FootBimoraic", false)
  1079. BOOLEAN (includeFootBisyllabic, U"Include FootBisyllabic", false)
  1080. BOOLEAN (includePeripheral, U"Include Peripheral", false)
  1081. OPTIONMENU (nonfinalityConstraint, U"Nonfinality constraint", 1)
  1082. OPTION (U"Nonfinal")
  1083. OPTION (U"MainNonfinal")
  1084. OPTION (U"HeadNonfinal")
  1085. BOOLEAN (overtFormsHaveSecondaryStress, U"Overt forms have secondary stress", true)
  1086. BOOLEAN (includeClashAndLapse, U"Include *Clash and *Lapse", false)
  1087. BOOLEAN (includeCodas, U"Include codas", false)
  1088. OK
  1089. DO
  1090. CREATE_ONE
  1091. autoOTMulti result = OTMulti_create_metrics (initialRanking, trochaicityConstraint,
  1092. includeFootBimoraic, includeFootBisyllabic, includePeripheral, nonfinalityConstraint,
  1093. overtFormsHaveSecondaryStress, includeClashAndLapse, includeCodas);
  1094. CREATE_ONE_END (kOTGrammar_createMetricsGrammar_initialRanking_getText (initialRanking))
  1095. }
  1096. // MARK: Draw
  1097. FORM (GRAPHICS_OTMulti_drawTableau, U"Draw tableau", U"OT learning") {
  1098. SENTENCE (partialForm1, U"Partial form 1", U"")
  1099. SENTENCE (partialForm2, U"Partial form 2", U"")
  1100. BOOLEAN (showDisharmonies, U"Show disharmonies", true)
  1101. OK
  1102. DO
  1103. GRAPHICS_EACH (OTMulti)
  1104. OTMulti_drawTableau (me, GRAPHICS, partialForm1, partialForm2, false, showDisharmonies);
  1105. GRAPHICS_EACH_END
  1106. }
  1107. FORM (GRAPHICS_OTMulti_drawTableau_narrowly, U"Draw tableau (narrowly)", U"OT learning") {
  1108. SENTENCE (partialForm1, U"Partial form 1", U"")
  1109. SENTENCE (partialForm2, U"Partial form 2", U"")
  1110. BOOLEAN (showDisharmonies, U"Show disharmonies", true)
  1111. OK
  1112. DO
  1113. GRAPHICS_EACH (OTMulti)
  1114. OTMulti_drawTableau (me, GRAPHICS, partialForm1, partialForm2, true, showDisharmonies);
  1115. GRAPHICS_EACH_END
  1116. }
  1117. // MARK: View & Edit
  1118. DIRECT (WINDOW_OTMulti_viewAndEdit) {
  1119. if (theCurrentPraatApplication -> batch) Melder_throw (U"Cannot edit an OTMulti from batch.");
  1120. FIND_ONE_WITH_IOBJECT (OTMulti)
  1121. autoOTMultiEditor editor = OTMultiEditor_create (ID_AND_FULL_NAME, me);
  1122. praat_installEditor (editor.get(), IOBJECT);
  1123. editor.releaseToUser();
  1124. END
  1125. }
  1126. // MARK: Query
  1127. DIRECT (INTEGER_OTMulti_getNumberOfConstraints) {
  1128. NUMBER_ONE (OTMulti)
  1129. integer result = my numberOfConstraints;
  1130. NUMBER_ONE_END (U" constraints")
  1131. }
  1132. FORM (STRING_OTMulti_getConstraint, U"Get constraint name", nullptr) {
  1133. NATURAL (constraintNumber, U"Constraint number", U"1")
  1134. OK
  1135. DO
  1136. STRING_ONE (OTMulti)
  1137. if (constraintNumber > my numberOfConstraints)
  1138. Melder_throw (U"Your constraint number should not exceed the number of constraints.");
  1139. const conststring32 result = my constraints [constraintNumber]. name.get();
  1140. STRING_ONE_END
  1141. }
  1142. FORM (INTEGER_OTMulti_getConstraintIndexFromName, U"OTMulti: Get constraint number", nullptr) {
  1143. SENTENCE (constraintName, U"Constraint name", U"")
  1144. OK
  1145. DO
  1146. NUMBER_ONE (OTMulti)
  1147. integer result = OTMulti_getConstraintIndexFromName (me, constraintName);
  1148. NUMBER_ONE_END (U" (index of constraint ", constraintName, U")")
  1149. }
  1150. FORM (REAL_OTMulti_getRankingValue, U"Get ranking value", nullptr) {
  1151. NATURAL (constraintNumber, U"Constraint number", U"1")
  1152. OK
  1153. DO
  1154. NUMBER_ONE (OTMulti)
  1155. if (constraintNumber > my numberOfConstraints)
  1156. Melder_throw (U"Your constraint number should not exceed the number of constraints.");
  1157. double result = my constraints [constraintNumber]. ranking;
  1158. NUMBER_ONE_END (U" (ranking of constraint ", constraintNumber, U")")
  1159. }
  1160. FORM (REAL_OTMulti_getDisharmony, U"Get disharmony", nullptr) {
  1161. NATURAL (constraintNumber, U"Constraint number", U"1")
  1162. OK
  1163. DO
  1164. NUMBER_ONE (OTMulti)
  1165. if (constraintNumber > my numberOfConstraints)
  1166. Melder_throw (U"Your constraint number should not exceed the number of constraints.");
  1167. double result = my constraints [constraintNumber]. disharmony;
  1168. NUMBER_ONE_END (U" (disharmony of constraint ", constraintNumber, U")")
  1169. }
  1170. DIRECT (INTEGER_OTMulti_getNumberOfCandidates) {
  1171. NUMBER_ONE (OTMulti)
  1172. integer result = my numberOfCandidates;
  1173. NUMBER_ONE_END (U" candidates")
  1174. }
  1175. FORM (STRING_OTMulti_getCandidate, U"Get candidate", nullptr) {
  1176. NATURAL (candidateNumber, U"Candidate number", U"1")
  1177. OK
  1178. DO
  1179. STRING_ONE (OTMulti)
  1180. if (candidateNumber > my numberOfCandidates)
  1181. Melder_throw (U"Your candidate number should not exceed the number of candidates.");
  1182. const conststring32 result = my candidates [candidateNumber]. string.get();
  1183. STRING_ONE_END
  1184. }
  1185. FORM (INTEGER_OTMulti_getNumberOfViolations, U"Get number of violations", nullptr) {
  1186. NATURAL (candidateNumber, U"Candidate number", U"1")
  1187. NATURAL (constraintNumber, U"Constraint number", U"1")
  1188. OK
  1189. DO
  1190. NUMBER_ONE (OTMulti)
  1191. if (candidateNumber > my numberOfCandidates)
  1192. Melder_throw (U"Your candidate number should not exceed the number of candidates.");
  1193. if (constraintNumber > my numberOfConstraints)
  1194. Melder_throw (U"Your constraint number should not exceed the number of constraints.");
  1195. integer result = my candidates [candidateNumber]. marks [constraintNumber];
  1196. NUMBER_ONE_END (U" violations")
  1197. }
  1198. FORM (INTEGER_OTMulti_getWinner, U"OTMulti: Get winner", nullptr) {
  1199. SENTENCE (partialForm1, U"Partial form 1", U"")
  1200. SENTENCE (partialForm2, U"Partial form 2", U"")
  1201. OK
  1202. DO
  1203. NUMBER_ONE (OTMulti)
  1204. integer result = OTMulti_getWinner (me, partialForm1, partialForm2);
  1205. NUMBER_ONE_END (U" (winner)")
  1206. }
  1207. // MARK: Evaluate
  1208. FORM (MODIFY_OTMulti_evaluate, U"OTMulti: Evaluate", nullptr) {
  1209. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1210. OK
  1211. DO
  1212. MODIFY_EACH (OTMulti)
  1213. OTMulti_newDisharmonies (me, evaluationNoise);
  1214. MODIFY_EACH_END
  1215. }
  1216. FORM (STRING_MODIFY_OTMulti_generateOptimalForm, U"OTMulti: Generate optimal form", nullptr) {
  1217. SENTENCE (partialForm1, U"Partial form 1", U"")
  1218. SENTENCE (partialForm2, U"Partial form 2", U"")
  1219. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1220. OK
  1221. DO
  1222. FIND_ONE (OTMulti)
  1223. autostring32 output = OTMulti_generateOptimalForm (me, partialForm1, partialForm2, evaluationNoise);
  1224. Melder_information (output.get());
  1225. praat_dataChanged (me);
  1226. END
  1227. }
  1228. FORM (NEW1_MODIFY_OTMulti_generateOptimalForms, U"OTMulti: Generate optimal forms", nullptr) {
  1229. SENTENCE (partialForm1, U"Partial form 1", U"")
  1230. SENTENCE (partialForm2, U"Partial form 2", U"")
  1231. NATURAL (numberOfTrials, U"Number of trials", U"1000")
  1232. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1233. OK
  1234. DO
  1235. FIND_ONE (OTMulti)
  1236. autoStrings thee = OTMulti_generateOptimalForms (me, partialForm1, partialForm2,
  1237. numberOfTrials, evaluationNoise);
  1238. praat_new (thee.move(), my name.get(), U"_out");
  1239. praat_dataChanged (me);
  1240. END
  1241. }
  1242. FORM (NEW_MODIFY_OTMulti_to_Distribution, U"OTMulti: Compute output distribution", nullptr) {
  1243. SENTENCE (partialForm1, U"Partial form 1", U"")
  1244. SENTENCE (partialForm2, U"Partial form 2", U"")
  1245. NATURAL (numberOfTrials, U"Number of trials", U"100000")
  1246. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1247. OK
  1248. DO
  1249. LOOP {
  1250. iam (OTMulti);
  1251. try {
  1252. autoDistributions result = OTMulti_to_Distribution (me, partialForm1, partialForm2,
  1253. numberOfTrials, evaluationNoise);
  1254. praat_new (result.move(), my name.get(), U"_out");
  1255. praat_dataChanged (me);
  1256. } catch (MelderError) {
  1257. praat_dataChanged (me);
  1258. throw;
  1259. }
  1260. }
  1261. END }
  1262. // MARK: Modify ranking
  1263. FORM (MODIFY_OTMulti_setRanking, U"OTMulti: Set ranking", nullptr) {
  1264. NATURAL (constraint, U"Constraint", U"1")
  1265. REAL (ranking, U"Ranking", U"100.0")
  1266. REAL (disharmony, U"Disharmony", U"100.0")
  1267. OK
  1268. DO
  1269. MODIFY_EACH (OTMulti)
  1270. OTMulti_setRanking (me, constraint, ranking, disharmony);
  1271. MODIFY_EACH_END
  1272. }
  1273. FORM (MODIFY_OTMulti_resetAllRankings, U"OTMulti: Reset all rankings", nullptr) {
  1274. REAL (ranking, U"Ranking", U"100.0")
  1275. OK
  1276. DO
  1277. MODIFY_EACH (OTMulti)
  1278. OTMulti_reset (me, ranking);
  1279. MODIFY_EACH_END
  1280. }
  1281. FORM (MODIFY_OTMulti_learnOne, U"OTMulti: Learn one", nullptr) {
  1282. SENTENCE (partialForm1, U"Partial form 1", U"")
  1283. SENTENCE (partialForm2, U"Partial form 2", U"")
  1284. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  1285. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  1286. OPTIONMENU (direction, U"Direction", 3)
  1287. OPTION (U"forward")
  1288. OPTION (U"backward")
  1289. OPTION (U"bidirectionally")
  1290. POSITIVE (plasticity, U"Plasticity", U"0.1")
  1291. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  1292. OK
  1293. DO
  1294. MODIFY_EACH_WEAK (OTMulti)
  1295. OTMulti_learnOne (me, partialForm1, partialForm2, updateRule,
  1296. direction, plasticity, relativePlasticitySpreading);
  1297. MODIFY_EACH_WEAK_END
  1298. }
  1299. // MARK: Modify behaviour
  1300. FORM (MODIFY_OTMulti_setDecisionStrategy, U"OTMulti: Set decision strategy", nullptr) {
  1301. RADIO_ENUM (kOTGrammar_decisionStrategy, decisionStrategy,
  1302. U"Decision strategy", kOTGrammar_decisionStrategy::DEFAULT)
  1303. OK
  1304. FIND_ONE (OTMulti)
  1305. SET_ENUM (decisionStrategy, kOTGrammar_decisionStrategy, my decisionStrategy);
  1306. DO
  1307. MODIFY_EACH (OTMulti)
  1308. my decisionStrategy = decisionStrategy;
  1309. MODIFY_EACH_END
  1310. }
  1311. FORM (MODIFY_OTMulti_setLeak, U"OTGrammar: Set leak", nullptr) {
  1312. REAL (leak, U"Leak", U"0.0")
  1313. OK
  1314. FIND_ONE (OTMulti)
  1315. SET_REAL (leak, my leak)
  1316. DO
  1317. MODIFY_EACH (OTMulti)
  1318. my leak = leak;
  1319. MODIFY_EACH_END
  1320. }
  1321. FORM (MODIFY_OTMulti_setConstraintPlasticity, U"OTMulti: Set constraint plasticity", nullptr) {
  1322. NATURAL (constraintNumber, U"Constraint number", U"1")
  1323. REAL (plasticity, U"Plasticity", U"1.0")
  1324. OK
  1325. DO
  1326. MODIFY_EACH (OTMulti)
  1327. OTMulti_setConstraintPlasticity (me, constraintNumber, plasticity);
  1328. MODIFY_EACH_END
  1329. }
  1330. // MARK: Modify structure
  1331. FORM (MODIFY_OTMulti_removeConstraint, U"OTMulti: Remove constraint", nullptr) {
  1332. SENTENCE (constraintName, U"Constraint name", U"")
  1333. OK
  1334. DO
  1335. MODIFY_EACH (OTMulti)
  1336. OTMulti_removeConstraint (me, constraintName);
  1337. MODIFY_EACH_END
  1338. }
  1339. // MARK: OTMULTI & PAIRDISTRIBUTION
  1340. FORM (DANGEROUS_MODIFY_OTMulti_PairDistribution_learn, U"OTMulti & PairDistribution: Learn", nullptr) {
  1341. REAL (evaluationNoise, U"Evaluation noise", U"2.0")
  1342. OPTIONMENU_ENUM (kOTGrammar_rerankingStrategy, updateRule,
  1343. U"Update rule", kOTGrammar_rerankingStrategy::SYMMETRIC_ALL)
  1344. OPTIONMENU (direction, U"Direction", 3)
  1345. OPTION (U"forward")
  1346. OPTION (U"backward")
  1347. OPTION (U"bidirectionally")
  1348. POSITIVE (initialPlasticity, U"Initial plasticity", U"1.0")
  1349. NATURAL (replicationsPerPlasticity, U"Replications per plasticity", U"100000")
  1350. REAL (plasticityDecrement, U"Plasticity decrement", U"0.1")
  1351. NATURAL (numberOfPlasticities, U"Number of plasticities", U"4")
  1352. REAL (relativePlasticitySpreading, U"Rel. plasticity spreading", U"0.1")
  1353. INTEGER (storeHistoryEvery, U"Store history every", U"0")
  1354. OK
  1355. DO
  1356. FIND_TWO (OTMulti, PairDistribution)
  1357. autoTable history;
  1358. try {
  1359. OTMulti_PairDistribution_learn (me, you, evaluationNoise,
  1360. updateRule, direction,
  1361. initialPlasticity, replicationsPerPlasticity, plasticityDecrement, numberOfPlasticities,
  1362. relativePlasticitySpreading, storeHistoryEvery, & history);
  1363. praat_dataChanged (me);
  1364. } catch (MelderError) {
  1365. praat_dataChanged (me); // e.g. in case of partial learning
  1366. Melder_flushError ();
  1367. // trickle down to save history
  1368. }
  1369. if (history) praat_new (history.move(), my name.get());
  1370. END
  1371. }
  1372. // MARK: OTMULTI & STRINGS
  1373. FORM (NEW1_MODIFY_OTMulti_Strings_generateOptimalForms, U"OTGrammar: Inputs to outputs", U"OTGrammar: Inputs to outputs...") {
  1374. REAL (evaluationNoide, U"Evaluation noise", U"2.0")
  1375. OK
  1376. DO
  1377. FIND_TWO (OTMulti, Strings)
  1378. autoStrings result = OTMulti_Strings_generateOptimalForms (me, you, evaluationNoide);
  1379. praat_new (result.move(), my name.get(), U"_out");
  1380. praat_dataChanged (me);
  1381. END
  1382. }
  1383. // MARK: - NET
  1384. // MARK: New
  1385. FORM (NEW1_CreateNetAsDeepBeliefNetwork, U"Create Net as DeepBeliefNetwork", nullptr) {
  1386. WORD (name, U"Name", U"network")
  1387. NUMVEC (numbersOfNodes, U"Numbers of nodes", U"{ 30, 50, 20 }")
  1388. BOOLEAN (inputsAreBinary, U"Inputs are binary", false)
  1389. OK
  1390. DO
  1391. CREATE_ONE
  1392. autoNet result = Net_createAsDeepBeliefNet (numbersOfNodes, inputsAreBinary);
  1393. CREATE_ONE_END (name)
  1394. }
  1395. // MARK: Modify
  1396. FORM (MODIFY_Net_spreadUp, U"Net: Spread up", nullptr) {
  1397. RADIO_ENUM (kLayer_activationType, activationType,
  1398. U"Activation type", kLayer_activationType::STOCHASTIC)
  1399. OK
  1400. DO
  1401. MODIFY_EACH (Net)
  1402. Net_spreadUp (me, activationType);
  1403. MODIFY_EACH_END
  1404. }
  1405. FORM (MODIFY_Net_spreadDown, U"Net: Spread down", nullptr) {
  1406. RADIO_ENUM (kLayer_activationType, activationType,
  1407. U"Activation type", kLayer_activationType::DETERMINISTIC)
  1408. OK
  1409. DO
  1410. MODIFY_EACH (Net)
  1411. Net_spreadDown (me, activationType);
  1412. MODIFY_EACH_END
  1413. }
  1414. DIRECT (MODIFY_Net_spreadUp_reconstruction) {
  1415. MODIFY_EACH (Net)
  1416. Net_spreadUp_reconstruction (me);
  1417. MODIFY_EACH_END
  1418. }
  1419. DIRECT (MODIFY_Net_spreadDown_reconstruction) {
  1420. MODIFY_EACH (Net)
  1421. Net_spreadDown_reconstruction (me);
  1422. MODIFY_EACH_END
  1423. }
  1424. DIRECT (MODIFY_Net_sampleInput) {
  1425. MODIFY_EACH (Net)
  1426. Net_sampleInput (me);
  1427. MODIFY_EACH_END
  1428. }
  1429. DIRECT (MODIFY_Net_sampleOutput) {
  1430. MODIFY_EACH (Net)
  1431. Net_sampleOutput (me);
  1432. MODIFY_EACH_END
  1433. }
  1434. FORM (MODIFY_Net_update, U"Net: Update", nullptr) {
  1435. POSITIVE (learningRate, U"Learning rate", U"0.001")
  1436. OK
  1437. DO
  1438. MODIFY_EACH (Net)
  1439. Net_update (me, learningRate);
  1440. MODIFY_EACH_END
  1441. }
  1442. // MARK: Extract
  1443. DIRECT (NEW_Net_extractInputActivities) {
  1444. CONVERT_EACH (Net)
  1445. autoMatrix result = Net_extractInputActivities (me);
  1446. CONVERT_EACH_END (my name.get(), U"_inputActivities")
  1447. }
  1448. DIRECT (NEW_Net_extractOutputActivities) {
  1449. CONVERT_EACH (Net)
  1450. autoMatrix result = Net_extractOutputActivities (me);
  1451. CONVERT_EACH_END (my name.get(), U"_outputActivities")
  1452. }
  1453. DIRECT (NEW_Net_extractInputReconstruction) {
  1454. CONVERT_EACH (Net)
  1455. autoMatrix result = Net_extractInputReconstruction (me);
  1456. CONVERT_EACH_END (my name.get(), U"_inputReconstruction")
  1457. }
  1458. DIRECT (NEW_Net_extractOutputReconstruction) {
  1459. CONVERT_EACH (Net)
  1460. autoMatrix result = Net_extractOutputReconstruction (me);
  1461. CONVERT_EACH_END (my name.get(), U"_outputReconstruction")
  1462. }
  1463. FORM (NEW_Net_extractInputBiases, U"Net: Extract input biases", nullptr) {
  1464. NATURAL (layerNumber, U"Layer number", U"1")
  1465. OK
  1466. DO
  1467. CONVERT_EACH (Net)
  1468. autoMatrix result = Net_extractInputBiases (me, layerNumber);
  1469. CONVERT_EACH_END (my name.get(), U"_inputBiases")
  1470. }
  1471. FORM (NEW_Net_extractOutputBiases, U"Net: Extract output biases", nullptr) {
  1472. NATURAL (layerNumber, U"Layer number", U"1")
  1473. OK
  1474. DO
  1475. CONVERT_EACH (Net)
  1476. autoMatrix result = Net_extractOutputBiases (me, layerNumber);
  1477. CONVERT_EACH_END (my name.get(), U"_outputBiases")
  1478. }
  1479. FORM (NEW_Net_extractWeights, U"Net: Extract weights", nullptr) {
  1480. NATURAL (layerNumber, U"Layer number", U"1")
  1481. OK
  1482. DO
  1483. CONVERT_EACH (Net)
  1484. autoMatrix result = Net_extractWeights (me, layerNumber);
  1485. CONVERT_EACH_END (my name.get(), U"_weights")
  1486. }
  1487. FORM (NUMMAT_Net_getWeights, U"Net: Get weigths", nullptr) {
  1488. NATURAL (layerNumber, U"Layer number", U"1")
  1489. OK
  1490. DO
  1491. NUMMAT_ONE (Net)
  1492. autoMAT result = Net_getWeights (me, layerNumber);
  1493. NUMMAT_ONE_END
  1494. }
  1495. // MARK: - NET & PATTERN
  1496. FORM (MODIFY_Net_PatternList_applyToInput, U"Net & PatternList: Apply to input", nullptr) {
  1497. NATURAL (rowNumber, U"Row number", U"1")
  1498. OK
  1499. DO
  1500. MODIFY_FIRST_OF_TWO (Net, PatternList)
  1501. Net_PatternList_applyToInput (me, you, rowNumber);
  1502. MODIFY_FIRST_OF_TWO_END
  1503. }
  1504. FORM (MODIFY_Net_PatternList_applyToOutput, U"Net & PatternList: Apply to output", nullptr) {
  1505. NATURAL (rowNumber, U"Row number", U"1")
  1506. OK
  1507. DO
  1508. MODIFY_FIRST_OF_TWO (Net, PatternList)
  1509. Net_PatternList_applyToOutput (me, you, rowNumber);
  1510. MODIFY_FIRST_OF_TWO_END
  1511. }
  1512. FORM (MODIFY_Net_PatternList_learn, U"Net & PatternList: Learn", nullptr) {
  1513. POSITIVE (learningRate, U"Learning rate", U"0.001")
  1514. OK
  1515. DO
  1516. MODIFY_FIRST_OF_TWO (Net, PatternList)
  1517. Net_PatternList_learn (me, you, learningRate);
  1518. MODIFY_FIRST_OF_TWO_END
  1519. }
  1520. FORM (MODIFY_Net_PatternList_learnByLayer, U"Net & PatternList: Learn by layer", nullptr) {
  1521. POSITIVE (learningRate, U"Learning rate", U"0.001")
  1522. OK
  1523. DO
  1524. MODIFY_FIRST_OF_TWO (Net, PatternList)
  1525. Net_PatternList_learnByLayer (me, you, learningRate);
  1526. MODIFY_FIRST_OF_TWO_END
  1527. }
  1528. FORM (NEW1_Net_PatternList_to_ActivationList, U"Net & PatternList: To ActivationList", nullptr) {
  1529. RADIO_ENUM (kLayer_activationType, activationType,
  1530. U"Activation type", kLayer_activationType::DETERMINISTIC)
  1531. OK
  1532. DO
  1533. CONVERT_TWO (Net, PatternList)
  1534. autoActivationList result = Net_PatternList_to_ActivationList (me, you, activationType);
  1535. CONVERT_TWO_END (my name.get(), U"_", your name.get())
  1536. }
  1537. // MARK: - NOULLIGRID
  1538. // MARK: View & Edit
  1539. DIRECT (WINDOW_NoulliGrid_viewAndEdit) {
  1540. if (theCurrentPraatApplication -> batch) Melder_throw (U"Cannot edit a NoulliGrid from batch.");
  1541. FIND_TWO_WITH_IOBJECT (NoulliGrid, Sound) // Sound may be null
  1542. autoNoulliGridEditor editor = NoulliGridEditor_create (ID_AND_FULL_NAME, me, you, true);
  1543. praat_installEditor (editor.get(), IOBJECT);
  1544. editor.releaseToUser();
  1545. END
  1546. }
  1547. // MARK: - buttons
  1548. void praat_uvafon_gram_init ();
  1549. void praat_uvafon_gram_init () {
  1550. Thing_recognizeClassesByName (classNetwork,
  1551. classOTGrammar, classOTHistory, classOTMulti,
  1552. classRBMLayer, classFullyConnectedLayer, classNet,
  1553. classNoulliTier, classNoulliGrid,
  1554. nullptr);
  1555. Thing_recognizeClassByOtherName (classOTGrammar, U"OTCase");
  1556. structNoulliGridEditor :: f_preferences ();
  1557. praat_addMenuCommand (U"Objects", U"New", U"Constraint grammars", nullptr, 0, nullptr);
  1558. praat_addMenuCommand (U"Objects", U"New", U"OT learning tutorial", nullptr, praat_DEPTH_1 | praat_NO_API, HELP_OT_learning_tutorial);
  1559. praat_addMenuCommand (U"Objects", U"New", U"-- tableau grammars --", nullptr, 1, nullptr);
  1560. praat_addMenuCommand (U"Objects", U"New", U"Create NoCoda grammar", nullptr, 1, NEW1_Create_NoCoda_grammar);
  1561. praat_addMenuCommand (U"Objects", U"New", U"Create place assimilation grammar", nullptr, 1, NEW1_Create_NPA_grammar);
  1562. praat_addMenuCommand (U"Objects", U"New", U"Create place assimilation distribution", nullptr, 1, NEW1_Create_NPA_distribution);
  1563. praat_addMenuCommand (U"Objects", U"New", U"Create tongue-root grammar...", nullptr, 1, NEW1_Create_tongue_root_grammar);
  1564. praat_addMenuCommand (U"Objects", U"New", U"Create metrics grammar...", nullptr, 1, NEW1_Create_metrics_grammar);
  1565. praat_addMenuCommand (U"Objects", U"New", U"Create multi-level metrics grammar...", nullptr, 1, NEW1_Create_multi_level_metrics_grammar);
  1566. praat_addAction1 (classOTGrammar, 1, U"Save as headerless spreadsheet file...", nullptr, 0, SAVE_OTGrammar_writeToHeaderlessSpreadsheetFile);
  1567. praat_addAction1 (classOTGrammar, 1, U"Write to headerless spreadsheet file...", U"*Save as headerless spreadsheet file...", praat_DEPRECATED_2011, SAVE_OTGrammar_writeToHeaderlessSpreadsheetFile);
  1568. praat_addAction1 (classOTGrammar, 0, U"OTGrammar help", nullptr, 0, HELP_OTGrammar_help);
  1569. praat_addAction1 (classOTGrammar, 0, U"View & Edit", nullptr, praat_ATTRACTIVE, WINDOW_OTGrammar_viewAndEdit);
  1570. praat_addAction1 (classOTGrammar, 0, U"Edit", U"*View & Edit", praat_DEPRECATED_2011, WINDOW_OTGrammar_viewAndEdit);
  1571. praat_addAction1 (classOTGrammar, 0, U"Draw -", nullptr, 0, nullptr);
  1572. praat_addAction1 (classOTGrammar, 0, U"Draw tableau...", nullptr, 0, GRAPHICS_OTGrammar_drawTableau);
  1573. praat_addAction1 (classOTGrammar, 0, U"Draw tableau (narrowly)...", nullptr, 0, GRAPHICS_OTGrammar_drawTableau_narrowly);
  1574. praat_addAction1 (classOTGrammar, 0, U"Query -", nullptr, 0, nullptr);
  1575. praat_addAction1 (classOTGrammar, 1, U"Get number of constraints", nullptr, 1, INTEGER_OTGrammar_getNumberOfConstraints);
  1576. praat_addAction1 (classOTGrammar, 1, U"Get constraint...", nullptr, 1, STRING_OTGrammar_getConstraint);
  1577. praat_addAction1 (classOTGrammar, 1, U"Get ranking value...", nullptr, 1, REAL_OTGrammar_getRankingValue);
  1578. praat_addAction1 (classOTGrammar, 1, U"Get disharmony...", nullptr, 1, REAL_OTGrammar_getDisharmony);
  1579. praat_addAction1 (classOTGrammar, 1, U"Get number of tableaus", nullptr, 1, INTEGER_OTGrammar_getNumberOfTableaus);
  1580. praat_addAction1 (classOTGrammar, 1, U"Get input...", nullptr, 1, STRING_OTGrammar_getInput);
  1581. praat_addAction1 (classOTGrammar, 1, U"Get number of candidates...", nullptr, 1, INTEGER_OTGrammar_getNumberOfCandidates);
  1582. praat_addAction1 (classOTGrammar, 1, U"Get candidate...", nullptr, 1, STRING_OTGrammar_getCandidate);
  1583. praat_addAction1 (classOTGrammar, 1, U"Get number of violations...", nullptr, 1, INTEGER_OTGrammar_getNumberOfViolations);
  1584. praat_addAction1 (classOTGrammar, 1, U"-- parse --", nullptr, 1, nullptr);
  1585. praat_addAction1 (classOTGrammar, 1, U"Get winner...", nullptr, 1, INTEGER_OTGrammar_getWinner);
  1586. praat_addAction1 (classOTGrammar, 1, U"Compare candidates...", nullptr, 1, INTEGER_OTGrammar_compareCandidates);
  1587. praat_addAction1 (classOTGrammar, 1, U"Get number of optimal candidates...", nullptr, 1, INTEGER_OTGrammar_getNumberOfOptimalCandidates);
  1588. praat_addAction1 (classOTGrammar, 1, U"Is candidate grammatical...", nullptr, 1, BOOLEAN_OTGrammar_isCandidateGrammatical);
  1589. praat_addAction1 (classOTGrammar, 1, U"Is candidate singly grammatical...", nullptr, 1, BOOLEAN_OTGrammar_isCandidateSinglyGrammatical);
  1590. praat_addAction1 (classOTGrammar, 1, U"Get interpretive parse...", nullptr, 1, STRING_OTGrammar_getInterpretiveParse);
  1591. praat_addAction1 (classOTGrammar, 1, U"Is partial output grammatical...", nullptr, 1, BOOLEAN_OTGrammar_isPartialOutputGrammatical);
  1592. praat_addAction1 (classOTGrammar, 1, U"Is partial output singly grammatical...", nullptr, 1, BOOLEAN_OTGrammar_isPartialOutputSinglyGrammatical);
  1593. praat_addAction1 (classOTGrammar, 0, U"Generate inputs...", nullptr, 0, NEW_OTGrammar_generateInputs);
  1594. praat_addAction1 (classOTGrammar, 0, U"Get inputs", nullptr, 0, NEW_OTGrammar_getInputs);
  1595. praat_addAction1 (classOTGrammar, 0, U"Measure typology", nullptr, 0, NEW_MODIFY_OTGrammar_measureTypology);
  1596. praat_addAction1 (classOTGrammar, 0, U"Evaluate", nullptr, 0, nullptr);
  1597. praat_addAction1 (classOTGrammar, 0, U"Evaluate...", nullptr, 0, MODIFY_OTGrammar_evaluate);
  1598. praat_addAction1 (classOTGrammar, 0, U"Input to output...", nullptr, 0, STRING_MODIFY_OTGrammar_inputToOutput);
  1599. praat_addAction1 (classOTGrammar, 0, U"Input to outputs...", nullptr, 0, NEW1_MODIFY_OTGrammar_inputToOutputs);
  1600. praat_addAction1 (classOTGrammar, 0, U"To output Distributions...", nullptr, 0, NEW_MODIFY_OTGrammar_to_Distributions);
  1601. praat_addAction1 (classOTGrammar, 0, U"To PairDistribution...", nullptr, 0, NEW_MODIFY_OTGrammar_to_PairDistribution);
  1602. praat_addAction1 (classOTGrammar, 0, U"Modify ranking -", nullptr, 0, nullptr);
  1603. praat_addAction1 (classOTGrammar, 0, U"Set ranking...", nullptr, 1, MODIFY_OTGrammar_setRanking);
  1604. praat_addAction1 (classOTGrammar, 0, U"Reset all rankings...", nullptr, 1, MODIFY_OTGrammar_resetAllRankings);
  1605. praat_addAction1 (classOTGrammar, 0, U"Reset to random ranking...", nullptr, 1, MODIFY_OTGrammar_resetToRandomRanking);
  1606. praat_addAction1 (classOTGrammar, 0, U"Reset to random total ranking...", nullptr, 1, MODIFY_OTGrammar_resetToRandomTotalRanking);
  1607. praat_addAction1 (classOTGrammar, 0, U"Learn one...", nullptr, 1, MODIFY_OTGrammar_learnOne);
  1608. praat_addAction1 (classOTGrammar, 0, U"Learn one from partial output...", nullptr, 1, MODIFY_OTGrammar_learnOneFromPartialOutput);
  1609. praat_addAction1 (classOTGrammar, 0, U"Modify behaviour -", nullptr, 0, nullptr);
  1610. praat_addAction1 (classOTGrammar, 1, U"Set decision strategy...", nullptr, 1, MODIFY_OTGrammar_setDecisionStrategy);
  1611. praat_addAction1 (classOTGrammar, 1, U"Set harmony computation method...", U"*Set decision strategy...", praat_DEPTH_1 | praat_DEPRECATED_2006, MODIFY_OTGrammar_setDecisionStrategy);
  1612. praat_addAction1 (classOTGrammar, 1, U"Set leak...", nullptr, 1, MODIFY_OTGrammar_setLeak);
  1613. praat_addAction1 (classOTGrammar, 1, U"Set constraint plasticity...", nullptr, 1, MODIFY_OTGrammar_setConstraintPlasticity);
  1614. praat_addAction1 (classOTGrammar, 0, U"Modify structure -", nullptr, 0, nullptr);
  1615. praat_addAction1 (classOTGrammar, 0, U"Remove constraint...", nullptr, 1, MODIFY_OTGrammar_removeConstraint);
  1616. praat_addAction1 (classOTGrammar, 0, U"Remove harmonically bounded candidates...", nullptr, 1, MODIFY_OTGrammar_removeHarmonicallyBoundedCandidates);
  1617. praat_TableOfReal_init (classOTHistory);
  1618. praat_addAction1 (classOTMulti, 0, U"View & Edit", nullptr, praat_ATTRACTIVE, WINDOW_OTMulti_viewAndEdit);
  1619. praat_addAction1 (classOTMulti, 0, U"Edit", U"*View & Edit", praat_DEPRECATED_2011, WINDOW_OTMulti_viewAndEdit);
  1620. praat_addAction1 (classOTMulti, 0, U"Draw -", nullptr, 0, nullptr);
  1621. praat_addAction1 (classOTMulti, 0, U"Draw tableau...", nullptr, 1, GRAPHICS_OTMulti_drawTableau);
  1622. praat_addAction1 (classOTMulti, 0, U"Draw tableau (narrowly)...", nullptr, 1, GRAPHICS_OTMulti_drawTableau_narrowly);
  1623. praat_addAction1 (classOTMulti, 0, U"Query -", nullptr, 0, nullptr);
  1624. praat_addAction1 (classOTMulti, 1, U"Get number of constraints", nullptr, 1, INTEGER_OTMulti_getNumberOfConstraints);
  1625. praat_addAction1 (classOTMulti, 1, U"Get constraint...", nullptr, 1, STRING_OTMulti_getConstraint);
  1626. praat_addAction1 (classOTMulti, 1, U"Get constraint number...", nullptr, 1, INTEGER_OTMulti_getConstraintIndexFromName);
  1627. praat_addAction1 (classOTMulti, 1, U"Get ranking value...", nullptr, 1, REAL_OTMulti_getRankingValue);
  1628. praat_addAction1 (classOTMulti, 1, U"Get disharmony...", nullptr, 1, REAL_OTMulti_getDisharmony);
  1629. praat_addAction1 (classOTMulti, 1, U"Get number of candidates", nullptr, 1, INTEGER_OTMulti_getNumberOfCandidates);
  1630. praat_addAction1 (classOTMulti, 1, U"Get candidate...", nullptr, 1, STRING_OTMulti_getCandidate);
  1631. praat_addAction1 (classOTMulti, 1, U"Get number of violations...", nullptr, 1, INTEGER_OTMulti_getNumberOfViolations);
  1632. praat_addAction1 (classOTMulti, 1, U"-- parse --", nullptr, 1, nullptr);
  1633. praat_addAction1 (classOTMulti, 1, U"Get winner...", nullptr, 1, INTEGER_OTMulti_getWinner);
  1634. praat_addAction1 (classOTMulti, 0, U"Evaluate", nullptr, 0, nullptr);
  1635. praat_addAction1 (classOTMulti, 0, U"Evaluate...", nullptr, 1, MODIFY_OTMulti_evaluate);
  1636. praat_addAction1 (classOTMulti, 0, U"Get output...", nullptr, 1, STRING_MODIFY_OTMulti_generateOptimalForm);
  1637. praat_addAction1 (classOTMulti, 0, U"Get outputs...", nullptr, 1, NEW1_MODIFY_OTMulti_generateOptimalForms);
  1638. praat_addAction1 (classOTMulti, 0, U"To output Distribution...", nullptr, 1, NEW_MODIFY_OTMulti_to_Distribution);
  1639. praat_addAction1 (classOTMulti, 0, U"Modify ranking", nullptr, 0, nullptr);
  1640. praat_addAction1 (classOTMulti, 0, U"Set ranking...", nullptr, 0, MODIFY_OTMulti_setRanking);
  1641. praat_addAction1 (classOTMulti, 0, U"Reset all rankings...", nullptr, 0, MODIFY_OTMulti_resetAllRankings);
  1642. praat_addAction1 (classOTMulti, 0, U"Learn one...", nullptr, 0, MODIFY_OTMulti_learnOne);
  1643. praat_addAction1 (classOTMulti, 0, U"Modify behaviour -", nullptr, 0, nullptr);
  1644. praat_addAction1 (classOTMulti, 1, U"Set decision strategy...", nullptr, 1, MODIFY_OTMulti_setDecisionStrategy);
  1645. praat_addAction1 (classOTMulti, 1, U"Set leak...", nullptr, 1, MODIFY_OTMulti_setLeak);
  1646. praat_addAction1 (classOTMulti, 1, U"Set constraint plasticity...", nullptr, 1, MODIFY_OTMulti_setConstraintPlasticity);
  1647. praat_addAction1 (classOTMulti, 0, U"Modify structure -", nullptr, 0, nullptr);
  1648. praat_addAction1 (classOTMulti, 0, U"Remove constraint...", nullptr, 1, MODIFY_OTMulti_removeConstraint);
  1649. praat_addAction2 (classOTGrammar, 1, classStrings, 1, U"Query -", nullptr, 0, nullptr);
  1650. praat_addAction2 (classOTGrammar, 1, classStrings, 1, U"Are all partial outputs grammatical?", nullptr, 1, BOOLEAN_OTGrammar_Strings_areAllPartialOutputsGrammatical);
  1651. praat_addAction2 (classOTGrammar, 1, classStrings, 1, U"Are all partial outputs singly grammatical?", nullptr, 1, BOOLEAN_OTGrammar_Strings_areAllPartialOutputsSinglyGrammatical);
  1652. praat_addAction2 (classOTGrammar, 1, classStrings, 1, U"Inputs to outputs...", nullptr, 0, NEW1_MODIFY_OTGrammar_Strings_inputsToOutputs);
  1653. praat_addAction2 (classOTGrammar, 1, classStrings, 1, U"Learn from partial outputs...", nullptr, 0, MODIFY_OTGrammar_Strings_learnFromPartialOutputs);
  1654. praat_addAction2 (classOTGrammar, 1, classStrings, 2, U"Learn...", nullptr, 0, MODIFY_OTGrammar_Stringses_learn);
  1655. praat_addAction2 (classOTGrammar, 1, classDistributions, 1, U"Learn from partial outputs...", nullptr, 0, MODIFY_OTGrammar_Distributions_learnFromPartialOutputs);
  1656. praat_addAction2 (classOTGrammar, 1, classDistributions, 1, U"Learn from partial outputs (rrip)...", nullptr, 0, MODIFY_OTGrammar_Distributions_learnFromPartialOutputs_rrip);
  1657. praat_addAction2 (classOTGrammar, 1, classDistributions, 1, U"Learn from partial outputs (eip)...", nullptr, 0, MODIFY_OTGrammar_Distributions_learnFromPartialOutputs_eip);
  1658. praat_addAction2 (classOTGrammar, 1, classDistributions, 1, U"Learn from partial outputs (wrip)...", nullptr, 0, MODIFY_OTGrammar_Distributions_learnFromPartialOutputs_wrip);
  1659. praat_addAction2 (classOTGrammar, 1, classDistributions, 1, U"Get fraction correct...", nullptr, 0, REAL_MODIFY_OTGrammar_Distributions_getFractionCorrect);
  1660. praat_addAction2 (classOTGrammar, 1, classDistributions, 1, U"List obligatory rankings...", nullptr, praat_HIDDEN, LIST_OTGrammar_Distributions_listObligatoryRankings);
  1661. praat_addAction2 (classOTGrammar, 1, classPairDistribution, 1, U"Learn...", nullptr, 0, MODIFY_OTGrammar_PairDistribution_learn);
  1662. praat_addAction2 (classOTGrammar, 1, classPairDistribution, 1, U"Find positive weights...", nullptr, 0, MODIFY_OTGrammar_PairDistribution_findPositiveWeights);
  1663. praat_addAction2 (classOTGrammar, 1, classPairDistribution, 1, U"Get fraction correct...", nullptr, 0, REAL_MODIFY_OTGrammar_PairDistribution_getFractionCorrect);
  1664. praat_addAction2 (classOTGrammar, 1, classPairDistribution, 1, U"Get minimum number correct...", nullptr, 0, INTEGER_MODIFY_OTGrammar_PairDistribution_getMinimumNumberCorrect);
  1665. praat_addAction2 (classOTGrammar, 1, classPairDistribution, 1, U"List obligatory rankings", nullptr, 0, LIST_OTGrammar_PairDistribution_listObligatoryRankings);
  1666. praat_addAction2 (classOTMulti, 1, classPairDistribution, 1, U"Learn...", nullptr, 0, DANGEROUS_MODIFY_OTMulti_PairDistribution_learn);
  1667. praat_addAction2 (classOTMulti, 1, classStrings, 1, U"Get outputs...", nullptr, 0, NEW1_MODIFY_OTMulti_Strings_generateOptimalForms);
  1668. praat_addMenuCommand (U"Objects", U"New", U"Symmetric neural networks", nullptr, 0, nullptr);
  1669. praat_addMenuCommand (U"Objects", U"New", U"Create empty Network...", nullptr, 1, NEW1_Create_empty_Network);
  1670. praat_addMenuCommand (U"Objects", U"New", U"Create rectangular Network...", nullptr, 1, NEW1_Create_rectangular_Network);
  1671. praat_addMenuCommand (U"Objects", U"New", U"Create rectangular Network (vertical)...", nullptr, 1, NEW1_Create_rectangular_Network_vertical);
  1672. praat_addMenuCommand (U"Objects", U"New", U"Create Net as deep belief network...", nullptr, 1, NEW1_CreateNetAsDeepBeliefNetwork);
  1673. praat_addAction1 (classNetwork, 0, U"Draw...", nullptr, 0, GRAPHICS_Network_draw);
  1674. praat_addAction1 (classNetwork, 1, U"Tabulate -", nullptr, 0, nullptr);
  1675. praat_addAction1 (classNetwork, 1, U"List nodes...", nullptr, 1, LIST_Network_listNodes);
  1676. praat_addAction1 (classNetwork, 1, U"Nodes down to table...", nullptr, 1, NEW_Network_nodes_downto_Table);
  1677. praat_addAction1 (classNetwork, 0, U"Query -", nullptr, 0, nullptr);
  1678. praat_addAction1 (classNetwork, 1, U"Get activity...", nullptr, 1, REAL_Network_getActivity);
  1679. praat_addAction1 (classNetwork, 1, U"Get weight...", nullptr, 1, REAL_Network_getWeight);
  1680. praat_addAction1 (classNetwork, 0, U"Modify -", nullptr, 0, nullptr);
  1681. praat_addAction1 (classNetwork, 0, U"Add node...", nullptr, 1, MODIFY_Network_addNode);
  1682. praat_addAction1 (classNetwork, 0, U"Add connection...", nullptr, 1, MODIFY_Network_addConnection);
  1683. praat_addAction1 (classNetwork, 0, U"-- activity --", nullptr, 1, nullptr);
  1684. praat_addAction1 (classNetwork, 0, U"Set activity...", nullptr, 1, MODIFY_Network_setActivity);
  1685. praat_addAction1 (classNetwork, 0, U"Set clamping...", nullptr, 1, MODIFY_Network_setClamping);
  1686. praat_addAction1 (classNetwork, 0, U"Zero activities...", nullptr, 1, MODIFY_Network_zeroActivities);
  1687. praat_addAction1 (classNetwork, 0, U"Normalize activities...", nullptr, 1, MODIFY_Network_normalizeActivities);
  1688. praat_addAction1 (classNetwork, 0, U"Spread activities...", nullptr, 1, MODIFY_Network_spreadActivities);
  1689. praat_addAction1 (classNetwork, 0, U"Set activity clipping rule...", nullptr, 1, MODIFY_Network_setActivityClippingRule);
  1690. praat_addAction1 (classNetwork, 0, U"Set activity leak...", nullptr, 1, MODIFY_Network_setActivityLeak);
  1691. praat_addAction1 (classNetwork, 0, U"Set shunting...", nullptr, 1, MODIFY_Network_setShunting);
  1692. praat_addAction1 (classNetwork, 0, U"-- weight --", nullptr, 1, nullptr);
  1693. praat_addAction1 (classNetwork, 0, U"Set weight...", nullptr, 1, MODIFY_Network_setWeight);
  1694. praat_addAction1 (classNetwork, 0, U"Update weights", nullptr, 1, MODIFY_Network_updateWeights);
  1695. praat_addAction1 (classNetwork, 0, U"Normalize weights...", nullptr, 1, MODIFY_Network_normalizeWeights);
  1696. praat_addAction1 (classNetwork, 0, U"Set instar...", nullptr, 1, MODIFY_Network_setInstar);
  1697. praat_addAction1 (classNetwork, 0, U"Set outstar...", nullptr, 1, MODIFY_Network_setOutstar);
  1698. praat_addAction1 (classNetwork, 0, U"Set weight leak...", nullptr, 1, MODIFY_Network_setWeightLeak);
  1699. praat_addAction1 (classNet, 0, U"Query", nullptr, 0, nullptr);
  1700. praat_addAction1 (classNet, 0, U"Get weights...", nullptr, 0, NUMMAT_Net_getWeights);
  1701. praat_addAction1 (classNet, 0, U"Modify", nullptr, 0, nullptr);
  1702. praat_addAction1 (classNet, 0, U"Spread up...", nullptr, 0, MODIFY_Net_spreadUp);
  1703. praat_addAction1 (classNet, 0, U"Spread down...", nullptr, 0, MODIFY_Net_spreadDown);
  1704. praat_addAction1 (classNet, 0, U"Spread up (reconstruction)", nullptr, 0, MODIFY_Net_spreadUp_reconstruction);
  1705. praat_addAction1 (classNet, 0, U"Spread down (reconstruction)", nullptr, 0, MODIFY_Net_spreadDown_reconstruction);
  1706. praat_addAction1 (classNet, 0, U"Sample input", nullptr, 0, MODIFY_Net_sampleInput);
  1707. praat_addAction1 (classNet, 0, U"Sample output", nullptr, 0, MODIFY_Net_sampleOutput);
  1708. praat_addAction1 (classNet, 0, U"Update...", nullptr, 0, MODIFY_Net_update);
  1709. praat_addAction1 (classNet, 0, U"Extract", nullptr, 0, nullptr);
  1710. praat_addAction1 (classNet, 0, U"Extract input activities", nullptr, 0, NEW_Net_extractInputActivities);
  1711. praat_addAction1 (classNet, 0, U"Extract output activities", nullptr, 0, NEW_Net_extractOutputActivities);
  1712. praat_addAction1 (classNet, 0, U"Extract input reconstruction", nullptr, 0, NEW_Net_extractInputReconstruction);
  1713. praat_addAction1 (classNet, 0, U"Extract output reconstruction", nullptr, 0, NEW_Net_extractOutputReconstruction);
  1714. praat_addAction1 (classNet, 0, U"Extract input biases...", nullptr, 0, NEW_Net_extractInputBiases);
  1715. praat_addAction1 (classNet, 0, U"Extract output biases...", nullptr, 0, NEW_Net_extractOutputBiases);
  1716. praat_addAction1 (classNet, 0, U"Extract weights...", nullptr, 0, NEW_Net_extractWeights);
  1717. praat_addAction2 (classNet, 1, classPatternList, 1, U"Apply to input...", nullptr, 0, MODIFY_Net_PatternList_applyToInput);
  1718. praat_addAction2 (classNet, 1, classPatternList, 1, U"Apply to output...", nullptr, 0, MODIFY_Net_PatternList_applyToOutput);
  1719. praat_addAction2 (classNet, 1, classPatternList, 1, U"Learn...", nullptr, 0, MODIFY_Net_PatternList_learn);
  1720. praat_addAction2 (classNet, 1, classPatternList, 1, U"Learn by layer...", nullptr, 0, MODIFY_Net_PatternList_learnByLayer);
  1721. praat_addAction2 (classNet, 1, classPatternList, 1, U"To ActivationList", nullptr, 0, NEW1_Net_PatternList_to_ActivationList);
  1722. praat_addAction1 (classNoulliGrid, 1, U"View & Edit", nullptr, praat_ATTRACTIVE, WINDOW_NoulliGrid_viewAndEdit);
  1723. praat_addAction2 (classNoulliGrid, 1, classSound, 1, U"View & Edit", nullptr, praat_ATTRACTIVE, WINDOW_NoulliGrid_viewAndEdit);
  1724. }
  1725. /* End of file praat_gram.cpp */