#!/usr/bin/env python
# coding: utf-8
# # Running Text-Fabric (Nestle1904GBI)
#
# Basic instructions on loading the Text-Fabric and start using it on your system.
# ## Table of content
# * [Step 1: Install Text-Fabric (if not yet installed)](#first-bullet)
# * [Step 2: Raise rate limit on Github](#second-bullet)
# * [Step 3: Load Text-Fabric code](#third-bullet)
# * [Step 4: Load app and data](#fourth-bullet)
# ## Step 1: Install Text-Fabric (if not yet installed)
# ##### [back to TOC](#TOC)
# ### Python
#
# You need to have Python on your system. Most systems have it out of the box,
# but alas, that is python2 and we need at least python **3.6**.
#
# Install it from [python.org](https://www.python.org) or from
# [Anaconda](https://www.anaconda.com/products/distribution).
#
# ### TF itself
#
# ```
# pip3 install text-fabric
# ```
#
# ### When using Jupyter notebook
#
# You need [Jupyter](http://jupyter.org) or a platform like [Anaconda](https://www.anaconda.com/products/distribution) which includes Jupyter.
#
# If it is not already installed:
#
# ```
# pip3 install jupyter
# ```
# ## Step 2: Raise rate limit on Github
# ##### [back to TOC](#TOC)
#
# It may be required to increase rate limit for GitHub. [See instructions](https://annotation.github.io/text-fabric/tf/advanced/repo.html) on aquiring and setting the GHPERS variable.
# See [here](https://www.howtogeek.com/789660/how-to-use-windows-cmd-environment-variables/#autotoc_anchor_2) if you want to set the varibale on windows using the command prompt.
# ## Step 3: Load Text-Fabric code
# ##### [back to TOC](#TOC)
# In[1]:
get_ipython().run_line_magic('load_ext', 'autoreload')
get_ipython().run_line_magic('autoreload', '2')
# In[32]:
# Loading the New Testament TextFabric code
from tf.fabric import Fabric
from tf.app import use
# ## Step 4: Load app and data
# ##### [back to TOC](#TOC)
# In[48]:
# load the app and data
N1904 = use ("tonyjurg/Nestle1904GBI:clone", hoist=globals())
# In[49]:
Search0 = '''
word sp=noun
'''
Search0 = NA.search(Search0)
N1904.show(Search0, start=1, end=3, condensed=True, extraFeatures={'sp', 'clauserule', 'phrasefunction', 'formaltag', 'functionaltag', 'type', 'case', 'ln'}, withNodes=False)
# # Dump some data
# In[42]:
show_book = T.nodeFromSection(('Jude',))
for verse in L.d(show_book, 'verse'):
print('{} {}:{}'.format(*T.sectionFromNode(verse)))
print('\t\t', T.text(verse))
# In[18]:
print(E.__dict__)
# In[20]:
print(N.__dict__)
# In[13]:
print(F.__dict__)
# In[15]:
print(L.__dict__)
# In[105]:
for chapter in L.d(show_book, 'chapter'):
print(F.book.v(show_book), 'ยง', F.chapter.v(chapter))
for verse in L.d(chapter, 'verse'):
book,chapter,vrs = T.sectionFromNode(verse)
print(f'({chapter}:{vrs}) {T.text(verse)}', end='\n')
print('\n')
# In[ ]:
# In[19]:
max=10
count=0
for node in F.otype.s('word'):
functionaltag=F.functionaltag.v(node)
formaltag=F.formaltag.v(node)
if formaltag != functionaltag:
count+=1
book=F.book_long.v(node)
chapter=F.chapter.v(node)
verse=F.verse.v(node)
word=F.word.v(node)
print (count,' - ',book,chapter,':',verse,'=\t',word,'\tformaltag:',formaltag,'\tfunctionaltag:',functionaltag)
if count==max: break
# In[20]:
# print value frequency for feature gn
ValueFreq = {}
for node in F.otype.s('word'):
gn=F.gn.v(node)
ValueFreq[gn] = ValueFreq.setdefault(gn, 0) + 1
print (ValueFreq)
# In[21]:
# print frequency for feature ln,lex_dom being populated
ValueFreq = {}
for node in F.otype.s('word'):
LnPresent='no'
if F.ln.v(node)!='': LnPresent='yes'
ValueFreq[LnPresent] = ValueFreq.setdefault(LnPresent, 0) + 1
print (ValueFreq)
# In[22]:
FeatureList = {'case', 'type', 'phrasetype', 'degree', 'mood', 'nu', 'number', 'person', 'sp', 'tense', 'voice', 'gn' }
for Feature in FeatureList:
ValueFreq = {}
for node in F.otype.s('word'):
# implementation of pseudo: gn=F.{Feature}.v(node)
Value= getattr(F, Feature).v(node)
ValueFreq[Value] = ValueFreq.setdefault(Value, 0) + 1
print ('Feature:',Feature,' Frequency:',ValueFreq)
# # Zip up the final product
# In[27]:
N1904.zipAll()
# In[ ]: