feature-change-applier/static/js/main.ebcfda61.chunk.js
2020-02-28 17:07:44 -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(16),n(17),n(3)),i=(n(18),n(19),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(20),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],p=i[1],m=Object(a.useState)("t\u02b0 / p\u02b0 / k\u02b0"),h=Object(u.a)(m,2),f=h[0],v=h[1],g=Object(a.useState)("t / p / k"),d=Object(u.a)(g,2),E=d[0],b=d[1],O=function(e){return""===e?[""]:e.split("/").map((function(e){return e.trim()}))},j=function(e){var t=Object(u.a)(e,3),n=t[0],a=t[1],r=t[2];return{type:"ADD_FEATURE",value:{positivePhones:O(n),negativePhones:O(a),feature:r}}};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=Object(u.a)(n,1)[0],c=e[a],i=c.plus,s=c.minus;return r.a.createElement("li",{key:"feature__".concat(a)},r.a.createElement("span",{className:"feature--names-and-phones"},r.a.createElement("span",{className:"feature--feature-name"},"[+ ".concat(a,"]")),r.a.createElement("span",{className:"feature--feature-phones"},i)),r.a.createElement("span",{className:"feature--names-and-phones"},r.a.createElement("span",{className:"feature--feature-name"},"[- ".concat(a,"]")),r.a.createElement("span",{className:"feature--feature-phones"},s)),r.a.createElement("button",{className:"delete-feature",onClick:function(e){return function(e,t){return e.preventDefault(),o({type:"DELETE_FEATURE",value:t})}(e,a)}},"X"))}))}(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 p(e.target.value)}}),r.a.createElement("label",{htmlFor:"positive-phones"},"+",r.a.createElement("input",{id:"positive-phones",type:"text",name:"phonemes",value:f,onChange:function(e){return v(e.target.value)}})),r.a.createElement("label",{htmlFor:"negative-phones"},"-",r.a.createElement("input",{id:"negative-phones",type:"text",name:"phonemes",value:E,onChange:function(e){return b(e.target.value)}})),r.a.createElement("input",{className:"form form--add",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)(j)([f,E,l])},value:"Add feature"})))}),p=(n(21),n(2)),m=(n(22),function(e){var t=e.epochIndex,n=e.error,o=e.removeEpoch,c=e.epochs,i=Object(a.useState)(e.epoch?e.epoch:{name:"",changes:[""],parent:"none"}),s=Object(u.a)(i,2),l=s[0],m=s[1],h=function(n,a){a(n),e.updateEpoch(l,t)};Object(a.useEffect)((function(){e.updateEpoch(l,t)}),[l]);var f=function(e){return r.a.createElement("option",{key:"".concat(l.name,"__parent-option--").concat(e.name),value:e.name},e.name)},v=function(e){return e.name===l.name?{name:"none"}:e},g=function(e){return!e.parent||e.parent!==l.name};return r.a.createElement(r.a.Fragment,null,r.a.createElement("h4",null,l.name),n?r.a.createElement("p",{className:"error"},n):r.a.createElement(r.a.Fragment,null),r.a.createElement("form",{className:"SoundChangeSuite__form","data-testid":"".concat(l.name,"_SoundChangeSuite_changes")},r.a.createElement("label",{htmlFor:"".concat(l.name,"-name")},"Name:"),r.a.createElement("input",{type:"text",name:"epoch",id:"".concat(l.name,"-name"),cols:"30",rows:"1",value:l.name,onChange:function(e){return h(e,(function(){m(Object(p.a)({},l,{name:e.target.value}))}))}}),t?r.a.createElement(r.a.Fragment,null,r.a.createElement("label",{htmlFor:"".concat(l.name,"-parent")},"Parent Epoch:"),r.a.createElement("select",{name:"parent",list:"".concat(l.name,"-parents-list"),value:l.parent||"none",onChange:function(e){return h(e,(function(){console.log(e.target.value),m(Object(p.a)({},l,{parent:e.target.value}))}))}},c.map(v).filter(g).map(f))):r.a.createElement(r.a.Fragment,null),r.a.createElement("textarea",{name:"changes",id:"",cols:"30",rows:"10",value:l.changes.join("\n"),onChange:function(e){return h(e,(function(){return m(Object(p.a)({},l,{changes:e.target.value.split(/\n/).map((function(e){return" "===e?"[+ feature]>[- feature]/_#":e}))}))}))}})),r.a.createElement("form",{onSubmit:function(e){return o(e,l.name)}},r.a.createElement("input",{className:"form form--remove",type:"submit",name:"remove-epoch",value:"remove ".concat(l.name)})))}),h=function(e){var t=e.epochs,n=e.errors,a=e.dispatch,o=function(e,t){e.preventDefault(),a({type:"REMOVE_EPOCH",value:{name:t}})},c=function(e,t){var n={name:e.name,index:t,changes:e.changes,parent:e.parent};a({type:"SET_EPOCH",value:n})},u=function(e){return e===t.length-1?r.a.createElement("form",{onSubmit:function(e){return function(e){e.preventDefault();var n=t.length+1;a({type:"ADD_EPOCH",value:{name:"Epoch ".concat(n)}})}(e)}},r.a.createElement("input",{className:"form form--add",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,a){var i=n.epoch?n.error:null;return r.a.createElement("div",{className:"SoundChangeSuite","data-testid":"".concat(e.name,"_SoundChangeSuite"),key:"epoch-".concat(a)},r.a.createElement(m,{epochIndex:a,epoch:e,updateEpoch:c,removeEpoch:o,epochs:t,error:i}),u(a))})):u(-1))},f=(n(23),n(24),function(e){var t=e.options,n=e.dispatch,o=Object(a.useState)(""),c=Object(u.a)(o,2);c[0],c[1];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 function(e){var t=e.target,a=t.name,r=t.id;n({type:"SET_OPTIONS",value:{option:a,setValue:r}})}(e)}}),r.a.createElement("label",{htmlFor:"default"},"Default",r.a.createElement("span",{className:"Options__output-example"}," output")),r.a.createElement("input",{className:"form form--add",type:"submit",value:"Run Changes"}),r.a.createElement("input",{className:"form form--remove",type:"button",value:"Clear Output",onClick:function(e){return function(e){e.preventDefault(),console.log("clearing"),n({type:"CLEAR",value:{}})}(e)}})))}),v=(n(27),function(e){var t=e.results,n=e.options,a=(e.errors,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)))}),g=n(1),d=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},E=function(e,t){return t.split("").reduce((function(t,n,a){return t=0===a?e[n]:t[n]}),{})},b=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(p.a)({},r.features,Object(s.a)({},n,a)))})),e},O=n(10),j=n(6);function x(){var e=Object(j.a)(["Error in line ",": ",""]);return x=function(){return e},e}function _(){var e=Object(j.a)(["Error in line ",": ",""]);return _=function(){return e},e}var w=function(e){return function(t){return t[e]}},y=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)},N=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 y(_(),t+1,c)}},F=function(e){return"-"!==e&&"+"!==e&&"]"!==e&&"["!==e&&" "!==e},C=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(F);if(t.length)throw"Unknown token '".concat(t[0],"'")}(r),r.trim().match(/\w+/g).reduce((o=t,function(e,t){return Object(p.a)({},e,Object(s.a)({},t,o))}),{})):{}}catch(c){throw c}var o},k=function(e){return Object(p.a)({},C(e,!0),{},C(e,!1))},S=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(k):function(e,t){var n=[],a=t.length-1,r={};return Object(g.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{}},P=function(e,t){var n=e.changes;try{return n.map(N).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:S(o,e),position:S(c,e),post:S(u,e)},newFeatures:S(a,e)}}catch(i){throw y(x(),n+1,i)}}}(t))}catch(a){throw{epoch:e.name,error:a}}},D=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},A=function(e){return Object.entries(e)},T=function(e,t){var n=Object(u.a)(t,2),a=n[0],r=n[1];return Object(p.a)({},e,Object(s.a)({},a,r))},L=function(e,t,n){if(!t)return{};var a=A(t).reduce(T,Object(p.a)({},e.features)),r=A(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(w(t)).includes(n[t])}}(t,"grapheme"))}),r[r.length-1])[0]},R=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(g.a)(e),[r]);if(!D([r],a))return[].concat(Object(g.a)(e),[r]);if(!D(c.slice(o+a.length,o+n.length+a.length),n))return[].concat(Object(g.a)(e),[r]);var s=L(r,u[0],i);return s.grapheme?[].concat(Object(g.a)(e),[s]):Object(g.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(g.a)(e),[r]);if(!D(c.slice(o-t.length,o),t))return[].concat(Object(g.a)(e),[r]);if(!D([r],a))return[].concat(Object(g.a)(e),[r]);var s=L(r,u[0],i);return s.grapheme?[].concat(Object(g.a)(e),[s]):Object(g.a)(e)}(a,r,o,c,u,i,e,t.newFeatures,n);if(i<r.length||i>=e.length-o.length)return[].concat(Object(g.a)(a),[u]);if(!D(e.slice(i-r.length,i),r))return[].concat(Object(g.a)(a),[u]);if(!D([u],c))return[].concat(Object(g.a)(a),[u]);if(!D(e.slice(i,i+o.length),o))return[].concat(Object(g.a)(a),[u]);var s=L(u,t.newFeatures[0],n);return s&&s.grapheme?[].concat(Object(g.a)(a),[s]):Object(g.a)(a)}),[])},I=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(g.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)}))}},U=function(e){return e.map(w("grapheme")).join("")},H=function(e){var t=e.lexicon,n=Object(O.a)(e,["lexicon"]);return Object(p.a)({},n,{lexicon:t.map(U)})},M=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=I(u)(o));var i=P(n,o),s=function(e){return function(t){return function(n){return e.map((function(e){return t.reduce((function(e,t,a){return R(e,t,n)}),e)}))}}}(r)(i)(c),l={pass:n.name,lexicon:s};return n.parent&&(l.parent=n.parent),[].concat(Object(g.a)(t),[l])}),[]).map(H);return Object(p.a)({},e,{results:n,errors:{}})}catch(a){return console.log(a),Object(p.a)({},e,{errors:a,results:[]})}},V=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},X=function(e,t){switch(t.type){case"INIT":return V();case"ADD_LEXEME":return function(e,t){var n=d(t.value.lexeme,t.value.epoch,e);return Object(p.a)({},e,{lexicon:[].concat(Object(g.a)(e.lexicon),[n])})}(e,t);case"SET_LEXICON":return function(e,t){var n=t.value;return n=n.map((function(t){return d(t.lexeme,t.epoch,e)})),Object(p.a)({},e,{lexicon:n})}(e,t);case"ADD_EPOCH":return function(e,t){var n={name:t.value.name,changes:t.value.changes||[""],parent:null};return Object(p.a)({},e,{epochs:[].concat(Object(g.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(p.a)({},e,{epochs:Object(g.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(p.a)({},e,{epochs:Object(g.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(g.a)(n),Object(g.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 b(e,t,r,!0)}),o),n=n.map((function(e){return E(o,e)}))),a&&(a.reduce((function(e,t){return b(e,t,r,!1)}),o),a=a.map((function(e){return E(o,e)})));var c=Object(s.a)({},t.value.feature,{positive:n,negative:a});return Object(p.a)({},e,{features:Object(p.a)({},e.features,{},c),phones:o})}(e,t);case"DELETE_FEATURE":return function(e,t){console.log("deleting");var n=t.value;return delete e.features[n],console.log(e),Object(p.a)({},e)}(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(p.a)({},e);return r.options[n]=a,r}(e,t);case"CLEAR":return function(e,t){return Object(p.a)({},e,{results:[],errors:{}})}(e);case"RUN":return M(e);default:return e}},W=function(){var e=Object(a.useReducer)(X,{},V),t=Object(u.a)(e,2),n=t[0],o=t[1],c=n.lexicon,s=n.phones,p=(n.phonemes,n.epochs),m=n.options,g=n.features,d=n.results,E=n.errors;return r.a.createElement("div",{className:"PhonoChangeApplier","data-testid":"PhonoChangeApplier"},r.a.createElement(i,{lexicon:c,dispatch:o}),r.a.createElement(l,{phones:s,features:g,dispatch:o}),r.a.createElement(h,{epochs:p,errors:E,dispatch:o}),r.a.createElement(f,{options:m,dispatch:o}),r.a.createElement(v,{results:d,options:m,dispatch:o}))};var B=function(){return r.a.createElement("div",{className:"App","data-testid":"App"},r.a.createElement("h1",null,"Feature Change Applier"),r.a.createElement(W,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(B,null),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then((function(e){e.unregister()}))}],[[11,1,2]]]);
//# sourceMappingURL=main.ebcfda61.chunk.js.map