Compare commits
2 Commits
600536794d
...
8752b6225c
Author | SHA1 | Date | |
---|---|---|---|
8752b6225c | |||
f3e8c366d5 |
|
@ -12,7 +12,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -20,7 +20,10 @@
|
||||||
"data_path = this_dir_path / \"Data\"\n",
|
"data_path = this_dir_path / \"Data\"\n",
|
||||||
"verb_path = data_path / \"PVC\" / \"Data\" / \"TXT\" / \"verb.txt\"\n",
|
"verb_path = data_path / \"PVC\" / \"Data\" / \"TXT\" / \"verb.txt\"\n",
|
||||||
"processed_past_verb_path = data_path / \"verbs_past_PVC.json\"\n",
|
"processed_past_verb_path = data_path / \"verbs_past_PVC.json\"\n",
|
||||||
"processed_present_verb_path = data_path / \"verbs_present_PVC.json\""
|
"processed_present_verb_path = data_path / \"verbs_present_PVC.json\"\n",
|
||||||
|
"\n",
|
||||||
|
"# You can download the PVC data from https://www.peykaregan.ir/dataset/%D9%85%D8%AC%D9%85%D9%88%D8%B9%D9%87-%D8%A7%D9%81%D8%B9%D8%A7%D9%84-%D8%AA%D8%B5%D8%B1%DB%8C%D9%81%E2%80%8C%D8%B4%D8%AF%D9%87-%D9%81%D8%A7%D8%B1%D8%B3%DB%8C\n",
|
||||||
|
"# After downloading, unzip the data and place it in a directory called Data."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,19 +2,20 @@
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": 39,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import requests\n",
|
"import requests\n",
|
||||||
"from bs4 import BeautifulSoup\n",
|
"from bs4 import BeautifulSoup\n",
|
||||||
"from pathlib import Path\n",
|
"from pathlib import Path\n",
|
||||||
"from tqdm import tqdm"
|
"from tqdm import tqdm\n",
|
||||||
|
"import json"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 3,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -27,7 +28,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -57,19 +58,19 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 16,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stderr",
|
"name": "stderr",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"100%|██████████| 4167/4167 [00:22<00:00, 186.02it/s]\n"
|
"100%|██████████| 4167/4167 [00:33<00:00, 122.76it/s]\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"result = {}\n",
|
"results = []\n",
|
||||||
"\n",
|
"\n",
|
||||||
"for verb in tqdm(verbs):\n",
|
"for verb in tqdm(verbs):\n",
|
||||||
" with open(htmls_path / (verb + \".html\"), \"r\") as f:\n",
|
" with open(htmls_path / (verb + \".html\"), \"r\") as f:\n",
|
||||||
|
@ -80,10 +81,27 @@
|
||||||
" past_stem = stems[0].text\n",
|
" past_stem = stems[0].text\n",
|
||||||
" present_stem = stems[1].text\n",
|
" present_stem = stems[1].text\n",
|
||||||
"\n",
|
"\n",
|
||||||
" result[verb] = {}\n",
|
" structures = soup.select(\"div.section-wrapper.more-examples\")\n",
|
||||||
"\n",
|
" for structure in structures:\n",
|
||||||
" result[verb][\"past_stem\"] = past_stem\n",
|
" examples = structure.findAll(\"div\", {\"class\": \"example\"})\n",
|
||||||
" result[verb][\"present_stem\"] = present_stem"
|
" for example in examples:\n",
|
||||||
|
" result = {}\n",
|
||||||
|
" result[\"verb\"] = verb\n",
|
||||||
|
" result[\"past_stem\"] = past_stem\n",
|
||||||
|
" result[\"present_stem\"] = present_stem\n",
|
||||||
|
" result[\"structure\"] = str(structure.findAll(\"div\", {\"class\": \"valency\"})[0])\n",
|
||||||
|
" result[\"text\"] = example.text\n",
|
||||||
|
" results.append(result)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 59,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"with open(output_verb_path, \"w\", encoding=\"utf-8\") as f:\n",
|
||||||
|
" json.dump(results, f, ensure_ascii=False, indent=4)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user