#!/usr/bin/env python # coding: utf-8 # # Lexical parallels in parasha #11 Vayigash (Genesis 44:18-47:27) # ## Table of Content (ToC) # # * 1 - Introduction # * 2 - Load Text-Fabric app and data # * 3 - Performing the queries # * 3.1 - Locate the parallels # * 4 - Required libraries # * 5 - Further reading # * 6 - Notebook version details # # 1 - Introduction # ##### [Back to ToC](#TOC) # # In this notebook we search for lexical parallels between verses in this parasha with other verses in the Tenach. # # 2 - Load Text-Fabric app and data # ##### [Back to ToC](#TOC) # # The following code will load the Text-Fabric version of the [Biblia Hebraica Stuttgartensia (Amstelodamensis)](https://etcbc.github.io/bhsa/). # In[1]: get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') # In[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 # In[3]: # load the app and data BHSA = use ("etcbc/BHSA", mod="tonyjurg/BHSaddons/tf/", hoist=globals()) # # 3 - Performing the queries # ##### [Back to ToC](#TOC) # # The main engine of our queries is the use of Text-Fabric feature `crossref`, part of `Parallel Passages` module. See also [this notebook](https://nbviewer.org/github/etcbc/parallels/blob/master/programs/parallels.ipynb) explaing the concepts and how this feature was created. # ## 3.1 - Locate the parallels # In[4]: # find all verse nodes for this parasha using its sequence number parashaQuery = ''' verse parashanum=11 ''' parashaResults = BHSA.search(parashaQuery) # In[5]: # 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}' htmlStart='' htmlFooter=f'

Data generated by `hapax.ipynb` at `github.com/tonyjurg/Parashot`

' # In[6]: 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"{comparisonText[j1:j2]}" 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"" f"{verseSection[0]} {verseSection[1]}:{verseSection[2]}" ) # Right-align the main verse text tableContent += f"

Cross-references for {linkStepBible}

" tableContent += f"
{mainVerseText}
" # Create table header tableContent += f"" # 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"" f"{targetSection[0]} {targetSection[1]}:{targetSection[2]}" ) # Highlight identical parts in target verse highlightedText = highlightMatches(mainVerseText, targetText) # Add the row for the cross-reference tableContent += f"" # Close the table tableContent += "
ReferenceMatchText
{targetStepBible}{confidence}%{highlightedText}

" return tableContent # Initialize HTML content htmlContent = f"

Lexical parallels for parasha {parashaNameEnglish} ({parashaStart}-{parashaEnd})

" # Process each verse and generate cross-reference tables for verse in parashaResults: htmlContent += generateCrossReferencesTable(verse[0]) # Save the content to an HTML file fileName = f"lexical_parallels({parashaNameEnglish.replace(' ','%20')}).html" with open(fileName, "w", encoding="utf-8") as file: file.write(htmlContent) # Display the HTML content in the notebook display(HTML(htmlContent)) # wrap html header and footer and display a download button htmlContentFull = f'{htmlStart}{htmlContent}{htmlFooter}' downloadButton = f""" """ display(HTML(downloadButton)) # # 4 - Required libraries # ##### [Back to ToC](#TOC) # # The scripts in this notebook require (beside `text-fabric`) the following Python libraries to be installed in the environment: # # difflib # # You can install any missing library from within Jupyter Notebook using either`pip` or `pip3`. # # 5 - Further reading # ##### [Back to ToC](#TOC) # # 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. # # 6 - Notebook version details # ##### [Back to ToC](#TOC) # #
# # # # # # # # # # # # # #
AuthorTony Jurg
Version1.1
Date18 November 2024
#