Skip to content

Commit

Permalink
Implement correct_versification for Psalms
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Jan 28, 2025
1 parent f4e5725 commit 21c4901
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 12 deletions.
5 changes: 3 additions & 2 deletions cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <vector>

#ifdef WITH_PBRST
extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ, int correct_cover, int show_dump);
extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ,
int correct_cover, int correct_versification, int show_dump);
// #include "statements/pbrst.tab.h" // use flex/bison parser for bibref statements (brst)
#include "pbrst.tab.h" // the statements folder must be included among the folders
#endif
Expand Down Expand Up @@ -852,7 +853,7 @@ void processGetrefsCmd(string input) {

#ifdef WITH_PBRST
void processStatementCmd(string input) {
char *output = brst_scan_string((char*)input.c_str(), 0, 0, 0, 0);
char *output = brst_scan_string((char*)input.c_str(), 0, 0, 0, 0, 0);
string output_s(output);
vector<string> statementAnalysis;
boost::split(statementAnalysis, output_s, boost::is_any_of("\n"));
Expand Down
5 changes: 3 additions & 2 deletions qt/statementwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp>

extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ, int correct_cover, int show_dump);
extern "C" char* brst_scan_string(char *string, int correct_raw, int correct_differ,
int correct_cover, int correct_versification, int show_dump);
#include "pbrst.tab.h" // the statements folder must be included among the folders

using namespace std;
Expand Down Expand Up @@ -118,7 +119,7 @@ void StatementWindow::setupFileMenu()
void StatementWindow::parse()
{
#ifdef WITH_PBRST
char* output = brst_scan_string((char*)editor->toPlainText().toStdString().c_str(), 0, 0, 0, 0);
char* output = brst_scan_string((char*)editor->toPlainText().toStdString().c_str(), 0, 0, 0, 0, 0);
string output_s(output);
vector<string> statementAnalysis;
boost::split(statementAnalysis, output_s, boost::is_any_of("\n"));
Expand Down
9 changes: 8 additions & 1 deletion statements/pbrst-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ int main(int ac, char **av)
extern int correct_raw;
extern int correct_differ;
extern int correct_cover;
extern int correct_versification;
extern int show_dump;

bool colorize = false;
bool graphviz = false;
correct_raw = 0;
correct_differ = 0;
correct_cover = 0;
correct_versification = 0;
show_dump = 0;
bool show_only_dump = false;

while (ac>1 && (!strcmp(av[1], "-d") || !strcmp(av[1], "-c")
|| !strcmp(av[1], "-g") || !strcmp(av[1], "-r")
|| !strcmp(av[1], "-D") || !strcmp(av[1], "-C")
|| !strcmp(av[1], "-h")
|| !strcmp(av[1], "-h") || !strcmp(av[1], "-v")
|| !strcmp(av[1], "-u") || !strcmp(av[1], "-U"))) {

if (!strcmp(av[1], "-h")) {
Expand All @@ -89,6 +91,7 @@ int main(int ac, char **av)
printf(" -r\tcorrect raw positions\n");
printf(" -D\tcorrect differings\n");
printf(" -C\tcorrect coverings\n");
printf(" -v\tcorrect versification from KJV to LXX\n");
printf(" -u\tshow BRST dump\n");
printf(" -U\tshow only BRST dump\n");
exit(0);
Expand Down Expand Up @@ -118,6 +121,10 @@ int main(int ac, char **av)
correct_cover = 1; ac--; av++;
}

if (!strcmp(av[1], "-v")) {
correct_versification = 1; ac--; av++;
}

if (!strcmp(av[1], "-u")) {
show_dump = 1; ac--; av++;
}
Expand Down
93 changes: 86 additions & 7 deletions statements/pbrst.y
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ bool fatal = false;
int correct_raw = 0; // fix raw positions if possible
int correct_differ = 0; // fix differing percents if possible
int correct_cover = 0; // fix covering percents if possible
int correct_versification = 0; // fix versification related issues if possible
int show_dump = 0; // if requested, print internal dump in BRST format

#ifdef IN_BIBREF
Expand Down Expand Up @@ -247,7 +248,7 @@ void check_fragment(char *passage, char *ay_nt, char *ay_ot);
double myatof(char *arr);
void create_diagram();
void create_dump();
void reset_data(int cr, int cd, int cc, int sd);
void reset_data(int cr, int cd, int cc, int cv, int sd);
}

%%
Expand Down Expand Up @@ -495,6 +496,72 @@ int detect_ot_book(char *book, char *info) {
return -1; // not found
}

char *versification_to_lxx(char *book, char *info, char *verse) {
if (strcmp(book, "LXX") != 0) return NULL;
int c, c0, v1, v2, o1, o2, n, f;
f = 1;
n = sscanf(verse, "%d:%d+%d %d:%d-%d", &c, &v1, &o1, &c0, &v2, &o2);
if (n<6) {
f = 2;
n = sscanf(verse, "%d:%d %d:%d-%d", &c, &v1, &c0, &v2, &o2);
if (n<5) {
f = 3;
n = sscanf(verse, "%d:%d+%d %d:%d", &c, &v1, &o1, &c0, &v2);
if (n<5) {
f = 4;
n = sscanf(verse, "%d:%d %d:%d", &c, &v1, &c0, &v2);
if (n<4) {
f = 5;
v2 = -1; // unused
n = sscanf(verse, "%d:%d", &c, &v1);
if (n<2) {
f = 0; // unsuccessful
}
}
}
}
}
if (f==0) return NULL;

if (strcmp(info, "Psalms") == 0) {
// Shifting the verse number by 1 (or 2):
if (c>2 && c<150 && c!=14 && c!=16 && c!=24 && c!=32
&& c!=78 && c!=82 && c!=91 && c!=94 && c!=95 && c!=104
&& c!=109 && c!=110 && c!=112 && c!=114 && c!=116 && c!=117 && c!=118 && c!=132) {
if (v1>=1) {
v1++;
if (c==51) v1++;
}
if (v2>=1) {
v2++;
if (c==51) v2++;
}
}
// Shifting the chapter number by 1 (or 2):
if (c>10) {
if (c!=115 && !(c==116 && v1<10)) c--;
else c-=2;
}
// Now c contains the new chapter.
// Some verse numbers need to have further adjustments:
if (c==115) {
if (v1>=1) v1-=9;
if (v2>=1) v2-=9;
}
if (c==113) {
if (v1>=1) v1+=8;
if (v2>=1) v2+=8;
}
} // Psalms

char *ret = malloc(MAX_VERSE_LENGTH + 1);
if (f==1) sprintf(ret, "%d:%d+%d %d:%d-%d", c, v1, o1, c, v2, o2);
if (f==2) sprintf(ret, "%d:%d %d:%d-%d", c, v1, c, v2, o2);
if (f==3) sprintf(ret, "%d:%d+%d %d:%d", c, v1, o1, c, v2);
if (f==4) sprintf(ret, "%d:%d %d:%d", c, v1, c, v2);
if (f==5) sprintf(ret, "%d:%d", c, v1);
return ret;
}

void
check_ot_passage(char *book, char *info, char *verse)
Expand All @@ -504,18 +571,29 @@ check_ot_passage(char *book, char *info, char *verse)
#ifdef IN_BIBREF
char *l;
bool err = false; // be optimistic
l = lookupVerse1(info, book, verse);
char *verse_fixed = NULL;
if (correct_versification == 1) {
add_parseinfo("%d,%d: debug: attempt to correct verse in %s %s %s\n", yylineno, yycolumn, book, info, verse);
verse_fixed = versification_to_lxx(book, info, verse);
}
if (verse_fixed == NULL) {
ot_verse = strdup(verse);
}
else {
ot_verse = strdup(verse_fixed);
add_parseinfo("%d,%d: corrected: verse in %s %s %s changed to %s\n", yylineno, yycolumn, book, info, verse, verse_fixed);
}
l = lookupVerse1(info, book, ot_verse);
if (strstr(l, "error: ") != NULL) {
add_parseinfo("%d,%d: %s\n", yylineno, yycolumn, l);
free(l);
fatal = true;
return; // this is fatal
} else {
add_parseinfo("%d,%d: info: `lookup1 %s %s %s` = %s\n", yylineno, yycolumn, book, info, verse, l);
add_parseinfo("%d,%d: info: `lookup1 %s %s %s` = %s\n", yylineno, yycolumn, book, info, ot_verse, l);
}
ot_info = strdup(info);
ot_book = strdup(book);
ot_verse = strdup(verse);
// Get passage as raw text:
char *r;
int length = intervals[iv_counter-1][1] - intervals[iv_counter-1][0] +1;
Expand Down Expand Up @@ -1463,7 +1541,7 @@ void create_dump() {
"dump: brst: end\n", D);
}

void reset_data(int cr, int cd, int cc, int sd) { // important if a previous run was already performed
void reset_data(int cr, int cd, int cc, int cv, int sd) { // important if a previous run was already performed
extern int yycolumn;
addbooks_done = true; // we assume it was already called
yycolumn = 0;
Expand All @@ -1485,6 +1563,7 @@ void reset_data(int cr, int cd, int cc, int sd) { // important if a previous run
correct_raw = cr;
correct_differ = cd;
correct_cover = cc;
correct_versification = cv;
show_dump = sd;
// yydebug = 1;

Expand All @@ -1506,8 +1585,8 @@ extern int yyparse();
extern YY_BUFFER_STATE yy_scan_string(char * str);
extern void yy_delete_buffer(YY_BUFFER_STATE buffer);

char* brst_scan_string(char *string, int cr, int cd, int cc, int sd) {
reset_data(cr, cd, cc, sd);
char* brst_scan_string(char *string, int cr, int cd, int cc, int cv, int sd) {
reset_data(cr, cd, cc, cv, sd);
YY_BUFFER_STATE buffer = yy_scan_string(string);
yyparse();
yy_delete_buffer(buffer);
Expand Down

0 comments on commit 21c4901

Please sign in to comment.