Showing
1 changed file
with
21 additions
and
0 deletions
... | @@ -148,6 +148,27 @@ def word2features(sent, i): | ... | @@ -148,6 +148,27 @@ def word2features(sent, i): |
148 | ''' | 148 | ''' |
149 | return features | 149 | return features |
150 | 150 | ||
151 | +def sent2features(sent): | ||
152 | + return [word2features(sent, i) for i in range(len(sent))] | ||
153 | + | ||
154 | + | ||
155 | +def sent2labels(sent): | ||
156 | + return [elem.split('|')[3] for elem in sent] | ||
157 | + | ||
158 | + | ||
159 | +def sent2tokens(sent): | ||
160 | + return [token for token, postag, label in sent] | ||
161 | + | ||
162 | + | ||
163 | +def print_transitions(trans_features, f): | ||
164 | + for (label_from, label_to), weight in trans_features: | ||
165 | + f.write("{:6} -> {:7} {:0.6f}\n".format(label_from, label_to, weight)) | ||
166 | + | ||
167 | + | ||
168 | +def print_state_features(state_features, f): | ||
169 | + for (attr, label), weight in state_features: | ||
170 | + f.write("{:0.6f} {:8} {}\n".format(weight, label, attr.encode("utf-8"))) | ||
171 | + | ||
151 | __author__ = 'CMendezC' | 172 | __author__ = 'CMendezC' |
152 | 173 | ||
153 | ########################################## | 174 | ########################################## | ... | ... |
-
Please register or login to post a comment