#!/usr/bin/env python
# coding: utf-8
# # The use of προσκυνέω (Nestle1904LFT)
#
# **Work in progress!**
# ## Table of content
# * 1 - Introduction
# * 1.1 - Why is this relevant?
# * 1.2 - Translating into Text-Fabric queries
# * 2 - Load Text-Fabric app and data
# * 3 - Performing the queries
# * 3.1 - Determine the renderings of προσκυνέω
# * 3.2 - Alternative way of coding
# * 3.3 - Using a search template
# * 3.4 - What is being 'προσκυνέω-ed'?
# * 3.5 - Pie chart showing the renderings
# * 4 - Discussion
# * 5 - Atribution and footnotes
# * 6 - Required libraries
# # 1 - Introduction
# ##### [Back to TOC](#TOC)
#
# In this Jupyter NoteBook we will examine the use of lemma προσκυνέω in the Greek New Testament.
#
#
# ## 1.1 - Why is this relevant?
# ##### [Back to TOC](#TOC)
#
# There is an ongoing debate whether προσκυνέω must mean "worship" in a divine sense, especialy when it refers to Jesus or God. The word can refer to homage or respect given to people in authority ([see also entry in Liddel-Scott-Jones Greek-English Lexion](https://stephanus.tlg.uci.edu/lsj/#eid=92238)). So verses that refer to Jesus receiving προσκυνέω may not always prove worship of him as God. The meaning depends on context.
# ## 1.2 - Translating into Text-Fabric queries
# ##### [Back to TOC](#TOC)
#
# The following examples gather data related to the use of προσκυνέω using various methods and present the results in different ways.
# # 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[1]:
# 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 N1904 app and data
N1904 = use ("tonyjurg/Nestle1904LFT", version="0.6", hoist=globals())
# In[4]:
# The following will push the Text-Fabric stylesheet to this notebook (to facilitate proper display with notebook viewer)
N1904.dh(N1904.getCss())
# In[5]:
# Set default view in a way to limit noise as much as possible.
N1904.displaySetup(condensed=True, multiFeatures=False, queryFeatures=False)
# # 3 - Performing the queries
# ##### [Back to TOC](#TOC)
# ## 3.1 - Determine the renderings of προσκυνέω
# ##### [Back to TOC](#TOC)
#
# This code will produce a list of occurrences of the lemma 'προσκυνέω' along with their accompanying gloss.
# In[6]:
# Library to format table
from tabulate import tabulate
# Gather the results
Results=[]
for node in F.lemma.s('προσκυνέω'):
# Following line creates a nicely formated presentation of the verse
location="{} {}:{}".format(F.book.v(node),F.chapter.v(node),F.verse.v(node))
result=(location,F.word.v(node),F.gloss.v(node))
Results.append(result)
# Produce the table
headers = ["location","word","gloss"]
print(tabulate(Results, headers=headers, tablefmt='fancy_grid'))
# ## 3.2 - Alternative way of coding
# ##### [Back to TOC](#TOC)
#
# Note that the the following line of code in previous example:
# ```
# for node in F.lemma.s('προσκυνέω'):
# {rest of the code}
# ```
#
# is functionaly equivalent to this three line of code:
# ```
# for node in F.otype.s('word'):
# lemma=F.lemma.v(node)
# if lemma == 'προσκυνέω':
# {rest of the code}
# ```
# ## 3.3 - Using a search template
# ##### [Back to TOC](#TOC)
#
# The same selection can also be made using a search template. Note that the number of results (56) differs from the previous code(59). The reasone is that here the selection is on clause and in the previous code on words. (John 4:23&24 and Revelation 13:4 and 19:10 have duplicate occurances of lemma προσκυνέω).
#
# In[7]:
SearchWorship = '''
book
chapter
verse
wg
word lemma=προσκυνέω gloss
'''
# This will create a list containing ordered tuples consisting of node numbers of the items as they appear in the query
WorshipList = N1904.search(SearchWorship)
# The resulting data (stored in WorshipList) can be further processed. For example to print the first 5 occurences in a table:
#
# In[8]:
N1904.table(WorshipList, condensed=True, end=5)
# ## 3.4 - What is being 'προσκυνέω-ed'?
# ##### [Back to TOC](#TOC)
#
# *this section needs rework!*
#
# A more interesting query is to print all occurences of the lemma προσκυνέω while adding the object of προσκυνέω.
#
# This query is using a number of [Locality functions](https://annotation.github.io/text-fabric/tf/cheatsheet.html#l-locality) from the Text-Fabric API. The following diagram shows the concept.
#
#
# In[9]:
for node in F.lemma.s('προσκυνέω'):
gloss=F.gloss.v(node)
# Following line creates a nicely formated presentation of the verse
location="{} {}:{}".format(F.book.v(node),F.chapter.v(node),F.verse.v(node))
print('\n',location)
# This finds the parrent clause
ParrentClause= L.u(node,'wg')[0]
# Create a list of phrases included in the ParrentClause
PhraseList=L.d(ParrentClause,'wg')
for phrase in PhraseList:
# check for the phrase containing the object
object_text=object_gloss=''
if F.phrasefunction.v(wg)=='O':
WordList=L.d(phrase, 'word')
for word in WordList:
object_text=object_text+F.word.v(word)+' '
object_gloss=object_gloss+F.gloss_EN.v(word)+' '
break
# print the result
print('\tGreek:',F.word.v(node),' - ',object_text,'\n\tGloss:',F.gloss_EN.v(node),' - ',object_gloss)
# ## 3.5 - Pie chart showing the renderings
# ##### [Back to TOC](#TOC)
# The next code generates a pie diagram showing the distribution of renderings of the word προσκυνέω. The grouping is basicly along 'kneeling' and 'worshipping'. When the rendering does not match one of these, it is counted as 'other'. In terms of coding, in this example, we first import the `matplotlib.pyplot` module. Then, we define the data for our pie chart: `labels` and `results`. Additionally, a legend will be included.
# In[10]:
import matplotlib.pyplot as plt
worship=knee=other=0
# This section can also be implemented using a different method (see below)
for node in F.otype.s('word'):
lemma=F.lemma.v(node)
if lemma == 'προσκυνέω':
gloss=F.gloss.v(node)
if 'worship' in gloss:
worship+=1
else:
if 'knee' in gloss:
knee+=1
else:
other+=1
# Dataset for the plot
labels = ['Worship', 'Kneeling', 'Other']
results = [worship, knee, other]
# create the pie chart with percentage and number of occurances
explode = [0.1,0.1,0.1] # To slice the perticuler section
plt.pie(results,
labels=labels,
explode = explode,
autopct=lambda pct: f'{pct:.1f}%\n({int(pct / 100 * sum(results)+0.5)})',
# The addition of 0.5 in the lambda function is to prevent rounding errors by the int() function.
textprops={'color': 'black'})
# add a title to the pie chart
plt.title('Renderings of προσκυνέω')
# Add a legend to the pie chart
plt.legend(title="English renderings",
loc="center left",
bbox_to_anchor=(1.5, 0, 1, 1))
# Show plot
plt.show()
# Alternatively the first part of this section could be implemented by means of a search function:
# In[11]:
# Define the query template
ProskuneoQuery = '''
word lemma=προσκυνέω
'''
# This will create a list containing ordered tuples consisting of node numbers of the items as they appear in the query
ProskuneoResult = N1904.search(ProskuneoQuery)
worship=knee=other=0
for NodeTuple in ProskuneoResult:
# The query result will be a list of node tuple. Hence we need to add index [0].
gloss=F.gloss.v(NodeTuple[0])
if 'worship' in gloss:
worship+=1
else:
if 'knee' in gloss:
knee+=1
else:
other+=1
# Print to compare the results
print ('worship=',worship,' knee=',knee,' other=',other)
# ## 4 - Discussion
# ##### [Back to TOC](#TOC)
#
# TBA
# # 5 - Attribution and footnotes
# ##### [Back to TOC](#TOC)
#
# N.A.
# # 6 - 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:
#
# ???
#
# You can install any missing library from within Jupyter Notebook using either`pip` or `pip3`.