This repository was archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv.js
More file actions
145 lines (120 loc) · 5.34 KB
/
Copy pathcsv.js
File metadata and controls
145 lines (120 loc) · 5.34 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const fs = require('fs');
var morphhb = require( "./morphhb.js" );
var tischendorf = require( "./tischendorf.js" );
var MorphParse = require( "./MorphParse.js" );
var parseGreekMorph = require( "./morphgnt-parse.js" );
var data = Object.assign( {}, morphhb, tischendorf );
var literalConsistent = require( "./LC.js" );
var words = {};
function getWordFromWord( word ) {
if ( word && word.length > 0 ) {
return word[0];
}
return null;
}
function getLemmaFromWord( word ) {
if ( word && word.length > 0 ) {
return word[1];
}
return null;
}
function getMorphFromWord( word ) {
if ( word && word.length > 0 ) {
return word[2];
}
return null;
}
function ConvertToCSV( words ) {
var str = '';
Object.keys( words ).forEach( word => {
Object.keys( words[ word ] ).forEach( lemma => {
Object.keys( words[ word ][ lemma ] ).forEach( morph => {
let morphCode;
if ( lemma.indexOf( 'G' ) === 0 ) {
morphCode = parseGreekMorph( morph );
} else {
const morphParseObject = new MorphParse();
morphCode = morphParseObject.Parse( morph );
}
str += word + ','
str += lemma + ','
str += morph + ','
str += morphCode + ','
str += words[ word ][ lemma ][ morph ]
str += '\r\n';
} );
} );
} );
return str;
}
function generateCSV() {
var allBooks = ['Genesis','Exodus','Leviticus','Numbers','Deuteronomy','Joshua','Judges','Ruth','I Samuel','II Samuel','I Kings','II Kings','I Chronicles','II Chronicles','Ezra','Nehemiah','Esther','Job','Psalms','Proverbs','Ecclesiastes','Song of Solomon','Isaiah','Jeremiah','Lamentations','Ezekiel','Daniel','Hosea','Joel','Amos','Obadiah','Jonah','Micah','Nahum','Habakkuk','Zephaniah','Haggai','Zechariah','Malachi', 'Matthew','Mark','Luke','John','Acts','Romans','I Corinthians','II Corinthians','Galatians','Ephesians','Philippians','Colossians','I Thessalonians','II Thessalonians','I Timothy','II Timothy','Titus','Philemon','Hebrews','James','I Peter','II Peter','I John','II John','III John','Jude','Revelation of John'];
var morphString = '';
allBooks.forEach( book => data[ book ].forEach( ( chapter, chapterNumber ) => chapter.forEach( ( verse, verseNumber ) => verse.forEach( word => {
const wordString = getWordFromWord( word );
const lemma = getLemmaFromWord( word );
const morph = getMorphFromWord( word )
if ( lemma ) {
wordArray = wordString.split('/');
lemmaArray = lemma.split('/');
morphArray = morph.split('/');
wordArray.forEach( ( wordInArray, key ) => {
var wordForWord = wordInArray.replace(/[,·;\.:]+\s*$/, "").toLowerCase();
if ( ! words[ wordForWord ] ) {
words[ wordForWord ] = {};
}
var lemmaForWord = lemmaArray[ key ];
if ( ! lemmaForWord ) {
lemmaForWord = '';
}
if ( ! words[ wordForWord][ lemmaForWord ] ) {
words[ wordForWord][ lemmaForWord ] = {};
}
var morphForWord = morphArray[ key ];
if ( ! morphForWord ) {
morphForWord = 'no-morph';
}
if ( morph.indexOf( 'H' ) === 0 && key > 0 ) {
morphForWord = 'H' + morphForWord;
}
if ( morph.indexOf( 'A' ) === 0 && key > 0 ) {
morphForWord = 'A' + morphForWord;
}
var literalTranslation = literalConsistent[ wordForWord ][ lemmaForWord ][ morphForWord ];
// remove commas
literalTranslation = literalTranslation ? literalTranslation.replace(/(^,)|(,$)/g, "") : literalTranslation;
literalTranslation = literalTranslation ? literalTranslation.replace(/"/g, "") : literalTranslation;
words[ wordForWord][ lemmaForWord ][ morphForWord ] = literalTranslation;
} );
}
} ) ) ) );
fs.writeFile('literalconsistent.csv', ConvertToCSV( words ), function() { console.log( 'export done - created literalconsistent.csv' ) } );
}
function generateObject() {
var file = fs.readFileSync( 'literalconsistent.csv', 'utf-8' );
if (file) {
var listOfWords = file.split('\r\n');
listOfWords.forEach( word => {
var wordArray = word.split( ',' );
if ( ! words[ wordArray[0] ] ) {
words[ wordArray[0] ] = {};
}
if ( ! words[ wordArray[0] ][ wordArray[1] ] ) {
words[ wordArray[0] ][ wordArray[1] ] = {};
}
words[ wordArray[0] ][ wordArray[1] ][ wordArray[2] ] = wordArray[4];
} );
fs.writeFile('LC.js', 'var literalConsistent = ' + JSON.stringify( words ) + ';module.exports=literalConsistent;', function() { console.log( 'inport done - created LC.js' ) } );
} else {
console.log( 'File not found' );
}
}
if ( process.argv[2] === 'import') {
generateObject();
return;
}
if ( process.argv[2] === 'export') {
generateCSV();
return;
}
console.log( 'specify an argument, either import or export' );