| 153 | |
| 154 | |
| 155 | class _FeatureDescription: |
| 156 | def __init__(self, fd_spec): |
| 157 | self._fd_spec = fd_spec |
| 158 | |
| 159 | def __repr__(self): |
| 160 | return "Features(%s)" % ",".join(map(lambda x: x.name, self._fd_spec)) |
| 161 | |
| 162 | def __len__(self): |
| 163 | return len(self._fd_spec) |
| 164 | |
| 165 | def __getitem__(self, key): |
| 166 | for f in self._fd_spec: |
| 167 | if key == f.name: |
| 168 | return f.shortDescription |
| 169 | raise KeyError("No feature with name %s." % key) |
| 170 | |
| 171 | def __contains__(self, key): |
| 172 | for f in self._fd_spec: |
| 173 | if key == f.name: |
| 174 | return True |
| 175 | return False |
| 176 | |
| 177 | def __setitem__(self, key, value): |
| 178 | for f in self._fd_spec: |
| 179 | if key == f.name: |
| 180 | f.shortDescription = value |
| 181 | return |
| 182 | raise AttributeError("No feature with name %s." % key) |
| 183 | |
| 184 | def __iter__(self): |
| 185 | for f in self._fd_spec: |
| 186 | yield f.name |
| 187 | |
| 188 | |
| 189 | class MLState: |