debug parse_latl, hook up Output to state

This commit is contained in:
Sorrel Bri 2020-03-02 22:46:08 -08:00
parent 78b513c9be
commit da45699c59
6 changed files with 13 additions and 15 deletions

View file

@ -21,7 +21,7 @@ const PhonoChangeApplier = () => {
{}, {},
initState initState
) )
const { lexicon, phones, phonemes, epochs, options, features, results, errors, latl } = state; const { lexicon, phones, phonemes, epochs, options, features, results, errors, latl, parseResults } = state;
return ( return (
<> <>
@ -30,7 +30,7 @@ const PhonoChangeApplier = () => {
<Link to="/">Back to GUI</Link> <Link to="/">Back to GUI</Link>
<div className="PhonoChangeApplier PhonoChangeApplier--latl"> <div className="PhonoChangeApplier PhonoChangeApplier--latl">
<Latl latl={latl} dispatch={dispatch}/> <Latl latl={latl} dispatch={dispatch}/>
<LatlOutput results={results} options={options} errors={errors} dispatch={dispatch}/> <LatlOutput results={results} options={options} parseResults={parseResults} errors={errors} dispatch={dispatch}/>
</div> </div>
</Route> </Route>

View file

@ -2,7 +2,7 @@ import React from 'react';
import './LatlOutput.scss'; import './LatlOutput.scss';
import Output from './Output'; import Output from './Output';
const LatlOutput = ({results, options, dispatch, errors}) => { const LatlOutput = ({results, options, dispatch, errors, parseResults}) => {
const handleClick = e => dispatchFunc => { const handleClick = e => dispatchFunc => {
e.preventDefault() e.preventDefault()
return dispatchFunc(); return dispatchFunc();
@ -61,7 +61,7 @@ const LatlOutput = ({results, options, dispatch, errors}) => {
value="Run" value="Run"
/> />
</form> </form>
<Output results={results} errors={errors} options={options}/> <Output results={results} errors={errors} options={options} parseResults={parseResults}/>
</div> </div>
); );
} }

View file

@ -2,7 +2,7 @@ import React from 'react';
import './Output.scss'; import './Output.scss';
const Output = props => { const Output = props => {
const { results, options, errors } = props; const { results, options, errors, parseResults } = props;
const renderResults = () => { const renderResults = () => {
switch(options.output) { switch(options.output) {
case 'default': case 'default':
@ -28,6 +28,7 @@ const Output = props => {
<div className="Output" data-testid="Output"> <div className="Output" data-testid="Output">
<h3>Results of Run</h3> <h3>Results of Run</h3>
<div data-testid="Output-lexicon" className="Output__container"> <div data-testid="Output-lexicon" className="Output__container">
{parseResults ? parseResults : <></>}
{results && results.length ? renderResults() : <></>} {results && results.length ? renderResults() : <></>}
</div> </div>
</div> </div>

View file

@ -1,3 +1,3 @@
export const clearOutput = (state, action) => { export const clearOutput = (state, action) => {
return { ...state, results: [], errors: {} }; return { ...state, results: [], errors: {}, parseResults: '' };
} }

View file

@ -1,6 +1,6 @@
export const setLatl = (state, action) => { export const setLatl = (state, action) => {
let latl = action.value; let latl = action.value;
return {...state, latl}; return {...state, latl, parseResults: ''};
} }
const getOneToken = (latl, tokens) => { const getOneToken = (latl, tokens) => {
@ -291,7 +291,6 @@ export const buildTree = tokens => {
} }
const nodes = tokens.reduce(addToken, []); const nodes = tokens.reduce(addToken, []);
// return nodes // return nodes
console.log(nodes)
const tree = nodes.reduce(connectNodes, bareTree); const tree = nodes.reduce(connectNodes, bareTree);
return tree; return tree;
} }
@ -309,12 +308,10 @@ export const parseLatl = (state, action) => {
const latl = state.latl; const latl = state.latl;
const AST = generateAST(latl); const AST = generateAST(latl);
Object.entries(AST).forEach(([key, value]) => state[key] = value); Object.entries(AST).forEach(([key, value]) => state[key] = value);
console.log(state) return { ...state, parseResults: 'latl parsed successfully', results:[] }
console.log(AST)
return { ...state, parseResults: 'success' }
} }
catch (e) { catch (e) {
return { ...state, errors: e} return { ...state, parseResults: e}
} }
} }

View file

@ -221,7 +221,7 @@ const transformLexemeCoda = (newLexeme, pre, post, position, phoneme, index, lex
if (!isEnvironmentBoundByRule([phoneme], position)) return [...newLexeme, phoneme]; if (!isEnvironmentBoundByRule([phoneme], position)) return [...newLexeme, phoneme];
const newPhoneme = transformPhoneme(phoneme, newFeatures[0], features); const newPhoneme = transformPhoneme(phoneme, newFeatures[0], features);
// if deletion occurs // if deletion occurs
if (!newPhoneme.grapheme) return [ ...newLexeme] ; if (!newPhoneme || !newPhoneme.grapheme) return [ ...newLexeme] ;
return [...newLexeme, newPhoneme]; return [...newLexeme, newPhoneme];
} }
@ -280,9 +280,9 @@ export const run = (state: stateType, action: resultsAction): stateType => {
}, []); }, []);
const results = passResults.map(stringifyResults); const results = passResults.map(stringifyResults);
return {...state, results, errors: {} } return {...state, results, errors: {}, parseResults: '' }
} catch (err) { } catch (err) {
console.log(err) console.log(err)
return {...state, errors: err, results:[] }; return {...state, errors: err, results:[], parseResults: '' };
} }
} }