MCPcopy Create free account
hub / github.com/baidu/DDParser / load

Method load

ddparser/parser/data_struct/corpus.py:111–127  ·  view source on GitHub ↗

Load data from path to generate corpus

(cls, path, fields)

Source from the content-addressed store, hash-verified

109
110 @classmethod
111 def load(cls, path, fields):
112 """Load data from path to generate corpus"""
113 start, sentences = 0, []
114 fields = [fd if fd is not None else Field(str(i)) for i, fd in enumerate(fields)]
115 with open(path, 'r', encoding='utf-8') as f:
116 lines = [
117 line.strip() for line in f.readlines()
118 if not line.startswith('#') and (len(line) == 1 or line.split()[0].isdigit())
119 ]
120 for i, line in enumerate(lines):
121 if not line:
122 values = list(zip(*[j.split('\t') for j in lines[start:i]]))
123 if values:
124 sentences.append(Sentence(fields, values))
125 start = i + 1
126
127 return cls(fields, sentences)
128
129 @classmethod
130 def load_lac_results(cls, inputs, fields):

Callers 10

eval_fileFunction · 0.45
_parseMethod · 0.45
_parseMethod · 0.45
__init__Method · 0.45
_read_jsonMethod · 0.45
trainFunction · 0.45
evaluateFunction · 0.45
predictFunction · 0.45
__init__Method · 0.45
loadFunction · 0.45

Calls 2

FieldClass · 0.90
SentenceClass · 0.85

Tested by

no test coverage detected