bibref-python 2026.3.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bibref/__init__.py +0 -0
- bibref/tools.py +225 -0
- bibref_python-2026.3.18.dist-info/METADATA +20 -0
- bibref_python-2026.3.18.dist-info/RECORD +7 -0
- bibref_python-2026.3.18.dist-info/WHEEL +5 -0
- bibref_python-2026.3.18.dist-info/licenses/LICENSE +5 -0
- bibref_python-2026.3.18.dist-info/top_level.txt +1 -0
bibref/__init__.py
ADDED
|
File without changes
|
bibref/tools.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import sys, pexpect, os, re, shutil
|
|
2
|
+
|
|
3
|
+
bibref_default_timeout = 5
|
|
4
|
+
bibref_default_timeout_max = 180
|
|
5
|
+
bibref_fullpath = ""
|
|
6
|
+
|
|
7
|
+
bibref = None
|
|
8
|
+
|
|
9
|
+
def set_bibref_path(fullpath = ""):
|
|
10
|
+
global bibref_fullpath
|
|
11
|
+
bibref_fullpath = fullpath
|
|
12
|
+
|
|
13
|
+
def spawn_bibref():
|
|
14
|
+
global bibref
|
|
15
|
+
if bibref is not None:
|
|
16
|
+
return
|
|
17
|
+
sys.stderr.write("Waiting for bibref's full startup...\n")
|
|
18
|
+
|
|
19
|
+
if bibref_fullpath != "":
|
|
20
|
+
bibref = pexpect.spawn(bibref_fullpath + " -a")
|
|
21
|
+
bibref.expect("Done loading books of SBLGNT.")
|
|
22
|
+
bibref.timeout = bibref_default_timeout
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
bibref_fullpath_auto = shutil.which("bibref")
|
|
26
|
+
|
|
27
|
+
if bibref_fullpath_auto is None:
|
|
28
|
+
raise RuntimeError(
|
|
29
|
+
"No 'bibref' binary can be found in PATH. "
|
|
30
|
+
"Install it first by using `snap install bibref`, for example. "
|
|
31
|
+
"Alternatively, use 'set_bibref_path(...)' to set the correct full path."
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
sys.stderr.write(f"Spawning {bibref_fullpath_auto}...\n")
|
|
35
|
+
bibref = pexpect.spawn(bibref_fullpath_auto + " -a")
|
|
36
|
+
bibref.expect("Done loading books of SBLGNT.")
|
|
37
|
+
bibref.timeout = bibref_default_timeout
|
|
38
|
+
|
|
39
|
+
def getrefs_maxlength(getrefs_input):
|
|
40
|
+
"""
|
|
41
|
+
Returns the length of the longest match.
|
|
42
|
+
:param getrefs_input: All parameters of getref as string
|
|
43
|
+
:return: The length of the longest match
|
|
44
|
+
"""
|
|
45
|
+
global bibref
|
|
46
|
+
spawn_bibref()
|
|
47
|
+
bibref.timeout = bibref_default_timeout_max
|
|
48
|
+
command = "getrefs " + getrefs_input
|
|
49
|
+
bibref.sendline(command)
|
|
50
|
+
bibref.expect("Finished")
|
|
51
|
+
lines = bibref.before.decode('utf-8').splitlines()
|
|
52
|
+
no_lines = len(lines)
|
|
53
|
+
length_regex = re.compile(r'length=([0-9]+),')
|
|
54
|
+
found = length_regex.search(lines[no_lines - 1])
|
|
55
|
+
maxlength0 = found.group()
|
|
56
|
+
maxlength1 = maxlength0.split("=")
|
|
57
|
+
maxlength2 = maxlength1[1]
|
|
58
|
+
maxlength3 = maxlength2.split(",")
|
|
59
|
+
maxlength = maxlength3[0]
|
|
60
|
+
bibref.timeout = bibref_default_timeout
|
|
61
|
+
return maxlength
|
|
62
|
+
|
|
63
|
+
def text_n(c, greektext):
|
|
64
|
+
"""
|
|
65
|
+
Stores the Greek input in the selected clipboard.
|
|
66
|
+
:param c: Clipboard number (1 or 2)
|
|
67
|
+
:param greektext: Greek input as string
|
|
68
|
+
:return: the input converted to Latin notation
|
|
69
|
+
"""
|
|
70
|
+
global bibref
|
|
71
|
+
spawn_bibref()
|
|
72
|
+
bibref.timeout = bibref_default_timeout
|
|
73
|
+
command = "text" + str(c) + " " + greektext
|
|
74
|
+
bibref.sendline(command)
|
|
75
|
+
bibref.expect("Stored internally as (\\w+).")
|
|
76
|
+
form = bibref.match.groups()
|
|
77
|
+
return form[0].decode('utf-8')
|
|
78
|
+
|
|
79
|
+
def latintext_n(c, latintext):
|
|
80
|
+
"""
|
|
81
|
+
Stores the Latin input in the selected clipboard.
|
|
82
|
+
:param c: Clipboard number (1 or 2)
|
|
83
|
+
:param greektext: Latin input as string
|
|
84
|
+
"""
|
|
85
|
+
global bibref
|
|
86
|
+
spawn_bibref()
|
|
87
|
+
bibref.timeout = bibref_default_timeout
|
|
88
|
+
command = "latintext" + str(c) + " " + latintext
|
|
89
|
+
bibref.sendline(command)
|
|
90
|
+
bibref.expect("Stored.")
|
|
91
|
+
|
|
92
|
+
def lookup_n(c, passage):
|
|
93
|
+
"""
|
|
94
|
+
Looks up the passage and stores it in the selected clipboard.
|
|
95
|
+
:param c: Clipboard number (1 or 2)
|
|
96
|
+
:param passage: The passage to look up
|
|
97
|
+
:return: the passage converted to Latin notation
|
|
98
|
+
"""
|
|
99
|
+
global bibref
|
|
100
|
+
spawn_bibref()
|
|
101
|
+
bibref.timeout = bibref_default_timeout
|
|
102
|
+
command = "lookup" + str(c) + " " + passage
|
|
103
|
+
bibref.sendline(command)
|
|
104
|
+
bibref.expect("Stored internally as (\\w+).")
|
|
105
|
+
form = bibref.match.groups()
|
|
106
|
+
return form[0].decode('utf-8')
|
|
107
|
+
|
|
108
|
+
def find_n(c, bible):
|
|
109
|
+
"""
|
|
110
|
+
Finds the clipboard text in a Bible edition.
|
|
111
|
+
:param c: Clipboard number (1 or 2)
|
|
112
|
+
:param bible: Bible edition
|
|
113
|
+
:return: list of strings that explain the matches (in bibref format: passage, raw_start, raw_end)
|
|
114
|
+
"""
|
|
115
|
+
global bibref
|
|
116
|
+
spawn_bibref()
|
|
117
|
+
bibref.timeout = bibref_default_timeout
|
|
118
|
+
command = "find" + str(c) + " " + bible
|
|
119
|
+
bibref.sendline(command)
|
|
120
|
+
ret = []
|
|
121
|
+
finished = False
|
|
122
|
+
# Found in Acts 13:33+88 13:33 (book position 43840-43871)
|
|
123
|
+
# Found in Hebrews 1:5+26 1:5-53 (book position 420-451)
|
|
124
|
+
# Found in Hebrews 5:5+70 5:5 (book position 6271-6302)
|
|
125
|
+
# 3 occurrences.
|
|
126
|
+
while not finished:
|
|
127
|
+
index = bibref.expect([r'Found in (.*?) \(book position ([0-9]+)\-([0-9]+)\)',r'([0-9]+) occurrences.'])
|
|
128
|
+
if index == 0:
|
|
129
|
+
passage, raw1, raw2 = bibref.match.groups()
|
|
130
|
+
ret.append([passage.decode('utf-8'), int(raw1), int(raw2)])
|
|
131
|
+
if index == 1:
|
|
132
|
+
finished = True
|
|
133
|
+
return ret
|
|
134
|
+
|
|
135
|
+
def jaccard12():
|
|
136
|
+
"""
|
|
137
|
+
Computes the Jaccard distance between the two clipboard texts.
|
|
138
|
+
:return: the Jaccard distance as a number between 0 and 1
|
|
139
|
+
"""
|
|
140
|
+
global bibref
|
|
141
|
+
spawn_bibref()
|
|
142
|
+
bibref.timeout = bibref_default_timeout
|
|
143
|
+
command = "jaccard12"
|
|
144
|
+
bibref.sendline(command)
|
|
145
|
+
bibref.expect("Jaccard distance is ([0-9]+\\.[0-9]+).")
|
|
146
|
+
jaccard12 = bibref.match.groups()
|
|
147
|
+
jaccard = float(jaccard12[0]) * 100
|
|
148
|
+
return jaccard
|
|
149
|
+
|
|
150
|
+
def jaccard(t1, t2):
|
|
151
|
+
"""
|
|
152
|
+
Puts the Greek inputs in the clipboards and compute their Jaccard distance.
|
|
153
|
+
:param t1: the first Greek text
|
|
154
|
+
:param t2: the second Greek text
|
|
155
|
+
:return: the Jaccard distance as a number between 0 and 1
|
|
156
|
+
"""
|
|
157
|
+
text_n(1, t1)
|
|
158
|
+
text_n(2, t2)
|
|
159
|
+
return jaccard12()
|
|
160
|
+
|
|
161
|
+
def latin_to_greek(latin):
|
|
162
|
+
"""
|
|
163
|
+
Converts the Latin input into Greek text.
|
|
164
|
+
:param latin: the input as Latin text
|
|
165
|
+
:return: the text in Greek letters
|
|
166
|
+
"""
|
|
167
|
+
greek = latin
|
|
168
|
+
greek = greek.replace("a", "α") # Note that the implementation is not very elegant.
|
|
169
|
+
greek = greek.replace("b", "β")
|
|
170
|
+
greek = greek.replace("c", "ψ")
|
|
171
|
+
greek = greek.replace("d", "δ")
|
|
172
|
+
greek = greek.replace("e", "ε")
|
|
173
|
+
greek = greek.replace("f", "φ")
|
|
174
|
+
greek = greek.replace("g", "γ")
|
|
175
|
+
greek = greek.replace("h", "η")
|
|
176
|
+
greek = greek.replace("i", "ι")
|
|
177
|
+
greek = greek.replace("j", "ξ")
|
|
178
|
+
greek = greek.replace("k", "κ")
|
|
179
|
+
greek = greek.replace("l", "λ")
|
|
180
|
+
greek = greek.replace("m", "μ")
|
|
181
|
+
greek = greek.replace("n", "ν")
|
|
182
|
+
greek = greek.replace("o", "ο")
|
|
183
|
+
greek = greek.replace("p", "π")
|
|
184
|
+
greek = greek.replace("q", "ζ")
|
|
185
|
+
greek = greek.replace("r", "ρ")
|
|
186
|
+
greek = greek.replace("s", "σ")
|
|
187
|
+
greek = greek.replace("t", "τ")
|
|
188
|
+
greek = greek.replace("u", "θ")
|
|
189
|
+
greek = greek.replace("v", "ω")
|
|
190
|
+
greek = greek.replace("w", "ς") # unused
|
|
191
|
+
greek = greek.replace("x", "χ")
|
|
192
|
+
greek = greek.replace("y", "υ")
|
|
193
|
+
greek = greek.replace("z", "ζ") # maybe unused
|
|
194
|
+
return greek
|
|
195
|
+
|
|
196
|
+
def nearest12():
|
|
197
|
+
"""
|
|
198
|
+
Computes the nearest substring of clipboard 1 and the text in clipboard2.
|
|
199
|
+
:return: a 2-element list of the minimal Jaccard distance as a number between 0 and 1 and the nearest substring
|
|
200
|
+
"""
|
|
201
|
+
global bibref
|
|
202
|
+
spawn_bibref()
|
|
203
|
+
bibref.timeout = bibref_default_timeout
|
|
204
|
+
command = "nearest12"
|
|
205
|
+
bibref.sendline(command)
|
|
206
|
+
bibref.expect("Nearest Jaccard distance is ([0-9]+\\.[0-9]+) with substring (\\w+).")
|
|
207
|
+
nearest12 = bibref.match.groups()
|
|
208
|
+
nearest = float(nearest12[0]) * 100
|
|
209
|
+
nearest_substring = nearest12[1].decode('utf-8')
|
|
210
|
+
return nearest, nearest_substring
|
|
211
|
+
|
|
212
|
+
def maxresults(m):
|
|
213
|
+
"""
|
|
214
|
+
Sets the maximal amount of matches to be found, for the find command.
|
|
215
|
+
:return: the value being actually set
|
|
216
|
+
"""
|
|
217
|
+
global bibref
|
|
218
|
+
spawn_bibref()
|
|
219
|
+
bibref.timeout = bibref_default_timeout
|
|
220
|
+
command = "maxresults " + str(m)
|
|
221
|
+
bibref.sendline(command)
|
|
222
|
+
bibref.expect("Set to ([0-9]+).")
|
|
223
|
+
maxresults = bibref.match.groups()
|
|
224
|
+
return int(maxresults[0])
|
|
225
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bibref-python
|
|
3
|
+
Version: 2026.3.18
|
|
4
|
+
Summary: Python wrapper for the bibref command-line tool for working with biblical references
|
|
5
|
+
Author: Zoltán Kovács
|
|
6
|
+
License: Copyright (C) 2026 Zoltán Kovács
|
|
7
|
+
|
|
8
|
+
Copying and distribution of these files, with or without modification,
|
|
9
|
+
are permitted in any medium without royalty provided the copyright
|
|
10
|
+
notice and this notice are preserved.
|
|
11
|
+
|
|
12
|
+
Project-URL: Homepage, https://github.com/kovzol/bibref-python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: License :: OSI Approved
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: pexpect>=4.8
|
|
20
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
bibref/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
bibref/tools.py,sha256=NguBO5bXUWhgm8IaMkpPw9dp6F_ftvZZR3u93THVrIY,7407
|
|
3
|
+
bibref_python-2026.3.18.dist-info/licenses/LICENSE,sha256=AE-9c3gRsMwA5aDYTqdjxGENJmM2k2EQVfUE8wbnRZk,212
|
|
4
|
+
bibref_python-2026.3.18.dist-info/METADATA,sha256=9vw2hA-HoCcdwDc9XPcsWxnzkfAjfTUz0Jyp3sRlpHo,771
|
|
5
|
+
bibref_python-2026.3.18.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
bibref_python-2026.3.18.dist-info/top_level.txt,sha256=RTH1l7THHwpMwkH5Ydrjmk5oQRI9UKUbyUuFtJRgYGs,7
|
|
7
|
+
bibref_python-2026.3.18.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bibref
|