#!/usr/bin/env python
# coding: utf-8
# # Speaking to objects (Nestle1904LFT)
#
# *Work in progress! it needs to be updated to the new datastructure*
# ## 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 - Find phrase combinations where someone is speaking
# * 3.2 - TBD
# * 4 - Discussion
# * 5 - Atribution and footnotes
# * 6 - Required libraries
# # 1 - Introduction
# ##### [Back to TOC](#TOC)
#
# TBD
# ## 1.1 - Why is this relevant?
#
# TBD
# ## 1.2 - Translating into Text-Fabric queries
#
# Since we are looking for situations where someone or something is speaking to an object, we first need to look for phrases with function 'Object function' (O).
#
#
# It is using the classification by [Louw-Nida](https://www.laparola.net/greco/louwnida.php):
# > ```
# 1 Geographical Objects and Features
# 2 Natural Substances
# 3 Plants
# 4 Animals
# 5 Foods and Condiments
# 6 Artifacts
# 7 Constructions
# ```
#
# Lookup of values for feature ln in [Louw-Nida Lexicon](https://www.laparola.net/greco/louwnida.php).
#
# In the Text-Fabric database the information is stored in feature [ln](https://github.com/tonyjurg/Nestle1904LFT/blob/main/docs/features/ln.md#readme).
#
# A related feature is [lex_dom](https://github.com/tonyjurg/Nestle1904LFT/blob/main/docs/features/lex_dom.md#readme)
# # 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 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 - Find phrase combinations where someone is speaking
# ##### [Back to TOC](#TOC)
#
# For demonstration purposes the table output is limited to 3 results.
# In[12]:
# Define the query template [still to be fine-tuned!]
SearchObjectPhrases = '''
sentence
a:wg wgrole=v|p
word lemma=λέγω
b:wg wgrole=o
word ln~^[12345679]\.
'''
# The following will create a list containing ordered tuples consisting of node numbers of the items as they appear in the query
ObjectPhrasesList = N1904.search(SearchObjectPhrases)
# Just print a few of the results in a table
N1904.table(ObjectPhrasesList, condensed=False, extraFeatures={'lemma'}, end=3)
# Another method to display a limit amount of output, this time using [`plainTuple`](https://annotation.github.io/text-fabric/tf/advanced/display.html#tf.advanced.display.plainTuple) is the following:
# In[13]:
# Limit the query result to 1
TruncatedObjectPhrasesList = N1904.search(SearchObjectPhrases,limit=1)
for NodesTuple in TruncatedObjectPhrasesList: N1904.plainTuple(NodesTuple)
# ## 3.2 - second try (in progress)
# ##### [Back to TOC](#TOC)
#
# For demonstration purposes the table output is limited to the first 10 results.
# *the query as it is now only selects the use of 'lego'*
# In[14]:
MaxNumberOfResuls=10
ThisResult=0
for node in F.lemma.s('λέγω'):
ThisResult+=1
gloss=F.gloss_EN.v(node)
# Following line creates a nicely formated presentation of the verse
VerseLocation=N1904.sectionStrFromNode(node)
# The following is an alternative allowing free formating:
# VerseLocation="{} {}:{}".format(F.book.v(node),F.chapter.v(node),F.verse.v(node))
print('\n',ThisResult,'\t',VerseLocation)
if ThisResult == MaxNumberOfResuls: break
# # 4 - Discussion
# ##### [Back to TOC](#TOC)
#
# TBA
# # 5 - Attribution and footnotes
# ##### [Back to TOC](#TOC)
#
# NA
# # 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:
#
# {none}
#
# You can install any missing library from within Jupyter Notebook using either`pip` or `pip3`.
# In[ ]: