|
1 | 1 | """MWT class represents a multi-word token.""" |
2 | 2 | from udapi.core.dualdict import DualDict |
3 | | - |
| 3 | +from udapi.core.feats import Feats |
4 | 4 |
|
5 | 5 | class MWT(object): |
6 | 6 | """Class for representing multi-word tokens in UD trees.""" |
7 | | - __slots__ = ['words', 'form', '_misc', 'root'] |
| 7 | + __slots__ = ['words', 'form', '_feats', '_misc', 'root'] |
8 | 8 |
|
9 | | - def __init__(self, words=None, form=None, misc=None, root=None): |
| 9 | + def __init__(self, words=None, form=None, feats=None, misc=None, root=None): |
10 | 10 | self.words = words if words is not None else [] |
11 | 11 | self.form = form |
| 12 | + self._feats = Feats(feats) if feats and feats != '_' else None |
12 | 13 | self._misc = DualDict(misc) if misc and misc != '_' else None |
13 | 14 | self.root = root |
14 | 15 | for word in self.words: |
15 | 16 | word._mwt = self # pylint: disable=W0212 |
16 | 17 |
|
| 18 | + @property |
| 19 | + def feats(self): |
| 20 | + """Property `feats` in MWT should be used only for `Typo=Yes`. |
| 21 | +
|
| 22 | + See https://universaldependencies.org/changes.html#typos-in-multiword-tokens |
| 23 | + However, Udapi does not enforce this restriction and mwt.feats works exactly the same as node.feats. |
| 24 | + """ |
| 25 | + if self._feats is None: |
| 26 | + self._feats = Feats() |
| 27 | + return self._feats |
| 28 | + |
| 29 | + @feats.setter |
| 30 | + def feats(self, value): |
| 31 | + if self._feats is None: |
| 32 | + self._feats = Feats(value) |
| 33 | + else: |
| 34 | + self._feats.set_mapping(value) |
| 35 | + |
17 | 36 | @property |
18 | 37 | def misc(self): |
19 | 38 | """Property for MISC attributes stored as a `DualDict` object. |
|
0 commit comments