Skip to content

Instantly share code, notes, and snippets.

@reflash
Created February 13, 2019 08:43
Show Gist options
  • Save reflash/0d7d8f4fc51fdf79c99285ab928e10b9 to your computer and use it in GitHub Desktop.
Save reflash/0d7d8f4fc51fdf79c99285ab928e10b9 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting textstat\n",
" Downloading https://files.pythonhosted.org/packages/9b/78/a050fa0f13c04db10c891167204e2cd0c0ae1be40842a10eaf5348360f94/textstat-0.5.4.tar.gz\n",
"Collecting pyphen (from textstat)\n",
" Downloading https://files.pythonhosted.org/packages/15/82/08a3629dce8d1f3d91db843bb36d4d7db6b6269d5067259613a0d5c8a9db/Pyphen-0.9.5-py2.py3-none-any.whl (3.0MB)\n",
"Collecting repoze.lru (from textstat)\n",
" Downloading https://files.pythonhosted.org/packages/b0/30/6cc0c95f0b59ad4b3b9163bff7cdcf793cc96fac64cf398ff26271f5cf5e/repoze.lru-0.7-py3-none-any.whl\n",
"Installing collected packages: pyphen, repoze.lru, textstat\n",
" Running setup.py install for textstat: started\n",
" Running setup.py install for textstat: finished with status 'done'\n",
"Successfully installed pyphen-0.9.5 repoze.lru-0.7 textstat-0.5.4\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"You are using pip version 18.1, however version 19.0.1 is available.\n",
"You should consider upgrading via the 'python -m pip install --upgrade pip' command.\n"
]
}
],
"source": [
"import sys\n",
"!{sys.executable} -m pip install textstat"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import textstat"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"text = \"\"\"\n",
"Venezuelan opposition leader Juan Guaidó has vowed at a rally in the capital Caracas to ensure humanitarian aid blocked by President Nicolás Maduro is brought in to the country.\n",
"Mr Guaidó said new collection points and routes into the country would allow volunteers to bring the aid in.\n",
"Mr Maduro told the BBC he would not allow aid in, claiming it was a means for the US to intervene in Venezuela.\n",
"Venezuelans are facing drastic food shortages amid an economic crisis.\n",
"\"We have almost 300,000 Venezuelans who will die if the aid doesn't enter. There are almost two million at health risk,\" said Mr Guaidó at the rally on Tuesday.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"66.07"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"textstat.flesch_reading_ease(text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"| Score | School level | Notes |\n",
"|:--------:|:----------:|:---------------- | \n",
"| 100.00-90.00 | 5th grade | Very easy to read. Easily understood by an average 11-year-old student.| \n",
"|90.0–80.0 |6th grade |Easy to read. Conversational English for consumers. |\n",
"|80.0–70.0 |7th grade |Fairly easy to read. |\n",
"|70.0–60.0 |8th & 9th grade |Plain English. Easily understood by 13- to 15-year-old students. |\n",
"|60.0–50.0 |10th to 12th grade |Fairly difficult to read. |\n",
"|50.0–30.0 |College |Difficult to read. |\n",
"|30.0–0.0 |College graduate |Very difficult to read. Best understood by university graduates. |"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.4"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"textstat.smog_index(text) # the output is grade level"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"|Total Polysyllabic Word Count|Approximate Grade Level (+1.5 Grades)|\n",
"|:--------:|:----------:| \n",
"| 1 - 6| 5 |\n",
"| 7 - 12| 6 |\n",
"| 13 - 20| 7 |\n",
"| 21 - 30| 8 |\n",
"| 31 - 42| 9 |\n",
"| 43 - 56| 10 |\n",
"| 57 - 72| 11 |\n",
"| 73 - 90| 12|\n",
"| 91 - 110| 13|\n",
"| 111 - 132| 14|\n",
"| 133 - 156| 15|\n",
"| 157 - 182| 16|\n",
"| 183 - 210| 17|\n",
"| 211 - 240| 18|"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment