2019-11-27 02:39:40 +00:00
|
|
|
import React, { useState } from 'react';
|
2019-11-26 22:42:19 +00:00
|
|
|
import './PhonoChangeApplier.scss';
|
|
|
|
|
2019-11-26 23:09:51 +00:00
|
|
|
import ProtoLang from './components/ProtoLang';
|
2019-11-27 02:44:07 +00:00
|
|
|
import Features from './components/Features';
|
2019-11-29 23:36:55 +00:00
|
|
|
import Epochs from './components/Epochs';
|
2019-11-30 05:48:37 +00:00
|
|
|
import Options from './components/Options';
|
2019-11-30 07:49:51 +00:00
|
|
|
import Output from './components/Output';
|
2019-11-26 23:09:51 +00:00
|
|
|
|
2019-11-26 22:42:19 +00:00
|
|
|
const PhonoChangeApplier = () => {
|
2019-11-27 07:34:00 +00:00
|
|
|
const [ lexicon, setLexicon ] = useState(['one']);
|
2019-11-29 22:57:40 +00:00
|
|
|
const [ phonemes, setPhonemes ] = useState(
|
2019-11-27 07:34:00 +00:00
|
|
|
{ phoneme: [ 'feature' ] }
|
|
|
|
);
|
2019-11-30 03:32:42 +00:00
|
|
|
const [ epochs, setEpochs ] = useState([{name: 'epoch 1', changes:['[+ feature]>[- feature]/_#']}]);
|
2019-11-30 06:54:52 +00:00
|
|
|
const [ options, setOptions ] = useState({output: 'default', save: false})
|
2019-11-30 08:00:09 +00:00
|
|
|
const [ results, setResults ] = useState([])
|
2019-11-30 23:58:44 +00:00
|
|
|
const [ errors, setErrors ] = useState({})
|
2019-11-30 07:37:32 +00:00
|
|
|
|
|
|
|
const runChanges = e => {
|
|
|
|
e.preventDefault();
|
2019-11-30 23:58:44 +00:00
|
|
|
|
|
|
|
let ruleError = epochs.reduce((errorObject, epoch) => {
|
2019-11-30 23:13:10 +00:00
|
|
|
epoch.changes.map((change, index) => {
|
|
|
|
if (!change.match(/>.*\/.*_/)) errorObject[epoch.name]
|
|
|
|
? errorObject[epoch.name].push(index)
|
|
|
|
: errorObject[epoch.name] = [index]
|
|
|
|
})
|
|
|
|
return errorObject;
|
|
|
|
}, {})
|
2019-11-30 21:50:37 +00:00
|
|
|
|
2019-11-30 23:58:44 +00:00
|
|
|
if (Object.entries(ruleError).length) return setErrors(ruleError)
|
|
|
|
setErrors({});
|
|
|
|
|
|
|
|
// setResults
|
2019-11-30 07:37:32 +00:00
|
|
|
}
|
2019-11-27 02:39:40 +00:00
|
|
|
|
2019-11-26 23:09:51 +00:00
|
|
|
return (
|
|
|
|
<div className="PhonoChangeApplier" data-testid="PhonoChangeApplier">
|
2019-11-27 02:39:40 +00:00
|
|
|
<ProtoLang lexicon={lexicon} setLexicon={setLexicon}/>
|
2019-11-27 07:34:00 +00:00
|
|
|
<Features phonemes={phonemes} setPhonemes={setPhonemes}/>
|
2019-11-30 23:58:44 +00:00
|
|
|
<Epochs epochs={epochs} setEpochs={setEpochs} errors={errors}/>
|
2019-11-30 07:37:32 +00:00
|
|
|
<Options options={options} setOptions={setOptions} runChanges={runChanges}/>
|
2019-11-30 08:00:09 +00:00
|
|
|
<Output results={results} setResults={setResults}/>
|
2019-11-26 23:09:51 +00:00
|
|
|
</div>
|
|
|
|
);
|
2019-11-26 22:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PhonoChangeApplier;
|