Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Dec 19, 2023
1 parent 79517a8 commit 3062a7d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 51 deletions.
8 changes: 4 additions & 4 deletions book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Book::Book (string n) {
// cerr << "Book " << n << " created" << endl;
}

void Book::setInfo(string n) {
info = n;
void Book::setModuleName(string n) {
moduleName = n;
}

string Book::getName() {
return name;
}

string Book::getInfo() {
return info;
string Book::getModuleName() {
return moduleName;
}

void Book::addVerse(string n, string i, vector<int> t) {
Expand Down
22 changes: 11 additions & 11 deletions book.dox
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private:
string name;
///
/// Sword module name of the book, e.g. "LXX".
string info;
string moduleName;
///
/// A Bible verse, in its traditional meaning.
typedef struct Verse {
Expand All @@ -41,23 +41,23 @@ public:
/// Create a new book with a name, e.g. "Genesis".
Book(string name);
/// Set the Sword module for the book, e.g. "LXX".
void setInfo(string info);
void setModuleName(string moduleName);
/// Get the Sword module name for the book, e.g. "LXX".
string getInfo();
string getModuleName();
/// Get the book name, e.g. "Genesis".
string getName();
/// Add a verse to a book.
void addVerse(string text, string verseInfo, vector<int> tokens) {
void addVerse(string text, string info, vector<int> tokens) {
/// @short Add a verse to a book.
/// Append a new verse to a Bible book by specifying the verse of the text
/// in a-z encoding (without spaces and punctuation and setting the tokens).
/// @param text The Greek text in a-z encoding, with no spaces or punctuation.
/// @param verseInfo The traditional verse numbering, e.g. "3:16".
/// @param info The traditional verse numbering, e.g. "3:16".
/// @param tokens Tokenized form of the verse.
};

/// Get the a-z encoded string of the verse defined by traditional numbering, e.g. "3:16".
string getVerse(string verseInfo);
string getVerse(string info);
/// Get the traditional numbering of the verse that contains the given character position in the book,
/// by appending a position modifier +N that gives the shift of characters to the beginning of the verse.
string getVerseInfoStart(int position);
Expand All @@ -73,17 +73,17 @@ public:
/// Get the a-z encoded string of the whole book.
string getText();
/// Get the tokenized form of the verse defined by traditional numbering, e.g. "3:16".
vector<int> getVerseTokens(string verseInfo);
vector<int> getVerseTokens(string info);
/// Get the tokenized form of the whole book.
vector<int> getTokens();
/// Get the character position of the start of verse defined by traditional numbering, e.g. "3:16".
int getVerseStart(string verseInfo);
int getVerseStart(string info);
/// Get the character position of the end of verse defined by traditional numbering, e.g. "3:16".
int getVerseEnd(string verseInfo);
int getVerseEnd(string info);
/// Get the token position of the start of verse defined by traditional numbering, e.g. "3:16".
int getVerseTokensStart(string verseInfo);
int getVerseTokensStart(string info);
/// Get the token position of the end of verse defined by traditional numbering, e.g. "3:16".
int getVerseTokensEnd(string verseInfo);
int getVerseTokensEnd(string info);
/// Set the text of a whole book. It is useful if the book is created by using the cache.
void setText(string text);

Expand Down
20 changes: 10 additions & 10 deletions book.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Book
{
private:
string name;
string info;
string moduleName;
typedef struct Verse {
int start;
int length;
Expand All @@ -23,22 +23,22 @@ class Book
vector<int> tokens;
public:
Book(string name);
void setInfo(string info);
string getInfo();
void setModuleName(string moduleName);
string getModuleName();
string getName();
void addVerse(string text, string verseInfo, vector<int> tokens);
string getVerse(string verseInfo);
void addVerse(string text, string info, vector<int> tokens);
string getVerse(string info);
string getVerseInfoStart(int position);
string getVerseInfoEnd(int position);
string getVerseTokensInfoStart(int position);
string getVerseTokensInfoEnd(int position);
string getText();
vector<int> getVerseTokens(string verseInfo);
vector<int> getVerseTokens(string info);
vector<int> getTokens();
int getVerseStart(string verseInfo);
int getVerseEnd(string verseInfo);
int getVerseTokensStart(string verseInfo);
int getVerseTokensEnd(string verseInfo);
int getVerseStart(string info);
int getVerseEnd(string info);
int getVerseTokensStart(string info);
int getVerseTokensEnd(string info);
// to load a book from cache:
void setText(string text);
void addVerse(int start, int length, string info, int tokensStart, int tokensLength);
Expand Down
38 changes: 19 additions & 19 deletions books.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ int addBook_cached(string moduleName) {
char reference[8]; // Psalms 119:176 needs 7 characters + "\n"
int start, end, tokensStart, tokensEnd;
try {
while (fscanf(verseFile, "%s %d %d %d %d", &reference, &start, &end, &tokensStart, &tokensEnd) != EOF) {
while (fscanf(verseFile, "%7s %d %d %d %d", reference, &start, &end, &tokensStart, &tokensEnd) != EOF) {
if (bookName == "Psalms") {
vector<string> r;
boost::split(r, reference, boost::is_any_of(":"));
Expand All @@ -467,7 +467,7 @@ int addBook_cached(string moduleName) {

fclose(verseFile);
add_vocabulary_item(bookName);
book.setInfo(moduleName);
book.setModuleName(moduleName);
books.push_back(book);
}
psalmsInfos.push_back(pi);
Expand Down Expand Up @@ -538,8 +538,8 @@ int addBook(string moduleName, string firstVerse, string lastVerse, bool removeA
if (verse.size() > 0) {
string verseInfo = module->getKeyText();
if (!firstInfoSet) {
lastBook.setInfo(module->getBibliography().c_str());
lastBook.setInfo(moduleName);
lastBook.setModuleName(module->getBibliography().c_str());
lastBook.setModuleName(moduleName);
firstInfoSet = true;
}
string verseText = processVerse(verse.c_str());
Expand Down Expand Up @@ -573,8 +573,8 @@ int addBook(string moduleName, string firstVerse, string lastVerse, bool removeA
add_vocabulary_item(lastBookName);
// new book
Book book = Book(bookName);
book.setInfo(module->getBibliography().c_str());
book.setInfo(moduleName);
book.setModuleName(module->getBibliography().c_str());
book.setModuleName(moduleName);
lastBook = book;
lastBookName = bookName;

Expand Down Expand Up @@ -650,7 +650,7 @@ int addBooks() {
Book getBook(string book, string info) {
for (int i=0; i<books.size(); i++) {
Book b = books[i];
if (b.getName().compare(book) == 0 && b.getInfo().compare(info) == 0) {
if (b.getName().compare(book) == 0 && b.getModuleName().compare(info) == 0) {
return b;
}
}
Expand Down Expand Up @@ -864,18 +864,18 @@ int findBestFit(string book1, string info1, string verseInfo1s, string verseInfo
return 0;
}

string _find(string text, string moduleName, int maxFound, int verb) {
string _find(string text, string moduleName, int maxFound, bool verbose) {
int found = 0;
size_t pos;
string book;
for (int i=0; i<books.size(); i++) {
Book b = books[i];
if (b.getInfo().compare(moduleName) == 0) {
if (b.getModuleName().compare(moduleName) == 0) {
book = b.getName();
string bookText = b.getText();
pos = bookText.find(text);
while (pos != std::string::npos) {
if (verb == 1) {
if (verbose) {
info("Found in " + book + " " + b.getVerseInfoStart(pos) + " "
+ b.getVerseInfoEnd(pos + text.length() - 1)
+ " (book position " + to_string(pos + 1)
Expand All @@ -892,14 +892,14 @@ string _find(string text, string moduleName, int maxFound, int verb) {
}
}
end:
if (verb == 1) {
if (verbose) {
info(to_string(found) + " occurrences.");
}
return to_string(found) + "," + book + "," + to_string(pos);
}

int find(string text, string moduleName, int maxFound, int verb) {
string f = _find(text, moduleName, maxFound, verb);
int find(string text, string moduleName, int maxFound, bool verbose) {
string f = _find(text, moduleName, maxFound, verbose);
vector<string> info;
boost::split(info, f, boost::is_any_of(","));
return stoi(info[0]);
Expand All @@ -912,7 +912,7 @@ string find(string text, string moduleName) {
return info[1] + "," + info[2];
}

vector<string> find_min_unique(string text, string moduleName, int verb) {
vector<string> find_min_unique(string text, string moduleName, bool verbose) {
int long_limit = 10000;
int extreme_limit = 50000;
vector<string> retval;
Expand Down Expand Up @@ -942,7 +942,7 @@ vector<string> find_min_unique(string text, string moduleName, int verb) {
int unique = find(subtext, moduleName, 2, 0);
if (unique == 1) {
is_unique[i][j] = 1;
if (verb == 1) {
if (verbose) {
info("Text " + subtext + " is minimal unique.");
}
retval.push_back(subtext);
Expand All @@ -955,7 +955,7 @@ vector<string> find_min_unique(string text, string moduleName, int verb) {
return retval;
}

string _extend(string moduleName1, string moduleName2, string book2, int pos2S, int pos2E, int verb) {
string _extend(string moduleName1, string moduleName2, string book2, int pos2S, int pos2E, bool verbose) {
Book b2 = getBook(book2, moduleName2);
string text = b2.getText().substr(pos2S, pos2E - pos2S + 1);

Expand Down Expand Up @@ -995,7 +995,7 @@ string _extend(string moduleName1, string moduleName2, string book2, int pos2S,
string verse1infoE = b1.getVerseInfoEnd(pos1E);
string verse2infoS = b2.getVerseInfoStart(pos2S);
string verse2infoE = b2.getVerseInfoEnd(pos2E);
if (verb == 1) {
if (verbose) {
info("Extended match is " + ot_color + moduleName1 + " " + book1 + " "
+ verse1infoS + " " + verse1infoE + reset_color + " = " + nt_color + moduleName2 + " "
+ book2 + " " + verse2infoS + " " + verse2infoE + reset_color + " ("
Expand Down Expand Up @@ -1023,7 +1023,7 @@ vector<string> find_all(string text, string moduleName, int maxFound) {
string book;
for (int i=0; i<books.size(); i++) {
Book b = books[i];
if (b.getInfo().compare(moduleName) == 0) {
if (b.getModuleName().compare(moduleName) == 0) {
book = b.getName();
string bookText = b.getText();
pos = bookText.find(text);
Expand Down Expand Up @@ -1177,7 +1177,7 @@ vector<string> searchTokenset(string moduleName, vector<int> pattern, int length
string book;
for (int i=0; i<books.size(); i++) {
Book b = books[i];
if (b.getInfo().compare(moduleName) == 0) {
if (b.getModuleName().compare(moduleName) == 0) {
book = b.getName();
vector<int> bookTokens = b.getTokens();
int tokensLength = bookTokens.size();
Expand Down
4 changes: 2 additions & 2 deletions books.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ int findBestFit(string book1, string info1, string verseInfo1s, string verseInfo
string book2, string info2, string verseInfo2s, string verseInfo2e);
string processVerse(const string &verse);
string getText(string book, string info, string VerseInfoS, string VerseInfoE, int startOffset, int endOffset);
int find(string text, string moduleName, int maxFound, int verb);
vector<string> find_min_unique(string text, string moduleName, int verb);
int find(string text, string moduleName, int maxFound, bool verbose);
vector<string> find_min_unique(string text, string moduleName, bool verbose);
void extend(string moduleName1, string moduleName2, string book2, string verse2S,
int start, string verse2E, int end);
void getrefs(string moduleName2, string moduleName1, string book1, string verse1S,
Expand Down
4 changes: 2 additions & 2 deletions cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ string cli_process(char *buf) {
error(errorFindEmpty);
goto end;
}
find(text[index], rest, maxresults, 1);
find(text[index], rest, maxresults, true);
goto end;
}

Expand Down Expand Up @@ -564,7 +564,7 @@ string cli_process(char *buf) {
goto end;
}
string rest = input.substr(input.find(" ") + 1);
find_min_unique(text[0], rest, 1);
find_min_unique(text[0], rest, true);
goto end;
}

Expand Down
4 changes: 2 additions & 2 deletions fingerprint.dox
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ typedef struct fingerprint {
} fingerprint;

/// Compute the fingerprint of a passage.
fingerprint getFingerprint(Book b, int start, int length) {
/// @param b A book in a Bible edition.
fingerprint getFingerprint(Book book, int start, int length) {
/// @param book A book in a Bible edition.
/// @param start Start of the passage in characters.
/// @param length Length of the passage in characters.
};
Expand Down
2 changes: 1 addition & 1 deletion fingerprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typedef struct fingerprint {
unsigned short int data [N][N];
} fingerprint;

fingerprint getFingerprint(Book b, int start, int length);
fingerprint getFingerprint(Book book, int start, int length);
fingerprint getFingerprint(string text);
int dist(fingerprint f1, fingerprint f2);
int dist(string text1, string text2);
Expand Down

0 comments on commit 3062a7d

Please sign in to comment.