Compare commits

..

No commits in common. "0331062120ae8dd38a509f669940e501109edbbf" and "4de6e718ff9cfcc5ca7669361d3edee4f1d93d63" have entirely different histories.

7 changed files with 999 additions and 1543 deletions

View File

@ -1,23 +0,0 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:react/recommended',
'xo',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: [
'react',
],
rules: {
"arrow-parens": ["error", "always"]
},
};

View File

@ -8,18 +8,12 @@
"private": true, "private": true,
"scripts": { "scripts": {
"start": "parcel index.html", "start": "parcel index.html",
"build": "parcel build index.html --no-source-maps", "build": "parcel build index.html"
"prebuild": "yarn run typecheck",
"typecheck": "tsc --noEmit"
}, },
"devDependencies": { "devDependencies": {
"@parcel/transformer-image": "2.0.0-rc.0", "@parcel/transformer-image": "2.0.0-rc.0",
"@parcel/transformer-sass": "2.0.0-rc.0", "@parcel/transformer-sass": "2.0.0-rc.0",
"eslint": "^7.32.0", "parcel": "^2.0.0-rc.0"
"eslint-config-xo": "^0.38.0",
"eslint-plugin-react": "^7.25.1",
"parcel": "^2.0.0-rc.0",
"typescript": "^4.4.3"
}, },
"dependencies": { "dependencies": {
"react": "^17.0.2", "react": "^17.0.2",

View File

@ -1,71 +1,70 @@
import React, {Component} from 'react'; import React, { Component } from "react";
import './App.scss'; import './App.scss';
import {declineSaimiar} from './saimiar_morphology.ts'; 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) => resp.json()) .then((resp) => {
.then((json) => { return resp.json()
jsonHandler(json); })
}); .then((json) => {
jsonHandler(json);
});
} }
function renderConlangName(name) { function renderConlangName(name) {
if (name === 'saimiar') { if (name == "saimiar") {
return 'Saimiar'; return "Saimiar";
} }
if (name == "elesu") {
return "Elésu";
}
if (name === 'elesu') { if (name === "juteyuji") {
return 'Elésu'; return "Juteyuji";
} }
if (name === "tukvaysi") {
if (name === 'juteyuji') { return "Tukvaysi";
return 'Juteyuji'; }
}
if (name === 'tukvaysi') {
return 'Tukvaysi';
}
} }
const Entry = (props) => { function Entry(props) {
const {conlang} = props; 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) {
}; const entry = props.entry;
const synCategory = entry.syn_category;
const SaiEntry = (props) => { const isNominal = synCategory == 'nominal';
const {entry} = props; console.log(isNominal);
const synCategory = entry.syn_category; return (
const isNominal = synCategory === 'nominal'; <div className="searchResult" key={ entry.id }>
return ( <b>{ entry.sai }</b> - { entry.eng }
<div className="searchResult" key={ entry.id }> <br />
<b>{ entry.sai }</b> - { entry.eng } <span className="synclass">
<br /> <i>{ entry.syn_category }</i>
<span className="synclass"> { entry.morph_type ? `\t\t${entry.morph_type}` : null }
<i>{ entry.syn_category }</i> <br/>
{ entry.morph_type ? `\t\t${entry.morph_type}` : null } { isNominal ? formatMorphology(entry) : null }
<br/> </span>
{ isNominal ? formatMorphology(entry) : null } </div>
</span> );
</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>,
@ -73,108 +72,118 @@ function formatMorphology(entry) {
Ell: <i>{decl.ell}</i>, Ell: <i>{decl.ell}</i>,
Inst: <i>{decl.inst}</i>, Inst: <i>{decl.inst}</i>,
Rel: <i>{decl.rel}</i> Rel: <i>{decl.rel}</i>
</span>); </span>);
} }
const Results = (props) => { class Results extends Component {
const content = () => { constructor(props) {
const {conlang} = props; super(props);
const num = props.searchResults.length; this.content = this.content.bind(this);
const renderedName = renderConlangName(conlang); }
const searchType = (props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = (
<div className="searchResultHeader" key="header">
Searched for <b>{ props.searchTerm }</b>, { searchType }, found { num } result(s)
</div>);
const entries = props.searchResults.map(
(entry, _idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />,
);
return [header].concat(entries);
};
const results = props.searchResults; content() {
return ( const conlang = this.props.conlang;
<div className="results"> const num = this.props.searchResults.length;
{ results ? content() : 'No search' } const renderedName = renderConlangName(conlang);
</div> const searchType = (this.props.direction === "toConlang") ? `English -> ${renderedName}` : `${renderedName} -> English`;
); const header = (
}; <div className="searchResultHeader" key="header">
Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s)
</div>);
const entries = this.props.searchResults.map(
(entry, idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />
);
return [header].concat(entries);
}
render() {
const results = this.props.searchResults;
return(
<div className='results'>
{ results ? this.content() : "No search" }
</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) { searchSaimiar(evt) {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?sai=like.*${searchTerm}*`; const request = `saimiar?sai=like.*${searchTerm}*`
if (searchTerm === '') { if (searchTerm === "") {
this.setState({searchResults: null, searchTerm: null, direction: null}); this.setState({ searchResults: null, searchTerm: null, direction: null });
} else { } else {
makeRequest(request, (json) => { makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toEnglish'}); this.setState({ searchResults: json, searchTerm, direction: "toEnglish" });
}); });
} }
} }
searchEng(_evt) { searchEng(evt) {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?eng=like.*${searchTerm}*`; const request = `saimiar?eng=like.*${searchTerm}*`
if (searchTerm === '') { if (searchTerm === "") {
this.setState({searchResults: null, searchTerm: null}); this.setState({ searchResults: null, searchTerm: null, });
} else { } else {
makeRequest(request, (json) => { makeRequest(request, (json) => {
this.setState({searchResults: json, searchTerm, direction: 'toConlang'}); this.setState({ searchResults: json, searchTerm, direction: "toConlang" });
}); });
} }
} }
handleLangChange(evt) { handleLangChange(evt) {
const conlang = evt.target.value; const conlang = evt.target.value;
this.setState({conlang}); this.setState({ conlang });
} }
render() { render() {
return (
<main> return(
<div className="container"> <main>
<div className="search"> <div className='container'>
<h1>Kucinako</h1> <div className='search'>
<div className="textInput"> <h1>Kucinako</h1>
<input className="textInput" type="text" ref={ this.input } /> <div className='textInput'>
</div> <input className='textInput' type="text" ref={ this.input } />
<br/> </div>
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar"> <br/>
<option value="saimiar">Saimiar</option> <select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
<option value="elesu">Elesu</option> <option value="saimiar">Saimiar</option>
<option value="tukvaysi">Tukvaysi</option> <option value="elesu">Elesu</option>
<option value="juteyuji">Juteyuji</option> <option value="tukvaysi">Tukvaysi</option>
</select> <option value="juteyuji">Juteyuji</option>
<button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button> </select>
<button onClick={ this.searchEng } className="searchButton">English</button> <button onClick={ this.searchSaimiar } className="searchButton">Saimiar</button>
</div> <button onClick={ this.searchEng } className="searchButton">English</button>
<Results </div>
searchResults={ this.state.searchResults } <Results
searchTerm= { this.state.searchTerm } searchResults={ this.state.searchResults }
conlang={ this.state.conlang } searchTerm= { this.state.searchTerm }
direction={ this.state.direction } conlang={ this.state.conlang }
/> direction={ this.state.direction }
</div> />
</main> </div>
); </main>
} );
}
} }
export default App; export default App;

96
src/saimiar_morphology.js Normal file
View File

@ -0,0 +1,96 @@
const rootEndingPair = (str) => {
return { root: str.slice(0, -1), ending: str.slice(-1) };
};
function declineSaimiar(entry) {
const split = entry.sai.split(" ");
const sai = split.at(-1);
const morph = entry.morph_type;
let declined;
if (morph == '-V') {
return vowelDeclension(sai);
} else if (morph == '-a/i') {
return aiDeclension(sai)
} else if (morph == "e-") {
return initalDeclension(sai);
} else if (morph == "-C") {
return consonantDeclension(sai);
} else {
console.warn(`Can't decline entry '${entry.sai}'`);
console.log(entry)
return null;
}
}
function vowelDeclension(sai) {
const { root, ending } = rootEndingPair(sai);
const adpEnding = ending == "u" ? "ys" : `${ending}s`;
return {
"abs": `${root}${ending}`,
"erg": `${root}${ending}na`,
"adp": `${root}${adpEnding}`,
"all": `so${root}${adpEnding}`,
"loc": `${root}${ending}xa`,
"ell": `tlê${root}${adpEnding}`,
"inst": `${root}${ending}ŕa`,
"rel": `${root}${ending}źi`
};
}
function aiDeclension(sai) {
const { root, ending } = rootEndingPair(sai);
return {
"abs": `${root}${ending}`,
"erg": `${root}iad`,
"adp": `${root}i`,
"all": `so${root}i`,
"loc": `${root}iath`,
"ell": `tlê${root}i`,
"inst": `${root}iar`,
"rel": `${root}iai`
};
}
function consonantDeclension(sai) {
const split = rootEndingPair(sai);
const root = split.ending == 'ø' ? split.root : sai;
const absFinal = split.ending == 'ø' ? 'ø' : '';
return {
"abs": `${root}${absFinal}`,
"erg": `${root}ad`,
"adp": `${root}e`,
"all": `so${root}i`,
"loc": `${root}ak`,
"ell": `tlê${root}i`,
"inst": `${root}ar`,
"rel": `${root}ai`
};
}
const vowels = ['a', 'e', 'ê', 'i', 'o', 'ô', 'u', 'y'];
function initalDeclension(sai) {
const initial = sai.slice(0,1);
const root = sai.slice(1);
const finalRootSound = root.slice(-1);
const finalVowel = vowels.includes(finalRootSound);
const instEnding = finalVowel ? "ŕø" : "ar";
const relEnding = finalVowel ? "źi" : "ai";
return {
"abs": `${initial}${root}`,
"erg": `da${root}`,
"adp": `i${root}`,
"all": `so${root}`,
"loc": `xa${root}`,
"ell": `tlê${root}`,
"inst": `i${root}${instEnding}`,
"rel": `${initial}${root}${relEnding}`,
};
}
export { declineSaimiar };

View File

@ -1,99 +0,0 @@
const rootEndingPair = (str) => ({root: str.slice(0, -1), ending: str.slice(-1)});
function declineSaimiar(entry) {
const split = entry.sai.split(' ');
const sai = split.at(-1);
const morph = entry.morph_type;
if (morph === '-V') {
return vowelDeclension(sai);
}
if (morph === '-a/i') {
return aiDeclension(sai);
}
if (morph === 'e-') {
return initalDeclension(sai);
}
if (morph === '-C') {
return consonantDeclension(sai);
}
console.warn(`Can't decline entry '${entry.sai}'`);
console.log(entry);
return null;
}
function vowelDeclension(sai: string) {
const {root, ending} = rootEndingPair(sai);
const adpEnding = ending === 'u' ? 'ys' : `${ending}s`;
return {
abs: `${root}${ending}`,
erg: `${root}${ending}na`,
adp: `${root}${adpEnding}`,
all: `so${root}${adpEnding}`,
loc: `${root}${ending}xa`,
ell: `tlê${root}${adpEnding}`,
inst: `${root}${ending}ŕa`,
rel: `${root}${ending}źi`,
};
}
function aiDeclension(sai) {
const {root, ending} = rootEndingPair(sai);
return {
abs: `${root}${ending}`,
erg: `${root}iad`,
adp: `${root}i`,
all: `so${root}i`,
loc: `${root}iath`,
ell: `tlê${root}i`,
inst: `${root}iar`,
rel: `${root}iai`,
};
}
function consonantDeclension(sai) {
const split = rootEndingPair(sai);
const root = split.ending === 'ø' ? split.root : sai;
const absFinal = split.ending === 'ø' ? 'ø' : '';
return {
abs: `${root}${absFinal}`,
erg: `${root}ad`,
adp: `${root}e`,
all: `so${root}i`,
loc: `${root}ak`,
ell: `tlê${root}i`,
inst: `${root}ar`,
rel: `${root}ai`,
};
}
const vowels = ['a', 'e', 'ê', 'i', 'o', 'ô', 'u', 'y'];
function initalDeclension(sai) {
const initial = sai.slice(0, 1);
const root = sai.slice(1);
const finalRootSound = root.slice(-1);
const finalVowel = vowels.includes(finalRootSound);
const instEnding = finalVowel ? 'ŕø' : 'ar';
const relEnding = finalVowel ? 'źi' : 'ai';
return {
abs: `${initial}${root}`,
erg: `da${root}`,
adp: `i${root}`,
all: `so${root}`,
loc: `xa${root}`,
ell: `tlê${root}`,
inst: `i${root}${instEnding}`,
rel: `${initial}${root}${relEnding}`,
};
}
export {declineSaimiar};

View File

@ -1,4 +0,0 @@
{
"compilerOptions": {},
"include": ["src/**/*"]
}

2011
yarn.lock

File diff suppressed because it is too large Load Diff