-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow export of all conjugations/declension into a JSON-like file words_forms.txt #159
Open
bt2901
wants to merge
8
commits into
sonic16x:master
Choose a base branch
from
bt2901:export
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
34997e7
commit first working prototype
bt2901 ff4cbe9
revert unneeded stuff
bt2901 6057149
change output format
bt2901 2687a45
add support for multi-form words
bt2901 72c67ae
fix declesion
bt2901 021996a
Merge branch 'master' into export
bt2901 4e4acbb
obnoviti eksport paradigmov
bt2901 416a82d
oddaliti debug
bt2901 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import { conjugationVerb } from 'legacy/conjugationVerb'; | ||
import { declensionAdjective } from 'legacy/declensionAdjective'; | ||
import { declensionNoun } from 'legacy/declensionNoun'; | ||
import { declensionNumeral } from 'legacy/declensionNumeral'; | ||
import { declensionPronoun } from 'legacy/declensionPronoun'; | ||
import { | ||
getGender, | ||
getNumeralType, | ||
getPartOfSpeech, | ||
getPronounType, | ||
getVerbDetails, | ||
isAnimated, | ||
isIndeclinable, | ||
isPlural, | ||
isSingular, | ||
} from 'utils/wordDetails'; | ||
import { validFields } from 'consts'; | ||
import * as fs from 'fs'; | ||
import request from 'request'; | ||
import { Dictionary } from 'services/dictionary'; | ||
|
||
import { useDispatch } from 'react-redux'; | ||
import { fetchDictionary } from 'services/fetchDictionary'; | ||
import { useDictionaryLanguages } from 'hooks/useDictionaryLanguages'; | ||
import { loadTablesData } from 'services/loadTablesData'; | ||
|
||
|
||
// await fetchDictionary(dispatch, dictionaryLanguages); | ||
|
||
function getWordMetadata(itemRaw) { | ||
const details = Dictionary.getField(itemRaw, 'partOfSpeech'); | ||
const pos = getPartOfSpeech(details); | ||
const word = Dictionary.getField(itemRaw, 'isv'); | ||
const add = Dictionary.getField(itemRaw, 'addition'); | ||
// const { details } = item; | ||
const arr = [String(pos)]; | ||
const animated = isAnimated(details); | ||
const gender = getGender(details); | ||
const plural = isPlural(details); | ||
const singular = isSingular(details); | ||
const indeclinable = isIndeclinable(details); | ||
switch (pos) { | ||
case 'noun': | ||
arr.push('noun-' + gender); | ||
if (gender.match(/masculine/)) { | ||
arr.push(animated ? 'noun-animated' : 'noun-inanimate'); | ||
} | ||
if (indeclinable) { arr.push('noun-indeclinable'); } | ||
if (plural) { arr.push('noun-plural'); } | ||
if (singular) { arr.push('noun-singular'); } | ||
break; | ||
case 'verb': | ||
const verbDetails = getVerbDetails(details); | ||
if (verbDetails) { | ||
arr.push(...verbDetails.map((e) => 'verb-' + e)); | ||
} | ||
break; | ||
case 'numeral': | ||
const numeralType = getNumeralType(details); | ||
if (numeralType) { | ||
arr.push('numeral-' + numeralType); | ||
} | ||
break; | ||
case 'pronoun': | ||
const pronounType = getPronounType(details); | ||
if (pronounType) { | ||
arr.push('pronoun-' + pronounType); | ||
} | ||
break; | ||
} | ||
return arr.join(', '); | ||
} | ||
|
||
function getSingleWordParadigm(word, add, details) { | ||
let wordData; | ||
|
||
switch (getPartOfSpeech(details)) { | ||
case 'noun': | ||
const gender = getGender(details); | ||
const animated = isAnimated(details); | ||
const plural = isPlural(details); | ||
const singular = isSingular(details); | ||
const indeclinable = isIndeclinable(details); | ||
|
||
wordData = declensionNoun(word, add, gender, animated, plural, singular, indeclinable); | ||
|
||
break; | ||
case 'adjective': | ||
// const { singularAdj, pluralAdj, comparison } = declensionAdjective(word, ''); | ||
|
||
// console.dir(declensionAdjective(word, '')); | ||
wordData = declensionAdjective(word, ''); | ||
break; | ||
case 'verb': | ||
let addVerb = add; | ||
// temporary fix for searching addition in parent verb | ||
// must be deleted when column 'addition' will be correct filled !!! | ||
if (!addVerb && word.includes(' ')) { | ||
const BaseWord = Dictionary.getWordList().filter((item) => { | ||
if (Dictionary.getField(item, 'isv') === word.split(' ')[0] && | ||
Dictionary.getField(item, 'addition') && | ||
Dictionary.getField(item, 'partOfSpeech').includes('v.')) { return true; } | ||
return false; | ||
}); | ||
if (BaseWord.length > 0) { | ||
addVerb = Dictionary.getField(BaseWord[0], 'addition'); | ||
} | ||
} | ||
// normal verb | ||
wordData = conjugationVerb(word, addVerb); | ||
break; | ||
case 'numeral': | ||
const numeralType = getNumeralType(details); | ||
wordData = declensionNumeral(word, numeralType); | ||
break; | ||
case 'pronoun': | ||
const pronounType = getPronounType(details); | ||
wordData = declensionPronoun(word, pronounType); | ||
break; | ||
default: | ||
wordData = null; | ||
} | ||
if (wordData === null) { | ||
return ('NO DATA ERROR'); | ||
} | ||
return wordData; | ||
} | ||
|
||
function getWordParadigm(rawItem) { | ||
// TODO: remove this when the issue is fixed | ||
const [ wordId, word, add, details2 ] = rawItem; | ||
let details = details2; | ||
const splitted = word.split(','); | ||
// HOTFIX TIME!! | ||
if (wordId === '36649') { | ||
details = 'f.'; | ||
} | ||
if (wordId === '36454') { | ||
details = 'adj.'; | ||
} | ||
|
||
if (details.indexOf('m./f.') !== -1 ) { | ||
if (splitted.length > 1) { | ||
return ['UNEXPECTED ERROR']; | ||
} else { | ||
return [ | ||
getSingleWordParadigm(word.trim(), add, details.replace('m./f.', 'm.')), | ||
getSingleWordParadigm(word.trim(), add, details.replace('m./f.', 'f.')), | ||
]; | ||
} | ||
} | ||
|
||
return splitted.map((word, i) => { | ||
return getSingleWordParadigm(word.trim(), add, details); | ||
}); | ||
} | ||
|
||
|
||
|
||
loadTablesData.then(({ data, columns }) => { | ||
/* | ||
const stat = await fetchStat(); | ||
const basicData = await fetchBasic(); | ||
const langsData = await fetchLangs(langList.filter((lang) => addLangs.includes(lang))); | ||
|
||
const wordList = data.body | ||
.replace(/#/g, '') | ||
.split('\n') | ||
.map((l) => l.split('\t')); | ||
const header = wordList[0]; | ||
const shortWordList = wordList.map((item) => { | ||
return validFields.map((fld) => item.find((_, i) => header[i] === fld)).map((e) => e.trim()); | ||
}); | ||
// Dictionary.init(basicData.wordList, basicData.searchIndex, stat); | ||
*/ | ||
Dictionary.init(data); | ||
const words = Dictionary.getWordList(); | ||
const paradigmData = words.map((item) => { | ||
// const itemRaw = Dictionary.getField(item, 'isv'); | ||
return [ | ||
JSON.stringify(item), | ||
JSON.stringify(getWordParadigm(item)), | ||
getWordMetadata(item), | ||
].join('\t'); | ||
}).join('\n'); | ||
fs.writeFileSync('./static/words_forms.txt', paradigmData); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
console.log
s in prod code, please :)