Run eslint
This commit is contained in:
parent
617e26112c
commit
5f11ed8e3a
282
App.jsx
282
App.jsx
@ -1,70 +1,70 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
|
|
||||||
import './App.scss';
|
import "./App.scss";
|
||||||
import { declineSaimiar } from './saimiar_morphology.js';
|
import { declineSaimiar } from "./saimiar_morphology.js";
|
||||||
|
|
||||||
const backendUrl = "https://kucinakobackend.ichigo.everydayimshuflin.com";
|
const backendUrl = "https://kucinakobackend.ichigo.everydayimshuflin.com";
|
||||||
|
|
||||||
function makeRequest(queryString, jsonHandler) {
|
function makeRequest(queryString, jsonHandler) {
|
||||||
const effectiveUrl = `${backendUrl}/${queryString}`
|
const effectiveUrl = `${backendUrl}/${queryString}`;
|
||||||
fetch(`${effectiveUrl}`)
|
fetch(`${effectiveUrl}`)
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
return resp.json()
|
return resp.json();
|
||||||
})
|
})
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
jsonHandler(json);
|
jsonHandler(json);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderConlangName(name) {
|
function renderConlangName(name) {
|
||||||
if (name == "saimiar") {
|
if (name == "saimiar") {
|
||||||
return "Saimiar";
|
return "Saimiar";
|
||||||
}
|
}
|
||||||
if (name == "elesu") {
|
if (name == "elesu") {
|
||||||
return "Elésu";
|
return "Elésu";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name === "juteyuji") {
|
if (name === "juteyuji") {
|
||||||
return "Juteyuji";
|
return "Juteyuji";
|
||||||
}
|
}
|
||||||
if (name === "tukvaysi") {
|
if (name === "tukvaysi") {
|
||||||
return "Tukvaysi";
|
return "Tukvaysi";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Entry(props) {
|
function Entry(props) {
|
||||||
const conlang = props.conlang;
|
const conlang = props.conlang;
|
||||||
if (conlang === "saimiar") {
|
if (conlang === "saimiar") {
|
||||||
return <SaiEntry entry={ props.entry } />;
|
return <SaiEntry entry={ props.entry } />;
|
||||||
}
|
}
|
||||||
return <div>Unknown entry type for { conlang }</div>;
|
return <div>Unknown entry type for { conlang }</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SaiEntry(props) {
|
function SaiEntry(props) {
|
||||||
const entry = props.entry;
|
const entry = props.entry;
|
||||||
const synCategory = entry.syn_category;
|
const synCategory = entry.syn_category;
|
||||||
const isNominal = synCategory == 'nominal';
|
const isNominal = synCategory == "nominal";
|
||||||
console.log(isNominal);
|
console.log(isNominal);
|
||||||
return (
|
return (
|
||||||
<div className="searchResult" key={ entry.id }>
|
<div className="searchResult" key={ entry.id }>
|
||||||
<b>{ entry.sai }</b> - { entry.eng }
|
<b>{ entry.sai }</b> - { entry.eng }
|
||||||
<br />
|
<br />
|
||||||
<span className="synclass">
|
<span className="synclass">
|
||||||
<i>{ entry.syn_category }</i>
|
<i>{ entry.syn_category }</i>
|
||||||
{ entry.morph_type ? `\t\t${entry.morph_type}` : null }
|
{ entry.morph_type ? `\t\t${entry.morph_type}` : null }
|
||||||
<br/>
|
<br/>
|
||||||
{ isNominal ? formatMorphology(entry) : null }
|
{ isNominal ? formatMorphology(entry) : null }
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatMorphology(entry) {
|
function formatMorphology(entry) {
|
||||||
const decl = declineSaimiar(entry);
|
const decl = declineSaimiar(entry);
|
||||||
if (!decl) {
|
if (!decl) {
|
||||||
return '';
|
return "";
|
||||||
}
|
}
|
||||||
return (<span style={ {fontSize: 'medium', color: '#6a3131'} } >
|
return (<span style={ {fontSize: "medium", color: "#6a3131"} } >
|
||||||
Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>,
|
Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>,
|
||||||
Adp: <i>{decl.adp}</i>,
|
Adp: <i>{decl.adp}</i>,
|
||||||
All: <i>{decl.all}</i>,
|
All: <i>{decl.all}</i>,
|
||||||
@ -76,114 +76,112 @@ function formatMorphology(entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Results extends Component {
|
class Results extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.content = this.content.bind(this);
|
this.content = this.content.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
content() {
|
content() {
|
||||||
const conlang = this.props.conlang;
|
const conlang = this.props.conlang;
|
||||||
const num = this.props.searchResults.length;
|
const num = this.props.searchResults.length;
|
||||||
const renderedName = renderConlangName(conlang);
|
const renderedName = renderConlangName(conlang);
|
||||||
const searchType = (this.props.direction === "toConlang") ? `English -> ${renderedName}` : `${renderedName} -> English`;
|
const searchType = (this.props.direction === "toConlang") ? `English -> ${renderedName}` : `${renderedName} -> English`;
|
||||||
const header = (
|
const header = (
|
||||||
<div className="searchResultHeader" key="header">
|
<div className="searchResultHeader" key="header">
|
||||||
Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s)
|
Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s)
|
||||||
</div>);
|
</div>);
|
||||||
const entries = this.props.searchResults.map(
|
const entries = this.props.searchResults.map(
|
||||||
(entry, idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />
|
(entry) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />
|
||||||
);
|
);
|
||||||
return [header].concat(entries);
|
return [header].concat(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const results = this.props.searchResults;
|
const results = this.props.searchResults;
|
||||||
return(
|
return(
|
||||||
<div className='results'>
|
<div className='results'>
|
||||||
{ results ? this.content() : "No search" }
|
{ results ? this.content() : "No search" }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.input = React.createRef();
|
this.input = React.createRef();
|
||||||
this.handleLangChange = this.handleLangChange.bind(this);
|
this.handleLangChange = this.handleLangChange.bind(this);
|
||||||
|
|
||||||
this.searchEng = this.searchEng.bind(this);
|
this.searchEng = this.searchEng.bind(this);
|
||||||
this.searchSaimiar = this.searchSaimiar.bind(this);
|
this.searchSaimiar = this.searchSaimiar.bind(this);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
searchResults: null,
|
searchResults: null,
|
||||||
conlang: "saimiar",
|
conlang: "saimiar",
|
||||||
direction: null,
|
direction: null,
|
||||||
searchTerm: null
|
searchTerm: null
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
searchSaimiar(evt) {
|
|
||||||
const searchTerm = this.input.current.value;
|
|
||||||
const request = `saimiar?sai=like.*${searchTerm}*`
|
|
||||||
if (searchTerm === "") {
|
|
||||||
this.setState({ searchResults: null, searchTerm: null, direction: null });
|
|
||||||
} else {
|
|
||||||
makeRequest(request, (json) => {
|
|
||||||
this.setState({ searchResults: json, searchTerm, direction: "toEnglish" });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
searchEng(evt) {
|
searchSaimiar(evt) {
|
||||||
const searchTerm = this.input.current.value;
|
const searchTerm = this.input.current.value;
|
||||||
const request = `saimiar?eng=like.*${searchTerm}*`
|
const request = `saimiar?sai=like.*${searchTerm}*`;
|
||||||
if (searchTerm === "") {
|
if (searchTerm === "") {
|
||||||
this.setState({ searchResults: null, searchTerm: null, });
|
this.setState({ searchResults: null, searchTerm: null, direction: null });
|
||||||
} else {
|
} else {
|
||||||
makeRequest(request, (json) => {
|
makeRequest(request, (json) => {
|
||||||
this.setState({ searchResults: json, searchTerm, direction: "toConlang" });
|
this.setState({ searchResults: json, searchTerm, direction: "toEnglish" });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
handleLangChange(evt) {
|
searchEng(evt) {
|
||||||
const conlang = evt.target.value;
|
const searchTerm = this.input.current.value;
|
||||||
this.setState({ conlang });
|
const request = `saimiar?eng=like.*${searchTerm}*`;
|
||||||
}
|
if (searchTerm === "") {
|
||||||
|
this.setState({ searchResults: null, searchTerm: null, });
|
||||||
|
} else {
|
||||||
|
makeRequest(request, (json) => {
|
||||||
|
this.setState({ searchResults: json, searchTerm, direction: "toConlang" });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
handleLangChange(evt) {
|
||||||
|
const conlang = evt.target.value;
|
||||||
|
this.setState({ conlang });
|
||||||
|
}
|
||||||
|
|
||||||
return(
|
render() {
|
||||||
<main>
|
|
||||||
<div className='container'>
|
return(
|
||||||
<div className='search'>
|
<main>
|
||||||
<h1>Kucinako</h1>
|
<div className='container'>
|
||||||
<div className='textInput'>
|
<div className='search'>
|
||||||
<input className='textInput' type="text" ref={ this.input } />
|
<h1>Kucinako</h1>
|
||||||
</div>
|
<div className='textInput'>
|
||||||
<br/>
|
<input className='textInput' type="text" ref={ this.input } />
|
||||||
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
|
</div>
|
||||||
<option value="saimiar">Saimiar</option>
|
<br/>
|
||||||
<option value="elesu">Elesu</option>
|
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
|
||||||
<option value="tukvaysi">Tukvaysi</option>
|
<option value="saimiar">Saimiar</option>
|
||||||
<option value="juteyuji">Juteyuji</option>
|
<option value="elesu">Elesu</option>
|
||||||
</select>
|
<option value="tukvaysi">Tukvaysi</option>
|
||||||
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
|
<option value="juteyuji">Juteyuji</option>
|
||||||
<button onClick={ this.searchEng } className="searchButton">English</button>
|
</select>
|
||||||
</div>
|
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
|
||||||
<Results
|
<button onClick={ this.searchEng } className="searchButton">English</button>
|
||||||
searchResults={ this.state.searchResults }
|
</div>
|
||||||
searchTerm= { this.state.searchTerm }
|
<Results
|
||||||
conlang={ this.state.conlang }
|
searchResults={ this.state.searchResults }
|
||||||
direction={ this.state.direction }
|
searchTerm= { this.state.searchTerm }
|
||||||
/>
|
conlang={ this.state.conlang }
|
||||||
</div>
|
direction={ this.state.direction }
|
||||||
</main>
|
/>
|
||||||
);
|
</div>
|
||||||
}
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
"@babel/core": "^7.0.0-0",
|
"@babel/core": "^7.0.0-0",
|
||||||
"@babel/preset-env": "^7.15.6",
|
"@babel/preset-env": "^7.15.6",
|
||||||
"@babel/preset-react": "^7.0.0",
|
"@babel/preset-react": "^7.0.0",
|
||||||
|
"eslint": "^7.32.0",
|
||||||
|
"eslint-plugin-react": "^7.25.1",
|
||||||
"parcel-bundler": "^1.11.0",
|
"parcel-bundler": "^1.11.0",
|
||||||
"sass": "^1.16.1"
|
"sass": "^1.16.1"
|
||||||
},
|
},
|
||||||
|
@ -1,81 +1,79 @@
|
|||||||
const vowelLetters = ['a', 'e', 'ê', 'i', 'o', 'ô', 'u', 'y', 'ø'];
|
|
||||||
|
|
||||||
const rootEndingPair = (str) => {
|
const rootEndingPair = (str) => {
|
||||||
return { root: str.slice(0, -1), ending: str.slice(-1) };
|
return { root: str.slice(0, -1), ending: str.slice(-1) };
|
||||||
};
|
};
|
||||||
|
|
||||||
function declineSaimiar(entry) {
|
function declineSaimiar(entry) {
|
||||||
const sai = entry.sai;
|
const sai = entry.sai;
|
||||||
const morph = entry.morph_type;
|
const morph = entry.morph_type;
|
||||||
if (morph == '-V') {
|
if (morph == "-V") {
|
||||||
return vowelDeclension(sai);
|
return vowelDeclension(sai);
|
||||||
} else if (morph == '-a/i') {
|
} else if (morph == "-a/i") {
|
||||||
return aiDeclension(sai)
|
return aiDeclension(sai);
|
||||||
} else if (morph == "e-") {
|
} else if (morph == "e-") {
|
||||||
return initalDeclension(sai);
|
return initalDeclension(sai);
|
||||||
} else if (morph == "-C") {
|
} else if (morph == "-C") {
|
||||||
return consonantDeclension(sai);
|
return consonantDeclension(sai);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Can't decline entry '${entry.sai}'`);
|
console.warn(`Can't decline entry '${entry.sai}'`);
|
||||||
console.log(entry)
|
console.log(entry);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function vowelDeclension(sai) {
|
function vowelDeclension(sai) {
|
||||||
const { root, ending } = rootEndingPair(sai);
|
const { root, ending } = rootEndingPair(sai);
|
||||||
const adpEnding = ending == "u" ? "ys" : `${ending}s`;
|
const adpEnding = ending == "u" ? "ys" : `${ending}s`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"abs": `${root}${ending}`,
|
"abs": `${root}${ending}`,
|
||||||
"erg": `${root}${ending}na`,
|
"erg": `${root}${ending}na`,
|
||||||
"adp": `${root}${adpEnding}`,
|
"adp": `${root}${adpEnding}`,
|
||||||
"all": `so${root}${adpEnding}`,
|
"all": `so${root}${adpEnding}`,
|
||||||
"loc": `${root}${ending}xa`,
|
"loc": `${root}${ending}xa`,
|
||||||
"ell": `tlê${root}${adpEnding}`,
|
"ell": `tlê${root}${adpEnding}`,
|
||||||
"inst": `${root}${ending}ŕa`,
|
"inst": `${root}${ending}ŕa`,
|
||||||
"rel": `${root}${ending}źi`
|
"rel": `${root}${ending}źi`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function aiDeclension(sai) {
|
function aiDeclension(sai) {
|
||||||
const { root, ending } = rootEndingPair(sai);
|
const { root, ending } = rootEndingPair(sai);
|
||||||
return {
|
return {
|
||||||
"abs": `${root}${ending}`,
|
"abs": `${root}${ending}`,
|
||||||
"erg": `${root}iad`,
|
"erg": `${root}iad`,
|
||||||
"adp": `${root}i`,
|
"adp": `${root}i`,
|
||||||
"all": `so${root}i`,
|
"all": `so${root}i`,
|
||||||
"loc": `${root}iath`,
|
"loc": `${root}iath`,
|
||||||
"ell": `tlê${root}i`,
|
"ell": `tlê${root}i`,
|
||||||
"inst": `${root}iar`,
|
"inst": `${root}iar`,
|
||||||
"rel": `${root}iai`
|
"rel": `${root}iai`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function consonantDeclension(sai) {
|
function consonantDeclension(sai) {
|
||||||
const split = rootEndingPair(sai);
|
const split = rootEndingPair(sai);
|
||||||
const root = split.ending == 'ø' ? split.root : sai;
|
const root = split.ending == "ø" ? split.root : sai;
|
||||||
const absFinal = split.ending == 'ø' ? 'ø' : '';
|
const absFinal = split.ending == "ø" ? "ø" : "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"abs": `${root}${absFinal}`,
|
"abs": `${root}${absFinal}`,
|
||||||
"erg": `${root}ad`,
|
"erg": `${root}ad`,
|
||||||
"adp": `${root}e`,
|
"adp": `${root}e`,
|
||||||
"all": `so${root}i`,
|
"all": `so${root}i`,
|
||||||
"loc": `${root}ak`,
|
"loc": `${root}ak`,
|
||||||
"ell": `tlê${root}i`,
|
"ell": `tlê${root}i`,
|
||||||
"inst": `${root}ar`,
|
"inst": `${root}ar`,
|
||||||
"rel": `${root}ai`
|
"rel": `${root}ai`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function initalDeclension(sai) {
|
function initalDeclension(sai) {
|
||||||
const { root, ending } = rootEndingPair(sai);
|
const { root, ending } = rootEndingPair(sai);
|
||||||
return {
|
return {
|
||||||
"abs": `${root}${ending}`,
|
"abs": `${root}${ending}`,
|
||||||
"erg": `${root}${ending}na`,
|
"erg": `${root}${ending}na`,
|
||||||
"adp": `${root}${ending}s`,
|
"adp": `${root}${ending}s`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { declineSaimiar };
|
export { declineSaimiar };
|
||||||
|
Loading…
Reference in New Issue
Block a user