#!/usr/bin/env python # coding: utf-8 # # The heart in the Tenakh (BHSA) # ## Table of content (TOC) # # * 1 - Introduction # * 2 - Load Text-Fabric app and data # * 3 - Performing the queries # * 3.1 - Print table with frequency for lev and levev # * 3.2 - Plotting the frequency per book # * 4 - Required libraries # * 5 - Notebook details # # # 1 - Introduction # ##### [Back to TOC](#TOC) # In Hebrew, the words for "heart" are written as follows: # # - לֵב ("lev"): This is the shorter form commonly used to mean "heart." # - לֵבָב ("levav"): This is a slightly longer, more poetic or emphatic form of the word, also meaning "heart." # # This Jupyter NoteBook investigates occurances per book. # # 2 - Load Text-Fabric app and data # ##### [Back to TOC](#TOC) # 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 BHSL app and data BHS = use ("etcbc/BHSA",hoist=globals()) # Note: Thefeature documentation can be found at [ETCBC GitHub](https://github.com/ETCBC/bhsa/blob/master/docs/features/0_home.md) # In[4]: # The following will push the Text-Fabric stylesheet to this notebook (to facilitate proper display with notebook viewer) BHS.dh(BHS.getCss()) # # 3 - Performing the queries # ##### [Back to TOC](#TOC) # ## 3.1 - Print table with frequency for lev and levev # In[5]: levQuery = ''' book chapter verse word lex=LBB/|LB/ ''' levResults = BHS.search(levQuery) # In[6]: # Libraries for table formatting and data display import pandas as pd from IPython.display import display # Initialize dictionary for storing results resultDict = {} # Process each item in the levResults for item in levResults: book = F.book.v(item[0]) lex = F.lex.v(item[3]) if book in resultDict: # If it exists, add the count to the existing value resultDict[book][0] += 1 if lex == 'LB/': resultDict[book][1] += 1 else: resultDict[book][2] += 1 else: # If it doesn't exist, initialize the count as the value if lex == 'LB/': resultDict[book] = [1, 1, 0] else: resultDict[book] = [1, 0, 1] # Convert the dictionary into a DataFrame and sort by total frequency tableData = pd.DataFrame( [[key, value[0], value[1], value[2]] for key, value in resultDict.items()], columns=["Book", "Total", "Lev", "Levav"] ) tableData = tableData.sort_values(by="Total", ascending=False) # Display the table display(tableData) # ## 3.2 - Plotting the frequency per book # In[7]: import matplotlib.pyplot as plt import seaborn as sns import pandas as pd # Sample data setup (replace with your actual data) # Initialize dictionary for storing results resultDict = {} # Process each item in the levResults for item in levResults: book = F.book.v(item[0]) lex = F.lex.v(item[3]) if book in resultDict: # If it exists, add the count to the existing value resultDict[book][0] += 1 if lex == 'LB/': resultDict[book][1] += 1 else: resultDict[book][2] += 1 else: # If it doesn't exist, initialize the count as the value if lex == 'LB/': resultDict[book] = [1, 1, 0] else: resultDict[book] = [1, 0, 1] # Convert the dictionary into a DataFrame and sort by total frequency tableData = pd.DataFrame( [[key, value[0], value[1], value[2]] for key, value in resultDict.items()], columns=["Book", "Total", "LB", "LBB"] ) # Set up the data for plotting with LB as positive and LBB as negative values tableData['LB_Positive'] = tableData['LB'] # LB counts as positive values tableData['LBB_Negative'] = -tableData['LBB'] # LBB counts as negative values # Set up the plot plt.figure(figsize=(14, 10)) # Plot LB (positive values) lb_bars = plt.barh(tableData["Book"], tableData["LB_Positive"], color='blue', label='לֵב') # Plot LBB (negative values) lbb_bars = plt.barh(tableData["Book"], tableData["LBB_Negative"], color='orange', label='לֵבָב') # Add the counts on each bar for bar, count in zip(lb_bars, tableData['LB']): plt.text(bar.get_width() + 1, bar.get_y() + bar.get_height()/2, str(count), va='center', color='blue') for bar, count in zip(lbb_bars, tableData['LBB']): plt.text(bar.get_width() - 1, bar.get_y() + bar.get_height()/2, str(count), va='center', ha='right', color='orange') # Customize x-axis to show absolute values x_ticks = plt.xticks()[0] # Get current tick positions plt.xticks(x_ticks, [str(int(abs(x))) for x in x_ticks]) # Set absolute values for labels # Add labels, title, and legend plt.xlabel("Count") plt.ylabel("Book") plt.title('Distribution of לֵב and לֵבָב Counts per Book in the Tenach') plt.axvline(0, color="black", linewidth=0.5) # Center line at x=0 plt.legend(title="Category") # Show the plot plt.show() # # 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: # # IPython # pandas # matplotlib # seaborn # # You can install any missing library from within Jupyter Notebook using either`pip` or `pip3`. # # 5 - Notebook details # ##### [Back to TOC](#TOC) # #
# # # # # # # # # # # # # #
AuthorTony Jurg
Version1.0
Date4 Novermber 2024
#