qanastek commited on
Commit
67a185d
1 Parent(s): e25c52f

Update PxCorpus.py

Browse files
Files changed (1) hide show
  1. PxCorpus.py +37 -2
PxCorpus.py CHANGED
@@ -36,8 +36,35 @@ of 55 participants (38% non-experts, 25% doctors, 36% medical practitioners), ma
36
 
37
  _URL = "https://zenodo.org/record/6524162/files/pxslu.zip?download=1"
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  class PxCorpus(datasets.GeneratorBasedBuilder):
40
 
 
 
41
  BUILDER_CONFIGS = [
42
  datasets.BuilderConfig(name=f"default", version="1.0.0", description=f"PxCorpus data"),
43
  ]
@@ -59,6 +86,11 @@ class PxCorpus(datasets.GeneratorBasedBuilder):
59
  names=['O', 'B-A', 'B-cma_event', 'B-d_dos_form', 'B-d_dos_form_ext', 'B-d_dos_up', 'B-d_dos_val', 'B-dos_cond', 'B-dos_uf', 'B-dos_val', 'B-drug', 'B-dur_ut', 'B-dur_val', 'B-fasting', 'B-freq_days', 'B-freq_int_v1', 'B-freq_int_v1_ut', 'B-freq_int_v2', 'B-freq_int_v2_ut', 'B-freq_startday', 'B-freq_ut', 'B-freq_val', 'B-inn', 'B-max_unit_uf', 'B-max_unit_ut', 'B-max_unit_val', 'B-min_gap_ut', 'B-min_gap_val', 'B-qsp_ut', 'B-qsp_val', 'B-re_ut', 'B-re_val', 'B-rhythm_hour', 'B-rhythm_perday', 'B-rhythm_rec_ut', 'B-rhythm_rec_val', 'B-rhythm_tdte', 'B-roa', 'I-cma_event', 'I-d_dos_form', 'I-d_dos_form_ext', 'I-d_dos_up', 'I-d_dos_val', 'I-dos_cond', 'I-dos_uf', 'I-dos_val', 'I-drug', 'I-fasting', 'I-freq_startday', 'I-inn', 'I-rhythm_tdte', 'I-roa'],
60
  ),
61
  ),
 
 
 
 
 
62
  }
63
  )
64
 
@@ -109,6 +141,7 @@ class PxCorpus(datasets.GeneratorBasedBuilder):
109
 
110
  tokens = []
111
  ner_tags = []
 
112
 
113
  for pair in document.split("\n"):
114
 
@@ -118,8 +151,9 @@ class PxCorpus(datasets.GeneratorBasedBuilder):
118
  text, label = pair.split("\t")
119
  tokens.append(text)
120
  ner_tags.append(label)
 
121
 
122
- return tokens, ner_tags
123
 
124
  def _generate_examples(self, filepath_1, filepath_2, filepath_3, split):
125
 
@@ -143,7 +177,7 @@ class PxCorpus(datasets.GeneratorBasedBuilder):
143
  text = seq_in[idx]
144
  label = seq_label[idx]
145
 
146
- tokens, ner_tags = self.getTokenTags(docs[idx])
147
 
148
  if len(text) <= 0 or len(label) <= 0:
149
  continue
@@ -154,6 +188,7 @@ class PxCorpus(datasets.GeneratorBasedBuilder):
154
  "label": label,
155
  "tokens": tokens,
156
  "ner_tags": ner_tags,
 
157
  })
158
 
159
  key += 1
 
36
 
37
  _URL = "https://zenodo.org/record/6524162/files/pxslu.zip?download=1"
38
 
39
+ class StringIndex:
40
+
41
+ def __init__(self, vocab):
42
+
43
+ self.vocab_struct = {}
44
+
45
+ print("Start building the index!")
46
+ for term in vocab:
47
+
48
+ if len(term) == 0:
49
+ continue
50
+
51
+ # Index terms by their first letter and length
52
+ key = (term[0], len(term))
53
+
54
+ if key not in self.vocab_struct:
55
+ self.vocab_struct[key] = []
56
+
57
+ self.vocab_struct[key].append(term)
58
+
59
+ print("Finished building the index!")
60
+
61
+ def find(self, term):
62
+ return term in self.vocab_struct[(term[0], len(term))]
63
+
64
  class PxCorpus(datasets.GeneratorBasedBuilder):
65
 
66
+ VOCAB = StringIndex(vocab=open("./vocabulary_nachos_lowercased.txt","r").read().split("\n"))
67
+
68
  BUILDER_CONFIGS = [
69
  datasets.BuilderConfig(name=f"default", version="1.0.0", description=f"PxCorpus data"),
70
  ]
 
86
  names=['O', 'B-A', 'B-cma_event', 'B-d_dos_form', 'B-d_dos_form_ext', 'B-d_dos_up', 'B-d_dos_val', 'B-dos_cond', 'B-dos_uf', 'B-dos_val', 'B-drug', 'B-dur_ut', 'B-dur_val', 'B-fasting', 'B-freq_days', 'B-freq_int_v1', 'B-freq_int_v1_ut', 'B-freq_int_v2', 'B-freq_int_v2_ut', 'B-freq_startday', 'B-freq_ut', 'B-freq_val', 'B-inn', 'B-max_unit_uf', 'B-max_unit_ut', 'B-max_unit_val', 'B-min_gap_ut', 'B-min_gap_val', 'B-qsp_ut', 'B-qsp_val', 'B-re_ut', 'B-re_val', 'B-rhythm_hour', 'B-rhythm_perday', 'B-rhythm_rec_ut', 'B-rhythm_rec_val', 'B-rhythm_tdte', 'B-roa', 'I-cma_event', 'I-d_dos_form', 'I-d_dos_form_ext', 'I-d_dos_up', 'I-d_dos_val', 'I-dos_cond', 'I-dos_uf', 'I-dos_val', 'I-drug', 'I-fasting', 'I-freq_startday', 'I-inn', 'I-rhythm_tdte', 'I-roa'],
87
  ),
88
  ),
89
+ "is_oov": datasets.Sequence(
90
+ datasets.features.ClassLabel(
91
+ names=['is_not_oov', 'is_oov'],
92
+ ),
93
+ ),
94
  }
95
  )
96
 
 
141
 
142
  tokens = []
143
  ner_tags = []
144
+ is_oov = []
145
 
146
  for pair in document.split("\n"):
147
 
 
151
  text, label = pair.split("\t")
152
  tokens.append(text)
153
  ner_tags.append(label)
154
+ is_oov.append(VOCAB.find(text))
155
 
156
+ return tokens, ner_tags, is_oov
157
 
158
  def _generate_examples(self, filepath_1, filepath_2, filepath_3, split):
159
 
 
177
  text = seq_in[idx]
178
  label = seq_label[idx]
179
 
180
+ tokens, ner_tags, is_oov = self.getTokenTags(docs[idx])
181
 
182
  if len(text) <= 0 or len(label) <= 0:
183
  continue
 
188
  "label": label,
189
  "tokens": tokens,
190
  "ner_tags": ner_tags,
191
+ "is_oov": is_oov,
192
  })
193
 
194
  key += 1