Skip to content

Commit

Permalink
cgel.py: add support for :xpos feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nschneid committed Jun 10, 2023
1 parent dd8ab96 commit 3da8aa9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cgel.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __init__(self, deprel: str, constituent: str, head: int, text: Optional[str]
self.correct = None
self.substrings = None
self.note = None
self.xpos = None
self._lemma = None # UD lemma

# coindexation nodes (i.e. gaps) should only hold a label
Expand Down Expand Up @@ -169,16 +170,16 @@ def __str__(self) -> str:
cons = (f'{self.label} / ' if self.label else '') + self.constituent
correction = f' :correct {quote(self.correct)}' if self.correct is not None else '' # includes omitted words with no text
lemma = f' :l {quote(self._lemma)}' if self._lemma else '' # lemma explicitly different from the token form
xpos = f' :xpos {quote(self.xpos)}' if self.xpos else '' # xpos if specified
suffix = ' :note ' + quote(self.note) if self.note else ''
if self.text:
s = f':{self.deprel} ({cons}' if self.deprel else f'({cons}'
for p in self.prepunct:
s += ' :p ' + quote(p)
s += f' :t {quote(self.text)}'
if correction:
s += correction
if lemma:
s += lemma
s += correction
s += lemma
s += xpos
if self.substrings:
for k,v in self.substrings:
s += ' ' + k + ' ' + quote(v)
Expand Down Expand Up @@ -268,6 +269,8 @@ def add_token(self, token: Optional[str], deprel: Optional[str], constituent: Op
self.tokens[head].correct = token
elif deprel == 'l':
self.tokens[head].lemma = token
elif deprel == 'xpos':
self.tokens[head].xpos = token
elif deprel == 'subt':
self.tokens[head].substrings = (self.tokens[head].substrings or []) + [(':subt', token)]
elif deprel == 'subp':
Expand Down

1 comment on commit 3da8aa9

@nschneid
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#88

Please sign in to comment.