Skip to content

Commit 578a0ba

Browse files
committed
Add nearest12 command
1 parent 442f699 commit 578a0ba

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

cli.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ string quitCmd = "quit";
7777
string helpCmd = "help";
7878
string statementCmd = "statement";
7979
string statementCmd2 = "Statement";
80+
string nearestCmd = "nearest";
8081

8182
string errorNotRecognized
8283
= "Sorry, the command you entered was not recognized or its syntax is invalid.";
@@ -108,6 +109,7 @@ string errorMisc = "Sorry, there were some problems with the command you entered
108109
vector<string> commands{addbooksCmd,
109110
compareCmd + "12",
110111
jaccardCmd + "12",
112+
nearestCmd + "12",
111113
textCmd + "1",
112114
textCmd + "2",
113115
lookupCmd + "1",
@@ -288,6 +290,9 @@ string getHelp(const string &key)
288290
"check, best match is reached at 1/(length1+length2).",
289291
"* `jaccard12`: Compare the two clipboards the same way how `compare12` does but use the "
290292
"\"Jaccard similarity for bags\" algorithm, best match is reached at 0.",
293+
"* `nearest12`: Find a substring of clipboard1 such that its Jaccard similarity for bags "
294+
" to clipboard2 is minimal.",
295+
"\"Jaccard similarity for bags\" algorithm, best match is reached at 0.",
291296
"* `sql` *switch*: Set some outputs to be shown also as an SQL query if *switch* is `on`.",
292297
"* `colors` *switch*: Show some outputs colored if *switch* is `on`.",
293298
"* `tokens` *Bible* *book* *verse*: Search for the given *verse* in the given *book* in "
@@ -678,6 +683,18 @@ void processJaccardCmd()
678683
}
679684
}
680685

686+
void processNearestCmd()
687+
{
688+
if (textset.at(0) && textset.at(1)) {
689+
string best_c_d = best_jaccard_substr(text[1], text[0]);
690+
vector<string> tokens;
691+
boost::split(tokens, best_c_d, boost::is_any_of(" "));
692+
info("Nearest Jaccard distance is " + tokens[1] + " with substring " + tokens[0] + ".");
693+
} else {
694+
error("Text 1 or 2 is not set.");
695+
}
696+
}
697+
681698
void processPsalminfoCmd(string input)
682699
{
683700
vector<string> tokens;
@@ -960,6 +977,8 @@ string cli_process(char *buf)
960977
processCompareCmd();
961978
else if (boost::starts_with(input, jaccardCmd + "12"))
962979
processJaccardCmd();
980+
else if (boost::starts_with(input, nearestCmd + "12"))
981+
processNearestCmd();
963982
else if (boost::starts_with(input, minuniqueCmd + "1"))
964983
processMinuniqueCmd(input);
965984
// TODO: Consider using this trick for the other commands:

cli.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef CLI_H
22
#define CLI_H
33

4-
#define BIBREF_VERSION "2025-04-19"
4+
#define BIBREF_VERSION "2025-07-13"
55

66
#include <string>
77

fingerprint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ string best_jaccard_substr(const string &fixtext, const string &subtext)
136136
}
137137
}
138138
}
139-
return subtext.substr(best_s1, best_s2 - best_s1 + 2);
139+
return subtext.substr(best_s1, best_s2 - best_s1 + 2) + " " + to_string(best);
140140
}
141141
// Example call:
142142
// best_jaccard_substr("panarsendianoigonmhtranagiontvkyrivklhuhsetai",

fingerprint.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ double jaccard_dist(const string& text1, const string& text2);
3838
string best_jaccard_substr(const string &fixtext, const string &subtext) {
3939
/// @param fixtext The fixed text.
4040
/// @param subtext The text for which a substring must be found.
41+
/// @return The nearest substring and the minimal Jaccard distance, separated by a space character.
4142
};

snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: bibref
22
base: core20
3-
version: '2025-04-08'
3+
version: '2025-07-13'
44
summary: A tool that helps discovering internal references in the Bible
55
icon: logo-Psalm40-192.png
66
description: |

0 commit comments

Comments
 (0)