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_biorxiv.py 3.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  1. ##############################################################################################
  2. ########### Cleaning and Preprocessing the bioRxiv publications related to COVID-19 ##########
  3. ##############################################################################################
  4. # The publications' data were collected from bioRxiv webpage
  5. # (https://connect.biorxiv.org/relate/content/181) 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 preprocess import Preprocess
  15. ########################################################################
  16. class ProcessBiorxiv(Preprocess):
  17. # Cleaning and preprocessing the dataframe.
  18. def _preprocess(self):
  19. # Removing unnecessary columns.
  20. self._dataframe.drop(axis=1, columns="rel_num_authors", inplace=True)
  21. # Renaming the columns.
  22. columns = {"rel_title": "title", "rel_doi": "doi", "rel_link": "id", "rel_abs": "abstract",
  23. "rel_authors": "author_affil", "rel_date": "publication_date", "rel_site": "source"}
  24. self._dataframe.rename(columns=columns, inplace=True)
  25. # Normalizing the feature "id".
  26. self._dataframe.id = self._dataframe.id.apply(lambda x: x.split("/")[-1])
  27. # Normalizing the features "title" and "abstract".
  28. self._dataframe.loc[:, ["title", "abstract"]] = self._dataframe.loc[:, ["title", "abstract"]
  29. ].apply(lambda x: x.apply(lambda y: re.sub("/r/", "",
  30. re.sub("@PER@CENT@", "%", re.sub(r"\^", "",
  31. LatexNodes2Text().latex_to_text(re.sub(r"\s+", " ", re.sub("\\\\?%", "@PER@CENT@",
  32. re.sub(r"\\href\{(.+)\}\{(.+)\}", "\g<2> \\url{\g<1>}", y))).strip()))))))
  33. # Changing the type of feature "author_affil".
  34. self._dataframe.author_affil = self._dataframe.author_affil.apply(eval)
  35. # Normalizing the feature "author_affil".
  36. self._dataframe.author_affil = [
  37. [{"name": re.sub(r"\s+", " ", LatexNodes2Text().latex_to_text(
  38. re.sub(r"^\"(.+)\"$", "\g<1>", re.sub("^-\s", "", author["author_name"])))),
  39. "affiliation": re.sub(r"\s+", " ", LatexNodes2Text().latex_to_text(
  40. re.sub(r"^\"(.+)\"$", "\g<1>", re.sub("Affiliation:", "",
  41. re.sub(r"[0-9]+\.\s", "", author["author_inst"]), flags=re.IGNORECASE))))}
  42. for author in authors] if len(authors) > 0 else None
  43. for authors in self._dataframe.author_affil]
  44. # Removing the invalid authors and affiliations.
  45. invalid_authors = ["Revision Created", "Revision Converted", "Newly Submitted Revision",
  46. "Final Decision"]
  47. for idx, authors in self._dataframe.author_affil.iteritems():
  48. if authors:
  49. for author in list(authors):
  50. if author["name"].strip() in invalid_authors:
  51. authors.remove(author)
  52. elif not author["affiliation"] or author["affiliation"].lower().replace(
  53. ".", "") == "none":
  54. author["affiliation"] = None
  55. self._dataframe.author_affil[idx] = tuple(authors)
  56. # Defining the "None" value for the "NaN" values.
  57. self._dataframe.replace(
  58. {np.nan: None, "none": None, "none.": None, "None": None}, inplace=True)
Tip!

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

Comments

Loading...