iluvvatar commited on
Commit
267e2bf
·
1 Parent(s): 35a45f1

added ent and rel types

Browse files
Files changed (3) hide show
  1. RuREBus.py +27 -7
  2. entity_types.txt +8 -0
  3. relation_types.txt +11 -0
RuREBus.py CHANGED
@@ -34,6 +34,8 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
34
  _RAW_TXT_URLS = {
35
  'raw_txt': raw_txt_url
36
  }
 
 
37
  VERSION = datasets.Version(_VERSION)
38
  BUILDER_CONFIGS = [
39
  datasets.BuilderConfig('data',
@@ -42,6 +44,12 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
42
  datasets.BuilderConfig('raw_txt',
43
  version=VERSION,
44
  description='Raw texts without annotations'),
 
 
 
 
 
 
45
  ]
46
  DEFAULT_CONFIG_NAME = 'data'
47
 
@@ -53,13 +61,15 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
53
  'entities': datasets.Sequence(datasets.Value('string')),
54
  'relations': datasets.Sequence(datasets.Value('string'))
55
  })
56
- else:
57
  features = datasets.Features({
58
  'region': datasets.Value('string'),
59
  'district': datasets.Value('string'),
60
  'title': datasets.Value('string'),
61
  'text': datasets.Value('string')
62
  })
 
 
63
  return datasets.DatasetInfo(
64
  description=_DESCRIPTION,
65
  features=features,
@@ -80,22 +90,28 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
80
  gen_kwargs={'filepath': files['test']},
81
  ),
82
  ]
83
- else:
84
  folder = dl_manager.download_and_extract(self._RAW_TXT_URLS)['raw_txt']
85
  return [
86
  datasets.SplitGenerator(
87
  name='raw_txt',
88
- gen_kwargs={'filepath': folder,
89
- 'raw_txt': True},
 
 
 
 
 
 
90
  )
91
  ]
92
 
93
- def _generate_examples(self, filepath, raw_txt=False):
94
- if not raw_txt:
95
  with open(filepath, encoding='utf-8') as f:
96
  for i, line in enumerate(f):
97
  yield i, json.loads(line)
98
- else:
99
  path = os.path.join(filepath, 'MED_txt/unparsed_txt')
100
  i = 0
101
  for root, dirs, files in os.walk(path):
@@ -123,3 +139,7 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
123
  }
124
  yield i, item
125
  i += 1
 
 
 
 
 
34
  _RAW_TXT_URLS = {
35
  'raw_txt': raw_txt_url
36
  }
37
+ _TYPES_PATHS = {'ent_types': 'ent_types.txt',
38
+ 'rel_types': 'rel_types.txt'}
39
  VERSION = datasets.Version(_VERSION)
40
  BUILDER_CONFIGS = [
41
  datasets.BuilderConfig('data',
 
44
  datasets.BuilderConfig('raw_txt',
45
  version=VERSION,
46
  description='Raw texts without annotations'),
47
+ datasets.BuilderConfig('ent_types',
48
+ version=VERSION,
49
+ description='All possible entity types'),
50
+ datasets.BuilderConfig('rel_types',
51
+ version=VERSION,
52
+ description='All possible relation types'),
53
  ]
54
  DEFAULT_CONFIG_NAME = 'data'
55
 
 
61
  'entities': datasets.Sequence(datasets.Value('string')),
62
  'relations': datasets.Sequence(datasets.Value('string'))
63
  })
64
+ elif self.config.name == 'raw_txt':
65
  features = datasets.Features({
66
  'region': datasets.Value('string'),
67
  'district': datasets.Value('string'),
68
  'title': datasets.Value('string'),
69
  'text': datasets.Value('string')
70
  })
71
+ else:
72
+ features = datasets.Features({'type': datasets.Value('string')})
73
  return datasets.DatasetInfo(
74
  description=_DESCRIPTION,
75
  features=features,
 
90
  gen_kwargs={'filepath': files['test']},
91
  ),
92
  ]
93
+ elif self.config.name == 'raw_txt':
94
  folder = dl_manager.download_and_extract(self._RAW_TXT_URLS)['raw_txt']
95
  return [
96
  datasets.SplitGenerator(
97
  name='raw_txt',
98
+ gen_kwargs={'filepath': folder},
99
+ )
100
+ ]
101
+ else:
102
+ return [
103
+ datasets.SplitGenerator(
104
+ name=self.config.name,
105
+ gen_kwargs={'filepath': self._TYPES_PATHS[self.config.name]},
106
  )
107
  ]
108
 
109
+ def _generate_examples(self, filepath):
110
+ if self.config.name == 'data':
111
  with open(filepath, encoding='utf-8') as f:
112
  for i, line in enumerate(f):
113
  yield i, json.loads(line)
114
+ elif self.config.name == 'raw_txt':
115
  path = os.path.join(filepath, 'MED_txt/unparsed_txt')
116
  i = 0
117
  for root, dirs, files in os.walk(path):
 
139
  }
140
  yield i, item
141
  i += 1
142
+ else:
143
+ with open(filepath, encoding='utf-8') as f:
144
+ for i, line in enumerate(f):
145
+ yield i, {'type': line.strip()}
entity_types.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ ACT
2
+ BIN
3
+ CMP
4
+ ECO
5
+ INST
6
+ MET
7
+ QUA
8
+ SOC
relation_types.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FNG
2
+ FNT
3
+ FPS
4
+ GOL
5
+ NNG
6
+ NNT
7
+ NPS
8
+ PNG
9
+ PNT
10
+ PPS
11
+ TSK