{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* [Main Page](https://oneadder.github.io/lingtypology/)\n",
    "* [Maps](https://oneadder.github.io/lingtypology/maps)\n",
    "* [Glottolog](https://oneadder.github.io/lingtypology/glottolog)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Database APIs <a name=\"up\"></a>\n",
    "\n",
    "APIs for different linguistic databases can be accessed with `lingtypology.db_apis`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import lingtypology.db_apis"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 0. Table of Contents\n",
    "### 1. [General](#general)\n",
    "#### 1.1. [List of Features](#features_list)\n",
    "#### 1.2. [Get DF or JSON](#get_df)\n",
    "#### 1.3. [Citation](#citation)\n",
    "### 2. [Wals](#wals)\n",
    "### 3. [Autotyp](#autotyp)\n",
    "### 4. [AfBo](#afbo)\n",
    "### 5. [SAILS](#sails)\n",
    "### 6. [Phoible](#phoible)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. General <a name=\"general\"></a>\n",
    "\n",
    "Lingtypology attempts to provide unified API for given language databases. Therefore, classes in this module share some common attributes and methods. In this paragraph I will describe them and provide examples for Autotyp, Wals and Phoible."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lingtypology.db_apis import Autotyp, Wals, Phoible"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1. `features_list` <a name=\"features_list\"></a>\n",
    "You can get the list of available features from the database using this attribute."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Agreement',\n",
       " 'Alienability',\n",
       " 'Alignment',\n",
       " 'Alignment_case_splits',\n",
       " 'Alignment_per_language',\n",
       " 'Clause_linkage',\n",
       " 'Clause_word_order',\n",
       " 'Clusivity',\n",
       " 'GR_per_language',\n",
       " 'Gender']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Autotyp().features_list[:10] #It's cutoff in order not to take took much space"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__Note__: `Phoible` has no `features_list` attribute because there are no features. However, it has `subsets_list` that shows list of available subsets of Phoible data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['all', 'UPSID', 'SPA', 'AA', 'PH', 'GM', 'RA', 'SAPHON']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Phoible().subsets_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2. `get_df` and `get_json` <a name=\"get_df\"></a>\n",
    "\n",
    "These two methods access the database and return data as `pandas.Series` or `dict`. Example of usage:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bickel, Balthasar, Johanna Nichols, Taras Zakharko,\n",
      "Alena Witzlack-Makarevich, Kristine Hildebrandt, Michael Rießler,\n",
      "Lennart Bierkandt, Fernando Zúñiga & John B. Lowe.\n",
      "2017. The AUTOTYP typological databases.\n",
      "Version 0.1.0 https://github.com/autotyp/autotyp-data/tree/0.1.0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>language</th>\n",
       "      <th>LID</th>\n",
       "      <th>VPolyagreement.Presence.v2</th>\n",
       "      <th>VPolyagreement.Presence.v1</th>\n",
       "      <th>InclExclAsPerson.Presence</th>\n",
       "      <th>InclExclAny.Presence</th>\n",
       "      <th>InclExclType</th>\n",
       "      <th>InclExclAsMinAug.Presence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ambulas</td>\n",
       "      <td>6</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>no i/e</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Abkhazian</td>\n",
       "      <td>7</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>no i/e</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Achinese</td>\n",
       "      <td>9</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>plain i/e type</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Western Keres</td>\n",
       "      <td>10</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>no i/e</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Hokkaido Ainu</td>\n",
       "      <td>12</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>plain i/e type</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        language  LID VPolyagreement.Presence.v2 VPolyagreement.Presence.v1  \\\n",
       "0        Ambulas    6                      False                      False   \n",
       "1      Abkhazian    7                       True                       True   \n",
       "2       Achinese    9                       True                      False   \n",
       "3  Western Keres   10                       True                       True   \n",
       "4  Hokkaido Ainu   12                       True                       True   \n",
       "\n",
       "  InclExclAsPerson.Presence  InclExclAny.Presence    InclExclType  \\\n",
       "0                     False                 False          no i/e   \n",
       "1                     False                 False          no i/e   \n",
       "2                     False                  True  plain i/e type   \n",
       "3                     False                 False          no i/e   \n",
       "4                     False                  True  plain i/e type   \n",
       "\n",
       "  InclExclAsMinAug.Presence  \n",
       "0                     False  \n",
       "1                     False  \n",
       "2                     False  \n",
       "3                     False  \n",
       "4                     False  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Autotyp('Agreement', 'Clusivity').get_df().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__Note__: for `Phoible` and `Autotyp` you can use `strip_na` parameter (`list`, default: `[]`) to strip rows in which there is empty cell in the given columns. Compare the following.  \n",
    "No `strip_na` (empty cells are replaced with `'~N/A~'`):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moran, Steven & McCloy, Daniel (eds.) 2019.\n",
      "PHOIBLE 2.0.\n",
      "Jena: Max Planck Institute for the Science of Human History.\n",
      "(Available online at http://phoible.org, Accessed on 2019-06-04.)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contribution_name</th>\n",
       "      <th>language</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>glottocode</th>\n",
       "      <th>macroarea</th>\n",
       "      <th>phonemes</th>\n",
       "      <th>consonants</th>\n",
       "      <th>vowels</th>\n",
       "      <th>tones</th>\n",
       "      <th>source</th>\n",
       "      <th>inventory_page</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Korean (SPA 1)</td>\n",
       "      <td>Korean</td>\n",
       "      <td>(37.5, 128.0)</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>40</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kor_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kore1280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>KOREAN (UPSID 423)</td>\n",
       "      <td>Korean</td>\n",
       "      <td>(37.5, 128.0)</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>32</td>\n",
       "      <td>21</td>\n",
       "      <td>11</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>http://web.phonetik.uni-frankfurt.de/L/L2170.html</td>\n",
       "      <td>https://phoible.org/languages/kore1280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ket (SPA 2)</td>\n",
       "      <td>Ket</td>\n",
       "      <td>(63.7551, 87.5466)</td>\n",
       "      <td>kett1243</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>32</td>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/ket_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kett1243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>KET (UPSID 399)</td>\n",
       "      <td>Ket</td>\n",
       "      <td>(63.7551, 87.5466)</td>\n",
       "      <td>kett1243</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>25</td>\n",
       "      <td>18</td>\n",
       "      <td>7</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>http://web.phonetik.uni-frankfurt.de/L/L2706.html</td>\n",
       "      <td>https://phoible.org/languages/kett1243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Lak (SPA 3)</td>\n",
       "      <td>Lak</td>\n",
       "      <td>(42.1328, 47.0809)</td>\n",
       "      <td>lakk1252</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>69</td>\n",
       "      <td>60</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/lbe_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/lakk1252</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    contribution_name language         coordinates glottocode macroarea  \\\n",
       "0      Korean (SPA 1)   Korean       (37.5, 128.0)   kore1280   Eurasia   \n",
       "1  KOREAN (UPSID 423)   Korean       (37.5, 128.0)   kore1280   Eurasia   \n",
       "2         Ket (SPA 2)      Ket  (63.7551, 87.5466)   kett1243   Eurasia   \n",
       "3     KET (UPSID 399)      Ket  (63.7551, 87.5466)   kett1243   Eurasia   \n",
       "4         Lak (SPA 3)      Lak  (42.1328, 47.0809)   lakk1252   Eurasia   \n",
       "\n",
       "   phonemes  consonants  vowels  tones  \\\n",
       "0        40          22      18      0   \n",
       "1        32          21      11  ~N/A~   \n",
       "2        32          18      14      0   \n",
       "3        25          18       7  ~N/A~   \n",
       "4        69          60       9      0   \n",
       "\n",
       "                                              source  \\\n",
       "0       https://archive.org/details/kor_SPA1979_phon   \n",
       "1  http://web.phonetik.uni-frankfurt.de/L/L2170.html   \n",
       "2       https://archive.org/details/ket_SPA1979_phon   \n",
       "3  http://web.phonetik.uni-frankfurt.de/L/L2706.html   \n",
       "4       https://archive.org/details/lbe_SPA1979_phon   \n",
       "\n",
       "                           inventory_page  \n",
       "0  https://phoible.org/languages/kore1280  \n",
       "1  https://phoible.org/languages/kore1280  \n",
       "2  https://phoible.org/languages/kett1243  \n",
       "3  https://phoible.org/languages/kett1243  \n",
       "4  https://phoible.org/languages/lakk1252  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Phoible().get_df().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`tones` column given to `strip_na`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moran, Steven & McCloy, Daniel (eds.) 2019.\n",
      "PHOIBLE 2.0.\n",
      "Jena: Max Planck Institute for the Science of Human History.\n",
      "(Available online at http://phoible.org, Accessed on 2019-06-04.)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contribution_name</th>\n",
       "      <th>language</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>glottocode</th>\n",
       "      <th>macroarea</th>\n",
       "      <th>phonemes</th>\n",
       "      <th>consonants</th>\n",
       "      <th>vowels</th>\n",
       "      <th>tones</th>\n",
       "      <th>source</th>\n",
       "      <th>inventory_page</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Korean (SPA 1)</td>\n",
       "      <td>Korean</td>\n",
       "      <td>(37.5, 128.0)</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>40</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kor_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kore1280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ket (SPA 2)</td>\n",
       "      <td>Ket</td>\n",
       "      <td>(63.7551, 87.5466)</td>\n",
       "      <td>kett1243</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>32</td>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/ket_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kett1243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Lak (SPA 3)</td>\n",
       "      <td>Lak</td>\n",
       "      <td>(42.1328, 47.0809)</td>\n",
       "      <td>lakk1252</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>69</td>\n",
       "      <td>60</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/lbe_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/lakk1252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Kabardian (SPA 4)</td>\n",
       "      <td>Kabardian</td>\n",
       "      <td>(43.5082, 43.3918)</td>\n",
       "      <td>kaba1278</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>56</td>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kbd_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kaba1278</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Georgian (SPA 5)</td>\n",
       "      <td>Georgian</td>\n",
       "      <td>(41.850396999999994, 43.78613)</td>\n",
       "      <td>nucl1302</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>35</td>\n",
       "      <td>29</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kat_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/nucl1302</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   contribution_name   language                     coordinates glottocode  \\\n",
       "0     Korean (SPA 1)     Korean                   (37.5, 128.0)   kore1280   \n",
       "2        Ket (SPA 2)        Ket              (63.7551, 87.5466)   kett1243   \n",
       "4        Lak (SPA 3)        Lak              (42.1328, 47.0809)   lakk1252   \n",
       "6  Kabardian (SPA 4)  Kabardian              (43.5082, 43.3918)   kaba1278   \n",
       "8   Georgian (SPA 5)   Georgian  (41.850396999999994, 43.78613)   nucl1302   \n",
       "\n",
       "  macroarea  phonemes  consonants  vowels tones  \\\n",
       "0   Eurasia        40          22      18     0   \n",
       "2   Eurasia        32          18      14     0   \n",
       "4   Eurasia        69          60       9     0   \n",
       "6   Eurasia        56          49       7     0   \n",
       "8   Eurasia        35          29       6     0   \n",
       "\n",
       "                                         source  \\\n",
       "0  https://archive.org/details/kor_SPA1979_phon   \n",
       "2  https://archive.org/details/ket_SPA1979_phon   \n",
       "4  https://archive.org/details/lbe_SPA1979_phon   \n",
       "6  https://archive.org/details/kbd_SPA1979_phon   \n",
       "8  https://archive.org/details/kat_SPA1979_phon   \n",
       "\n",
       "                           inventory_page  \n",
       "0  https://phoible.org/languages/kore1280  \n",
       "2  https://phoible.org/languages/kett1243  \n",
       "4  https://phoible.org/languages/lakk1252  \n",
       "6  https://phoible.org/languages/kaba1278  \n",
       "8  https://phoible.org/languages/nucl1302  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Phoible().get_df(strip_na=['tones']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__Note:__ By default when you call `get_df` or `get_json` it prints the citation. If you want to disable it, you shoud set the `show_citation` to `False`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contribution_name</th>\n",
       "      <th>language</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>glottocode</th>\n",
       "      <th>macroarea</th>\n",
       "      <th>phonemes</th>\n",
       "      <th>consonants</th>\n",
       "      <th>vowels</th>\n",
       "      <th>tones</th>\n",
       "      <th>source</th>\n",
       "      <th>inventory_page</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Korean (SPA 1)</td>\n",
       "      <td>Korean</td>\n",
       "      <td>(37.5, 128.0)</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>40</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kor_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kore1280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ket (SPA 2)</td>\n",
       "      <td>Ket</td>\n",
       "      <td>(63.7551, 87.5466)</td>\n",
       "      <td>kett1243</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>32</td>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/ket_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kett1243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Lak (SPA 3)</td>\n",
       "      <td>Lak</td>\n",
       "      <td>(42.1328, 47.0809)</td>\n",
       "      <td>lakk1252</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>69</td>\n",
       "      <td>60</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/lbe_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/lakk1252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Kabardian (SPA 4)</td>\n",
       "      <td>Kabardian</td>\n",
       "      <td>(43.5082, 43.3918)</td>\n",
       "      <td>kaba1278</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>56</td>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kbd_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kaba1278</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Georgian (SPA 5)</td>\n",
       "      <td>Georgian</td>\n",
       "      <td>(41.850396999999994, 43.78613)</td>\n",
       "      <td>nucl1302</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>35</td>\n",
       "      <td>29</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kat_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/nucl1302</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   contribution_name   language                     coordinates glottocode  \\\n",
       "0     Korean (SPA 1)     Korean                   (37.5, 128.0)   kore1280   \n",
       "2        Ket (SPA 2)        Ket              (63.7551, 87.5466)   kett1243   \n",
       "4        Lak (SPA 3)        Lak              (42.1328, 47.0809)   lakk1252   \n",
       "6  Kabardian (SPA 4)  Kabardian              (43.5082, 43.3918)   kaba1278   \n",
       "8   Georgian (SPA 5)   Georgian  (41.850396999999994, 43.78613)   nucl1302   \n",
       "\n",
       "  macroarea  phonemes  consonants  vowels tones  \\\n",
       "0   Eurasia        40          22      18     0   \n",
       "2   Eurasia        32          18      14     0   \n",
       "4   Eurasia        69          60       9     0   \n",
       "6   Eurasia        56          49       7     0   \n",
       "8   Eurasia        35          29       6     0   \n",
       "\n",
       "                                         source  \\\n",
       "0  https://archive.org/details/kor_SPA1979_phon   \n",
       "2  https://archive.org/details/ket_SPA1979_phon   \n",
       "4  https://archive.org/details/lbe_SPA1979_phon   \n",
       "6  https://archive.org/details/kbd_SPA1979_phon   \n",
       "8  https://archive.org/details/kat_SPA1979_phon   \n",
       "\n",
       "                           inventory_page  \n",
       "0  https://phoible.org/languages/kore1280  \n",
       "2  https://phoible.org/languages/kett1243  \n",
       "4  https://phoible.org/languages/lakk1252  \n",
       "6  https://phoible.org/languages/kaba1278  \n",
       "8  https://phoible.org/languages/nucl1302  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = Phoible()\n",
    "p.show_citation = False\n",
    "p.get_df(strip_na=['tones']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3. `citation` <a name=\"citation\"></a>\n",
    "\n",
    "You can get the citation for each database using `citation` attribute.\n",
    "E.g.:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bickel, Balthasar, Johanna Nichols, Taras Zakharko,\n",
      "Alena Witzlack-Makarevich, Kristine Hildebrandt, Michael Rießler,\n",
      "Lennart Bierkandt, Fernando Zúñiga & John B. Lowe.\n",
      "2017. The AUTOTYP typological databases.\n",
      "Version 0.1.0 https://github.com/autotyp/autotyp-data/tree/0.1.0\n"
     ]
    }
   ],
   "source": [
    "from lingtypology.db_apis import Autotyp\n",
    "print(Autotyp().citation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__Note__: if you use `Wals`, citation will be shown for every feature. If you want general citation for the whole Wals, use `general_citation`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Citation for feature 1A:\n",
      "Ian Maddieson. 2013. Consonant Inventories.\n",
      "In: Dryer, Matthew S. & Haspelmath, Martin (eds.)\n",
      "The World Atlas of Language Structures Online.\n",
      "Leipzig: Max Planck Institute for Evolutionary Anthropology.\n",
      "(Available online at http://wals.info/chapter/1, Accessed on 2019-06-04.)\n",
      "\n",
      "Citation for feature 2A:\n",
      "Ian Maddieson. 2013. Vowel Quality Inventories.\n",
      "In: Dryer, Matthew S. & Haspelmath, Martin (eds.)\n",
      "The World Atlas of Language Structures Online.\n",
      "Leipzig: Max Planck Institute for Evolutionary Anthropology.\n",
      "(Available online at http://wals.info/chapter/2, Accessed on 2019-06-04.)\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "w = Wals('1a', '2a')\n",
    "print(w.citation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dryer, Matthew S. & Haspelmath, Martin (eds.) 2013.\n",
      "The World Atlas of Language Structures Online.\n",
      "Leipzig: Max Planck Institute for Evolutionary Anthropology.\n",
      "(Available online at http://wals.info, Accessed on 2019-06-04.)\n"
     ]
    }
   ],
   "source": [
    "print(w.general_citation)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Wals <a name=\"wals\"></a>\n",
    "\n",
    "It is possible to access Wals data (online) using `lingtypology.db_apis.Wals`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lingtypology.db_apis import Wals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Citation for feature 1A:\n",
      "Ian Maddieson. 2013. Consonant Inventories.\n",
      "In: Dryer, Matthew S. & Haspelmath, Martin (eds.)\n",
      "The World Atlas of Language Structures Online.\n",
      "Leipzig: Max Planck Institute for Evolutionary Anthropology.\n",
      "(Available online at http://wals.info/chapter/1, Accessed on 2019-06-04.)\n",
      "\n",
      "Citation for feature 2A:\n",
      "Ian Maddieson. 2013. Vowel Quality Inventories.\n",
      "In: Dryer, Matthew S. & Haspelmath, Martin (eds.)\n",
      "The World Atlas of Language Structures Online.\n",
      "Leipzig: Max Planck Institute for Evolutionary Anthropology.\n",
      "(Available online at http://wals.info/chapter/2, Accessed on 2019-06-04.)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>wals_code</th>\n",
       "      <th>language</th>\n",
       "      <th>genus</th>\n",
       "      <th>family</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>_1A_area</th>\n",
       "      <th>_1A</th>\n",
       "      <th>_1A_num</th>\n",
       "      <th>_1A_desc</th>\n",
       "      <th>_2A_area</th>\n",
       "      <th>_2A</th>\n",
       "      <th>_2A_num</th>\n",
       "      <th>_2A_desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>kiw</td>\n",
       "      <td>Kiwai (Southern)</td>\n",
       "      <td>Kiwaian</td>\n",
       "      <td>Kiwaian</td>\n",
       "      <td>(-8.0, 143.5)</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>1. Small</td>\n",
       "      <td>1</td>\n",
       "      <td>Small</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>2. Average (5-6)</td>\n",
       "      <td>2</td>\n",
       "      <td>Average (5-6)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>xoo</td>\n",
       "      <td>!Xóõ</td>\n",
       "      <td>Tu</td>\n",
       "      <td>Tu</td>\n",
       "      <td>(-24.0, 21.5)</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>5. Large</td>\n",
       "      <td>5</td>\n",
       "      <td>Large</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>2. Average (5-6)</td>\n",
       "      <td>2</td>\n",
       "      <td>Average (5-6)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ani</td>\n",
       "      <td>//Ani</td>\n",
       "      <td>Khoe-Kwadi</td>\n",
       "      <td>Khoe-Kwadi</td>\n",
       "      <td>(-18.9166666667, 21.9166666667)</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>5. Large</td>\n",
       "      <td>5</td>\n",
       "      <td>Large</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>2. Average (5-6)</td>\n",
       "      <td>2</td>\n",
       "      <td>Average (5-6)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>abi</td>\n",
       "      <td>Abipón</td>\n",
       "      <td>South Guaicuruan</td>\n",
       "      <td>Guaicuruan</td>\n",
       "      <td>(-29.0, -61.0)</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>2. Moderately small</td>\n",
       "      <td>2</td>\n",
       "      <td>Moderately small</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>2. Average (5-6)</td>\n",
       "      <td>2</td>\n",
       "      <td>Average (5-6)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>abk</td>\n",
       "      <td>Abkhaz</td>\n",
       "      <td>Northwest Caucasian</td>\n",
       "      <td>Northwest Caucasian</td>\n",
       "      <td>(43.0833333333, 41.0)</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>5. Large</td>\n",
       "      <td>5</td>\n",
       "      <td>Large</td>\n",
       "      <td>Phonology</td>\n",
       "      <td>1. Small (2-4)</td>\n",
       "      <td>1</td>\n",
       "      <td>Small (2-4)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  wals_code           language                genus               family  \\\n",
       "0       kiw   Kiwai (Southern)              Kiwaian              Kiwaian   \n",
       "1       xoo               !Xóõ                   Tu                   Tu   \n",
       "2       ani              //Ani           Khoe-Kwadi           Khoe-Kwadi   \n",
       "3       abi             Abipón     South Guaicuruan           Guaicuruan   \n",
       "4       abk             Abkhaz  Northwest Caucasian  Northwest Caucasian   \n",
       "\n",
       "                       coordinates   _1A_area                  _1A  _1A_num  \\\n",
       "0                    (-8.0, 143.5)  Phonology             1. Small        1   \n",
       "1                    (-24.0, 21.5)  Phonology             5. Large        5   \n",
       "2  (-18.9166666667, 21.9166666667)  Phonology             5. Large        5   \n",
       "3                   (-29.0, -61.0)  Phonology  2. Moderately small        2   \n",
       "4            (43.0833333333, 41.0)  Phonology             5. Large        5   \n",
       "\n",
       "           _1A_desc   _2A_area               _2A  _2A_num       _2A_desc  \n",
       "0             Small  Phonology  2. Average (5-6)        2  Average (5-6)  \n",
       "1             Large  Phonology  2. Average (5-6)        2  Average (5-6)  \n",
       "2             Large  Phonology  2. Average (5-6)        2  Average (5-6)  \n",
       "3  Moderately small  Phonology  2. Average (5-6)        2  Average (5-6)  \n",
       "4             Large  Phonology    1. Small (2-4)        1    Small (2-4)  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wals_page = Wals('1a', '2a').get_df()\n",
    "wals_page.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Map example for feature **1A**:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,[encoded data, 1297720 characters]\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fc2343fd2b0>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = lingtypology.LingMap(wals_page.language)\n",
    "m.add_custom_coordinates(wals_page.coordinates)\n",
    "m.add_features(wals_page._1A)\n",
    "m.legend_title = 'Consonant Inventory'\n",
    "m.colors = lingtypology.gradient(5, 'yellow', 'green')\n",
    "m.create_map()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Autotyp <a name=\"autotyp\"></a>\n",
    "\n",
    "It is possible to access Autotyp data (online) using `lingtypology.db_apis`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Unlike in Wals, each new tablename passed into `Autotyp` gives several additional columns:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bickel, Balthasar, Johanna Nichols, Taras Zakharko,\n",
      "Alena Witzlack-Makarevich, Kristine Hildebrandt, Michael Rießler,\n",
      "Lennart Bierkandt, Fernando Zúñiga & John B. Lowe.\n",
      "2017. The AUTOTYP typological databases.\n",
      "Version 0.1.0 https://github.com/autotyp/autotyp-data/tree/0.1.0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>language</th>\n",
       "      <th>LID</th>\n",
       "      <th>Gender.n</th>\n",
       "      <th>Gender.binned4</th>\n",
       "      <th>Gender.Presence</th>\n",
       "      <th>VPolyagreement.Presence.v2</th>\n",
       "      <th>VPolyagreement.Presence.v1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Godoberi</td>\n",
       "      <td>1531</td>\n",
       "      <td>3</td>\n",
       "      <td>3 genders</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Bininj Kun-Wok</td>\n",
       "      <td>655</td>\n",
       "      <td>4</td>\n",
       "      <td>4 genders</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Luvale</td>\n",
       "      <td>553</td>\n",
       "      <td>10</td>\n",
       "      <td>more than 4 genders</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>North-Central Dargwa</td>\n",
       "      <td>2949</td>\n",
       "      <td>3</td>\n",
       "      <td>3 genders</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Gaagudju</td>\n",
       "      <td>82</td>\n",
       "      <td>4</td>\n",
       "      <td>4 genders</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               language   LID Gender.n       Gender.binned4 Gender.Presence  \\\n",
       "0              Godoberi  1531        3            3 genders            True   \n",
       "1        Bininj Kun-Wok   655        4            4 genders            True   \n",
       "2                Luvale   553       10  more than 4 genders            True   \n",
       "3  North-Central Dargwa  2949        3            3 genders            True   \n",
       "4              Gaagudju    82        4            4 genders            True   \n",
       "\n",
       "  VPolyagreement.Presence.v2 VPolyagreement.Presence.v1  \n",
       "0                      False                      False  \n",
       "1                       True                       True  \n",
       "2                       True                      False  \n",
       "3                       True                       True  \n",
       "4                       True                       True  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Autotyp_table = Autotyp('Gender', 'Agreement').get_df(strip_na=['Gender.binned4'])\n",
    "Autotyp_table.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can draw a map out of gender data from multiple languages."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,[encoded data, 223316 characters]\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fc2343fd400>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = lingtypology.LingMap(Autotyp_table.language)\n",
    "m.add_features(Autotyp_table['Gender.binned4'])\n",
    "m.colors = lingtypology.gradient(4, color1='yellow', color2='red')\n",
    "m.legend_title = 'Genders'\n",
    "m.create_map()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. AfBo <a name=\"afbo\"></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lingtypology.db_apis import AfBo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Seifart, Frank. 2013.\n",
      "AfBo: A world-wide survey of affix borrowing.\n",
      "Leipzig: Max Planck Institute for Evolutionary Anthropology.\n",
      "(Available online at http://afbo.info, Accessed on 2019-06-04.)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>language_recipient</th>\n",
       "      <th>language_donor</th>\n",
       "      <th>reliability</th>\n",
       "      <th>adjectivizer</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Resígaro</td>\n",
       "      <td>Bora</td>\n",
       "      <td>high</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Gurindji Kriol</td>\n",
       "      <td>Gurindji</td>\n",
       "      <td>high</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Copper Island Aleut</td>\n",
       "      <td>Russian</td>\n",
       "      <td>high</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Sakha</td>\n",
       "      <td>Mongolian</td>\n",
       "      <td>high</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Kalderash Romani</td>\n",
       "      <td>Romanian</td>\n",
       "      <td>high</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    language_recipient language_donor reliability adjectivizer\n",
       "0             Resígaro           Bora        high            0\n",
       "1       Gurindji Kriol       Gurindji        high            0\n",
       "2  Copper Island Aleut        Russian        high            0\n",
       "3                Sakha      Mongolian        high            4\n",
       "4     Kalderash Romani       Romanian        high            1"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adj = AfBo('adjectivizer').get_df()\n",
    "adj.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,[encoded data, 106032 characters]\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fc233938048>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = lingtypology.LingMap(adj.language_recipient)\n",
    "m.add_features(adj['adjectivizer'], numeric=True)\n",
    "m.legend_title = 'Adj'\n",
    "m.create_map()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. SAILS <a name=\"sails\"></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lingtypology.db_apis import Sails"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get a `pandas.DataFrame` of features and descriptions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Feature</th>\n",
       "      <th>Description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ICU17</td>\n",
       "      <td>Is plurality in independent pronouns expressed...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ICU16</td>\n",
       "      <td>Is plurality in independent pronouns expressed...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ICU15</td>\n",
       "      <td>Is plurality in independent pronouns expressed...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ICU14</td>\n",
       "      <td>Is an associative or collective plural disting...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ICU13</td>\n",
       "      <td>Are nouns denoting inanimates marked for plural?</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Feature                                        Description\n",
       "0   ICU17  Is plurality in independent pronouns expressed...\n",
       "1   ICU16  Is plurality in independent pronouns expressed...\n",
       "2   ICU15  Is plurality in independent pronouns expressed...\n",
       "3   ICU14  Is an associative or collective plural disting...\n",
       "4   ICU13   Are nouns denoting inanimates marked for plural?"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sails().features_descriptions.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get description for particular features:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Feature</th>\n",
       "      <th>Description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ICU10</td>\n",
       "      <td>Is nominal plural marking obligatory?</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ICU11</td>\n",
       "      <td>Are nouns denoting humans marked for plural?</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Feature                                   Description\n",
       "0   ICU10         Is nominal plural marking obligatory?\n",
       "1   ICU11  Are nouns denoting humans marked for plural?"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Sails().feature_descriptions('ICU10', 'ICU11')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To get the SAILS data as `dict`, you can use `get_json` method. To get data as `pandas.DataFrame` you can run:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You probably should cite it, but I don't understand how. Please, consult https://sails.clld.org/\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>language</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>ICU3</th>\n",
       "      <th>ICU3_desc</th>\n",
       "      <th>ICU4</th>\n",
       "      <th>ICU4_desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Baniva</td>\n",
       "      <td>&lt;zip object at 0x7fc233a96788&gt;</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Apolista</td>\n",
       "      <td>&lt;zip object at 0x7fc233a96788&gt;</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Yavitero</td>\n",
       "      <td>&lt;zip object at 0x7fc233a96788&gt;</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Resígaro</td>\n",
       "      <td>&lt;zip object at 0x7fc233a96788&gt;</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Tol</td>\n",
       "      <td>&lt;zip object at 0x7fc233a96788&gt;</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>~N/A~</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   language                     coordinates   ICU3 ICU3_desc   ICU4 ICU4_desc\n",
       "0    Baniva  <zip object at 0x7fc233a96788>  ~N/A~     ~N/A~  ~N/A~     ~N/A~\n",
       "1  Apolista  <zip object at 0x7fc233a96788>  ~N/A~     ~N/A~  ~N/A~     ~N/A~\n",
       "2  Yavitero  <zip object at 0x7fc233a96788>  ~N/A~     ~N/A~  ~N/A~     ~N/A~\n",
       "3  Resígaro  <zip object at 0x7fc233a96788>  ~N/A~     ~N/A~  ~N/A~     ~N/A~\n",
       "4       Tol  <zip object at 0x7fc233a96788>  ~N/A~     ~N/A~  ~N/A~     ~N/A~"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sails = Sails('ICU3', 'ICU4')\n",
    "df = sails.get_df()\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Map example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,[encoded data, 228236 characters]\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fc2591e3908>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = lingtypology.LingMap(df.language)\n",
    "m.add_features(df.ICU3_desc)\n",
    "m.legend_title = sails.feature_descriptions('ICU3').Description.at[0]\n",
    "m.start_location = (9, -79)\n",
    "m.start_zoom = 5\n",
    "m.legend_position = 'bottomleft'\n",
    "m.create_map()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6. Phoible <a name=\"phoible\"></a>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "from lingtypology.db_apis import Phoible"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Unlike in other databases you do not pass features into Phoible. You should pass the subset.\n",
    "Take a look:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moran, Steven & McCloy, Daniel (eds.) 2019.\n",
      "PHOIBLE 2.0.\n",
      "Jena: Max Planck Institute for the Science of Human History.\n",
      "(Available online at http://phoible.org, Accessed on 2019-06-04.)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contribution_name</th>\n",
       "      <th>language</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>glottocode</th>\n",
       "      <th>macroarea</th>\n",
       "      <th>phonemes</th>\n",
       "      <th>consonants</th>\n",
       "      <th>vowels</th>\n",
       "      <th>tones</th>\n",
       "      <th>source</th>\n",
       "      <th>inventory_page</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Korean (SPA 1)</td>\n",
       "      <td>Korean</td>\n",
       "      <td>(37.5, 128.0)</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>40</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kor_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kore1280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>KOREAN (UPSID 423)</td>\n",
       "      <td>Korean</td>\n",
       "      <td>(37.5, 128.0)</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>32</td>\n",
       "      <td>21</td>\n",
       "      <td>11</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>http://web.phonetik.uni-frankfurt.de/L/L2170.html</td>\n",
       "      <td>https://phoible.org/languages/kore1280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ket (SPA 2)</td>\n",
       "      <td>Ket</td>\n",
       "      <td>(63.7551, 87.5466)</td>\n",
       "      <td>kett1243</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>32</td>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/ket_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kett1243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>KET (UPSID 399)</td>\n",
       "      <td>Ket</td>\n",
       "      <td>(63.7551, 87.5466)</td>\n",
       "      <td>kett1243</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>25</td>\n",
       "      <td>18</td>\n",
       "      <td>7</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>http://web.phonetik.uni-frankfurt.de/L/L2706.html</td>\n",
       "      <td>https://phoible.org/languages/kett1243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Lak (SPA 3)</td>\n",
       "      <td>Lak</td>\n",
       "      <td>(42.1328, 47.0809)</td>\n",
       "      <td>lakk1252</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>69</td>\n",
       "      <td>60</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/lbe_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/lakk1252</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    contribution_name language         coordinates glottocode macroarea  \\\n",
       "0      Korean (SPA 1)   Korean       (37.5, 128.0)   kore1280   Eurasia   \n",
       "1  KOREAN (UPSID 423)   Korean       (37.5, 128.0)   kore1280   Eurasia   \n",
       "2         Ket (SPA 2)      Ket  (63.7551, 87.5466)   kett1243   Eurasia   \n",
       "3     KET (UPSID 399)      Ket  (63.7551, 87.5466)   kett1243   Eurasia   \n",
       "4         Lak (SPA 3)      Lak  (42.1328, 47.0809)   lakk1252   Eurasia   \n",
       "\n",
       "   phonemes  consonants  vowels  tones  \\\n",
       "0        40          22      18      0   \n",
       "1        32          21      11  ~N/A~   \n",
       "2        32          18      14      0   \n",
       "3        25          18       7  ~N/A~   \n",
       "4        69          60       9      0   \n",
       "\n",
       "                                              source  \\\n",
       "0       https://archive.org/details/kor_SPA1979_phon   \n",
       "1  http://web.phonetik.uni-frankfurt.de/L/L2170.html   \n",
       "2       https://archive.org/details/ket_SPA1979_phon   \n",
       "3  http://web.phonetik.uni-frankfurt.de/L/L2706.html   \n",
       "4       https://archive.org/details/lbe_SPA1979_phon   \n",
       "\n",
       "                           inventory_page  \n",
       "0  https://phoible.org/languages/kore1280  \n",
       "1  https://phoible.org/languages/kore1280  \n",
       "2  https://phoible.org/languages/kett1243  \n",
       "3  https://phoible.org/languages/kett1243  \n",
       "4  https://phoible.org/languages/lakk1252  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = Phoible()\n",
    "p.get_df().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are several entries for different languages: it happens because Phoible data consists of several different subsets. You can get the list of available subsets:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['all', 'UPSID', 'SPA', 'AA', 'PH', 'GM', 'RA', 'SAPHON']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p.subsets_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "... and pass them into the class:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moran, Steven & McCloy, Daniel (eds.) 2019.\n",
      "PHOIBLE 2.0.\n",
      "Jena: Max Planck Institute for the Science of Human History.\n",
      "(Available online at http://phoible.org, Accessed on 2019-06-04.)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>contribution_name</th>\n",
       "      <th>language</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>glottocode</th>\n",
       "      <th>macroarea</th>\n",
       "      <th>phonemes</th>\n",
       "      <th>consonants</th>\n",
       "      <th>vowels</th>\n",
       "      <th>tones</th>\n",
       "      <th>source</th>\n",
       "      <th>inventory_page</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Korean (SPA 1)</td>\n",
       "      <td>Korean</td>\n",
       "      <td>(37.5, 128.0)</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>40</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kor_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kore1280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ket (SPA 2)</td>\n",
       "      <td>Ket</td>\n",
       "      <td>(63.7551, 87.5466)</td>\n",
       "      <td>kett1243</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>32</td>\n",
       "      <td>18</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/ket_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kett1243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Lak (SPA 3)</td>\n",
       "      <td>Lak</td>\n",
       "      <td>(42.1328, 47.0809)</td>\n",
       "      <td>lakk1252</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>69</td>\n",
       "      <td>60</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/lbe_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/lakk1252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Kabardian (SPA 4)</td>\n",
       "      <td>Kabardian</td>\n",
       "      <td>(43.5082, 43.3918)</td>\n",
       "      <td>kaba1278</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>56</td>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kbd_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/kaba1278</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Georgian (SPA 5)</td>\n",
       "      <td>Georgian</td>\n",
       "      <td>(41.850396999999994, 43.78613)</td>\n",
       "      <td>nucl1302</td>\n",
       "      <td>Eurasia</td>\n",
       "      <td>35</td>\n",
       "      <td>29</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>https://archive.org/details/kat_SPA1979_phon</td>\n",
       "      <td>https://phoible.org/languages/nucl1302</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   contribution_name   language                     coordinates glottocode  \\\n",
       "0     Korean (SPA 1)     Korean                   (37.5, 128.0)   kore1280   \n",
       "1        Ket (SPA 2)        Ket              (63.7551, 87.5466)   kett1243   \n",
       "2        Lak (SPA 3)        Lak              (42.1328, 47.0809)   lakk1252   \n",
       "3  Kabardian (SPA 4)  Kabardian              (43.5082, 43.3918)   kaba1278   \n",
       "4   Georgian (SPA 5)   Georgian  (41.850396999999994, 43.78613)   nucl1302   \n",
       "\n",
       "  macroarea  phonemes  consonants  vowels tones  \\\n",
       "0   Eurasia        40          22      18     0   \n",
       "1   Eurasia        32          18      14     0   \n",
       "2   Eurasia        69          60       9     0   \n",
       "3   Eurasia        56          49       7     0   \n",
       "4   Eurasia        35          29       6     0   \n",
       "\n",
       "                                         source  \\\n",
       "0  https://archive.org/details/kor_SPA1979_phon   \n",
       "1  https://archive.org/details/ket_SPA1979_phon   \n",
       "2  https://archive.org/details/lbe_SPA1979_phon   \n",
       "3  https://archive.org/details/kbd_SPA1979_phon   \n",
       "4  https://archive.org/details/kat_SPA1979_phon   \n",
       "\n",
       "                           inventory_page  \n",
       "0  https://phoible.org/languages/kore1280  \n",
       "1  https://phoible.org/languages/kett1243  \n",
       "2  https://phoible.org/languages/lakk1252  \n",
       "3  https://phoible.org/languages/kaba1278  \n",
       "4  https://phoible.org/languages/nucl1302  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = Phoible(subset='SPA')\n",
    "df = p.get_df(strip_na=['tones'])\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also get non-aggregated data by setting `aggregated` to `False` while initializing the class."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moran, Steven & McCloy, Daniel (eds.) 2019.\n",
      "PHOIBLE 2.0.\n",
      "Jena: Max Planck Institute for the Science of Human History.\n",
      "(Available online at http://phoible.org, Accessed on 2019-06-04.)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InventoryID</th>\n",
       "      <th>Glottocode</th>\n",
       "      <th>ISO6393</th>\n",
       "      <th>LanguageName</th>\n",
       "      <th>SpecificDialect</th>\n",
       "      <th>GlyphID</th>\n",
       "      <th>Phoneme</th>\n",
       "      <th>Allophones</th>\n",
       "      <th>Marginal</th>\n",
       "      <th>SegmentClass</th>\n",
       "      <th>...</th>\n",
       "      <th>retractedTongueRoot</th>\n",
       "      <th>advancedTongueRoot</th>\n",
       "      <th>periodicGlottalSource</th>\n",
       "      <th>epilaryngealSource</th>\n",
       "      <th>spreadGlottis</th>\n",
       "      <th>constrictedGlottis</th>\n",
       "      <th>fortis</th>\n",
       "      <th>raisedLarynxEjective</th>\n",
       "      <th>loweredLarynxImplosive</th>\n",
       "      <th>click</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>kor</td>\n",
       "      <td>Korean</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>0061</td>\n",
       "      <td>a</td>\n",
       "      <td>a</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>vowel</td>\n",
       "      <td>...</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>kor</td>\n",
       "      <td>Korean</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>0061+02D0</td>\n",
       "      <td>aː</td>\n",
       "      <td>aː</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>vowel</td>\n",
       "      <td>...</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>kor</td>\n",
       "      <td>Korean</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>00E6</td>\n",
       "      <td>æ</td>\n",
       "      <td>ɛ æ</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>vowel</td>\n",
       "      <td>...</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>kor</td>\n",
       "      <td>Korean</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>00E6+02D0</td>\n",
       "      <td>æː</td>\n",
       "      <td>æː</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>vowel</td>\n",
       "      <td>...</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>kore1280</td>\n",
       "      <td>kor</td>\n",
       "      <td>Korean</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>0065</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>vowel</td>\n",
       "      <td>...</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 48 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   InventoryID Glottocode ISO6393 LanguageName SpecificDialect    GlyphID  \\\n",
       "0            1   kore1280     kor       Korean           ~N/A~       0061   \n",
       "1            1   kore1280     kor       Korean           ~N/A~  0061+02D0   \n",
       "2            1   kore1280     kor       Korean           ~N/A~       00E6   \n",
       "3            1   kore1280     kor       Korean           ~N/A~  00E6+02D0   \n",
       "4            1   kore1280     kor       Korean           ~N/A~       0065   \n",
       "\n",
       "  Phoneme Allophones Marginal SegmentClass  ... retractedTongueRoot  \\\n",
       "0       a          a    ~N/A~        vowel  ...                   -   \n",
       "1      aː         aː    ~N/A~        vowel  ...                   -   \n",
       "2       æ        ɛ æ    ~N/A~        vowel  ...                   -   \n",
       "3      æː         æː    ~N/A~        vowel  ...                   -   \n",
       "4       e          e    ~N/A~        vowel  ...                   -   \n",
       "\n",
       "  advancedTongueRoot periodicGlottalSource epilaryngealSource spreadGlottis  \\\n",
       "0                  -                     +                  -             -   \n",
       "1                  -                     +                  -             -   \n",
       "2                  -                     +                  -             -   \n",
       "3                  -                     +                  -             -   \n",
       "4                  -                     +                  -             -   \n",
       "\n",
       "  constrictedGlottis fortis raisedLarynxEjective loweredLarynxImplosive click  \n",
       "0                  -      0                    -                      -     0  \n",
       "1                  -      0                    -                      -     0  \n",
       "2                  -      0                    -                      -     0  \n",
       "3                  -      0                    -                      -     0  \n",
       "4                  -      0                    -                      -     0  \n",
       "\n",
       "[5 rows x 48 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Phoible(aggregated=False).get_df().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Map example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,[encoded data, 462788 characters]\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fc23053e860>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = lingtypology.LingMap(df.language)\n",
    "m.colormap_colors = ('white', 'red')\n",
    "m.add_features(df.tones, numeric=True)\n",
    "m.start_zoom = 1\n",
    "m.legend_title = 'Tones'\n",
    "m.create_map()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another example (slow due to large amount of data):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Moran, Steven & McCloy, Daniel (eds.) 2019.\n",
      "PHOIBLE 2.0.\n",
      "Jena: Max Planck Institute for the Science of Human History.\n",
      "(Available online at http://phoible.org, Accessed on 2019-06-04.)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>InventoryID</th>\n",
       "      <th>Glottocode</th>\n",
       "      <th>ISO6393</th>\n",
       "      <th>LanguageName</th>\n",
       "      <th>SpecificDialect</th>\n",
       "      <th>GlyphID</th>\n",
       "      <th>Phoneme</th>\n",
       "      <th>Allophones</th>\n",
       "      <th>Marginal</th>\n",
       "      <th>SegmentClass</th>\n",
       "      <th>...</th>\n",
       "      <th>retractedTongueRoot</th>\n",
       "      <th>advancedTongueRoot</th>\n",
       "      <th>periodicGlottalSource</th>\n",
       "      <th>epilaryngealSource</th>\n",
       "      <th>spreadGlottis</th>\n",
       "      <th>constrictedGlottis</th>\n",
       "      <th>fortis</th>\n",
       "      <th>raisedLarynxEjective</th>\n",
       "      <th>loweredLarynxImplosive</th>\n",
       "      <th>click</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7570</th>\n",
       "      <td>198</td>\n",
       "      <td>afad1236</td>\n",
       "      <td>aal</td>\n",
       "      <td>KOTOKO</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>0063+02BC</td>\n",
       "      <td>cʼ</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>False</td>\n",
       "      <td>consonant</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7802</th>\n",
       "      <td>206</td>\n",
       "      <td>ahte1237</td>\n",
       "      <td>aht</td>\n",
       "      <td>AHTNA</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>006B+02BC</td>\n",
       "      <td>kʼ</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>False</td>\n",
       "      <td>consonant</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7920</th>\n",
       "      <td>211</td>\n",
       "      <td>qawa1238</td>\n",
       "      <td>alc</td>\n",
       "      <td>QAWASQAR</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>006B+02BC</td>\n",
       "      <td>kʼ</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>False</td>\n",
       "      <td>consonant</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8131</th>\n",
       "      <td>218</td>\n",
       "      <td>hame1242</td>\n",
       "      <td>amf</td>\n",
       "      <td>HAMER</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>0071+02BC</td>\n",
       "      <td>qʼ</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>False</td>\n",
       "      <td>consonant</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8157</th>\n",
       "      <td>219</td>\n",
       "      <td>amha1245</td>\n",
       "      <td>amh</td>\n",
       "      <td>AMHARIC</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>006B+02B7+02BC</td>\n",
       "      <td>kʷʼ</td>\n",
       "      <td>~N/A~</td>\n",
       "      <td>False</td>\n",
       "      <td>consonant</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>+</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 48 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      InventoryID Glottocode ISO6393 LanguageName SpecificDialect  \\\n",
       "7570          198   afad1236     aal       KOTOKO           ~N/A~   \n",
       "7802          206   ahte1237     aht        AHTNA           ~N/A~   \n",
       "7920          211   qawa1238     alc     QAWASQAR           ~N/A~   \n",
       "8131          218   hame1242     amf        HAMER           ~N/A~   \n",
       "8157          219   amha1245     amh      AMHARIC           ~N/A~   \n",
       "\n",
       "             GlyphID Phoneme Allophones  Marginal SegmentClass  ...  \\\n",
       "7570       0063+02BC      cʼ      ~N/A~     False    consonant  ...   \n",
       "7802       006B+02BC      kʼ      ~N/A~     False    consonant  ...   \n",
       "7920       006B+02BC      kʼ      ~N/A~     False    consonant  ...   \n",
       "8131       0071+02BC      qʼ      ~N/A~     False    consonant  ...   \n",
       "8157  006B+02B7+02BC     kʷʼ      ~N/A~     False    consonant  ...   \n",
       "\n",
       "     retractedTongueRoot advancedTongueRoot periodicGlottalSource  \\\n",
       "7570                   0                  0                     -   \n",
       "7802                   0                  0                     -   \n",
       "7920                   0                  0                     -   \n",
       "8131                   0                  0                     -   \n",
       "8157                   0                  0                     -   \n",
       "\n",
       "     epilaryngealSource spreadGlottis constrictedGlottis fortis  \\\n",
       "7570                  -             -                  +      -   \n",
       "7802                  -             -                  +      -   \n",
       "7920                  -             -                  +      -   \n",
       "8131                  -             -                  +      -   \n",
       "8157                  -             -                  +      -   \n",
       "\n",
       "     raisedLarynxEjective loweredLarynxImplosive click  \n",
       "7570                    +                      -     -  \n",
       "7802                    +                      -     -  \n",
       "7920                    +                      -     -  \n",
       "8131                    +                      -     -  \n",
       "8157                    +                      -     -  \n",
       "\n",
       "[5 rows x 48 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = Phoible(subset='UPSID', aggregated=False).get_df()\n",
    "#Get all languages with ejectives\n",
    "df = df[df.raisedLarynxEjective == '+']\n",
    "#Remove duplicates\n",
    "df = df.drop_duplicates(subset='Glottocode')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,[encoded data, 169268 characters]\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fc231350f98>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = lingtypology.LingMap(df.Glottocode, glottocode=True)\n",
    "m.title = 'Languages with Ejectives'\n",
    "m.create_map()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Go back up](#up)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.3rc1"
  },
  "title": "Lingtypology"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
