#!/usr/bin/env python
# coding: utf-8
# # Loading Text-Fabric (Nestle1904LFT)
#
# **Work in progress!**
# ## Table of content
# * 1 - Introduction
# * 1.1 - Text-Fabric data versions
# * 2 - Preparation / installation
# * 2.1 - Install Python
# * 2.2 - Install Text-Fabric
# * 2.3 - Raise rate limit on Github
# * 3 - Load Text-Fabric into memory
# * 3.1 - Load the code
# * 3.2 - Load the app and data
# * 4 - Add additional features
# * 4.1 - The official method
# * 4.2 - The unofficial method
# * 4.3 - Additional dataset
# * 4.4 - Further reference
# * 5 - Using multiple Text-Fabric corpora
# # 1 - Introduction
#
# Basic instructions on loading the Text-Fabric and start using it on your system. It will provide examples of the various ways you can invoke Text-Fabric.
# ### 1.1 - Text-Fabric data versions
#
# Some discussion related to versions
# ## 2 - Preparation / installation
# ##### [back to TOC](#TOC)
#
# The instructions in this section are only required once to be executed. This will result in the Text-Fabric code being available for loading into memory of your system.
# ### 2.1 - Install 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).
# ### 2.2 - Install Text-Fabric
#
# (if not yet installed)
#
# **TF itself**
#
# pip3 install text-fabric
#
# **When using Jupyter notebook**
#
# You can install Jupyter Notebook by command:
#
# pip3 install jupyter
#
# **When using Anaconda**
#
# A platform like [Anaconda](https://www.anaconda.com/products/distribution) allows for easy installation of Jupyter.
#
# It is advisable to define a new environment in Anaconda on which Text-Fabric can be installed [(documentation)](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html).
# ### 2.3 - 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#increase-the-rate-limit) 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.
# ## 3 - Load Text-Fabric into memory
# ##### [back to TOC](#TOC)
#
# The instructions in this section are required once to be executed each time you want to use Text_Fabric. It will load the Text-Fabric code and data into memory.
# ### 3.1 - Load the code
# ##### [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
# ### 3.2 - Load app and data
# ##### [back to TOC](#TOC)
#
# The following invocation of function [`use`](https://annotation.github.io/text-fabric/tf/about/usefunc.html) loads all features of the corpus (and extra modules, see section 4). It creates an variable (in this example `N1904LFT`) with its associated methods and function, the 'Advanced API'. In the 'cheat sheet' there are many references to `A.*something*`. In this notebook they should be read as `N1904LFT`.
# In[7]:
# load the app and data
N1904LFT = use ("tonyjurg/Nestle1904LFT", version="0.6", hoist=globals())
# In[5]:
# The following will push the Text-Fabric stylesheet to this notebook (to facilitate proper display with notebook viewer)
N1904LFT.dh(N1904LFT.getCss())
# # 4 - Add additional features
# ##### [back to TOC](#TOC)
#
#
# **The following is optional.**
#
# ## 4.1 - The official method
# ##### [back to TOC](#TOC)
#
# Still to be done: find good example
# In[7]:
# load the app and data with additional features
N1904LFT = use ("tonyjurg/Nestle1904LFT:latest", mod=f"annotation/banks/sim/tf" hoist=globals())
# ## 4.2 - The unofficial method
# ##### [back to TOC](#TOC)
#
# Warning: to use this method it is critical to verify that **ALL** the following match:
# * most importantly, the Text-Fabric dataset should be based upon the same corpus (in the most literal sense of the word!)
# * the node range(s) (check output of command `F.otype.all` or values found in file `otype.tf`).
# * the slot order (i.e. the order of the wordsin the Text-Fabric corpus; usualy refered to as monad).
#
# If these conditions are met, it is possible to copy the .tf files from the donor dataset to your local Text-Fabric directory..
# ## 4.3 - Additional dataset
# ##### [back to TOC](#TOC)
#
# Some additional dataset that should work with this Text-Fabric implementation are:
#
# Dataset location | additions
# --- | ---
# [CenterBLC](https://github.com/CenterBLC/NA/tree/main/tf/202201) | *additional grammatical features, Bible Online Learner details*
#
# ## 4.4 - Further reference
# ##### [back to TOC](#TOC)
# Further reference [module tf.about.datasharing](https://annotation.github.io/text-fabric/tf/about/datasharing.html)
# # 5 - Using multiple Text-Fabric corpora
# ##### [back to TOC](#TOC)
#
# When using multiple Text-Fabric corpora there are a few things to take care of.
# The most important are to invocate function [`use`](https://annotation.github.io/text-fabric/tf/about/usefunc.html) twice using a different variables (name) to create two Advanced API's. In the following example two `A` (Advanced API) objects are created named CORPUS1 and CORPUS2:
#
CORPUS1 = use ( ... )
CORPUS2 = use ( ... )
# **IMPORTANT:** When working with multiple corpora, do not add 'hoist=globals()' to the invocation!. See the comments on [section hoist of function use](https://annotation.github.io/text-fabric/tf/about/usefunc.html#hoisting).
#
# In order to access to the variables `F`, `L`, `T`, and `TF` for the relevant CORPUS dataset, you need to first issue `api = A.api` like in the following example. This example will create two lists containing the nodes for that corpus where feature `word` has value `λόγος`. See also [Hoisting](https://annotation.github.io/text-fabric/tf/about/usefunc.html#hoisting).
# We also need to add the app reference before we can access the F API functions
api=CORPUS1.api
LogosList1=api.F.word.s(λόγος)
api=CORPUS2.api
LogosList2=api.F.word.s(λόγος)