File tree 8 files changed +18
-122009
lines changed
8 files changed +18
-122009
lines changed Original file line number Diff line number Diff line change 5
5
This is an open database anyone can use to find Sinhala definitions for English words and vice versa. This project has a build script you can use to generate databases in different formats (see "Build" section for more information).
6
6
7
7
## Files
8
- - Main database files are in ``` comma-separated values (.csv )``` format and they are located inside the ``` inputs ``` directory.
9
- - You can open them using a spreadsheet program such as LibreOffice Calc .
10
- - ``` en2sn ``` database contains English-Sinhala definitions.
11
- - ``` sn2en ``` database contains Sinhala-English definitions.
8
+ - Main input files are in ``` JavaScript Object Notation (JSON )``` format and they are located inside the ``` inputs ``` directory.
9
+ - You can open them using a text editor such as VSCode .
10
+ - ``` en2sn.json ``` database contains English-Sinhala definitions.
11
+ - ``` sn2en.json ``` database contains Sinhala-English definitions.
12
12
- These are the main files used by build script to generate databases.
13
13
- Do not rename them if you are planning on using the build script.
14
14
@@ -17,7 +17,7 @@ You can use the build script in this project to automatically generate databases
17
17
18
18
### Currently supported formats,
19
19
- SQLite
20
- - JSON
20
+ - JSON (Structure is different than input files)
21
21
22
22
### Building Instructions
23
23
1 . Install Nodejs.
Original file line number Diff line number Diff line change 1
- const csv = require ( "csvtojson" ) ;
2
1
const argio = require ( 'argio' ) ;
3
2
const parser = argio ( ) ;
4
3
5
- const init = async ( ) => {
6
- const data = await readCSV ( ) . catch ( e => console . log ( e ) ) ;
4
+ const init = ( ) => {
5
+ const data = readInputs ( ) ;
7
6
if ( parser . get ( "f" ) ) {
8
7
let formats = parser . params . f ;
9
8
build ( data , formats ) ;
10
9
} else {
11
10
console . log ( "Usage: node build.js -f [formats]\n" ) ;
12
11
console . log ( "Options:\n\t-f\t\tDefine output formats" )
13
12
}
14
-
15
13
}
16
14
17
15
const build = ( data , formats ) => {
@@ -25,13 +23,13 @@ const build = (data, formats) => {
25
23
} )
26
24
}
27
25
28
- const readCSV = async ( ) => {
26
+ const readInputs = ( ) => {
29
27
try {
30
- const en2sn = await csv ( ) . fromFile ( "./inputs/en2sn.csv " ) ;
31
- const sn2en = await csv ( ) . fromFile ( "./inputs/sn2en.csv " ) ;
28
+ const en2sn = require ( "./inputs/en2sn.json " ) ;
29
+ const sn2en = require ( "./inputs/sn2en.json " ) ;
32
30
return { en2sn, sn2en } ;
33
31
} catch ( e ) {
34
- throw ( `Unable to read csv files. : ${ e } ` ) ;
32
+ console . log ( `Unable to read input files. : ${ e } ` ) ;
35
33
}
36
34
}
37
35
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ const build = (data) => {
5
5
const jsonPath = `${ __dirname } /../outputs/json` ;
6
6
const en2sn = { } ;
7
7
const sn2en = { } ;
8
- data . en2sn . forEach ( row => { en2sn [ row . word ] = row . definitions . split ( "," ) } ) ;
9
- data . sn2en . forEach ( row => { sn2en [ row . word ] = row . definitions . split ( "," ) } ) ;
8
+ data . en2sn . forEach ( row => { en2sn [ row . word ] = row . definitions } ) ;
9
+ data . sn2en . forEach ( row => { sn2en [ row . word ] = row . definitions } ) ;
10
10
fs . writeFileSync ( `${ jsonPath } /en2sn.json` , JSON . stringify ( en2sn ) ) ;
11
11
fs . writeFileSync ( `${ jsonPath } /sn2en.json` , JSON . stringify ( sn2en ) ) ;
12
12
console . log ( `Success: JSON files have been generated!.` ) ;
Original file line number Diff line number Diff line change @@ -22,11 +22,11 @@ const save = async (table, data) => {
22
22
let rowCount = data . length ;
23
23
let values = "" ;
24
24
let count = 1 ;
25
- let limit = 3000 ;
25
+ let limit = 1000 ;
26
26
27
27
try {
28
28
for ( let row of data ) {
29
- values += `(' ${ row . word } ', ' ${ row . definitions } ' )` ;
29
+ values += `(" ${ row . word } ", " ${ row . definitions } " )` ;
30
30
if ( count < limit ) values += "," ;
31
31
if ( count == limit ) {
32
32
let sql = `INSERT INTO ${ table } (word, definitions) VALUES${ values } ` ;
@@ -55,6 +55,7 @@ const insert = (sql) => {
55
55
return new Promise ( ( resolve , reject ) => {
56
56
osdb . run ( sql , [ ] , ( err ) => {
57
57
if ( err ) {
58
+ console . log ( sql ) ;
58
59
console . log ( `Error: Unable to insert data to the database! ${ err } ` ) ;
59
60
reject ( ) ;
60
61
}
Load Diff This file was deleted.
Load Diff Large diffs are not rendered by default.
Load Diff This file was deleted.
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments