HSG-MCS-HS21_Julia/Problemsets/PS09c_WarAndPeace.ipynb

133 lines
2.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using Downloads"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Download a Book from Internet\n",
"\n",
"and read it into a string in Julia. Then report the number of letters etc (see below)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"File to download: http://www.gutenberg.org/files/2600/2600-0.txt\n",
"\n",
"check the subfolder Results\n",
"\n"
]
}
],
"source": [
"if !isdir(\"Results\")\n",
" error(\"create the subfolder Results before running this program\")\n",
"end\n",
"\n",
"http = \"http://www.gutenberg.org/files/2600/2600-0.txt\"\n",
"\n",
"println(\"File to download: \",http)\n",
"Downloads.download(http,\"Results/WarAndPeace.txt\")\n",
"\n",
"println(\"\\ncheck the subfolder Results\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"fh = open(\"Results/WarAndPeace.txt\")\n",
"str = read(fh,String) \n",
"close(fh)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Task 1\n",
"\n",
"1. Count the number of letters and the unique letters in `str`. Hint: `length() and `unique()`\n",
"\n",
"2. Count the number of word and lines. Hint: `split(str)` and `split(str,\"\\n\")`\n",
"\n",
"3. Count the number of unique words."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Task 2\n",
"\n",
"1. How often is Borodinó mentioned. Hint: `occursin.(,words)`\n",
"\n",
"2. Print all lines that contain the word Borodinó. Hint: `occursin(,line)`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Task 3\n",
"\n",
"1. Change Borodinó everywhere to Berëzina and then count the occurances"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"anaconda-cloud": {},
"kernel_info": {
"name": "julia-1.2"
},
"kernelspec": {
"display_name": "Julia 1.6.3",
"language": "julia",
"name": "julia-1.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.6.3"
},
"nteract": {
"version": "0.24.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}