Compare commits

..

No commits in common. "8752b6225ce75a5cd5f87404f29105dbc874b91a" and "600536794db347c29e86e2c865d6936c95d2d414" have entirely different histories.

2 changed files with 13 additions and 34 deletions

View File

@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@ -20,10 +20,7 @@
"data_path = this_dir_path / \"Data\"\n",
"verb_path = data_path / \"PVC\" / \"Data\" / \"TXT\" / \"verb.txt\"\n",
"processed_past_verb_path = data_path / \"verbs_past_PVC.json\"\n",
"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."
"processed_present_verb_path = data_path / \"verbs_present_PVC.json\""
]
},
{

View File

@ -2,20 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from bs4 import BeautifulSoup\n",
"from pathlib import Path\n",
"from tqdm import tqdm\n",
"import json"
"from tqdm import tqdm"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -28,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@ -58,19 +57,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 4167/4167 [00:33<00:00, 122.76it/s]\n"
"100%|██████████| 4167/4167 [00:22<00:00, 186.02it/s]\n"
]
}
],
"source": [
"results = []\n",
"result = {}\n",
"\n",
"for verb in tqdm(verbs):\n",
" with open(htmls_path / (verb + \".html\"), \"r\") as f:\n",
@ -81,27 +80,10 @@
" past_stem = stems[0].text\n",
" present_stem = stems[1].text\n",
"\n",
" structures = soup.select(\"div.section-wrapper.more-examples\")\n",
" for structure in structures:\n",
" examples = structure.findAll(\"div\", {\"class\": \"example\"})\n",
" 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)"
" result[verb] = {}\n",
"\n",
" result[verb][\"past_stem\"] = past_stem\n",
" result[verb][\"present_stem\"] = present_stem"
]
},
{