#!/usr/bin/env python
# coding: utf-8
#
#
#
#
# ---
#
# To get started: consult [start](start.ipynb)
#
# ---
#
# # Rich display
#
# The apps of Text-Fabric know more about a corpus than vanilla TF.
# That knowledge is used by the apps to define pretty and plain displays of textual objects.
#
# A **plain** display of an object is a simple reference to that object if it is big, or the text of that object if it is small.
#
# A **pretty** display of an object is a representation of the structure of that object. It contains text and features of sub objects.
# Provided the object is not too big.
# In[1]:
get_ipython().run_line_magic('load_ext', 'autoreload')
get_ipython().run_line_magic('autoreload', '2')
# In[2]:
from tf.app import use
# In[3]:
A = use("q-ran/quran", hoist=globals())
# # Arbitrary nodes
# We pretty-print an arbitrary node.
# In[4]:
aya = F.otype.s("aya")[1000]
A.pretty(aya)
# Where is this phrase on Tanzil?
# You can click on the passage reference.
#
# You can generate this link as follows:
# In[5]:
A.webLink(aya)
# A link to another passage:
# In[6]:
z = A.nodeFromSectionStr("3:4")
# In[7]:
A.webLink(z)
# # Plain
#
# We can represent a node in plain representation and highlight specific portions.
# In[8]:
aya = F.otype.s("aya")[1000]
groups = L.d(aya, otype="group")
words = L.d(aya, otype="word")
# First we highlight some words:
# In[9]:
wordHighlights = set(words[i] for i in {1, 3, 5, 7, 9})
A.plain(aya, highlights=wordHighlights)
# Now some word groups:
# In[10]:
groupHighlights = set(groups[i] for i in {7, 12})
A.plain(aya, highlights=groupHighlights)
# As you see, when we highlight bigger things than words, we put a
# highlighted border around the words in those things.
# We can do both:
# In[11]:
highlights = set(wordHighlights) | set(groupHighlights)
A.plain(aya, highlights=highlights)
# We can also highlight the aya itself.
# In[12]:
highlights = {aya}
A.plain(aya, highlights=highlights)
# As you see, only the aya label is highlighted, not the contents.
# The same policy is followed for suras and other sectional units.
# In[13]:
juz = F.otype.s("juz")[20]
A.plain(juz, highlights={juz})
# In[14]:
ruku = F.otype.s("ruku")[20]
A.plain(ruku, highlights={ruku})
# But if we pass a condense type that is bigger than the condense type, we do not get the material of the section!
#
# Remember that we can see the types and their bigness as follows:
# In[15]:
C.levels.data
# So the `hizb` is bigger than the *page*.
#
# Let's print a plain *page* with condense type `hizb`:
# In[16]:
page = F.otype.s("page")[20]
A.plain(page, condenseType="hizb")
# We can use different colours for highlighting.
# Lets color even words differently from uneven words, and ayas in yet another color.
# In[17]:
highlights = {i: "lightsalmon" for i in words if i % 2 == 0}
highlights.update({i: "mediumaquamarine" for i in words if i % 2 == 1})
highlights.update({i: "blue" for i in groups if i % 5 == 1})
highlights[aya] = "#eeeeff"
A.plain(aya, highlights=highlights)
# # Ayas
#
# Now a couple of ayas:
# In[18]:
aya1 = A.nodeFromSectionStr("2:7")
aya2 = A.nodeFromSectionStr("3:17")
# In[19]:
A.pretty(aya2)
# The other aya with node numbers and standard features.
# In[20]:
A.pretty(aya1, withNodes=True, standardFeatures=True)
# Now we selectively remove a few features from the display:
# In[21]:
A.pretty(aya1, suppress={"posx", "tense"}, standardFeatures=True)
# Now we add features to the display:
# In[22]:
A.displaySetup(extraFeatures=["ps", "nu", "gn"])
# In[23]:
A.pretty(aya1)
# and we reset the pretty features to the default values:
# In[24]:
A.displayReset("extraFeatures")
# In[25]:
A.pretty(aya1)
# In[26]:
A.displaySetup(extraFeatures=["translation@en", "translation@nl"])
# In[27]:
A.pretty(aya1)
# # Translations in pretty display
#
# We can add the translation features `translation@ll` for `ll = en` or `nl` to the extra features for pretty display.
# Let's pretty display the first sura with both translations.
# In[28]:
sura1 = F.otype.s("sura")[0]
# In[29]:
A.pretty(sura1)
# That is a bit meagre. The reason is that the *sura* is a **big** type.
# In[30]:
A.pretty(sura1, full=True)
# ---
#
# All chapters:
#
# * **[start](start.ipynb)** introduction to computing with your corpus
# * **display** become an expert in creating pretty displays of your text structures
# * **[search](search.ipynb)** turbo charge your hand-coding with search templates
# * **[exportExcel](exportExcel.ipynb)** make tailor-made spreadsheets out of your results
# * **[share](share.ipynb)** draw in other people's data and let them use yours
# * **[similarAyas](similarAyas.ipynb)** spot the similarities between lines
# * **[rings](rings.ipynb)** ring structures in sura 2
#
# CC-BY Dirk Roorda