{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "\n", "\n", "You might want to consider the [start](search.ipynb) of this tutorial.\n", "\n", "Short introductions to other TF datasets:\n", "\n", "* [Dead Sea Scrolls](https://nbviewer.jupyter.org/github/annotation/tutorials/blob/master/lorentz2020/dss.ipynb),\n", "* [Old Babylonian Letters](https://nbviewer.jupyter.org/github/annotation/tutorials/blob/master/lorentz2020/oldbabylonian.ipynb),\n", "or the\n", "* [Quran](https://nbviewer.jupyter.org/github/annotation/tutorials/blob/master/lorentz2020/quran.ipynb)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Search Introduction\n", "\n", "*Search* in Text-Fabric is a template based way of looking for structural patterns in your dataset.\n", "\n", "It is inspired by the idea of\n", "[topographic query](http://books.google.nl/books?id=9ggOBRz1dO4C),\n", "as worked out in\n", "[MQL](https://github.com/ETCBC/shebanq/wiki/Documents/MQL-Query-Guide.pdf)\n", "which has been implemented in\n", "[Emdros](http://emdros.org).\n", "See also [pitfalls of MQL](https://etcbc.github.io/bhsa/mql#pitfalls-of-mql)\n", "\n", "Within Text-Fabric we have the unique possibility to combine the ease of formulating search templates for\n", "complicated syntactical patterns with the power of programmatically processing the results.\n", "\n", "This notebook will show you how to get up and running.\n", "\n", "See the notebook\n", "[search From MQL](searchFromMQL.ipynb)\n", "for examples how MQL queries can be expressed in Text-Fabric search.\n", "\n", "## Alternative for hand-coding\n", "\n", "Search is a powerful feature for a wide range of purposes.\n", "\n", "Quite a bit of the implementation work has been dedicated to optimize performance.\n", "Yet I do not pretend to have found optimal strategies for all\n", "possible search templates.\n", "Some search tasks may turn out to be somewhat costly or even very costly.\n", "\n", "That being said, I think search might turn out helpful in many cases,\n", "especially by reducing the amount of hand-coding needed to work with special subsets of your data.\n", "\n", "## Easy command\n", "\n", "Search is as simple as saying (just an example)\n", "\n", "```python\n", "results = A.search(template)\n", "A.show(results)\n", "```\n", "\n", "See all ins and outs in the\n", "[search template docs](https://annotation.github.io/text-fabric/tf/about/searchusage.html)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Incantation\n", "\n", "The ins and outs of installing Text-Fabric, getting the corpus, and initializing a notebook are\n", "explained in the [start tutorial](start.ipynb)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T10:06:39.818664Z", "start_time": "2018-05-24T10:06:39.796588Z" } }, "outputs": [], "source": [ "from tf.app import use" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T10:06:51.615044Z", "start_time": "2018-05-24T10:06:50.161456Z" } }, "outputs": [ { "data": { "text/markdown": [ "**Locating corpus resources ...**" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "app: ~/text-fabric-data/github/ETCBC/bhsa/app" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "data: ~/text-fabric-data/github/ETCBC/bhsa/tf/2021" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "data: ~/text-fabric-data/github/ETCBC/phono/tf/2021" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "data: ~/text-fabric-data/github/ETCBC/parallels/tf/2021" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " TF: TF API 12.2.1, ETCBC/bhsa/app v3, Search Reference
\n", " Data: ETCBC - bhsa 2021, Character table, Feature docs
\n", "
Node types\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", "\n", "
Name# of nodes# slots / node% coverage
book3910938.21100
chapter929459.19100
lex923046.22100
verse2321318.38100
half_verse451799.44100
sentence637176.70100
sentence_atom645146.61100
clause881314.84100
clause_atom907044.70100
phrase2532031.68100
phrase_atom2675321.59100
subphrase1138501.4238
word4265901.00100
\n", " Sets: no custom sets
\n", " Features:
\n", "
Parallel Passages\n", "
\n", "\n", "
\n", "
\n", "crossref\n", "
\n", "
int
\n", "\n", " 🆗 links between similar passages\n", "\n", "
\n", "\n", "
\n", "
\n", "\n", "
BHSA = Biblia Hebraica Stuttgartensia Amstelodamensis\n", "
\n", "\n", "
\n", "
\n", "book\n", "
\n", "
str
\n", "\n", " ✅ book name in Latin (Genesis; Numeri; Reges1; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "book@ll\n", "
\n", "
str
\n", "\n", " ✅ book name in amharic (ኣማርኛ)\n", "\n", "
\n", "\n", "
\n", "
\n", "chapter\n", "
\n", "
int
\n", "\n", " ✅ chapter number (1; 2; 3; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "code\n", "
\n", "
int
\n", "\n", " ✅ identifier of a clause atom relationship (0; 74; 367; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "det\n", "
\n", "
str
\n", "\n", " ✅ determinedness of phrase(atom) (det; und; NA.)\n", "\n", "
\n", "\n", "
\n", "
\n", "domain\n", "
\n", "
str
\n", "\n", " ✅ text type of clause (? (Unknown); N (narrative); D (discursive); Q (Quotation).)\n", "\n", "
\n", "\n", "
\n", "
\n", "freq_lex\n", "
\n", "
int
\n", "\n", " ✅ frequency of lexemes\n", "\n", "
\n", "\n", "
\n", "
\n", "function\n", "
\n", "
str
\n", "\n", " ✅ syntactic function of phrase (Cmpl; Objc; Pred; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "g_cons\n", "
\n", "
str
\n", "\n", " ✅ word consonantal-transliterated (B R>CJT BR> >LHJM ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "g_cons_utf8\n", "
\n", "
str
\n", "\n", " ✅ word consonantal-Hebrew (ב ראשׁית ברא אלהים)\n", "\n", "
\n", "\n", "
\n", "
\n", "g_lex\n", "
\n", "
str
\n", "\n", " ✅ lexeme pointed-transliterated (B.:- R;>CIJT B.@R@> >:ELOH ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "g_lex_utf8\n", "
\n", "
str
\n", "\n", " ✅ lexeme pointed-Hebrew (בְּ רֵאשִׁית בָּרָא אֱלֹה)\n", "\n", "
\n", "\n", "
\n", "
\n", "g_word\n", "
\n", "
str
\n", "\n", " ✅ word pointed-transliterated (B.:- R;>CI73JT B.@R@74> >:ELOHI92JM)\n", "\n", "
\n", "\n", "
\n", "
\n", "g_word_utf8\n", "
\n", "
str
\n", "\n", " ✅ word pointed-Hebrew (בְּ רֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים)\n", "\n", "
\n", "\n", "
\n", "
\n", "gloss\n", "
\n", "
str
\n", "\n", " 🆗 english translation of lexeme (beginning create god(s))\n", "\n", "
\n", "\n", "
\n", "
\n", "gn\n", "
\n", "
str
\n", "\n", " ✅ grammatical gender (m; f; NA; unknown.)\n", "\n", "
\n", "\n", "
\n", "
\n", "label\n", "
\n", "
str
\n", "\n", " ✅ (half-)verse label (half verses: A; B; C; verses: GEN 01,02)\n", "\n", "
\n", "\n", "
\n", "
\n", "language\n", "
\n", "
str
\n", "\n", " ✅ of word or lexeme (Hebrew; Aramaic.)\n", "\n", "
\n", "\n", "
\n", "
\n", "lex\n", "
\n", "
str
\n", "\n", " ✅ lexeme consonantal-transliterated (B R>CJT/ BR>[ >LHJM/)\n", "\n", "
\n", "\n", "
\n", "
\n", "lex_utf8\n", "
\n", "
str
\n", "\n", " ✅ lexeme consonantal-Hebrew (ב ראשׁית֜ ברא אלהים֜)\n", "\n", "
\n", "\n", "
\n", "
\n", "ls\n", "
\n", "
str
\n", "\n", " ✅ lexical set, subclassification of part-of-speech (card; ques; mult)\n", "\n", "
\n", "\n", "
\n", "
\n", "nametype\n", "
\n", "
str
\n", "\n", " ⚠️ named entity type (pers; mens; gens; topo; ppde.)\n", "\n", "
\n", "\n", "
\n", "
\n", "nme\n", "
\n", "
str
\n", "\n", " ✅ nominal ending consonantal-transliterated (absent; n/a; JM, ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "nu\n", "
\n", "
str
\n", "\n", " ✅ grammatical number (sg; du; pl; NA; unknown.)\n", "\n", "
\n", "\n", "
\n", "
\n", "number\n", "
\n", "
int
\n", "\n", " ✅ sequence number of an object within its context\n", "\n", "
\n", "\n", "
\n", "
\n", "otype\n", "
\n", "
str
\n", "\n", " \n", "\n", "
\n", "\n", "
\n", "
\n", "pargr\n", "
\n", "
str
\n", "\n", " 🆗 hierarchical paragraph number (1; 1.2; 1.2.3.4; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "pdp\n", "
\n", "
str
\n", "\n", " ✅ phrase dependent part-of-speech (art; verb; subs; nmpr, ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "pfm\n", "
\n", "
str
\n", "\n", " ✅ preformative consonantal-transliterated (absent; n/a; J, ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "prs\n", "
\n", "
str
\n", "\n", " ✅ pronominal suffix consonantal-transliterated (absent; n/a; W; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "prs_gn\n", "
\n", "
str
\n", "\n", " ✅ pronominal suffix gender (m; f; NA; unknown.)\n", "\n", "
\n", "\n", "
\n", "
\n", "prs_nu\n", "
\n", "
str
\n", "\n", " ✅ pronominal suffix number (sg; du; pl; NA; unknown.)\n", "\n", "
\n", "\n", "
\n", "
\n", "prs_ps\n", "
\n", "
str
\n", "\n", " ✅ pronominal suffix person (p1; p2; p3; NA; unknown.)\n", "\n", "
\n", "\n", "
\n", "
\n", "ps\n", "
\n", "
str
\n", "\n", " ✅ grammatical person (p1; p2; p3; NA; unknown.)\n", "\n", "
\n", "\n", "
\n", "
\n", "qere\n", "
\n", "
str
\n", "\n", " ✅ word pointed-transliterated masoretic reading correction\n", "\n", "
\n", "\n", "
\n", "
\n", "qere_trailer\n", "
\n", "
str
\n", "\n", " ✅ interword material -pointed-transliterated (Masoretic correction)\n", "\n", "
\n", "\n", "
\n", "
\n", "qere_trailer_utf8\n", "
\n", "
str
\n", "\n", " ✅ interword material -pointed-transliterated (Masoretic correction)\n", "\n", "
\n", "\n", "
\n", "
\n", "qere_utf8\n", "
\n", "
str
\n", "\n", " ✅ word pointed-Hebrew masoretic reading correction\n", "\n", "
\n", "\n", "
\n", "
\n", "rank_lex\n", "
\n", "
int
\n", "\n", " ✅ ranking of lexemes based on freqnuecy\n", "\n", "
\n", "\n", "
\n", "
\n", "rela\n", "
\n", "
str
\n", "\n", " ✅ linguistic relation between clause/(sub)phrase(atom) (ADJ; MOD; ATR; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "sp\n", "
\n", "
str
\n", "\n", " ✅ part-of-speech (art; verb; subs; nmpr, ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "st\n", "
\n", "
str
\n", "\n", " ✅ state of a noun (a (absolute); c (construct); e (emphatic).)\n", "\n", "
\n", "\n", "
\n", "
\n", "tab\n", "
\n", "
int
\n", "\n", " ✅ clause atom: its level in the linguistic embedding\n", "\n", "
\n", "\n", "
\n", "
\n", "trailer\n", "
\n", "
str
\n", "\n", " ✅ interword material pointed-transliterated (& 00 05 00_P ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "trailer_utf8\n", "
\n", "
str
\n", "\n", " ✅ interword material pointed-Hebrew (־ ׃)\n", "\n", "
\n", "\n", "
\n", "
\n", "txt\n", "
\n", "
str
\n", "\n", " ✅ text type of clause and surrounding (repetion of ? N D Q as in feature domain)\n", "\n", "
\n", "\n", "
\n", "
\n", "typ\n", "
\n", "
str
\n", "\n", " ✅ clause/phrase(atom) type (VP; NP; Ellp; Ptcp; WayX)\n", "\n", "
\n", "\n", "
\n", "
\n", "uvf\n", "
\n", "
str
\n", "\n", " ✅ univalent final consonant consonantal-transliterated (absent; N; J; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "vbe\n", "
\n", "
str
\n", "\n", " ✅ verbal ending consonantal-transliterated (n/a; W; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "vbs\n", "
\n", "
str
\n", "\n", " ✅ root formation consonantal-transliterated (absent; n/a; H; ...)\n", "\n", "
\n", "\n", "
\n", "
\n", "verse\n", "
\n", "
int
\n", "\n", " ✅ verse number\n", "\n", "
\n", "\n", "
\n", "
\n", "voc_lex\n", "
\n", "
str
\n", "\n", " ✅ vocalized lexeme pointed-transliterated (B.: R;>CIJT BR> >:ELOHIJM)\n", "\n", "
\n", "\n", "
\n", "
\n", "voc_lex_utf8\n", "
\n", "
str
\n", "\n", " ✅ vocalized lexeme pointed-Hebrew (בְּ רֵאשִׁית ברא אֱלֹהִים)\n", "\n", "
\n", "\n", "
\n", "
\n", "vs\n", "
\n", "
str
\n", "\n", " ✅ verbal stem (qal; piel; hif; apel; pael)\n", "\n", "
\n", "\n", "
\n", "
\n", "vt\n", "
\n", "
str
\n", "\n", " ✅ verbal tense (perf; impv; wayq; infc)\n", "\n", "
\n", "\n", "
\n", "
\n", "mother\n", "
\n", "
none
\n", "\n", " ✅ linguistic dependency between textual objects\n", "\n", "
\n", "\n", "
\n", "
\n", "oslots\n", "
\n", "
none
\n", "\n", " \n", "\n", "
\n", "\n", "
\n", "
\n", "\n", "
Phonetic Transcriptions\n", "
\n", "\n", "
\n", "
\n", "phono\n", "
\n", "
str
\n", "\n", " 🆗 phonological transcription (bᵊ rēšˌîṯ bārˈā ʔᵉlōhˈîm)\n", "\n", "
\n", "\n", "
\n", "
\n", "phono_trailer\n", "
\n", "
str
\n", "\n", " 🆗 interword material in phonological transcription\n", "\n", "
\n", "\n", "
\n", "
\n", "\n", " Settings:
specified
  1. apiVersion: 3
  2. appName: ETCBC/bhsa
  3. appPath: /Users/me/text-fabric-data/github/ETCBC/bhsa/app
  4. commit: gb112c161cfd21eae403d51a2733740d8743460e7
  5. css: ''
  6. dataDisplay:
    • exampleSectionHtml:<code>Genesis 1:1</code> (use <a href=\"https://github.com/{org}/{repo}/blob/master/tf/{version}/book%40en.tf\" target=\"_blank\">English book names</a>)
    • excludedFeatures:
      • g_uvf_utf8
      • g_vbs
      • kq_hybrid
      • languageISO
      • g_nme
      • lex0
      • is_root
      • g_vbs_utf8
      • g_uvf
      • dist
      • root
      • suffix_person
      • g_vbe
      • dist_unit
      • suffix_number
      • distributional_parent
      • kq_hybrid_utf8
      • crossrefSET
      • instruction
      • g_prs
      • lexeme_count
      • rank_occ
      • g_pfm_utf8
      • freq_occ
      • crossrefLCS
      • functional_parent
      • g_pfm
      • g_nme_utf8
      • g_vbe_utf8
      • kind
      • g_prs_utf8
      • suffix_gender
      • mother_object_type
    • noneValues:
      • absent
      • n/a
      • none
      • unknown
      • no value
      • NA
  7. docs:
    • docBase: {docRoot}/{repo}
    • docExt: ''
    • docPage: ''
    • docRoot: https://{org}.github.io
    • featurePage: 0_home
  8. interfaceDefaults: {}
  9. isCompatible: True
  10. local: local
  11. localDir: /Users/me/text-fabric-data/github/ETCBC/bhsa/_temp
  12. provenanceSpec:
    • corpus: BHSA = Biblia Hebraica Stuttgartensia Amstelodamensis
    • doi: 10.5281/zenodo.1007624
    • extraData: ner
    • moduleSpecs:
      • :
        • backend: no value
        • corpus: Phonetic Transcriptions
        • docUrl:https://nbviewer.jupyter.org/github/etcbc/phono/blob/master/programs/phono.ipynb
        • doi: 10.5281/zenodo.1007636
        • org: ETCBC
        • relative: /tf
        • repo: phono
      • :
        • backend: no value
        • corpus: Parallel Passages
        • docUrl:https://nbviewer.jupyter.org/github/ETCBC/parallels/blob/master/programs/parallels.ipynb
        • doi: 10.5281/zenodo.1007642
        • org: ETCBC
        • relative: /tf
        • repo: parallels
    • org: ETCBC
    • relative: /tf
    • repo: bhsa
    • version: 2021
    • webBase: https://shebanq.ancient-data.org/hebrew
    • webHint: Show this on SHEBANQ
    • webLang: la
    • webLexId: True
    • webUrl:{webBase}/text?book=<1>&chapter=<2>&verse=<3>&version={version}&mr=m&qw=q&tp=txt_p&tr=hb&wget=v&qget=v&nget=vt
    • webUrlLex: {webBase}/word?version={version}&id=<lid>
  13. release: v1.8.1
  14. typeDisplay:
    • clause:
      • label: {typ} {rela}
      • style: ''
    • clause_atom:
      • hidden: True
      • label: {code}
      • level: 1
      • style: ''
    • half_verse:
      • hidden: True
      • label: {label}
      • style: ''
      • verselike: True
    • lex:
      • featuresBare: gloss
      • label: {voc_lex_utf8}
      • lexOcc: word
      • style: orig
      • template: {voc_lex_utf8}
    • phrase:
      • label: {typ} {function}
      • style: ''
    • phrase_atom:
      • hidden: True
      • label: {typ} {rela}
      • level: 1
      • style: ''
    • sentence:
      • label: {number}
      • style: ''
    • sentence_atom:
      • hidden: True
      • label: {number}
      • level: 1
      • style: ''
    • subphrase:
      • hidden: True
      • label: {number}
      • style: ''
    • word:
      • features: pdp vs vt
      • featuresBare: lex:gloss
  15. writing: hbo
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
TF API: names N F E L T S C TF Fs Fall Es Eall Cs Call directly usable

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A = use('ETCBC/bhsa', hoist=globals())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Basic search command\n", "\n", "We start with the most simple form of issuing a query.\n", "Let's look for the proper nouns in 1 Samuel.\n", "We also want to show the clauses in which they occur.\n", "\n", "All work involved in searching takes place under the hood." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:46:55.998382Z", "start_time": "2018-05-24T07:46:55.137956Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.21s 1868 results\n" ] } ], "source": [ "query = \"\"\"\n", "book book=Samuel_I\n", " clause\n", " word sp=nmpr\n", "\"\"\"\n", "results = A.search(query)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have the results. We only need to display them. Here are the first few in a table:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:46:55.998382Z", "start_time": "2018-05-24T07:46:55.137956Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
npbookclauseword
11_Samuel 1:11_Samuelוַיְהִי֩ אִ֨ישׁ אֶחָ֜ד מִן־הָרָמָתַ֛יִם צֹופִ֖ים מֵהַ֣ר אֶפְרָ֑יִם אֶפְרָ֑יִם
21_Samuel 1:11_Samuelוּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃ אֶ֠לְקָנָה
31_Samuel 1:11_Samuelוּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃ יְרֹחָ֧ם
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.table(results, end=3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The hyperlinks in the `p` column point to SHEBANQ, to the verse most relevant to the individual results.\n", "\n", "The columns with the book is not very informative. We can leave it out.\n", "You can leave columns out by passing `skipCols=xxx` where `xxx` is a set of numbers, which may also be passed as\n", "a space-separated string of numbers.\n", "\n", "Note that the book column is the first column (starting after the `p` column, counting starts at 1)." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:46:55.998382Z", "start_time": "2018-05-24T07:46:55.137956Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
npbookclauseword
11_Samuel 1:1וַיְהִי֩ אִ֨ישׁ אֶחָ֜ד מִן־הָרָמָתַ֛יִם צֹופִ֖ים מֵהַ֣ר אֶפְרָ֑יִם אֶפְרָ֑יִם
21_Samuel 1:1וּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃ אֶ֠לְקָנָה
31_Samuel 1:1וּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃ יְרֹחָ֧ם
41_Samuel 1:1וּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃ אֱלִיה֛וּא
51_Samuel 1:1וּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃ תֹּ֥חוּ
61_Samuel 1:1וּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃ צ֖וּף
71_Samuel 1:2שֵׁ֤ם אַחַת֙ חַנָּ֔ה חַנָּ֔ה
81_Samuel 1:2וְשֵׁ֥ם הַשֵּׁנִ֖ית פְּנִנָּ֑ה פְּנִנָּ֑ה
91_Samuel 1:2לִפְנִנָּה֙ יְלָדִ֔ים פְנִנָּה֙
101_Samuel 1:2וּלְחַנָּ֖ה אֵ֥ין יְלָדִֽים׃ חַנָּ֖ה
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.table(results, end=10, skipCols=\"1\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is the first one in a pretty display:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book 1_Samuel
book=Samuel_I
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Samuel_I
sentence 1
clause WayX NA
phrase CP Conj
sp=conj
phrase VP Pred
phrase NP Subj
sentence 2
clause NmCl NA
phrase CP Conj
sp=conj
phrase NP Subj
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, end=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to do some more work where we want to skip column 1, so we make that the temporary default:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "A.displaySetup(skipCols=\"1\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we show a few results without the book column:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book 1_Samuel
book=Samuel_I
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Samuel_I
sentence 1
clause WayX NA
phrase CP Conj
sp=conj
phrase VP Pred
phrase NP Subj
sentence 2
clause NmCl NA
phrase CP Conj
sp=conj
phrase NP Subj
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 2" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book 1_Samuel
book=Samuel_I
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Samuel_I
sentence 1
clause WayX NA
phrase CP Conj
sp=conj
phrase VP Pred
phrase NP Subj
sentence 2
clause NmCl NA
phrase CP Conj
sp=conj
phrase NP Subj
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, end=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or, stopping at the clause level:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book 1_Samuel
book=Samuel_I
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Samuel_I
sentence 1
clause וַיְהִי֩ אִ֨ישׁ אֶחָ֜ד מִן־הָרָמָתַ֛יִם צֹופִ֖ים מֵהַ֣ר אֶפְרָ֑יִם
sentence 2
clause וּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 2" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book 1_Samuel
book=Samuel_I
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Samuel_I
sentence 1
clause וַיְהִי֩ אִ֨ישׁ אֶחָ֜ד מִן־הָרָמָתַ֛יִם צֹופִ֖ים מֵהַ֣ר אֶפְרָ֑יִם
sentence 2
clause וּשְׁמֹ֡ו אֶ֠לְקָנָה בֶּן־יְרֹחָ֧ם בֶּן־אֱלִיה֛וּא בֶּן־תֹּ֥חוּ בֶן־צ֖וּף אֶפְרָתִֽי׃
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, end=2, baseTypes={\"clause\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can view result in phonetic representation as well:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
npbookclauseword
11_Samuel 1:1wayᵊhˌî ʔˌîš ʔeḥˈāḏ min-rāmāṯˈayim ṣôfˌîm hˈar ʔefrˈāyim ʔefrˈāyim
21_Samuel 1:1ûšᵊmˈô ʔelqānˌā ben-yᵊrōḥˈām ben-ʔᵉlîhˈû ben-tˌōḥû ven-ṣˌûf ʔefrāṯˈî . ʔelqānˌā
31_Samuel 1:1ûšᵊmˈô ʔelqānˌā ben-yᵊrōḥˈām ben-ʔᵉlîhˈû ben-tˌōḥû ven-ṣˌûf ʔefrāṯˈî . yᵊrōḥˈām
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.table(results, end=3, fmt=\"text-phono-full\")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:06.875859Z", "start_time": "2018-05-24T07:47:06.757345Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book 1_Samuel
book=Samuel_I
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Samuel_I
sentence 1
clause WayX NA
phrase CP Conj
sp=conj
phrase VP Pred
sp=verb
phrase NP Subj
sp=subs
sp=prep
sp=art
sp=prep
sp=subs
sentence 2
clause NmCl NA
phrase CP Conj
sp=conj
phrase NP Subj
phrase PrNP PreC
sp=subs
sp=subs
sp=subs
sp=subs
sp=nmpr
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, end=1, fmt=\"text-phono-full\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are done with this query and its results. We reset the `skipCols` parameter." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "A.displayReset(\"skipCols\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Condense results\n", "\n", "There are two fundamentally different ways of presenting the results: condensed and uncondensed.\n", "\n", "In **uncondensed** view, all results are listed individually.\n", "You can keep track of which parts belong to which results.\n", "The display can become unwieldy.\n", "\n", "This is the default view, because it is the straightest, most logical, answer to your query.\n", "\n", "In **condensed** view all nodes of all results are grouped in containers first (e.g. verses), and then presented\n", "container by container.\n", "You loose the information of what parts belong to what result.\n", "\n", "Here is an example of the difference." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:14.547656Z", "start_time": "2018-05-24T07:47:14.544433Z" } }, "outputs": [], "source": [ "query = \"\"\"\n", "book book=Genesis\n", " chapter chapter=1\n", " verse verse=1\n", " sentence\n", "% order is not important!\n", " word nu=sg\n", " word nu=pl\n", "\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that you can have comments in a search template. Comment lines start with a `%`." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:18.913432Z", "start_time": "2018-05-24T07:47:17.357992Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.45s 6 results\n" ] } ], "source": [ "results = A.search(query)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The book, chapter, verse columns are completely uninformative, so:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "A.displaySetup(skipCols=\"1 2 3\")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:18.913432Z", "start_time": "2018-05-24T07:47:17.357992Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "
npbookchapterversesentencewordword
1Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ רֵאשִׁ֖ית אֱלֹהִ֑ים
2Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ רֵאשִׁ֖ית שָּׁמַ֖יִם
3Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ בָּרָ֣א אֱלֹהִ֑ים
4Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ בָּרָ֣א שָּׁמַ֖יִם
5Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ אָֽרֶץ׃ אֱלֹהִ֑ים
6Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ אָֽרֶץ׃ שָּׁמַ֖יִם
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.table(results, withPassage=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are two plural and three singular words in Genesis 1:1.\n", "Search templates do not specify order, so all six combinations qualify as results.\n", "\n", "Let's expand the results display:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:21.573937Z", "start_time": "2018-05-24T07:47:21.561079Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 2" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 4" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 5" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 6" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you see, the results are listed per result tuple, even if they occur all in the same verse.\n", "This way you can keep track of what exactly belongs to each result.\n", "\n", "Now in condensed mode:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:21.573937Z", "start_time": "2018-05-24T07:47:21.561079Z" } }, "outputs": [ { "data": { "text/html": [ "

verse 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, condensed=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we have all words of all results in one display. But we cannot see that each results has two words, let alone which ones." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Custom highlighting\n", "\n", "Note that we can apply different highlight colours to different parts of the result.\n", "The words in the pair are member 5 and 6 of the result tuples.\n", "The members that we do not map, will not be highlighted.\n", "The members that we map to the empty string will be highlighted with the default color.\n", "\n", "**NB:** Choose your colours from the\n", "[CSS specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value)." ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:25.094797Z", "start_time": "2018-05-24T07:47:25.048277Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 2" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 4" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 5" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 6" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, condensed=False, colorMap={4: \"\", 5: \"cyan\", 6: \"magenta\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Color mapping works best for uncondensed results. If you condense results, some nodes may occupy\n", "different positions in different results. It is unpredictable which color will be used\n", "for such nodes:" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:35.832254Z", "start_time": "2018-05-24T07:47:35.821001Z" } }, "outputs": [ { "data": { "text/html": [ "

verse 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, condensed=True, colorMap={4: \"\", 5: \"cyan\", 6: \"magenta\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can specify to what container you want to condense. By default, everything is condensed to verses.\n", "\n", "Let's change that to phrases:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
sentence 1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
phrase PP Time
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
phrase NP Subj
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 2" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
sentence 1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
phrase PP Time
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
sentence 1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
phrase VP Pred
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
phrase NP Subj
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 4" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
sentence 1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
phrase VP Pred
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 5" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
sentence 1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
phrase NP Subj
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 6" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
sentence 1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(\n", " results,\n", " condensed=False,\n", " condenseType=\"phrase\",\n", " colorMap={4: \"\", 5: \"cyan\", 6: \"magenta\"},\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Constraining order\n", "You can stipulate an order on the words in your template.\n", "You only have to put a relational operator between them.\n", "Say we want only results where the plural follows the singular." ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:47:59.832291Z", "start_time": "2018-05-24T07:47:59.827343Z" } }, "outputs": [], "source": [ "query = \"\"\"\n", "book book=Genesis\n", " chapter chapter=1\n", " verse verse=1\n", " sentence\n", " word nu=sg\n", " < word nu=pl\n", "\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we keep the `skipCols=\"1 2 3\"` display setting in force, since it is relevant for this query as well." ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:48:04.746084Z", "start_time": "2018-05-24T07:48:03.223548Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.44s 4 results\n" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
npbookchapterversesentencewordword
1Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ רֵאשִׁ֖ית אֱלֹהִ֑ים
2Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ רֵאשִׁ֖ית שָּׁמַ֖יִם
3Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ בָּרָ֣א אֱלֹהִ֑ים
4Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ בָּרָ֣א שָּׁמַ֖יִם
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results = A.search(query)\n", "A.table(results)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also require the words to be adjacent." ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:49:20.315639Z", "start_time": "2018-05-24T07:49:20.311979Z" } }, "outputs": [], "source": [ "query = \"\"\"\n", "book book=Genesis\n", " chapter chapter=1\n", " verse verse=1\n", " sentence\n", " word nu=sg\n", " <: word nu=pl\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:49:25.158646Z", "start_time": "2018-05-24T07:49:23.718047Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.41s 1 result\n" ] }, { "data": { "text/html": [ "\n", "
npbookchapterversesentencewordword
1Genesis 1:1בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃ בָּרָ֣א אֱלֹהִ֑ים
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "results = A.search(query)\n", "colorMap = {5: \"lightsalmon\", 6: \"mediumaquamarine\"}\n", "A.table(results, colorMap=colorMap)\n", "A.show(results, condensed=False, colorMap=colorMap)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Custom feature display\n", "\n", "We would like to see the gender, number and person for words.\n", "The way to do that, is to perform a `A.displaySetup(...)` first." ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:49:51.867815Z", "start_time": "2018-05-24T07:49:51.864197Z" } }, "outputs": [], "source": [ "A.displaySetup(\n", " extraFeatures=\"ps gn nu\", colorMap={2: \"lightsalmon\", 3: \"mediumaquamarine\"}\n", ")" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:49:53.189127Z", "start_time": "2018-05-24T07:49:53.176377Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
phrase PP Time
phrase VP Pred
gn=mnu=sgps=p3
phrase NP Subj
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, condensed=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The features without meaningful values have been left out. We can also change that by passing a set of values\n", "we think are not meaningful. The default set is\n", "\n", "```python\n", "{None, 'NA', 'none', 'unknown'}\n", "```" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:49:56.593302Z", "start_time": "2018-05-24T07:49:56.579038Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesischapter=gn=nu=ps=verse=
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1gn=nu=ps=verse=
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1gn=nu=ps=verse=1
sentence 1
book=chapter=gn=nu=ps=verse=
clause xQtX NA
book=chapter=gn=nu=ps=verse=
phrase PP Time
book=chapter=gn=nu=ps=verse=
book=chapter=gn=NAnu=NAps=NAverse=
book=chapter=gn=fnu=sgps=NAverse=
phrase VP Pred
book=chapter=gn=nu=ps=verse=
book=chapter=gn=mnu=sgps=p3verse=
phrase NP Subj
book=chapter=gn=nu=ps=verse=
book=chapter=gn=mnu=plps=NAverse=
phrase PP Objc
book=chapter=gn=nu=ps=verse=
book=chapter=gn=NAnu=NAps=NAverse=
book=chapter=gn=NAnu=NAps=NAverse=
book=chapter=gn=mnu=plps=NAverse=
book=chapter=gn=NAnu=NAps=NAverse=
book=chapter=gn=NAnu=NAps=NAverse=
book=chapter=gn=NAnu=NAps=NAverse=
book=chapter=gn=unknownnu=sgps=NAverse=
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.displaySetup(noneValues=set())\n", "A.show(results, condensed=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This makes clear that it is convenient to keep `None` in the `noneValues`:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:50:03.094084Z", "start_time": "2018-05-24T07:50:03.080237Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
phrase PP Time
gn=NAnu=NAps=NA
gn=fnu=sgps=NA
phrase VP Pred
gn=mnu=sgps=p3
phrase NP Subj
gn=mnu=plps=NA
phrase PP Objc
gn=NAnu=NAps=NA
gn=NAnu=NAps=NA
gn=mnu=plps=NA
gn=NAnu=NAps=NA
gn=NAnu=NAps=NA
gn=NAnu=NAps=NA
gn=unknownnu=sgps=NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.displaySetup(noneValues={None})\n", "A.show(results, condensed=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can even choose to suppress other values, e.g. the male gender values and the singular number values." ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:50:08.244221Z", "start_time": "2018-05-24T07:50:08.232311Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
clause xQtX NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.displaySetup(noneValues={None, \"NA\", \"unknown\", \"none\", \"m\", \"sg\"})\n", "A.show(results, condensed=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the rest of the notebook we stick to our normal setup, so we reset the extra features." ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:50:18.030145Z", "start_time": "2018-05-24T07:50:18.019245Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

book Genesis
book=Genesis
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
chapter Genesis 1
book=Genesischapter=1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
verse
book=Genesischapter=1verse=1
sentence 1
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.displayReset(\"extraFeatures\")\n", "A.show(results, condensed=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we completely reset the display customization." ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "A.displayReset()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Only display selected query features\n", "\n", "Sometimes you want to show only some query features, but not all.\n", "\n", "For example, after this query ..." ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.20s 5992 results\n" ] } ], "source": [ "results = A.search(\"\"\"\n", "word gn=f nu=pl sp=subs\n", "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "you want to show the `nu` feature, but not the `gn` and `sp` features:" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

clause WQt0 NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, end=1, condenseType=\"clause\", queryFeatures=False, extraFeatures=\"nu\") " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An other way to achieve this is by means of `tupleFeatures`.\n", "Before we do that, let's examine the value of `tupleFeatures` in the current display setup:" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "tupleFeatures = ((0, ('gn', 'nu', 'sp')),)\n" ] } ], "source": [ "A.displaySetup(\"tupleFeatures\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ah, here are the features stored in the last query." ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

clause WQt0 NA
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(results, end=1, condenseType=\"clause\", tupleFeatures=\"nu\") " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Show your own tuples\n", "\n", "So far we have show the results of searches with `show()`.\n", "But you can also construct your own tuples and show them.\n", "\n", "Whereas you can use search to get a pretty good approximation of what you want, most of the times\n", "you do not arrive precisely at your destination.\n", "\n", "Here is an example where we use search to come close, and then work our way to produce the end result.\n", "\n", "## Disagreement in number\n", "\n", "We look for clauses with a one-word subject that does not agree in number with its predicate.\n", "\n", "In our search templates we cannot formulate that a feature has different values on two nodes in the template.\n", "We could spell out all possible combinations of values and make a search template for each of them,\n", "but that is needlessly complex.\n", "\n", "Let's first use search to find all clauses containing a one word subject and a predicate.\n", "And, to narrow down it further, we require that the word in the subject and the verb in the predicate are\n", "marked for number.\n", "\n", "(You may want to consult the feature docs, see the link at the start of the notebook, where `Bhsa()` is called).\n", "\n", "Note that the order of the phrases does not matter." ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:51:05.187418Z", "start_time": "2018-05-24T07:51:02.450365Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.83s 10638 results\n" ] } ], "source": [ "query = \"\"\"\n", "clause\n", " phrase function=Subj\n", " =: word nu=sg|pl\n", " :=\n", " phrase function=Pred|PreO\n", " word sp=verb\n", " nu=sg|pl\n", "\"\"\"\n", "results = A.search(query)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now the hand coding begins. We are going to extract the tuples we want." ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:51:06.901462Z", "start_time": "2018-05-24T07:51:06.878281Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "467 filtered results\n" ] } ], "source": [ "wantedResults = tuple(\n", " (subj, pred)\n", " for (clause, phraseS, subj, phraseV, pred) in results\n", " if F.nu.v(subj) != F.nu.v(pred)\n", ")\n", "print(f\"{len(wantedResults)} filtered results\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And now we can show them:" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((4, 3), (34, 33), (42, 41), (50, 49))" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wantedResults[0:4]" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
npwordword
1Genesis 1:1אֱלֹהִ֑ים בָּרָ֣א
2Genesis 1:3אֱלֹהִ֖ים יֹּ֥אמֶר
3Genesis 1:4אֱלֹהִ֛ים יַּ֧רְא
4Genesis 1:4אֱלֹהִ֔ים יַּבְדֵּ֣ל
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.table(\n", " wantedResults, start=1, end=4, colorMap={1: \"lightsalmon\", 2: \"mediumaquamarine\"}\n", ")" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:51:11.465916Z", "start_time": "2018-05-24T07:51:11.423636Z" } }, "outputs": [ { "data": { "text/html": [ "

result 1" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

verse
sentence 1
clause xQtX NA
phrase PP Time
function=Time
sp=prep
phrase VP Pred
function=Pred
nu=sgsp=verb
phrase NP Subj
function=Subj
phrase PP Objc
function=Objc
sp=prep
sp=art
sp=conj
sp=prep
sp=art
nu=sgsp=subs
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 2" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

verse
sentence 5
clause WayX NA
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
nu=sgsp=verb
phrase NP Subj
function=Subj
sentence 6
clause ZYqX NA
phrase VP Pred
function=Pred
nu=sgsp=verb
phrase NP Subj
function=Subj
nu=sgsp=subs
sentence 7
clause WayX NA
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
nu=sgsp=verb
phrase NP Subj
function=Subj
nu=sgsp=subs
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

verse
sentence 8
clause WayX NA
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
nu=sgsp=verb
phrase NP Subj
function=Subj
phrase PP Objc
function=Objc
sp=prep
sp=art
nu=sgsp=subs
clause xQt0 Objc
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
nu=sgsp=verb
sentence 9
clause WayX NA
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
phrase NP Subj
function=Subj
phrase PP Cmpl
function=Cmpl
nu=sgsp=subs
sp=art
nu=sgsp=subs
sp=conj
nu=sgsp=subs
sp=art
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

result 4" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

verse
sentence 8
clause WayX NA
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
nu=sgsp=verb
phrase NP Subj
function=Subj
phrase PP Objc
function=Objc
sp=prep
sp=art
nu=sgsp=subs
clause xQt0 Objc
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
nu=sgsp=verb
sentence 9
clause WayX NA
phrase CP Conj
function=Conj
sp=conj
phrase VP Pred
function=Pred
phrase NP Subj
function=Subj
phrase PP Cmpl
function=Cmpl
nu=sgsp=subs
sp=art
nu=sgsp=subs
sp=conj
nu=sgsp=subs
sp=art
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(\n", " wantedResults, start=1, end=4, colorMap={1: \"lightsalmon\", 2: \"mediumaquamarine\"}\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now suppose that we want to highlight the non-qal verb forms with a different color.\n", "\n", "We have to assign colours to the members of our tuples:" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:51:16.633433Z", "start_time": "2018-05-24T07:51:16.628359Z" } }, "outputs": [], "source": [ "highlights = {}\n", "for (subj, pred) in wantedResults:\n", " highlights[subj] = \"lightsalmon\"\n", " highlights[pred] = \"mediumaquamarine\" if F.vs.v(pred) == \"qal\" else \"yellow\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can call show with the `highlights` parameter instead of the `colorMap` parameter." ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:51:19.423335Z", "start_time": "2018-05-24T07:51:19.391463Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
npwordword
1Genesis 1:1אֱלֹהִ֑ים בָּרָ֣א
2Genesis 1:3אֱלֹהִ֖ים יֹּ֥אמֶר
3Genesis 1:4אֱלֹהִ֛ים יַּ֧רְא
4Genesis 1:4אֱלֹהִ֔ים יַּבְדֵּ֣ל
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.table(wantedResults, start=1, end=4, highlights=highlights)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or in condensed pretty display:" ] }, { "cell_type": "code", "execution_count": 45, "metadata": { "ExecuteTime": { "end_time": "2018-05-24T07:51:19.423335Z", "start_time": "2018-05-24T07:51:19.391463Z" } }, "outputs": [ { "data": { "text/html": [ "

verse 3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

verse:1414392
sentence:1172315 8
clause:427566 WayX NA
phrase:651596 CP Conj
function=Conj
40 וַ
sp=conj
phrase:651597 VP Pred
function=Pred
vs=qalnu=sgsp=verb
phrase:651598 NP Subj
function=Subj
nu=plsp=subs
phrase:651599 PP Objc
function=Objc
sp=prep
44 הָ
sp=art
nu=sgsp=subs
clause:427567 xQt0 Objc
phrase:651600 CP Conj
function=Conj
sp=conj
phrase:651601 VP Pred
function=Pred
vs=qalnu=sgsp=verb
sentence:1172316 9
clause:427568 WayX NA
phrase:651602 CP Conj
function=Conj
48 וַ
sp=conj
phrase:651603 VP Pred
function=Pred
vs=hifnu=sgsp=verb
phrase:651604 NP Subj
function=Subj
nu=plsp=subs
phrase:651605 PP Cmpl
function=Cmpl
nu=sgsp=subs
52 הָ
sp=art
nu=sgsp=subs
54 וּ
sp=conj
nu=sgsp=subs
56 הַ
sp=art
nu=sgsp=subs
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A.show(\n", " wantedResults,\n", " condensed=True,\n", " start=3,\n", " end=3,\n", " highlights=highlights,\n", " extraFeatures=\"vs\",\n", " withNodes=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you see, you have total control." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# All steps\n", "\n", "* **[start](start.ipynb)** your first step in mastering the bible computationally\n", "* **[display](display.ipynb)** become an expert in creating pretty displays of your text structures\n", "* **search** turbo charge your hand-coding with search templates\n", "\n", "---\n", "\n", "You know how to run queries and show off with their results.\n", "\n", "The next thing is to dive deeper into the power of templates:\n", "\n", "[advanced](searchAdvanced.ipynb)\n", "[sets](searchSets.ipynb)\n", "[relations](searchRelations.ipynb)\n", "[quantifiers](searchQuantifiers.ipynb)\n", "[from MQL](searchFromMQL.ipynb)\n", "[rough](searchRough.ipynb)\n", "[gaps](searchGaps.ipynb)\n", "\n", "---\n", "\n", "* **[export Excel](exportExcel.ipynb)** make tailor-made spreadsheets out of your results\n", "* **[share](share.ipynb)** draw in other people's data and let them use yours\n", "* **[export](export.ipynb)** export your dataset as an Emdros database\n", "* **[annotate](annotate.ipynb)** annotate plain text by means of other tools and import the annotations as TF features\n", "* **[map](map.ipynb)** map somebody else's annotations to a new version of the corpus\n", "* **[volumes](volumes.ipynb)** work with selected books only\n", "* **[trees](trees.ipynb)** work with the BHSA data as syntax trees\n", "\n", "CC-BY Dirk Roorda" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.0" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }