summaryrefslogtreecommitdiffstats
path: root/modules/mt-lxx-parallel/convert.pl
blob: 7ffff0505243ede5e9f08df592154cd104563824 (plain) (blame)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/perl -w

#
# This tool is supposed to convert the ccat Parallel MT/LXX
# to a valid OSIS file.
#
# @author Martin Gruner
# @copyright GPL
#

use strict;

my $prefix = "parallel/";

#
# grabVerseContent - if the Verse can be found, returns its Content, otherwise nothing
#
sub grabVerseContent(){  #Bookname, chapter, verse, @list
	my @result;
	my $bookname = shift; my $chapter = shift; my $verse = shift; my @buffer = @_;

	my $index=0;

	if ($bookname eq "Obad"){ #special handling, no chapter:verse structure
		LOOP: foreach my $current_item (@buffer){
			if ($chapter == 1 and $current_item =~ m/^$bookname $verse/){ #only for the first chapter
				while ( not $buffer[++$index] =~ m/^\n|^\s*$/ ){
					push(@result, $buffer[$index] );
				}
				return @result;
			}
			$index++;
		}
	}
	else{
		LOOP: foreach my $current_item (@buffer){
			if ($current_item =~ m/^$bookname $chapter:$verse/){
				while ( not $buffer[++$index] =~ m/^\n|^\s*$/ ){
					push(@result, $buffer[$index] );
				}
				return @result;
			}
			$index++;
		}
	}
	return;
}	#Nothing found, don't return a value.

sub processBook(){
# File	File id		ThML id		OSIS id		Short Book Title

	my $filename = shift;
	my $bookname_infile = shift;
	my $thml_id = shift;
	my $osis_id = shift;
	my $short_book_title = shift;

	open( FILE, "$prefix/$filename") or die("Could not open file $prefix/$filename");
	my @BUF = <FILE>; chomp(@BUF); close( FILE );

	my @result;

	CHAPTER: foreach my $chapter(1..1000){
		print("Processing $bookname_infile chapter $chapter.\n");
		my $verse_found;
		VERSE: foreach my $verse(1..1000){
			my @verseContent = &grabVerseContent($bookname_infile, $chapter, $verse, @BUF);
			if (@verseContent) {
				if ($bookname_infile eq "Obad"){
					push(@result, "$osis_id $verse"); #chapter will be ignored for >1 by grabVerseContent
				}
				else{
					push(@result, "$osis_id $chapter:$verse");
				}
				push(@result, @verseContent);
				$verse_found = 1;
			}
			else{ #verse nonexistent, goto next chapter
				last VERSE;
			}
		}
		if (not $verse_found){ #chapter empty, stop here
			if ($chapter == 1) { die("Error: no content in $bookname_infile"); }
			last CHAPTER;
		}
	}
	return(@result);
	print("done.\n");
}

sub processBookVariant(){
# FileA	File_id_A		VariantNameA		FileB		File_id_B		VariantNameB		ThML id		OSIS id		Short Book Title

	my $filenameA = shift;
	my $bookname_infile_A = shift;
	my $variantNameA = shift;
	my $filenameB = shift;
	my $bookname_infile_B = shift;
	my $variantNameB = shift;
	my $thml_id = shift;
	my $osis_id = shift;
	my $short_book_title = shift;

#	print("Processing $booknameA $filenameA $booknameB $filenameB $neutralBookname... \n");

	open( FILE, "$prefix/$filenameA") or die("Could not open file $prefix/$filenameA");
	my @BUFA = <FILE>; chomp(@BUFA); close( FILE );

	open( FILE, "$prefix/$filenameB") or die("Could not open file $prefix/$filenameB");
	my @BUFB = <FILE>; chomp(@BUFB); close( FILE );

	my @result;

	CHAPTER: foreach my $chapter(1..1000){
		print("Processing $bookname_infile_A and $bookname_infile_B chapter $chapter.\n");
		my $verse_found;
		VERSE: foreach my $verse(1..1000){
			my @verseContentA = &grabVerseContent($bookname_infile_A, $chapter, $verse, @BUFA);
			my @verseContentB = &grabVerseContent($bookname_infile_B, $chapter, $verse, @BUFB);
			if (@verseContentA or @verseContentB) { 
				push(@result, "$osis_id $chapter:$verse");
				$verse_found = 1;
			}
			else{ #verse nonexistent, goto next chapter
				last VERSE;
			}
			if (@verseContentA){
				if (@verseContentB){ push(@result, $variantNameA) };
				push(@result, @verseContentA);
				if (@verseContentB){ push(@result, "") };
			}
			if (@verseContentB){
				if (@verseContentA){ push(@result, $variantNameB) };
				push(@result, @verseContentB);
			}
		}
		if (not $verse_found){ #chapter empty, stop here
			if ($chapter == 1) { die("Error: no content in $bookname_infile_A and $bookname_infile_B"); }
			last CHAPTER;
		}
	}
	return(@result);
	print("done.\n");

}

sub fixDaniel(){ #@buffer
	my @buffer = @_;
	my @result;
	my $index = 0;
	foreach my $currentItem (@buffer){
		if ($buffer[$index] =~ m/^DANIHL/){}#Do not add this line to the result
		else{
			if ($buffer[$index + 1] =~ m/^DANIHL/){ #Push both lines on one
				push(@result, $buffer[$index] . $buffer[$index +1] );
			}
			else{
				push(@result, $buffer[$index] ); #The normal case
			}
		}
		$index++;
	}
	return @result;
}

my @result;


	# File				File id			ThML id		OSIS id		Short Book Title
push(@result, &processBook("01.Genesis.par", "Gen", "Gen", "Gen", "Genesis") );
push(@result, &processBook("02.Exodus.par", "Exod", "Exod", "Exod", "Exodus") );
push(@result, &processBook("03.Lev.par", "Lev", "Lev", "Lev", "Leviticus") );
push(@result, &processBook("04.Num.par", "Num", "Num", "Num", "Numbers") );
push(@result, &processBook("05.Deut.par", "Deut", "Deut", "Deut", "Deuteronomy") );

push(@result, &processBookVariant("07.JoshA.par", "JoshA", "Codex Alexandrinus:", "06.JoshB.par", "JoshB", "Codex Vaticanus:", "Josh", "Josh", "Joshua") );
push(@result, &processBookVariant("09.JudgesA.par", "JudgA", "Codex Alexandrinus:", "08.JudgesB.par", "JudgB", "Codex Vaticanus:", "Judg", "Judg", "Judges") );
 
push(@result, &processBook("10.Ruth.par", "Ruth", "Ruth", "Ruth", "Ruth") );
push(@result, &processBook("11.1Sam.par", "1Sam/K", "iSam", "1Sam", "1 Samuel") );
push(@result, &processBook("12.2Sam.par", "2Sam/K", "iiSam", "2Sam", "2 Samuel") );
push(@result, &processBook("13.1Kings.par", "1/3Kgs", "iKgs", "1Kgs", "1 Kings") );
push(@result, &processBook("14.2Kings.par", "2/4Kgs", "iiKgs", "2Kgs", "2 Kings") );
push(@result, &processBook("15.1Chron.par", "1Chr", "iChr", "1Chr", "1 Chronicles") );
push(@result, &processBook("16.2Chron.par", "2Chr", "iiChr", "2Chr", "2 Chronicles") );
push(@result, &processBook("18.Ezra.par", "Ezr", "Ezra", "Ezra", "Ezra") );
push(@result, &processBook("19.Neh.par", "Neh", "Neh", "Neh", "Nehemiah") );
push(@result, &processBook("18.Esther.par", "Esth", "Esth", "Esth", "Esther") );
push(@result, &processBook("26.Job.par", "Job", "Job", "Job", "Job") );
 
 #This might need special handling
 #push(@result, &processBook("Psalms.par", "Ps", "Ps", "Ps", "Psalms",
 
push(@result, &processBook("23.Prov.par", "Prov", "Prov", "Prov", "Proverbs") );
push(@result, &processBook("24.Qoh.par", "Qoh", "Eccl", "Eccl", "Ecclesiastes") );
push(@result, &processBook("25.Cant.par", "Song", "Song", "Song", "Song of Solomon") );
push(@result, &processBook("40.Isaiah.par", "Isa", "Isa", "Isa", "Isaiah") );
push(@result, &processBook("41.Jer.par", "Jer", "Jer", "Jer", "Jeremiah") );
push(@result, &processBook("43.Lam.par", "Lam", "Lam", "Lam", "Lamentations") );
push(@result, &processBook("44.Ezekiel.par", "Ezek", "Ezek", "Ezek", "Ezekiel") );

my @danielTmp = &processBookVariant("45.DanielOG.par", "Dan", "Old Greek:", "46.DanielTh.par", "DanTh", "Theodotion:", "Dan", "Dan", "Daniel");
push(@result, &fixDaniel( @danielTmp ) );

push(@result, &processBook("28.Hosea.par", "Hos", "Hos", "Hos", "Hosea") );
push(@result, &processBook("31.Joel.par", "Joel", "Joel", "Joel", "Joel") );
push(@result, &processBook("30.Amos.par", "Amos", "Amos", "Amos", "Amos") );
push(@result, &processBook("33.Obadiah.par", "Obad", "Obad", "Obad", "Obadiah") );
push(@result, &processBook("32.Jonah.par", "Jonah", "Jonah", "Jonah", "Jonah") );
push(@result, &processBook("29.Micah.par", "Mic", "Mic", "Mic", "Micah") );
push(@result, &processBook("34.Nahum.par", "Nah", "Nah", "Nah", "Nahum") );
push(@result, &processBook("35.Hab.par", "Hab", "Hab", "Hab", "Habakkuk") );
push(@result, &processBook("36.Zeph.par", "Zeph", "Zeph", "Zeph", "Zephaniah") );
push(@result, &processBook("37.Haggai.par", "Hag", "Hag", "Hag", "Haggai") );
push(@result, &processBook("38.Zech.par", "Zech", "Zech", "Zech", "Zechariah") );
push(@result, &processBook("39.Malachi.par", "Mal", "Mal", "Mal", "Malachi") );


print( join("\n", @result) );