{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-03T07:32:49.839037Z",
     "start_time": "2019-09-03T07:32:48.629488Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('She held out her hand.', '彼女は手を差し出した。'),\n",
       " ('I heard that beer was cheaper than water in Germany. Is that true?',\n",
       "  'ドイツは水よりビールが安いって聞いたんだけどほんと？'),\n",
       " ('My father has never gotten sick in his life.', '父は今まで一度も病気をしたことがない。'),\n",
       " ('She went to that store.', '彼女はその店へ行った。'),\n",
       " (\"I haven't read all of his novels.\", '私は彼の小説を全部読んだわけではない。'),\n",
       " ('Get going.', 'さあ行った、行った。'),\n",
       " ('The cherry blossoms are at their best now.', '桜の花は今が見頃です。'),\n",
       " ('When I got up, the sun was already high in the sky.', '目が覚めた時にはもう日が高かった。'),\n",
       " ('He came down with a cold.', '彼は風邪にかかった。'),\n",
       " ('You can count on me any time.', 'いつでも相談にのりますよ。')]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sagas.train.parallel_corpus import load_corpus, take_samples\n",
    "items=load_corpus()\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-03T07:32:52.023443Z",
     "start_time": "2019-09-03T07:32:51.941276Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('The children were swimming naked.', 'بچه ها لخت شنا می کنند.'),\n",
       " ('She took a deep breath.', 'او نفس عمیقی کشید.'),\n",
       " ('I had not gone a mile when it began to rain.',\n",
       "  'یک مایل نرفته بودم که باران شروع شد.'),\n",
       " ('We need a place to stay for the night.',\n",
       "  'ما به جایی نیاز داریم، که شب آنجا بمانیم.'),\n",
       " ('Tom decided to take matters into his own hands.',\n",
       "  'تام تصمیم گرفت موارد را خود بدست گیرد.'),\n",
       " (\"Words can't express our gratitude.\",\n",
       "  'کلمات قادر به بیان قدردانی ما نیستند.'),\n",
       " ('Wonderful!', 'حیرت آورست!'),\n",
       " ('Like father, like son.', 'همانا پدر، همانا پسر.'),\n",
       " ('Of course.', 'البته.'),\n",
       " ('Who made the doll?', 'چه کسی عروسک را درست کرده است؟')]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prefix='/pi/ai/seq2seq'\n",
    "items=load_corpus(f\"{prefix}/en_Persian/pes-eng/pes.txt\")\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-03T07:41:58.555013Z",
     "start_time": "2019-09-03T07:41:58.551672Z"
    }
   },
   "outputs": [],
   "source": [
    "from sagas.nlu.transliterations import translits\n",
    "# translits.translit('내 친구들은 멍청하다.', 'ko')\n",
    "# translits.translit('چه کسی عروسک را درست کرده است؟', 'fa')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-03T07:41:52.657432Z",
     "start_time": "2019-09-03T07:41:52.652552Z"
    }
   },
   "outputs": [],
   "source": [
    "# for l in rows:\n",
    "#     print(l[1])\n",
    "#     print(translits.translit(l[1], 'fa'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-30T14:39:26.149969Z",
     "start_time": "2019-08-30T14:39:25.928119Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Thanks to the bad weather, the game was canceled.',\n",
       "  'أُلغيت المباراة بسبب تغير الجو.'),\n",
       " ('How many kids do you have?', 'كم ابناً عندك؟'),\n",
       " (\"I'll get the food.\", 'سوف أُحضرُ الطعام.'),\n",
       " ('Why are you acting this way?', 'لما تتصرف هكذا؟'),\n",
       " ('She screamed for help.', 'صرخت طالبة المساعدة.'),\n",
       " (\"Since you're here, we might as well begin.\", 'بما أنك هنا، لعلنا نبدأ.'),\n",
       " ('I swim once a week.', 'أسبح مرةً في الأسبوع.'),\n",
       " (\"I'll return to get my handbag.\", 'سأعود لآخذ حقيبة يدي.'),\n",
       " (\"My mother can't come.\", 'أمي لا يمكنها المجيء.'),\n",
       " ('I eat here.', 'سآكل هنا.')]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "items=load_corpus(f\"{prefix}/ara-eng/ara.txt\")\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-30T14:46:42.766259Z",
     "start_time": "2019-08-30T14:46:42.755630Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(\"Here's your dog.\", 'ها هو كلبك.')\n",
      "('Are these your dogs?', 'هل هذه كلابك؟')\n",
      "('Are those your dogs?', 'هل تلك كلابك؟')\n",
      "('If you feed your dog properly, you can increase his lifespan.', 'إذا أطعمت كلبك بشكل صحيح، تستطيع أن ترفع من عمره.')\n",
      ".\n"
     ]
    }
   ],
   "source": [
    "def search_in(items, phrase):\n",
    "    for item in items:\n",
    "        if phrase in item[0]:\n",
    "            print(item)\n",
    "    print('.')\n",
    "search_in(items, 'your dog')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-26T17:02:48.811503Z",
     "start_time": "2019-08-26T17:02:48.651083Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Now keep calm.', 'Сега спокойно.'),\n",
       " ('I sympathize with you.', 'Съчувствам ти.'),\n",
       " (\"It'll save time if we avoid Park Street.\",\n",
       "  'Ще спестим време ако избегнем Park Street.'),\n",
       " ('I heard it, too.', 'Аз също го чух.'),\n",
       " ('I have some things to take care of.',\n",
       "  'Има някои неща, за които трябва да се погрижа.'),\n",
       " (\"What's in it for us?\", 'На нас каква ни е ползата от това?'),\n",
       " (\"I'll sue you.\", 'Ще те съдя.'),\n",
       " (\"No matter what you say, I won't give up.\",\n",
       "  'Каквото и да кажете, няма да се откажа.'),\n",
       " (\"I'm crazy about football.\", 'Луд съм по футбола.'),\n",
       " ('You must be careful.', 'Трябва да бъдеш внимателен.')]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "items=load_corpus(f\"{prefix}/en_Bulgarian/bul-eng/bul.txt\")\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-26T17:03:35.982317Z",
     "start_time": "2019-08-26T17:03:35.864358Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(\"You're much faster than I am.\", 'Είσαι πολύ γρηγορότερος από μένα.'),\n",
       " ('Do what you like.', 'Κάνε ό, τι θες.'),\n",
       " ('No, thank you.', 'Όχι, ευχαριστώ.'),\n",
       " ('I like chocolate.', 'Μου αρέσει η σοκολάτα.'),\n",
       " ('Are you crazy?', 'Είσαι τρελός;'),\n",
       " ('Where did you put my book?', 'Που έβαλες το βιβλίο μου;'),\n",
       " ('Tom is afraid of the dark.', 'Ο Τομ φοβάται το σκοτάδι.'),\n",
       " ('Unbelievable!', 'Απίστευτο!'),\n",
       " ('I wonder which way is faster.',\n",
       "  'Αναρωτιέμαι ποιος τρόπος είναι γρηγορότερος.'),\n",
       " ('They are singers.', 'Είναι τραγουδίστριες.')]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "items=load_corpus(f\"{prefix}/en_Greek/ell-eng/ell.txt\")\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-26T17:05:14.274923Z",
     "start_time": "2019-08-26T17:05:12.930755Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('You should always spend time doing things that help your children get ahead in life.',\n",
       "  'Siempre deberías ocupar tiempo en hacer cosas que les ayuden a tus hijos a salir adelante en la vida.'),\n",
       " ('I know what Tom was doing.', 'Sé lo que Tomás estaba haciendo.'),\n",
       " ('He felt her hand on his shoulder.', 'Él sintió su mano sobre su hombro.'),\n",
       " (\"I'll be there shortly.\", 'Estaré allí pronto.'),\n",
       " ('She is playing with a doll.', 'Ella está jugando con una muñeca.'),\n",
       " ('My sister likes melons and so do I.',\n",
       "  'A mi hermana le gustan los melones, y a mí también.'),\n",
       " ('I feel very comfortable with you.', 'Me siento muy cómoda con vos.'),\n",
       " (\"I'm not disorganized.\", 'No soy desorganizado.'),\n",
       " ('I want this.', 'Quiero este.'),\n",
       " (\"I can't explain it.\", 'No lo puedo explicar.')]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "items=load_corpus(f\"{prefix}/spa-eng-2019/spa.txt\")\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-26T17:05:52.680347Z",
     "start_time": "2019-08-26T17:05:50.951653Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(\"Tom doesn't think that Mary's performance was very good.\",\n",
       "  'Tom considérait la performance de Marie comme très mauvaise.'),\n",
       " ('My phone rang again.', 'Mon téléphone a sonné à nouveau.'),\n",
       " ('You can work faster than that.',\n",
       "  'Vous pouvez travailler plus vite que cela.'),\n",
       " (\"I've just finished dinner.\", 'Je vient de finir mon dîner.'),\n",
       " (\"We don't have a moment to lose.\", \"On n'a pas un instant à perdre.\"),\n",
       " (\"It's clear from his actions that he loves her.\",\n",
       "  \"Il est clair, d'après ses actions, qu'il l'aime.\"),\n",
       " ('I have an account at that book shop.',\n",
       "  \"J'ai un compte ouvert dans cette librairie.\"),\n",
       " ('We have to be careful with expenses.',\n",
       "  'Il nous faut faire attention à nos dépenses.'),\n",
       " ('To our surprise, she has gone to Brazil alone.',\n",
       "  'À notre surprise, elle est allée seule au Brésil.'),\n",
       " (\"I'm going to tell you a secret.\", 'Je vais vous dire un secret.')]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "items=load_corpus(f\"{prefix}/fra-eng-2019/fra.txt\")\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-26T17:06:39.100380Z",
     "start_time": "2019-08-26T17:06:35.744842Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('There are many craters on the moon.', 'На Луне много кратеров.'),\n",
       " (\"I don't think Tom would agree with you.\",\n",
       "  'Не думаю, что Том согласился бы с вами.'),\n",
       " ('When do you run?', 'Когда ты бежишь?'),\n",
       " ('The other day I visited the museum.', 'Недавно я был в музее.'),\n",
       " ('The ocean was calm.', 'Океан был тихим.'),\n",
       " (\"Tom won't be able to do that that soon.\",\n",
       "  'Том не сможет так скоро это сделать.'),\n",
       " ('I admit nothing.', 'Я ничего не признаю.'),\n",
       " (\"I don't care what you wear.\", 'Мне всё равно, что ты носишь.'),\n",
       " (\"I'm not gullible.\", 'Я не доверчив.'),\n",
       " ('City life has advantages and disadvantages.',\n",
       "  'Жизнь в большом городе имеет свои преимущества и недостатки.')]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "items=load_corpus(f\"{prefix}/rus-eng/rus.txt\")\n",
    "rows=take_samples(items)\n",
    "rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-03T16:59:04.764196Z",
     "start_time": "2019-09-03T16:59:04.758116Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "you are a\n"
     ]
    }
   ],
   "source": [
    "def join_str(*args):    \n",
    "    text = ' '.join([str(arg[0]) if isinstance(arg, tuple) else arg for arg in args])\n",
    "    print(text)\n",
    "join_str('you', ('are',), 'a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-03T16:58:30.621701Z",
     "start_time": "2019-09-03T16:58:30.612799Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'are'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=('are',)\n",
    "isinstance(x, tuple)\n",
    "x[0]"
   ]
  }
 ],
 "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.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
