Datasets:

Modalities:
Text
Formats:
parquet
Languages:
English
Libraries:
Datasets
pandas
License:
sileod commited on
Commit
24f97d4
1 Parent(s): b345365

Update disrpt.py

Browse files
Files changed (1) hide show
  1. disrpt.py +20 -4
disrpt.py CHANGED
@@ -71,23 +71,39 @@ files = [
71
  "zho.rst.sctb",
72
  ]
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  def parse_conll_stream(file_stream):
76
  names = ['id', 'form', 'lemma', 'upos', 'xpos', 'feats', 'head', 'deprel', 'deps', 'misc']
77
  sentence = {name: [] for name in names}
78
-
79
  for line in file_stream:
80
  line = line.strip()
81
  if line.startswith("#"):
82
  continue
83
  if not line:
84
  if sentence['id']:
85
- yield sentence
86
  sentence = {name: [] for name in names}
87
  continue
88
  token_data = line.split('\t')
89
  for name, value in zip(names, token_data):
90
- sentence[name].append(value)
 
 
 
91
 
92
  def get_kwarg_names(func):
93
  return [k for k, v in inspect.signature(func).parameters.items() if v.default != v.empty]
@@ -96,7 +112,7 @@ _URLs = {f'{task}-{split}.{type}':f"https://raw.githubusercontent.com/disrpt/sha
96
  for task in files for split in 'train dev test'.split() for type in ['rels','conllu']}
97
  #_URLs = {k:v for k,v in _URLs.items() if requests.get(v).status_code!=404}
98
 
99
- conllu_features = ['id', 'form', 'lemma', 'upos', 'xpos', 'feats', 'head', 'deprel', 'deps', 'misc', 'seg']
100
  feature_type = {"seg":datasets.features.Sequence(
101
  datasets.features.ClassLabel(names=["O","B-Segment"])),
102
  'id':datasets.Value("string")}
 
71
  "zho.rst.sctb",
72
  ]
73
 
74
+ def fix_mwe(sentence):
75
+ mwe={}
76
+ for i, x in enumerate(sentence['id']):
77
+ if '-' in x:
78
+ for a in x.split('-'):
79
+ mwe[a]=sentence['form'][i]
80
+ sentence['parent_mwe']+=[mwe.get(x,'')]
81
+
82
+ for i, x in enumerate(sentence['id']):
83
+ if "-" in x:
84
+ for k,v in sentence.items():
85
+ del v[i]
86
+ return sentence
87
 
88
  def parse_conll_stream(file_stream):
89
  names = ['id', 'form', 'lemma', 'upos', 'xpos', 'feats', 'head', 'deprel', 'deps', 'misc']
90
  sentence = {name: [] for name in names}
91
+ mwe_id=[]
92
  for line in file_stream:
93
  line = line.strip()
94
  if line.startswith("#"):
95
  continue
96
  if not line:
97
  if sentence['id']:
98
+ yield fix_mwe(sentence)
99
  sentence = {name: [] for name in names}
100
  continue
101
  token_data = line.split('\t')
102
  for name, value in zip(names, token_data):
103
+ if name=='id' and '-' in value:
104
+ mwe_id=value.split('-')
105
+ else:
106
+ sentence[name].append(value)
107
 
108
  def get_kwarg_names(func):
109
  return [k for k, v in inspect.signature(func).parameters.items() if v.default != v.empty]
 
112
  for task in files for split in 'train dev test'.split() for type in ['rels','conllu']}
113
  #_URLs = {k:v for k,v in _URLs.items() if requests.get(v).status_code!=404}
114
 
115
+ conllu_features = ['id', 'form', 'lemma', 'upos', 'xpos', 'feats', 'head', 'deprel', 'deps', 'misc', 'seg','parent_mwe']
116
  feature_type = {"seg":datasets.features.Sequence(
117
  datasets.features.ClassLabel(names=["O","B-Segment"])),
118
  'id':datasets.Value("string")}