Skip to content

Commit 8fa04d3

Browse files
author
Kevin Barry
committed
Commit 072924
1 parent 16705a5 commit 8fa04d3

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed

part11.ipynb

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 5,
5+
"execution_count": 3,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 8,
14+
"execution_count": 4,
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
@@ -21,40 +21,74 @@
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": 17,
24+
"execution_count": 5,
2525
"metadata": {},
2626
"outputs": [
2727
{
2828
"name": "stdout",
2929
"output_type": "stream",
3030
"text": [
31-
"Python\n",
32-
"is\n",
33-
"n't\n",
34-
"just\n",
35-
"a\n",
36-
"language\n",
37-
".\n",
38-
"It\n",
39-
"'s\n",
40-
"a\n",
41-
"framework\n",
42-
"!\n"
31+
"Python PROPN\n",
32+
"is AUX\n",
33+
"n't PART\n",
34+
"just ADV\n",
35+
"a DET\n",
36+
"language NOUN\n",
37+
". PUNCT\n",
38+
"It PRON\n",
39+
"'s AUX\n",
40+
"a DET\n",
41+
"framework NOUN\n",
42+
"! PUNCT\n"
4343
]
4444
}
4545
],
4646
"source": [
4747
"doc = nlp(\"Python isn't just a language. It's a framework!\")\n",
4848
"for token in doc:\n",
49-
" print(token)"
49+
" print(token, token.pos_)"
5050
]
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": null,
54+
"execution_count": 7,
5555
"metadata": {},
56-
"outputs": [],
57-
"source": []
56+
"outputs": [
57+
{
58+
"name": "stdout",
59+
"output_type": "stream",
60+
"text": [
61+
"\n",
62+
"text lemma pos ent shape punct morph \n",
63+
"------ ------ ----- ------ ----- ----- ------------------------------\n",
64+
"Hi hi INTJ Xx False \n",
65+
", , PUNCT , True PunctType=Comm \n",
66+
"my my PRON xx False Number=Sing|Person=1|Poss=Yes|PronType=Prs\n",
67+
"name name NOUN xxxx False Number=Sing \n",
68+
"is be AUX xx False Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin\n",
69+
"Kevin Kevin PROPN PERSON Xxxxx False Number=Sing \n",
70+
". . PUNCT . True PunctType=Peri \n",
71+
"I I PRON X False Case=Nom|Number=Sing|Person=1|PronType=Prs\n",
72+
"like like VERB xxxx False Tense=Pres|VerbForm=Fin \n",
73+
"to to PART xx False \n",
74+
"write write VERB xxxx False VerbForm=Inf \n",
75+
"Python Python PROPN Xxxxx False Number=Sing \n",
76+
"\n"
77+
]
78+
}
79+
],
80+
"source": [
81+
"from wasabi import table\n",
82+
"\n",
83+
"def text_to_doctable(txt):\n",
84+
" doc = nlp(txt)\n",
85+
" header = (\"text\", \"lemma\", \"pos\", \"ent\", \"shape\", \"punct\", \"morph\")\n",
86+
" data = [(tok.text, tok.lemma_, tok.pos_, tok.ent_type_, tok.shape_, tok.is_punct, tok.morph) for tok in doc]\n",
87+
" formatted = table(data, header=header, divider=True)\n",
88+
" print(formatted)\n",
89+
"\n",
90+
"text_to_doctable(\"Hi, my name is Kevin. I like to write Python\")"
91+
]
5892
}
5993
],
6094
"metadata": {

0 commit comments

Comments
 (0)