2021-09-12 00:55:17 -07:00
|
|
|
import React, {Component} from 'react';
|
2019-01-22 00:41:13 -08:00
|
|
|
|
2019-01-25 02:19:22 -08:00
|
|
|
import './App.scss';
|
2021-09-12 02:22:50 -07:00
|
|
|
import {declineSaimiar} from './saimiar_morphology';
|
2019-01-25 02:19:22 -08:00
|
|
|
|
2021-09-12 00:55:17 -07:00
|
|
|
const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
|
2019-01-24 02:56:41 -08:00
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
enum Conlang {
|
2021-09-12 20:48:11 -07:00
|
|
|
Saimiar = 'saimiar',
|
|
|
|
Elesu = 'elesu',
|
|
|
|
Tukvaysi = 'tukvaysi',
|
|
|
|
Juteyuji = 'juteyuji',
|
2019-01-24 02:56:41 -08:00
|
|
|
}
|
|
|
|
|
2021-09-12 21:11:52 -07:00
|
|
|
enum SearchDirection {
|
|
|
|
ToConlang,
|
|
|
|
ToEnglish
|
|
|
|
}
|
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
const renderConlang = (conlang: Conlang): string => {
|
|
|
|
if (conlang === Conlang.Saimiar) {
|
2021-09-12 02:07:44 -07:00
|
|
|
return 'Saimiar';
|
|
|
|
}
|
2021-09-12 00:55:17 -07:00
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
if (conlang === Conlang.Elesu) {
|
2021-09-12 02:07:44 -07:00
|
|
|
return 'Elésu';
|
|
|
|
}
|
2021-09-12 00:55:17 -07:00
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
if (conlang === Conlang.Juteyuji) {
|
2021-09-12 02:07:44 -07:00
|
|
|
return 'Juteyuji';
|
|
|
|
}
|
2021-09-12 00:55:17 -07:00
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
if (conlang === Conlang.Tukvaysi) {
|
2021-09-12 02:07:44 -07:00
|
|
|
return 'Tukvaysi';
|
|
|
|
}
|
2021-09-12 17:22:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
function makeRequest(queryString, jsonHandler) {
|
|
|
|
const effectiveUrl = `${backendUrl}/${queryString}`;
|
|
|
|
fetch(`${effectiveUrl}`)
|
|
|
|
.then((resp) => resp.json())
|
|
|
|
.then((json) => {
|
|
|
|
jsonHandler(json);
|
|
|
|
});
|
2019-01-28 23:08:43 -08:00
|
|
|
}
|
|
|
|
|
2021-09-12 21:35:46 -07:00
|
|
|
interface EntryProps {
|
|
|
|
conlang: Conlang;
|
|
|
|
entry: SaiEntryProps | JutEntryProps;
|
|
|
|
key: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Entry = (props: EntryProps) => {
|
2021-09-12 02:07:44 -07:00
|
|
|
const {conlang} = props;
|
2021-09-12 17:22:00 -07:00
|
|
|
if (conlang === Conlang.Saimiar) {
|
2021-09-12 21:35:46 -07:00
|
|
|
return <SaiEntry entry={ props.entry as SaiEntryProps } />;
|
2021-09-12 02:07:44 -07:00
|
|
|
}
|
2021-09-12 00:55:17 -07:00
|
|
|
|
2021-09-12 20:48:11 -07:00
|
|
|
if (conlang === Conlang.Juteyuji) {
|
2021-09-12 21:35:46 -07:00
|
|
|
return <JutEntry entry={ props.entry as JutEntryProps } />;
|
2021-09-12 20:48:11 -07:00
|
|
|
}
|
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
return <div>Conlang { conlang } not yet supported</div>;
|
2021-09-12 01:07:30 -07:00
|
|
|
};
|
2019-01-28 23:08:43 -08:00
|
|
|
|
2021-09-12 21:35:46 -07:00
|
|
|
interface SaiEntryProps {
|
|
|
|
id: number;
|
|
|
|
sai: string;
|
|
|
|
eng: string;
|
|
|
|
syn_category: string;
|
|
|
|
morph_type: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SaiEntry = (props: {entry: SaiEntryProps}) => {
|
2021-09-12 02:07:44 -07:00
|
|
|
const {entry} = props;
|
|
|
|
const synCategory = entry.syn_category;
|
|
|
|
const isNominal = synCategory === 'nominal';
|
|
|
|
return (
|
|
|
|
<div className="searchResult" key={ entry.id }>
|
|
|
|
<b>{ entry.sai }</b> - { entry.eng }
|
|
|
|
<br />
|
|
|
|
<span className="synclass">
|
|
|
|
<i>{ entry.syn_category }</i>
|
|
|
|
{ entry.morph_type ? `\t\t${entry.morph_type}` : null }
|
|
|
|
<br/>
|
|
|
|
{ isNominal ? formatMorphology(entry) : null }
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
2021-09-12 01:07:30 -07:00
|
|
|
};
|
2019-01-26 01:34:35 -08:00
|
|
|
|
2021-09-12 21:35:46 -07:00
|
|
|
interface JutEntryProps {
|
|
|
|
id: number;
|
|
|
|
jut: string;
|
|
|
|
eng: string;
|
|
|
|
syn_category: string;
|
|
|
|
gender: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const JutEntry = (props: {entry: JutEntryProps}) => {
|
2021-09-12 20:48:11 -07:00
|
|
|
const {entry} = props;
|
|
|
|
console.log(props);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="searchResult" key={ entry.id }>
|
|
|
|
<b>{ entry.jut }</b> - { entry.eng }
|
|
|
|
<br/>
|
|
|
|
<span className="synclass">
|
|
|
|
{ entry.syn_category === 'noun' ? entry.gender : null }
|
|
|
|
</span>
|
|
|
|
</div>);
|
|
|
|
};
|
|
|
|
|
2019-07-23 02:54:10 -07:00
|
|
|
function formatMorphology(entry) {
|
2021-09-12 02:07:44 -07:00
|
|
|
const decl = declineSaimiar(entry);
|
|
|
|
if (!decl) {
|
|
|
|
return '';
|
|
|
|
}
|
2021-09-12 00:55:17 -07:00
|
|
|
|
2021-09-12 02:07:44 -07:00
|
|
|
return (<span style={ {fontSize: 'medium', color: '#6a3131'} } >
|
2021-09-11 20:14:59 -07:00
|
|
|
Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>,
|
|
|
|
Adp: <i>{decl.adp}</i>,
|
|
|
|
All: <i>{decl.all}</i>,
|
|
|
|
Loc: <i>{decl.loc}</i>,
|
|
|
|
Ell: <i>{decl.ell}</i>,
|
|
|
|
Inst: <i>{decl.inst}</i>,
|
|
|
|
Rel: <i>{decl.rel}</i>
|
2021-09-12 02:07:44 -07:00
|
|
|
</span>);
|
2019-07-23 02:54:10 -07:00
|
|
|
}
|
|
|
|
|
2021-09-12 21:35:46 -07:00
|
|
|
interface ResultsProps {
|
|
|
|
searchResults: any;
|
|
|
|
searchTerm: string;
|
|
|
|
conlang: Conlang;
|
|
|
|
direction: SearchDirection;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Results = (props: ResultsProps) => {
|
2021-09-12 02:07:44 -07:00
|
|
|
const content = () => {
|
|
|
|
const {conlang} = props;
|
|
|
|
const num = props.searchResults.length;
|
2021-09-12 20:48:11 -07:00
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
const renderedName = renderConlang(conlang);
|
2021-09-12 21:11:52 -07:00
|
|
|
const searchType = (props.direction === SearchDirection.ToConlang) ? `English -> ${renderedName}` : `${renderedName} -> English`;
|
2021-09-12 02:07:44 -07:00
|
|
|
const header = (
|
|
|
|
<div className="searchResultHeader" key="header">
|
2021-09-12 01:07:30 -07:00
|
|
|
Searched for <b>{ props.searchTerm }</b>, { searchType }, found { num } result(s)
|
2021-09-12 02:07:44 -07:00
|
|
|
</div>);
|
|
|
|
const entries = props.searchResults.map(
|
|
|
|
(entry, _idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />,
|
|
|
|
);
|
|
|
|
return [header].concat(entries);
|
|
|
|
};
|
|
|
|
|
|
|
|
const results = props.searchResults;
|
|
|
|
return (
|
|
|
|
<div className="results">
|
|
|
|
{ results ? content() : 'No search' }
|
|
|
|
</div>
|
|
|
|
);
|
2021-09-12 01:07:30 -07:00
|
|
|
};
|
2019-01-26 01:18:27 -08:00
|
|
|
|
2021-09-12 02:22:50 -07:00
|
|
|
interface App {
|
|
|
|
[x: string]: any;
|
2021-09-12 17:22:00 -07:00
|
|
|
}
|
2021-09-12 02:22:50 -07:00
|
|
|
|
2019-01-22 00:41:13 -08:00
|
|
|
class App extends Component {
|
2021-09-12 02:07:44 -07:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.input = React.createRef();
|
|
|
|
this.handleLangChange = this.handleLangChange.bind(this);
|
|
|
|
|
|
|
|
this.searchEng = this.searchEng.bind(this);
|
|
|
|
this.searchSaimiar = this.searchSaimiar.bind(this);
|
2021-09-12 20:48:11 -07:00
|
|
|
this.searchJuteyuji = this.searchJuteyuji.bind(this);
|
2021-09-12 17:22:00 -07:00
|
|
|
this.searchConlang = this.searchConlang.bind(this);
|
2021-09-12 02:07:44 -07:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
searchResults: null,
|
2021-09-12 17:22:00 -07:00
|
|
|
conlang: Conlang.Saimiar,
|
2021-09-12 02:07:44 -07:00
|
|
|
direction: null,
|
|
|
|
searchTerm: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-12 17:22:00 -07:00
|
|
|
searchConlang(_evt) {
|
2021-09-12 02:07:44 -07:00
|
|
|
const searchTerm = this.input.current.value;
|
2021-09-12 17:22:00 -07:00
|
|
|
const {conlang} = this.state;
|
|
|
|
if (conlang === Conlang.Saimiar) {
|
|
|
|
this.searchSaimiar(searchTerm);
|
2021-09-12 21:21:55 -07:00
|
|
|
} else if (conlang === Conlang.Juteyuji) {
|
2021-09-12 20:48:11 -07:00
|
|
|
this.searchJuteyuji(searchTerm);
|
2021-09-12 17:22:00 -07:00
|
|
|
} else {
|
|
|
|
console.error(`Conlang ${conlang} not supported`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
searchSaimiar(searchTerm: string) {
|
2021-09-12 02:07:44 -07:00
|
|
|
const request = `saimiar?sai=like.*${searchTerm}*`;
|
|
|
|
if (searchTerm === '') {
|
|
|
|
this.setState({searchResults: null, searchTerm: null, direction: null});
|
|
|
|
} else {
|
|
|
|
makeRequest(request, (json) => {
|
2021-09-12 21:11:52 -07:00
|
|
|
this.setState({searchResults: json, searchTerm, direction: SearchDirection.ToEnglish});
|
2021-09-12 02:07:44 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 20:48:11 -07:00
|
|
|
searchJuteyuji(searchTerm: string) {
|
|
|
|
const request = `juteyuji?jut=like.*${searchTerm}*`;
|
|
|
|
if (searchTerm === '') {
|
|
|
|
this.setState({searchResults: null, searchTerm: null, direction: null});
|
|
|
|
} else {
|
|
|
|
makeRequest(request, (json) => {
|
2021-09-12 21:11:52 -07:00
|
|
|
this.setState({searchResults: json, searchTerm, direction: SearchDirection.ToEnglish});
|
2021-09-12 20:48:11 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 02:07:44 -07:00
|
|
|
searchEng(_evt) {
|
|
|
|
const searchTerm = this.input.current.value;
|
2021-09-12 20:48:11 -07:00
|
|
|
const {conlang} = this.state;
|
|
|
|
const request = `${conlang}?eng=like.*${searchTerm}*`;
|
2021-09-12 02:07:44 -07:00
|
|
|
if (searchTerm === '') {
|
|
|
|
this.setState({searchResults: null, searchTerm: null});
|
|
|
|
} else {
|
|
|
|
makeRequest(request, (json) => {
|
2021-09-12 21:11:52 -07:00
|
|
|
this.setState({searchResults: json, searchTerm, direction: SearchDirection.ToConlang});
|
2021-09-12 02:07:44 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLangChange(evt) {
|
2021-09-12 17:22:00 -07:00
|
|
|
const conlang: Conlang = evt.target.value as Conlang;
|
|
|
|
console.log('Conlang in handlelangchange', conlang);
|
2021-09-12 20:48:11 -07:00
|
|
|
this.setState({conlang, searchResults: null});
|
2021-09-12 02:07:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-09-12 17:22:00 -07:00
|
|
|
const conlangs = [Conlang.Saimiar, Conlang.Elesu, Conlang.Tukvaysi, Conlang.Juteyuji];
|
|
|
|
const langSelectDropdown = (
|
|
|
|
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue={Conlang.Saimiar}>
|
|
|
|
{conlangs.map((conlang) => <option value={conlang} key={conlang}>{renderConlang(conlang)}</option>)}
|
|
|
|
</select>
|
|
|
|
);
|
|
|
|
|
2021-09-12 02:07:44 -07:00
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<div className="container">
|
|
|
|
<div className="search">
|
|
|
|
<h1>Kucinako</h1>
|
|
|
|
<div className="textInput">
|
|
|
|
<input className="textInput" type="text" ref={ this.input } />
|
|
|
|
</div>
|
|
|
|
<br/>
|
2021-09-12 17:22:00 -07:00
|
|
|
{ langSelectDropdown }
|
|
|
|
<button onClick={ this.searchConlang } className="searchButton">{renderConlang(this.state.conlang)}</button>
|
2021-09-12 02:07:44 -07:00
|
|
|
<button onClick={ this.searchEng } className="searchButton">English</button>
|
|
|
|
</div>
|
|
|
|
<Results
|
|
|
|
searchResults={ this.state.searchResults }
|
|
|
|
searchTerm= { this.state.searchTerm }
|
|
|
|
conlang={ this.state.conlang }
|
|
|
|
direction={ this.state.direction }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
2019-01-22 00:41:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|