feature-change-applier/static/js/main.e83b5fcd.chunk.js
2020-02-27 14:50:47 -08:00

2 lines
No EOL
19 KiB
JavaScript

(this["webpackJsonpfeature-change-applier"]=this["webpackJsonpfeature-change-applier"]||[]).push([[0],[,,,,,,,,,,,,function(e,t,n){e.exports=n(28)},,,,,function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},,,function(e,t,n){},function(e,t,n){"use strict";n.r(t);var a=n(0),r=n.n(a),o=n(5),c=n.n(o),u=(n(17),n(18),n(3)),i=(n(19),n(20),function(e){var t=e.lexicon,n=e.dispatch;return r.a.createElement("div",{className:"ProtoLang","data-testid":"ProtoLang"},r.a.createElement("h3",null,"Proto Language Lexicon"),r.a.createElement("br",null),r.a.createElement("form",{"data-testid":"ProtoLang-Lexicon"},r.a.createElement("textarea",{name:"lexicon",cols:"30",rows:"10","data-testid":"ProtoLang-Lexicon__textarea",value:function(){return t?t.map((e="lexeme",function(t){return t[e]})).join("\n"):"";var e}(),onChange:function(e){console.log(e.target.value.split(/\n/).map((function(e){return{lexeme:e.split("#")[0].trim(),epoch:e.split("#")[1]||""}}))),n({type:"SET_LEXICON",value:e.target.value.split(/\n/).map((function(e){return{lexeme:e.split("#")[0].trim(),epoch:e.split("#")[1]||""}}))})}})))}),s=n(4),l=(n(21),function(e){return""===e?[""]:e.split("/").map((function(e){return e.trim()}))}),p=function(e){var t=Object(u.a)(e,3),n=t[0],a=t[1],r=t[2];return{type:"ADD_FEATURE",value:{positivePhones:l(n),negativePhones:l(a),feature:r}}},m=function(e){var t=e.phones,n=e.features,o=e.dispatch,c=Object(a.useState)("aspirated"),i=Object(u.a)(c,2),l=i[0],m=i[1],h=Object(a.useState)("t\u02b0 / p\u02b0 / k\u02b0"),f=Object(u.a)(h,2),v=f[0],g=f[1],d=Object(a.useState)("t / p / k"),E=Object(u.a)(d,2),b=E[0],O=E[1];return r.a.createElement("div",{className:"Features","data-testid":"Features"},r.a.createElement("h3",null,"Phonetic Features"),r.a.createElement("ul",{className:"Features__list","data-testid":"Features-list"},t?r.a.createElement(r.a.Fragment,null,function(e){var t=function(e){return function(t){return t[e]}};return function(e){return e.map((function(e,t){var n=Object.keys(e),a=e[n],o=a.plus,c=a.minus;return r.a.createElement("li",{key:"feature__".concat(n)},r.a.createElement("span",{className:"feature--names-and-phones"},r.a.createElement("span",{className:"feature--feature-name"},"[+ ".concat(n,"]")),r.a.createElement("span",{className:"feature--feature-phones"},o)),r.a.createElement("span",{className:"feature--names-and-phones"},r.a.createElement("span",{className:"feature--feature-name"},"[- ".concat(n,"]")),r.a.createElement("span",{className:"feature--feature-phones"},c)))}))}(function(e){return Object.keys(e).map((function(n){var a=e[n].positive.map(t("grapheme")).join(" / "),r=e[n].negative.map(t("grapheme")).join(" / ");return Object(s.a)({},n,{plus:a,minus:r})}))}(e))}(n)):r.a.createElement(r.a.Fragment,null)),r.a.createElement("form",{className:"Features__form","data-testid":"Features-form"},r.a.createElement("input",{type:"text",name:"feature",value:l,onChange:function(e){return m(e.target.value)}}),r.a.createElement("label",{htmlFor:"positive-phones"},"+",r.a.createElement("input",{id:"positive-phones",type:"text",name:"phonemes",value:v,onChange:function(e){return g(e.target.value)}})),r.a.createElement("label",{htmlFor:"negative-phones"},"-",r.a.createElement("input",{id:"negative-phones",type:"text",name:"phonemes",value:b,onChange:function(e){return O(e.target.value)}})),r.a.createElement("input",{type:"submit",onClick:function(e){return function(e){return function(t){return function(n){return function(a){return e.preventDefault(),t(n(a))}}}}(e)(o)(p)([v,b,l])},value:"Add feature"})))},h=(n(22),n(2)),f=(n(23),function(e){var t=e.epochIndex,n=e.removeEpoch,o=e.epochs,c=Object(a.useState)(e.epoch?e.epoch:{name:"",changes:[""],parent:"none"}),i=Object(u.a)(c,2),s=i[0],l=i[1],p=function(n,a){a(n),e.updateEpoch(s,t)};Object(a.useEffect)((function(){e.updateEpoch(s,t)}),[s]);var m=function(e){return r.a.createElement("option",{key:"".concat(s.name,"__parent-option--").concat(e.name),value:e.name},e.name)},f=function(e){return e.name===s.name?{name:"none"}:e},v=function(e){return!e.parent||e.parent!==s.name};return r.a.createElement(r.a.Fragment,null,r.a.createElement("h4",null,s.name),r.a.createElement("form",{className:"SoundChangeSuite__form","data-testid":"".concat(s.name,"_SoundChangeSuite_changes")},r.a.createElement("label",{htmlFor:"".concat(s.name,"-name")},"Name:"),r.a.createElement("input",{type:"text",name:"epoch",id:"".concat(s.name,"-name"),cols:"30",rows:"1",value:s.name,onChange:function(e){return p(e,(function(){l(Object(h.a)({},s,{name:e.target.value}))}))}}),t?r.a.createElement(r.a.Fragment,null,r.a.createElement("label",{htmlFor:"".concat(s.name,"-parent")},"Parent Epoch:"),r.a.createElement("select",{name:"parent",list:"".concat(s.name,"-parents-list"),value:s.parent,onChange:function(e){return p(e,(function(){l(Object(h.a)({},s,{parent:e.target.value}))}))}},o.map(f).filter(v).map(m))):r.a.createElement(r.a.Fragment,null),r.a.createElement("textarea",{name:"changes",id:"",cols:"30",rows:"10",value:s.changes.join("\n"),onChange:function(e){return p(e,(function(){return l(Object(h.a)({},s,{changes:e.target.value.split(/\n/).map((function(e){return" "===e?"[+ feature]>[- feature]/_#":e}))}))}))}})),r.a.createElement("form",{onSubmit:function(e){return n(e,s.name)}},r.a.createElement("input",{type:"submit",name:"remove-epoch",value:"remove ".concat(s.name)})))}),v=function(e){var t=e.epochs,n=e.dispatch,a=function(e,t){e.preventDefault(),n({type:"REMOVE_EPOCH",value:{name:t}})},o=function(e,t){var a={name:e.name,index:t,changes:e.changes,parent:e.parent};n({type:"SET_EPOCH",value:a})},c=function(e){return e===t.length-1?r.a.createElement("form",{onSubmit:function(e){return function(e){e.preventDefault();var a=t.length+1;n({type:"ADD_EPOCH",value:{name:"Epoch ".concat(a)}})}(e)}},r.a.createElement("input",{type:"submit",name:"add-epoch",value:"Add Epoch"})):r.a.createElement(r.a.Fragment,null)};return r.a.createElement(r.a.Fragment,null,t.length?t.map((function(e,n){return r.a.createElement("div",{className:"SoundChangeSuite","data-testid":"".concat(e.name,"_SoundChangeSuite"),key:"epoch-".concat(n)},r.a.createElement(f,{epochIndex:n,epoch:e,updateEpoch:o,removeEpoch:a,epochs:t}),c(n))})):c(-1))},g=(n(24),n(10)),d=n.n(g),E=function(e){var t=e.options,n=e.dispatch,o=Object(a.useState)(""),c=Object(u.a)(o,2),i=c[0],s=c[1],l=function(e){var t=e.target,a=t.name,r=t.id;n({type:"SET_OPTIONS",value:{option:a,setValue:r}})};return r.a.createElement("div",{className:"Options","data-testid":"Options"},r.a.createElement("h3",null,"Modeling Options"),r.a.createElement("form",{onSubmit:function(e){return function(e,t){e.preventDefault(),n({type:"RUN",value:t})}(e,t)},"data-testid":"Options-form"},r.a.createElement("input",{type:"radio",name:"output",id:"default",checked:!t||"default"===t.output,onChange:function(e){return l(e)}}),r.a.createElement("label",{htmlFor:"default"},"Default",r.a.createElement("span",{className:"Options__output-example"}," output")),r.a.createElement("input",{type:"radio",name:"output",id:"proto",checked:!!t&&"proto"===t.output,onChange:function(e){return l(e)}}),r.a.createElement("label",{htmlFor:"proto"},"Proto",r.a.createElement("span",{className:"Options__output-example"}," output [proto]")),r.a.createElement("input",{type:"radio",name:"output",id:"diachronic",checked:!!t&&"diachronic"===t.output,onChange:function(e){return l(e)}}),r.a.createElement("label",{htmlFor:"diachronic"},"Diachronic",r.a.createElement("span",{className:"Options__output-example"}," *proto > *epoch > output")),r.a.createElement("input",{type:"submit",value:"Run Changes"})),r.a.createElement("form",{onSubmit:function(){}},r.a.createElement("label",null,"Load from a prior run:",r.a.createElement("select",{value:i,onChange:function(e){return s(e.target.value)}},localStorage.phonoChange?d.a.get("phonoChange").map((function(e){return r.a.createElement("option",{key:e.name,value:e.name},e.name)})):r.a.createElement(r.a.Fragment,null))),r.a.createElement("input",{type:"submit",value:"Submit"})))},b=(n(27),function(e){var t=e.results,n=e.options,a=function(){return t.map((function(e,t){var n=e.lexicon.map((function(t,n){return r.a.createElement("span",{key:"".concat(e.pass,"-").concat(n)},t)}));return r.a.createElement("div",{key:"epoch-".concat(t),className:"Output-epoch"},r.a.createElement("h5",null,e.pass),r.a.createElement("p",{className:"lexicon"},n))}))};return r.a.createElement("div",{className:"Output","data-testid":"Output"},r.a.createElement("h3",null,"Results of Run"),r.a.createElement("div",{"data-testid":"Output-lexicon",className:"Output__container"},t&&t.length?function(){switch(n.output){case"default":return a();default:return r.a.createElement(r.a.Fragment,null)}}():r.a.createElement(r.a.Fragment,null)))}),O=n(1),j=function(e,t,n){var a={lexeme:e,epoch:n.epochs[0]};if(t){var r=n.epochs.findIndex((function(e){return e.name===t}));r>0&&(a.epoch=n.epochs[r])}return a},x=function(e,t){return t.split("").reduce((function(t,n,a){return t=0===a?e[n]:t[n]}),{})},_=function(e,t,n,a){var r={};return t.split("").forEach((function(o,c){r=0===c?e[o]:r[o],c===t.split("").length-1&&(r.features=Object(h.a)({},r.features,Object(s.a)({},n,a)))})),e},w=n(11),y=n(6);function F(){var e=Object(y.a)(["Error in line ",": ",""]);return F=function(){return e},e}function C(){var e=Object(y.a)(["Error in line ",": ",""]);return C=function(){return e},e}var N=function(e){return function(t){return t[e]}},S=function(e,t,n){var a=Object(u.a)(e,2),r=a[0],o=a[1];return"".concat(r).concat(t).concat(o).concat(n)},k=function(e,t){try{var n=function(e){if(!e.match(/>/g))throw"Insert '>' operator between target and result";if(!e.match(/\//g))throw"Insert '/' operator between change and environment";if(!e.match(/_/g))throw"Insert '_' operator in environment";if(e.match(/>/g).length>1)throw"Too many '>' operators";if(e.match(/\//g).length>1)throw"Too many '/' operators";if(e.match(/_/g).length>1)throw"Too many '_' operators";return e.split(/>|\/|_/g)}(e),a=Object(u.a)(n,4),r=a[0],o=a[1];return{environment:{pre:a[2],position:r,post:a[3]},newFeatures:o}}catch(c){throw S(C(),t+1,c)}},P=function(e){return"-"!==e&&"+"!==e&&"]"!==e&&"["!==e&&" "!==e},D=function(e,t){try{var n=t?/(?=\+.).*(?<=\-)|(?=\+.).*(?!\-).*(?<=\])/g:/(?=\-.).*(?<=\+)|(?=\-.).*(?!\+).*(?<=\])/g,a=e.match(n)||[null],r=Object(u.a)(a,1)[0];return r?(function(e){var t=e.match(/\W/g).filter(P);if(t.length)throw"Unknown token '".concat(t[0],"'")}(r),r.trim().match(/\w+/g).reduce((o=t,function(e,t){return Object(h.a)({},e,Object(s.a)({},t,o))}),{})):{}}catch(c){throw c}var o},A=function(e){return Object(h.a)({},D(e,!0),{},D(e,!1))},T=function(e,t){if(e){if("."===e)return[];if("#"===e)return["#"];if("0"===e)return[];var n=e.match(/\[.*\]/);try{return n?e.split("[").filter((function(e){return e})).map(A):function(e,t){var n=[],a=t.length-1,r={};return Object(O.a)(t).forEach((function(t,o){return o||a||n.push(e[t].features),o?o===a?r[t]?n.push(r[t]):n.push(r,e[t]):!r[t]&&r.features?(n.push(r),r=e[t]):r[t]?void 0:r=r[t]:r=e[t]})),n}(t,e)}catch(a){throw a}}return{}},I=function(e,t){var n=e.changes;try{return n.map(k).map(function(e){return function(t,n){try{var a=t.newFeatures,r=t.environment,o=r.pre,c=r.position,u=r.post;return{environment:{pre:T(o,e),position:T(c,e),post:T(u,e)},newFeatures:T(a,e)}}catch(i){throw S(F(),n+1,i)}}}(t))}catch(a){return a}},L=function(e,t){return!t||t.filter(function(e){return function(t,n){var a=e[n].features;return Object.entries(t).reduce((function(e,t){var n=Object(u.a)(t,2),r=n[0],o=n[1];return!!e&&(!!a.hasOwnProperty(r)&&(!a[r]&&!o||a[r]===o))}),!0)}}(e)).length===t.length},R=function(e){return Object.entries(e)},H=function(e,t){var n=Object(u.a)(t,2),a=n[0],r=n[1];return Object(h.a)({},e,Object(s.a)({},a,r))},U=function(e,t,n){if(!t)return{};var a=R(t).reduce(H,Object(h.a)({},e.features)),r=R(a).map(function(e){return function(t){var n=Object(u.a)(t,2),a=n[0],r=n[1];return e[a][r?"positive":"negative"]}}(n));return r.reduce((function(e,t,n,a){return e.filter(function(e,t){return function(n){return e.map(N(t)).includes(n[t])}}(t,"grapheme"))}),r[r.length-1])[0]},M=function(e,t,n){var a=t.environment,r=a.pre,o=a.post,c=a.position;return e.reduce((function(a,u,i){if(r.find((function(e){return"#"===e})))return function(e,t,n,a,r,o,c,u,i){if(o!==t.length-1)return[].concat(Object(O.a)(e),[r]);if(!L([r],a))return[].concat(Object(O.a)(e),[r]);if(!L(c.slice(o+a.length,o+n.length+a.length),n))return[].concat(Object(O.a)(e),[r]);var s=U(r,u[0],i);return s.grapheme?[].concat(Object(O.a)(e),[s]):Object(O.a)(e)}(a,r,o,c,u,i,e,t.newFeatures,n);if(o.find((function(e){return"#"===e})))return function(e,t,n,a,r,o,c,u,i){if(o+n.length!==c.length)return[].concat(Object(O.a)(e),[r]);if(!L(c.slice(o-t.length,o),t))return[].concat(Object(O.a)(e),[r]);if(!L([r],a))return[].concat(Object(O.a)(e),[r]);var s=U(r,u[0],i);return s.grapheme?[].concat(Object(O.a)(e),[s]):Object(O.a)(e)}(a,r,o,c,u,i,e,t.newFeatures,n);if(i<r.length||i>=e.length-o.length)return[].concat(Object(O.a)(a),[u]);if(!L(e.slice(i-r.length,i),r))return[].concat(Object(O.a)(a),[u]);if(!L([u],c))return[].concat(Object(O.a)(a),[u]);if(!L(e.slice(i,i+o.length),o))return[].concat(Object(O.a)(a),[u]);var s=U(u,t.newFeatures[0],n);return s&&s.grapheme?[].concat(Object(O.a)(a),[s]):Object(O.a)(a)}),[])},V=function(e){return function(t){return e.map((function(e){var n=e.lexeme;return function(e,t){var n=[],a=t.length-1,r={};return Object(O.a)(t).forEach((function(t,o){return o?o===a?r[t]?n.push(r[t]):n.push(r,e[t]):!r[t]&&r.features?(n.push(r),r=e[t]):r[t]?void 0:r=r[t]:r=e[t]})),n}(t,n)}))}},W=function(e){return e.map(N("grapheme")).join("")},X=function(e){var t=e.lexicon,n=Object(w.a)(e,["lexicon"]);return Object(h.a)({},n,{lexicon:t.map(W)})},B=function(e,t){try{var n=e.epochs.reduce((function(t,n,a){var r,o=e.phones,c=e.features,u=e.lexicon;n.parent&&(r=t.find((function(e){return e.pass===n.parent})).lexicon),n.parent||(r=V(u)(o));var i=I(n,o),s=function(e){return function(t){return function(n){return e.map((function(e){return t.reduce((function(e,t,a){return M(e,t,n)}),e)}))}}}(r)(i)(c),l={pass:n.name,lexicon:s};return n.parent&&(l.parent=n.parent),[].concat(Object(O.a)(t),[l])}),[]).map(X);return Object(h.a)({},e,{results:n})}catch(a){return console.log(a),Object(h.a)({},e,{errors:a})}},J=function(e){var t={epochs:[{name:"epoch 1",changes:["[+ occlusive - nasal]>[+ occlusive + nasal]/n_.","a>\u026f/._#","[+ sonorant - low rounded high back]>0/._.","[+ obstruent]>[+ obstruent aspirated ]/#_.","[+ sonorant - rounded]>[+ sonorant + rounded]/._#"]}],phones:{a:{grapheme:"a",features:{sonorant:!0,back:!0,low:!0,high:!1,rounded:!1}},u:{grapheme:"u",features:{sonorant:!0,back:!0,low:!1,high:!0,rounded:!0}},"\u026f":{grapheme:"\u026f",features:{sonorant:!0,back:!0,low:!1,high:!0,rounded:!1}},"\u0259":{grapheme:"\u0259",features:{sonorant:!0,low:!1,rounded:!1,high:!1,back:!1}},t:{grapheme:"t",features:{occlusive:!0,coronal:!0,obstruent:!0,nasal:!1},"\u02b0":{grapheme:"t\u02b0",features:{occlusive:!0,coronal:!0,obstruent:!0,aspirated:!0}}},n:{grapheme:"n",features:{sonorant:!0,nasal:!0,occlusive:!0,coronal:!0}}},options:{output:"default",save:!1},results:[],errors:{},features:{},lexicon:[]};return t.features={sonorant:{positive:[t.phones.a,t.phones.u,t.phones.\u026f,t.phones.\u0259,t.phones.n],negative:[]},back:{positive:[t.phones.a,t.phones.u,t.phones.\u026f],negative:[t.phones.\u0259]},low:{positive:[t.phones.a],negative:[t.phones.u,t.phones.\u026f,t.phones.\u0259]},high:{positive:[t.phones.u,t.phones.\u026f],negative:[t.phones.a,t.phones.\u0259]},rounded:{positive:[t.phones.u],negative:[t.phones.a,t.phones.\u026f,t.phones.\u0259]},occlusive:{positive:[t.phones.t,t.phones.n,t.phones.t.\u02b0],negative:[]},coronal:{positive:[t.phones.t,t.phones.n,t.phones.t.\u02b0],negative:[]},obstruent:{positive:[t.phones.t,t.phones.n,t.phones.t.\u02b0],negative:[]},nasal:{positive:[t.phones.n],negative:[t.phones.t,t.phones.t.\u02b0]},aspirated:{positive:[t.phones.t.\u02b0],negative:[t.phones.t]}},t.lexicon=[{lexeme:"anta",epoch:t.epochs[0]},{lexeme:"anat",epoch:t.epochs[0]},{lexeme:"an\u0259t",epoch:t.epochs[0]},{lexeme:"anna",epoch:t.epochs[0]},{lexeme:"tan",epoch:t.epochs[0]},{lexeme:"\u0259nta",epoch:t.epochs[0]}],e>-1&&(t.epochs[0].changes=t.epochs[0].changes.splice(0,e)),t},$=function(e,t){switch(t.type){case"INIT":return J();case"ADD_LEXEME":return function(e,t){var n=j(t.value.lexeme,t.value.epoch,e);return Object(h.a)({},e,{lexicon:[].concat(Object(O.a)(e.lexicon),[n])})}(e,t);case"SET_LEXICON":return function(e,t){var n=t.value;return n=n.map((function(t){return j(t.lexeme,t.epoch,e)})),Object(h.a)({},e,{lexicon:n})}(e,t);case"ADD_EPOCH":return function(e,t){var n={name:t.value.name,changes:t.value.changes||[""]};return Object(h.a)({},e,{epochs:[].concat(Object(O.a)(e.epochs),[n])})}(e,t);case"SET_EPOCH":return function(e,t){var n=t.value.index;if("number"!==typeof n)return e;var a=e.epochs;return a[n].name=t.value.name?t.value.name:a[n].name,a[n].changes=t.value.changes?t.value.changes:a[n].changes,a[n].parent=t.value.parent&&"none"!==t.value.parent?t.value.parent:null,Object(h.a)({},e,{epochs:Object(O.a)(a)})}(e,t);case"REMOVE_EPOCH":return function(e,t){var n=e.epochs.filter((function(e){return e.name!==t.value.name}));return Object(h.a)({},e,{epochs:Object(O.a)(n)})}(e,t);case"ADD_FEATURE":return function(e,t){var n=t.value.positivePhones||[],a=t.value.negativePhones||[],r=t.value.feature,o=[].concat(Object(O.a)(n),Object(O.a)(a)).reduce((function(e,t){return function(e,t){var n={};return t.split("").forEach((function(a,r){r&&(n[a]={}),r||e[a]||(e[a]={}),n=0===r?e[a]:n[a],r===t.length-1&&(n.grapheme=t)})),e}(e,t)}),e.phones);n&&(n.reduce((function(e,t){return _(e,t,r,!0)}),o),n=n.map((function(e){return x(o,e)}))),a&&(a.reduce((function(e,t){return _(e,t,r,!1)}),o),a=a.map((function(e){return x(o,e)})));var c=Object(s.a)({},t.value.feature,{positive:n,negative:a});return Object(h.a)({},e,{features:Object(h.a)({},e.features,{},c),phones:o})}(e,t);case"SET_OPTIONS":return function(e,t){var n=t.value.option,a=t.value.setValue;"true"===a&&(a=!0),"false"===a&&(a=!1);var r=Object(h.a)({},e);return r.options[n]=a,r}(e,t);case"RUN":return B(e);default:return e}},q=function(){var e=Object(a.useReducer)($,{},J),t=Object(u.a)(e,2),n=t[0],o=t[1],c=n.lexicon,s=n.phones,l=(n.phonemes,n.epochs),p=n.options,h=n.features,f=n.results;return r.a.createElement("div",{className:"PhonoChangeApplier","data-testid":"PhonoChangeApplier"},r.a.createElement(i,{lexicon:c,dispatch:o}),r.a.createElement(m,{phones:s,features:h,dispatch:o}),r.a.createElement(v,{epochs:l,dispatch:o}),r.a.createElement(E,{options:p,dispatch:o}),r.a.createElement(b,{results:f,options:p,dispatch:o}))};var z=function(){return r.a.createElement("div",{className:"App","data-testid":"App"},r.a.createElement("h1",null,"Phono Change Applier"),r.a.createElement(q,null))};Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));c.a.render(r.a.createElement(z,null),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then((function(e){e.unregister()}))}],[[12,1,2]]]);
//# sourceMappingURL=main.e83b5fcd.chunk.js.map