Datasets:

License:
MotzWanted commited on
Commit
7bf19f4
·
1 Parent(s): 412c50c

Update medwiki.py

Browse files
Files changed (1) hide show
  1. medwiki.py +17 -1
medwiki.py CHANGED
@@ -99,6 +99,22 @@ class MedWikipediaCorpusGenerator(datasets.GeneratorBasedBuilder):
99
  )
100
  ]
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  def _generate_examples(self, output_dir: str):
103
  logger.info("generating examples from = %s", output_dir)
104
  paths = [
@@ -118,4 +134,4 @@ class MedWikipediaCorpusGenerator(datasets.GeneratorBasedBuilder):
118
  # the first line is the title
119
  title = f.readline()
120
  text = f.read()
121
- yield i, {"document.text": text, "document.idx": i, "document.title": title}
 
99
  )
100
  ]
101
 
102
+ @staticmethod
103
+ _clean_text(text)-> str:
104
+ text = text.lower()
105
+ # remove "\u" followed by 4 characters
106
+ text = re.sub(r"\\u[0-9a-fA-F]{4}", "", text)
107
+ # remove scientific citations (e.g. (Smith, J. et al., 2014) )
108
+ text = re.sub(r"\((?:[\w \.&]+\, )+[0-9]{4}\)", "", text)
109
+ # remove figure and table references (e.g. (figure 7\xe2\x80\x9377) )
110
+ text = re.sub(r"\s*\(\s*(?:table|figure)[^()]*\)", "", text)
111
+ # remove hex characters (e.g. \xe2\x80\x94\xe2\x80\x89)
112
+ text = re.sub(r"[^\x00-\x7f]+", " ", text)
113
+ text = re.sub(r"[\n\r\t]+", " ", text)
114
+ text = re.sub(r"([^a-zA-Z0-9\.])", " ", text)
115
+
116
+ return text
117
+
118
  def _generate_examples(self, output_dir: str):
119
  logger.info("generating examples from = %s", output_dir)
120
  paths = [
 
134
  # the first line is the title
135
  title = f.readline()
136
  text = f.read()
137
+ yield i, {"document.text": self._clean_text(text), "document.idx": i, "document.title": self._clean_text(title)}