{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import os\n", "from easynmt import EasyNMT\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "URL_BASE = \"https://arxiv.org/pdf/\"\n", "PDF_PATH = 'PDF'\n", "TXT_PATH= 'TXT'\n", "CSV_PATH = 'CSV'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get Data from TXT" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = pd.read_json('ARxiv/arxiv-metadata-oai-snapshot.json',lines=True, chunksize=2001,dtype={'id':'str'})\n", "df = None\n", "for i in data:\n", " df = i \n", " print(type(i))\n", " break\n", "df = df[['id','title','abstract']]\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for file in df['id']:\n", " file_path = TXT_PATH+'/'+str(file)+'.pdf.txt'\n", " if os.path.isfile(file_path):\n", " with open(file_path,'r',encoding='utf8') as f:\n", " s =str( f.read()) \n", " df.loc[df['id'] == str(file),'full_text'] = s " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = df.dropna()\n", "df.reset_index()\n", "df.to_csv(CSV_PATH+'/scientific_paper_en.csv',index=False,encoding='utf-8')\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# first run \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(CSV_PATH +'/scientific_paper_en.csv',dtype={'id':'str'})\n", "df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# leer datos" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(CSV_PATH +'/scientific_paper_full_text_translated.csv',dtype={'id':'str'})\n", "print(len(df.index))\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# translate" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model = EasyNMT('opus-mt')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## translate full text" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "max = len(df.index)\n", "for i in range(0,1754):\n", " text = df.iloc[i]['full_text']\n", " translated_text = model.translate(text, target_lang='es')\n", " df.loc[i,'translated'] = translated_text \n", " print(\"listo documento \",i)\n", " if(i%10==0):\n", " df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')\n", "df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## translate abstract" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "max = len(df.index)\n", "for i in range(0,1754):\n", " text = df.iloc[i]['abstract']\n", " translated_text = model.translate(text, target_lang='es')\n", " df.loc[i,'translated_abstract'] = translated_text \n", " print(\"listo documento \",i)\n", " if(i%100==0):\n", " df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')\n", "df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# remove abstract" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "max = len(df.index)-1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "end = 'Introducción'\n", "for i in range(0,max):\n", " text = df.iloc[i]['translated'] \n", " p = text.find(end)\n", " if(p != -1): \n", " df.loc[i,'translated_no_abstract'] = text[p:] \n", " else:\n", " df.loc[i,'translated_no_abstract']= text\n", " print(\"listo documento \",i,p)\n", " if(i%1000==0):\n", " df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')\n", "df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "end = 'Abstract'\n", "for i in range(0,max):\n", " text = df.iloc[i]['full_text'] \n", " p = text.find(end)\n", " if(p != -1): \n", " df.loc[i,'text_no_abstract'] = text[p:] \n", " else:\n", " df.loc[i,'text_no_abstract']= text \n", " if(i%1000==0):\n", " df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')\n", "df.to_csv(CSV_PATH+'/scientific_paper_full_text_translated.csv',index=False,encoding='utf-8')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# split data to csv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(CSV_PATH +'/scientific_paper_full_text_translated.csv',dtype={'id':'str'})\n", "df" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idtitlefull_textabstracttext_no_abstract
00704.0002Sparsity-certifying Graph DecompositionsDescomposiciones del gráfico de certificación ...Describimos un nuevo algoritmo, el juego de ...Introducción y preliminares\\nEl foco de este d...
10704.0003The evolution of the Earth-Moon system based o...La evolución del sistema Tierra-Luna basado en...La evolución del sistema Tierra-Luna es desc...Introducción \\nLa teoría aceptada popularmente...
20704.0004A determinant of Stirling cycle numbers counts...Un determinante de los números de ciclo de Sti...Demostramos que un determinante de los númer...Introducción El propósito principal de este ar...
30704.0005From dyadic $\\Lambda_{\\alpha}$ to $\\Lambda_{\\a...DE DÍA A DÍA\\nWAEL ABU-SHAMMALA Y ALBERTO TORC...En este artículo mostramos cómo calcular la ...DE DÍA A DÍA\\nWAEL ABU-SHAMMALA Y ALBERTO TORC...
40704.0007Polymer Quantum Mechanics and its Continuum LimitLa mecánica cuántica de polímeros y su límite ...Una representación cuántica no estándar de l...La mecánica cuántica de polímeros y su límite ...
..................
17490704.1996A Wave-function for Stringy UniversesLPTENS–07/16\\nAbril de 2007\\nUna función de on...Definimos una función de onda para los fondo...Introducción\\nNuestro objetivo en este documen...
17500704.1997Query on Negative Temperature, Internal Intera...Microsoft Word - negEntr.doc\\nConsulta sobre t...Después de que la temperatura negativa se vu...Microsoft Word - negEntr.doc\\nConsulta sobre t...
17510704.1998Absence of the Fifth Force Problem in a Model ...Ausencia del problema de la quinta fuerza en u...Un modelo de escala invariante que contiene ...Introducción\\n\\tBase de Dos Medidas Teoría de ...
17520704.1999Dark matter caustics and the enhancement of se...Proyecto de versión 16 de noviembre de 2018\\nT...Los haloes fríos de materia oscura están pob...Proyecto de versión 16 de noviembre de 2018\\nT...
17530704.2000Search for a Higgs boson produced in associati...FERMILAB-PUB-07/076-E\\nBúsqueda de un bosón Hi...Describimos una búsqueda para el modelo está...FERMILAB-PUB-07/076-E\\nBúsqueda de un bosón Hi...
\n", "

1754 rows × 5 columns

\n", "
" ], "text/plain": [ " id title \\\n", "0 0704.0002 Sparsity-certifying Graph Decompositions \n", "1 0704.0003 The evolution of the Earth-Moon system based o... \n", "2 0704.0004 A determinant of Stirling cycle numbers counts... \n", "3 0704.0005 From dyadic $\\Lambda_{\\alpha}$ to $\\Lambda_{\\a... \n", "4 0704.0007 Polymer Quantum Mechanics and its Continuum Limit \n", "... ... ... \n", "1749 0704.1996 A Wave-function for Stringy Universes \n", "1750 0704.1997 Query on Negative Temperature, Internal Intera... \n", "1751 0704.1998 Absence of the Fifth Force Problem in a Model ... \n", "1752 0704.1999 Dark matter caustics and the enhancement of se... \n", "1753 0704.2000 Search for a Higgs boson produced in associati... \n", "\n", " full_text \\\n", "0 Descomposiciones del gráfico de certificación ... \n", "1 La evolución del sistema Tierra-Luna basado en... \n", "2 Un determinante de los números de ciclo de Sti... \n", "3 DE DÍA A DÍA\\nWAEL ABU-SHAMMALA Y ALBERTO TORC... \n", "4 La mecánica cuántica de polímeros y su límite ... \n", "... ... \n", "1749 LPTENS–07/16\\nAbril de 2007\\nUna función de on... \n", "1750 Microsoft Word - negEntr.doc\\nConsulta sobre t... \n", "1751 Ausencia del problema de la quinta fuerza en u... \n", "1752 Proyecto de versión 16 de noviembre de 2018\\nT... \n", "1753 FERMILAB-PUB-07/076-E\\nBúsqueda de un bosón Hi... \n", "\n", " abstract \\\n", "0 Describimos un nuevo algoritmo, el juego de ... \n", "1 La evolución del sistema Tierra-Luna es desc... \n", "2 Demostramos que un determinante de los númer... \n", "3 En este artículo mostramos cómo calcular la ... \n", "4 Una representación cuántica no estándar de l... \n", "... ... \n", "1749 Definimos una función de onda para los fondo... \n", "1750 Después de que la temperatura negativa se vu... \n", "1751 Un modelo de escala invariante que contiene ... \n", "1752 Los haloes fríos de materia oscura están pob... \n", "1753 Describimos una búsqueda para el modelo está... \n", "\n", " text_no_abstract \n", "0 Introducción y preliminares\\nEl foco de este d... \n", "1 Introducción \\nLa teoría aceptada popularmente... \n", "2 Introducción El propósito principal de este ar... \n", "3 DE DÍA A DÍA\\nWAEL ABU-SHAMMALA Y ALBERTO TORC... \n", "4 La mecánica cuántica de polímeros y su límite ... \n", "... ... \n", "1749 Introducción\\nNuestro objetivo en este documen... \n", "1750 Microsoft Word - negEntr.doc\\nConsulta sobre t... \n", "1751 Introducción\\n\\tBase de Dos Medidas Teoría de ... \n", "1752 Proyecto de versión 16 de noviembre de 2018\\nT... \n", "1753 FERMILAB-PUB-07/076-E\\nBúsqueda de un bosón Hi... \n", "\n", "[1754 rows x 5 columns]" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "es = df[['id','title','translated','translated_abstract','translated_no_abstract']]\n", "es.columns = [\"id\",\"title\", \"full_text\",\"abstract\",\"text_no_abstract\"]\n", "es.to_csv(CSV_PATH+'/scientific_paper_es.csv',index=False,encoding='utf-8')\n", "es" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idtitlefull_textabstracttext_no_abstract
00704.0002Sparsity-certifying Graph DecompositionsSparsity-certifying Graph Decompositions\\nIlea...We describe a new algorithm, the $(k,\\ell)$-...Introduction and preliminaries\\nThe focus of t...
10704.0003The evolution of the Earth-Moon system based o...The evolution of the Earth-Moon system based o...The evolution of Earth-Moon system is descri...Introduction \\nThe popularly accepted theory f...
20704.0004A determinant of Stirling cycle numbers counts...A Determinant of Stirling Cycle Numbers Counts...We show that a determinant of Stirling cycle...Introduction The chief purpose of this paper i...
30704.0005From dyadic $\\Lambda_{\\alpha}$ to $\\Lambda_{\\a...FROM DYADIC Λα TO Λα\\nWAEL ABU-SHAMMALA AND AL...In this paper we show how to compute the $\\L...FROM DYADIC Λα TO Λα\\nWAEL ABU-SHAMMALA AND AL...
40704.0007Polymer Quantum Mechanics and its Continuum LimitPolymer Quantum Mechanics and its Continuum Li...A rather non-standard quantum representation...Polymer Quantum Mechanics and its Continuum Li...
..................
17490704.1996A Wave-function for Stringy UniversesLPTENS–07/16\\nApril 2007\\nA Wave-function for ...We define a wave-function for string theory ...Introduction\\nOur goal in this paper is to emb...
17500704.1997Query on Negative Temperature, Internal Intera...Microsoft Word - negEntr.doc\\nQuery on Negativ...After negative temperature is restated, we f...Microsoft Word - negEntr.doc\\nQuery on Negativ...
17510704.1998Absence of the Fifth Force Problem in a Model ...Absence of the Fifth Force Problem in a Model ...A scale invariant model containing dilaton $...Introduction\\n\\tBasis of Two Measures Field Th...
17520704.1999Dark matter caustics and the enhancement of se...Draft version November 16, 2018\\nPreprint type...Cold dark matter haloes are populated by cau...Draft version November 16, 2018\\nPreprint type...
17530704.2000Search for a Higgs boson produced in associati...FERMILAB-PUB-07/076-E\\nSearch for a Higgs boso...We describe a search for the standard model ...FERMILAB-PUB-07/076-E\\nSearch for a Higgs boso...
\n", "

1754 rows × 5 columns

\n", "
" ], "text/plain": [ " id title \\\n", "0 0704.0002 Sparsity-certifying Graph Decompositions \n", "1 0704.0003 The evolution of the Earth-Moon system based o... \n", "2 0704.0004 A determinant of Stirling cycle numbers counts... \n", "3 0704.0005 From dyadic $\\Lambda_{\\alpha}$ to $\\Lambda_{\\a... \n", "4 0704.0007 Polymer Quantum Mechanics and its Continuum Limit \n", "... ... ... \n", "1749 0704.1996 A Wave-function for Stringy Universes \n", "1750 0704.1997 Query on Negative Temperature, Internal Intera... \n", "1751 0704.1998 Absence of the Fifth Force Problem in a Model ... \n", "1752 0704.1999 Dark matter caustics and the enhancement of se... \n", "1753 0704.2000 Search for a Higgs boson produced in associati... \n", "\n", " full_text \\\n", "0 Sparsity-certifying Graph Decompositions\\nIlea... \n", "1 The evolution of the Earth-Moon system based o... \n", "2 A Determinant of Stirling Cycle Numbers Counts... \n", "3 FROM DYADIC Λα TO Λα\\nWAEL ABU-SHAMMALA AND AL... \n", "4 Polymer Quantum Mechanics and its Continuum Li... \n", "... ... \n", "1749 LPTENS–07/16\\nApril 2007\\nA Wave-function for ... \n", "1750 Microsoft Word - negEntr.doc\\nQuery on Negativ... \n", "1751 Absence of the Fifth Force Problem in a Model ... \n", "1752 Draft version November 16, 2018\\nPreprint type... \n", "1753 FERMILAB-PUB-07/076-E\\nSearch for a Higgs boso... \n", "\n", " abstract \\\n", "0 We describe a new algorithm, the $(k,\\ell)$-... \n", "1 The evolution of Earth-Moon system is descri... \n", "2 We show that a determinant of Stirling cycle... \n", "3 In this paper we show how to compute the $\\L... \n", "4 A rather non-standard quantum representation... \n", "... ... \n", "1749 We define a wave-function for string theory ... \n", "1750 After negative temperature is restated, we f... \n", "1751 A scale invariant model containing dilaton $... \n", "1752 Cold dark matter haloes are populated by cau... \n", "1753 We describe a search for the standard model ... \n", "\n", " text_no_abstract \n", "0 Introduction and preliminaries\\nThe focus of t... \n", "1 Introduction \\nThe popularly accepted theory f... \n", "2 Introduction The chief purpose of this paper i... \n", "3 FROM DYADIC Λα TO Λα\\nWAEL ABU-SHAMMALA AND AL... \n", "4 Polymer Quantum Mechanics and its Continuum Li... \n", "... ... \n", "1749 Introduction\\nOur goal in this paper is to emb... \n", "1750 Microsoft Word - negEntr.doc\\nQuery on Negativ... \n", "1751 Introduction\\n\\tBasis of Two Measures Field Th... \n", "1752 Draft version November 16, 2018\\nPreprint type... \n", "1753 FERMILAB-PUB-07/076-E\\nSearch for a Higgs boso... \n", "\n", "[1754 rows x 5 columns]" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "en = df[['id','title','full_text','abstract','text_no_abstract']]\n", "en.columns = [\"id\",\"title\", \"full_text\",\"abstract\",\"text_no_abstract\"]\n", "en.to_csv(CSV_PATH+'/scientific_paper_en.csv',index=False,encoding='utf-8')\n", "en" ] } ], "metadata": { "interpreter": { "hash": "05def4d9d0834781cbeb6b95fd92421f8bd6a45e945308f90d88567f4afc1911" }, "kernelspec": { "display_name": "Python 3.8.12 ('tensorflow')", "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.9.7" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }