Skip to content

Commit

Permalink
Merge pull request #10 from tmu-nlp/tomoki
Browse files Browse the repository at this point in the history
testcommit
  • Loading branch information
numauo authored Apr 20, 2024
2 parents 39a2008 + 19d284b commit 621e2a7
Show file tree
Hide file tree
Showing 10 changed files with 493 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tomoki/chapter01/knock00.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "8eb58b71",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (Temp/ipykernel_12420/270510482.py, line 2)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"C:\\Users\\81807\\AppData\\Local\\Temp/ipykernel_12420/270510482.py\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m $ git clone https://github.com/tmu-nlp/100knock2024.git\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"#No0(文字列の逆順)\n",
"$ git clone https://github.com/tmu-nlp/100knock2024.git\n",
"s=\"stressed\"\n",
"s_reversed=s[::-1]\n",
"print(s_reversed)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
38 changes: 38 additions & 0 deletions tomoki/chapter01/knock01.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "5f253e2f",
"metadata": {},
"outputs": [],
"source": [
"#No1(「パタトクカシー」)\n",
"word=\"パタトクカシー\"\n",
"answer=word[::2]\n",
"print(answer)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
39 changes: 39 additions & 0 deletions tomoki/chapter01/knock02.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "6621d739",
"metadata": {},
"outputs": [],
"source": [
"#No2(「パトカー」+「タクシー」=「パタトクカシーー」)\n",
"answer = \"\"\n",
"for i in range(0,4):\n",
" answer += \"パトカー\"[i] + \"タクシー\"[i]\n",
"print(answer)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
44 changes: 44 additions & 0 deletions tomoki/chapter01/knock03.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "28967523",
"metadata": {},
"outputs": [],
"source": [
"#No3(円周率)\n",
"sentence=\"Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.\"\n",
"k={\",\":None,\".\":None}\n",
"l=str.maketrans(k)\n",
"sentence2=sentence.translate(l)\n",
"Pi=sentence2.split()\n",
"list=[]\n",
"for i in Pi:\n",
" list.append(len(i))\n",
"print(list)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
44 changes: 44 additions & 0 deletions tomoki/chapter01/knock04.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "b76dbf8f",
"metadata": {},
"outputs": [],
"source": [
"#No4(元素記号)\n",
"sentence=\"Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can.\"\n",
"num=[1,5,6,7,8,9,15,16,19]\n",
"element_dict={}\n",
"for i, j in enumerate(sentence.split(),1):\n",
" if i in num:\n",
" element_dict[j[0]]=i\n",
" else:\n",
" element_dict[j[0:2]]=i\n",
"print(element_dict)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
62 changes: 62 additions & 0 deletions tomoki/chapter01/knock05.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "b18c669a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[['I', 'am'], ['am', 'an'], ['an', 'NLPer'], ['NLPer']]\n",
"['I ', ' a', 'am', 'm ', ' a', 'an', 'n ', ' N', 'NL', 'LP', 'Pe', 'er', 'r']\n"
]
}
],
"source": [
"#No05(n-gram)\n",
"sentence='I am an NLPer'\n",
"\n",
"def ngram(S,n):\n",
" list=[]\n",
" #ngramを作成する時、繰り返し回数は必ずlen(S)以下になる。\n",
" for i in range(len(S)):\n",
" try:\n",
" list.append(S[i:i+n])\n",
" \n",
" # list out of range(余分な繰り返し)はNoneにする。 \n",
" except IndexError:\n",
" None\n",
" return list\n",
" \n",
"print(ngram(sentence.split(),2))\n",
"print(ngram(sentence,2))\n",
"\n",
"#n-gram 任意の文字数(単語数)で文章を分割する手法のこと"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
74 changes: 74 additions & 0 deletions tomoki/chapter01/knock06.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "53c3fd9e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'di', 'ar', 'ap', 'se', 'is', 'e', 'ra', 'ad', 'pa'}\n",
"{'ar', 'ap', 'ph', 'h', 'gr', 'ra', 'ag', 'pa'}\n",
"{'di', 'ar', 'ap', 'ph', 'h', 'se', 'is', 'e', 'gr', 'ra', 'ag', 'ad', 'pa'}\n",
"{'ar', 'ap', 'pa', 'ra'}\n",
"{'di', 'se', 'is', 'e', 'ad'}\n",
"Xにreが含まれる\n"
]
}
],
"source": [
"#NO6(集合)\n",
"sentence='paraparaparadise'\n",
"sentence2=\"paragraph\"\n",
"\n",
"def ngram(S,n):\n",
" list=[]\n",
" for i in range(len(S)):\n",
" try:\n",
" list.append(S[i:i+n])\n",
" \n",
" except IndexError:\n",
" None\n",
" return list\n",
" \n",
"X=set(ngram(sentence,2))\n",
"Y=set(ngram(sentence2,2))\n",
"\n",
"print(X)\n",
"print(Y)\n",
"print(X.union(Y))\n",
"print(X.intersection(Y))\n",
"print(X.difference(Y))\n",
"\n",
"if \"se\" in X:\n",
" print(\"Xにreが含まれる\")\n",
"if \"se\" in Y:\n",
" print(\"Yにreが含まれる\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
38 changes: 38 additions & 0 deletions tomoki/chapter01/knock07.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "7f176f90",
"metadata": {},
"outputs": [],
"source": [
"#No07(テンプレートによる文作成)\n",
"def template(x,y,z):\n",
" print(str(x)+\"時の\"+y+\"\"+str(z))\n",
"template(12,\"気温\",22.4)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 621e2a7

Please sign in to comment.