Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

preprocess_arxiv.py 2.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  1. ##############################################################################################
  2. ############ Cleaning and Preprocessing the arXiv publications related to COVID-19 ###########
  3. ##############################################################################################
  4. # The publications' data were collected from arXiv webpage (https://arxiv.org/covid19search)
  5. # related to COVID-19.
  6. ########################################################################
  7. # Uncomment to install the library.
  8. # %pip install pylatexenc
  9. ########################################################################
  10. ########################################################################
  11. # Importing the required libraries.
  12. import re, numpy as np
  13. from pylatexenc.latex2text import LatexNodes2Text
  14. from datetime import datetime
  15. from preprocess import Preprocess
  16. ########################################################################
  17. class ProcessArxiv(Preprocess):
  18. # Cleaning and preprocessing the dataframe.
  19. def _preprocess(self):
  20. # Defining the "None" value for the "NaN" values.
  21. self._dataframe.replace({np.nan: None}, inplace=True)
  22. # Normalizing the feature "id".
  23. self._dataframe.id = self._dataframe.id.apply(lambda x: x.replace("arXiv:", "").strip())
  24. # Normalizing the feature "subject_areas".
  25. self._dataframe.subject_areas = self._dataframe.subject_areas.apply(lambda x: tuple(eval(x)))
  26. # Normalizing the features "title" and "abstract".
  27. self._dataframe.loc[:, ["title", "abstract"]] = self._dataframe.loc[:, ["title", "abstract"]
  28. ].apply(lambda x: x.apply(lambda y: re.sub("/r/", "",
  29. re.sub("@PER@CENT@", "%", re.sub(r"[\^_]", "",
  30. LatexNodes2Text().latex_to_text(re.sub(r"\s+", " ",
  31. re.sub(r"\\?%", "@PER@CENT@", y))).strip())))))
  32. # Normalizing the feature "authors".
  33. self._dataframe.authors = [tuple([{"name": author} for author in eval(authors)])
  34. for authors in self._dataframe.authors]
  35. # Normalizing the feature "date".
  36. self._dataframe.date = self._dataframe.date.apply(lambda x: re.sub(
  37. r"\s+", " ", x.split(".")[0]))
  38. self._dataframe.date = self._dataframe.date.apply(lambda x: x.replace("submitted ", ""))
  39. # Creating the feature "publication_date" from the feature "date".
  40. self._dataframe["publication_date"] = self._dataframe.date.apply(
  41. lambda x: datetime.strptime(x.split(";")[0].strip(), "%d %B, %Y").date())
  42. # Removing unnecessary columns.
  43. self._dataframe.drop(axis=1, columns="date", inplace=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...