forked from KlonD90/workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
word_halmg_ors.js
58 lines (48 loc) · 1.38 KB
/
word_halmg_ors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const R = require('ramda')
const axios = require('axios')
const dictionary = require('./dictionaries/halimag_oros_toli')
const isOneWord = (str) => str.trim().split(/[ \.;,]/).length === 1
const numStartEx = /^\d\)/
const numStart = (str) => {
return numStartEx.test(str)
}
const metaRegex = /^\w+\./
const isMeta = (str) => metaRegex.test(str.trim())
const from = 'от'
const translated = R.compose(
R.reduce((r, x) => r.concat(x), []),
R.filter(x => x),
R.map(([word, {translations, transcript}]) => {
if (translations.length === 1 && isOneWord(translations[0])) {
return [[word, translations[0]]]
}
if (translations) {
const acc = []
for (const t of translations) {
if (numStart(t)) {
// single word case
const startStr = t.slice(2).trim();
const words = startStr.split(' ').filter(x => x)
if (words.length === 1) {
acc.push([word, words[0]])
}
}
}
if (acc.length) return acc
}
return false
}),
// R.slice(0, 100),
R.toPairs,
)(dictionary)
const send = async (d) => {
for (const [word, translation] of d) {
try {
await axios.post(`http://80.93.177.192:3000/words/`, {kalmyk: word, russian: translation})
} catch(e) {
console.log(e)
process.exit(1)
}
}
}
send(translated)