In this notebook we search for lexical parallels between verses in this parasha with other verses in the Tenach.
The following code will load the Text-Fabric version of the Biblia Hebraica Stuttgartensia (Amstelodamensis).
%load_ext autoreload
%autoreload 2
# Loading the Text-Fabric code
# Note: it is assumed Text-Fabric is installed in your environment.
from tf.fabric import Fabric
from tf.app import use
# load the app and data
BHSA = use ("etcbc/BHSA", mod="tonyjurg/BHSaddons/tf/", hoist=globals())
Locating corpus resources ...
Name | # of nodes | # slots / node | % coverage |
---|---|---|---|
book | 39 | 10938.21 | 100 |
chapter | 929 | 459.19 | 100 |
lex | 9230 | 46.22 | 100 |
verse | 23213 | 18.38 | 100 |
half_verse | 45179 | 9.44 | 100 |
sentence | 63717 | 6.70 | 100 |
sentence_atom | 64514 | 6.61 | 100 |
clause | 88131 | 4.84 | 100 |
clause_atom | 90704 | 4.70 | 100 |
phrase | 253203 | 1.68 | 100 |
phrase_atom | 267532 | 1.59 | 100 |
subphrase | 113850 | 1.42 | 38 |
word | 426590 | 1.00 | 100 |
3
etcbc/BHSA
C:/Users/tonyj/text-fabric-data/github/etcbc/BHSA/app
gd905e3fb6e80d0fa537600337614adc2af157309
''
<code>Genesis 1:1</code> (use <a href="https://github.com/{org}/{repo}/blob/master/tf/{version}/book%40en.tf" target="_blank">English book names</a>)
g_uvf_utf8
g_vbs
kq_hybrid
languageISO
g_nme
lex0
is_root
g_vbs_utf8
g_uvf
dist
root
suffix_person
g_vbe
dist_unit
suffix_number
distributional_parent
kq_hybrid_utf8
crossrefSET
instruction
g_prs
lexeme_count
rank_occ
g_pfm_utf8
freq_occ
crossrefLCS
functional_parent
g_pfm
g_nme_utf8
g_vbe_utf8
kind
g_prs_utf8
suffix_gender
mother_object_type
none
unknown
NA
{docRoot}/{repo}
''
''
https://{org}.github.io
0_home
{}
True
local
C:/Users/tonyj/text-fabric-data/github/etcbc/BHSA/_temp
BHSA = Biblia Hebraica Stuttgartensia Amstelodamensis
10.5281/zenodo.1007624
Phonetic Transcriptions
https://nbviewer.jupyter.org/github/etcbc/phono/blob/master/programs/phono.ipynb
10.5281/zenodo.1007636
etcbc
/tf
phono
Parallel Passages
https://nbviewer.jupyter.org/github/etcbc/parallels/blob/master/programs/parallels.ipynb
10.5281/zenodo.1007642
etcbc
/tf
parallels
etcbc
/tf
BHSA
2021
https://shebanq.ancient-data.org/hebrew
Show this on SHEBANQ
la
True
{webBase}/text?book=<1>&chapter=<2>&verse=<3>&version={version}&mr=m&qw=q&tp=txt_p&tr=hb&wget=v&qget=v&nget=vt
{webBase}/word?version={version}&id=<lid>
v1.8
{typ} {rela}
''
True
{code}
1
''
True
{label}
''
True
gloss
{voc_lex_utf8}
word
orig
{voc_lex_utf8}
{typ} {function}
''
True
{typ} {rela}
1
''
{number}
''
True
{number}
1
''
True
{number}
''
pdp vs vt
lex:gloss
hbo
The main engine of our queries is the use of Text-Fabric feature crossref
, part of Parallel Passages
module. See also this notebook explaing the concepts and how this feature was created.
# find all verse nodes for this parasha using its sequence number
parashaQuery = '''
verse parashanum=3
'''
parashaResults = BHSA.search(parashaQuery)
0.01s 126 results
# Store parashname, start and end verse for future use
startNode=parashaResults[0][0]
endNode=parashaResults[-1][0]
parashaNameHebrew=F.parashahebr.v(startNode)
parashaNameEnglish=F.parashatrans.v(startNode)
bookStart,chapterStart,startVerse=T.sectionFromNode(startNode)
parashaStart=f'{bookStart} {chapterStart}:{startVerse}'
bookEnd,chapterEnd,startEnd=T.sectionFromNode(endNode)
parashaEnd=f'{chapterEnd}:{startEnd}'
def wrapHTML(body, title):
output = (
f'<html><head><title>{title}</title></head>'
f'<body>{body}<p>Data generated by `lexical_parallels.ipynb` at '
'`<a href="https://github.com/tonyjurg/Parashot" target="_blank">'
'github.com/tonyjurg/Parashot</a>`</p></body></html>'
)
return output
from difflib import SequenceMatcher
from IPython.display import HTML, display
# Function to find and highlight matching parts between two strings
def highlightMatches(baseText, comparisonText):
matcher = SequenceMatcher(None, baseText, comparisonText)
highlightedComparisonText = ""
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
if tag == "equal": # Identical parts
highlightedComparisonText += f"<mark>{comparisonText[j1:j2]}</mark>"
else: # Non-matching parts
highlightedComparisonText += comparisonText[j1:j2]
return highlightedComparisonText
# Function to process cross-references and format them into an HTML table
def generateCrossReferencesTable(verseNode):
"""
Generates an HTML table with cross-references for a single verse node, highlighting identical parts.
The main verse text will be right-aligned.
"""
# Get cross-references for the specified verseNode
crossRefs = Es("crossref").f(verseNode)
tableContent = ""
# Check if there are any cross-references for this verse
if crossRefs:
verseSection = T.sectionFromNode(verseNode)
mainVerseText = T.text(verseNode)
linkStepBible = (
f"<a href=\"https://www.stepbible.org/?q=version=NASB2020%7Creference={verseSection[0]}.{verseSection[1]}:{verseSection[2]}&options=HNVUG\" target=\"_blank\">"
f"{verseSection[0]} {verseSection[1]}:{verseSection[2]}</a>"
)
# Right-align the main verse text
tableContent += f"<h4>Cross-references for {linkStepBible}</h4>"
tableContent += f"<div style='text-align: right; font-weight: bold;'>{mainVerseText}</div>"
# Create table header
tableContent += f"<table border='1' style='border-collapse: collapse; width: 100%;'><tr><th>Reference</th><th>Match</th><th>Text</th></tr>"
# Process each cross-reference and add a row to the table
for target, confidence in crossRefs:
targetSection = T.sectionFromNode(target)
targetText = T.text(target)
targetStepBible = (
f"<a href=\"https://www.stepbible.org/?q=version=NASB2020%7Creference={targetSection[0]}.{targetSection[1]}:{targetSection[2]}&options=HNVUG\" target=\"_blank\">"
f"{targetSection[0]} {targetSection[1]}:{targetSection[2]}</a>"
)
# Highlight identical parts in target verse
highlightedText = highlightMatches(mainVerseText, targetText)
# Add the row for the cross-reference
tableContent += f"<tr><td>{targetStepBible}</td><td>{confidence}%</td><td>{highlightedText}</td></tr>"
# Close the table
tableContent += "</table><br>"
return tableContent
# Initialize HTML content
reportTitle=f'Lexical parallels for parasha {parashaNameEnglish} ({parashaStart}-{parashaEnd})'
htmlContent = f"<h2>{reportTitle}</h2>"
# Process each verse and generate cross-reference tables
for verse in parashaResults:
htmlContent += generateCrossReferencesTable(verse[0])
# Display the HTML content in the notebook
display(HTML(htmlContent))
# Define the HTML filename and store to file
fileName = f"lexical_parallels({parashaNameEnglish.replace(' ','_')}).html"
htmlContentFull = wrapHTML(htmlContent,reportTitle)
with open(fileName, "w", encoding="utf-8") as file:
file.write(htmlContentFull)
# display download button
downloadButton = f"""
<a download="{fileName}" href="data:text/html;charset=utf-8,{htmlContentFull.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')}" target="_blank">
<button>Download as HTML</button>
</a>
"""
display(HTML(downloadButton))
Reference | Match | Text |
---|---|---|
Genesis 10:17 | 76% | וְאֶת־הַֽחִוִּ֥י וְאֶת־הַֽעַרְקִ֖י וְאֶת־הַסִּינִֽי׃ |
1_Chronicles 1:15 | 76% | וְאֶת־הַחִוִּ֥י וְאֶת־הַֽעַרְקִ֖י וְאֶת־הַסִּינִֽי׃ |
Reference | Match | Text |
---|---|---|
Genesis 10:16 | 83% | וְאֶת־הַיְבוּסִי֙ וְאֶת־הָ֣אֱמֹרִ֔י וְאֵ֖ת הַגִּרְגָּשִֽׁי׃ |
1_Chronicles 1:14 | 83% | וְאֶת־הַיְבוּסִי֙ וְאֶת־הָ֣אֱמֹרִ֔י וְאֵ֖ת הַגִּרְגָּשִֽׁי׃ |
The scripts in this notebook require (beside text-fabric
) the following Python libraries to be installed in the environment:
difflib
IPython
You can install any missing library from within Jupyter Notebook using eitherpip
or pip3
.
For an elaborate treatment of parallel passages, see:
Willem Th. van Peursen and Eep Talstra. "Computer-Assisted Analysis of Parallel Texts in the Bible - The Case of 2 Kings xviii-xix and its Parallels in Isaiah and Chronicles" in Vetus Testamentum 57, pp. 45-72. 2007, Brill, Leiden.