2018-07-19 17:49:00 +02:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2018-07-19 17:53:16 +02:00
|
|
|
"%matplotlib ipympl"
|
2018-07-19 17:49:00 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"# Count emoji occurences"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
2018-07-19 17:53:16 +02:00
|
|
|
"outputs": [],
|
2018-07-19 17:49:00 +02:00
|
|
|
"source": [
|
|
|
|
"import numpy as np\n",
|
|
|
|
"import json\n",
|
|
|
|
"import glob\n",
|
|
|
|
"import matplotlib\n",
|
|
|
|
"import matplotlib.pyplot as plt\n",
|
2018-07-20 11:30:28 +02:00
|
|
|
"from __future__ import unicode_literals\n"
|
2018-07-19 17:49:00 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2018-07-20 11:30:28 +02:00
|
|
|
"json_root = \"./emoji_counts/\""
|
2018-07-19 17:49:00 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"json_files = sorted(glob.glob(json_root + \"/*.json\"))"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
2018-07-20 11:30:28 +02:00
|
|
|
"outputs": [],
|
2018-07-19 17:49:00 +02:00
|
|
|
"source": [
|
|
|
|
"json_files"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"json_lists = []"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"for path in json_files:\n",
|
|
|
|
" with open(path) as f:\n",
|
|
|
|
" data = json.load(f)\n",
|
|
|
|
" json_lists.append(data)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"merged_dict = {}\n"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"for j in json_lists:\n",
|
|
|
|
" for emoji in j.keys():\n",
|
|
|
|
" if emoji in merged_dict:\n",
|
|
|
|
" merged_dict[emoji] = merged_dict[emoji] + j[emoji]\n",
|
|
|
|
" else:\n",
|
|
|
|
" merged_dict[emoji] = j[emoji]"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2018-07-20 11:30:28 +02:00
|
|
|
"n_top = 50"
|
2018-07-19 17:49:00 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"keysort = np.argsort(list(merged_dict.values()))[-n_top:]"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2018-07-20 11:30:28 +02:00
|
|
|
"execution_count": null,
|
2018-07-19 17:49:00 +02:00
|
|
|
"metadata": {},
|
2018-07-20 11:30:28 +02:00
|
|
|
"outputs": [],
|
2018-07-19 17:49:00 +02:00
|
|
|
"source": [
|
2018-07-20 11:30:28 +02:00
|
|
|
"matplotlib.rc('font', family='EmojiOne Color')\n",
|
|
|
|
"plt.figure(figsize=(10,5))\n",
|
2018-07-19 17:49:00 +02:00
|
|
|
"plt.bar(np.array(list(merged_dict.keys()))[keysort], np.array(list(merged_dict.values()))[keysort], color='g')\n",
|
|
|
|
"plt.savefig(\"histogram.png\", bbox_inches='tight')\n",
|
|
|
|
"plt.show()"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"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.6.5"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 2
|
|
|
|
}
|