#!/usr/bin/env python
# coding: utf-8
# # Speaking to objects (Nestle1904GBI)
#
# **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 - Find phrase combinations where someone is speaking
# * 3.2 - TBD
# * 4 - Footnotes and attribution
# * 5 - 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
# ```
# # 2 - Load Text-Fabric app and data
# ##### [Back to TOC](#TOC)
# In[2]:
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[2]:
# load the N1904 app and data
N1904 = use ("tonyjurg/Nestle1904GBI", version="0.4", hoist=globals())
# In[3]:
# The following will push the Text-Fabric stylesheet to this notebook (to facilitate proper display with notebook viewer)
N1904.dh(N1904.getCss())
# # 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[4]:
# Define the query template
SearchObjectPhrases = '''
book
chapter
clause
a:phrase phrasefunction=V
word lemma=λέγω
b:phrase phrasefunction=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[5]:
# 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[6]:
MaxNumberOfResuls=10
ThisResult=0
for node in F.lemma.s('λέγω'):
ThisResult+=1
gloss=F.gloss.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 - Footnotes and attribution
# ##### [Back to TOC](#TOC)
#
# N.A.
# # 5 - 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[ ]: