@@ -68,14 +68,20 @@ def nonempty_fields(self):
6868 [self .form , self .lemma , self .cpos , self .pos , self .feats , self .head , self .deprel , self .phead ,
6969 self .pdeprel ] if f )
7070
71- def get_pos (self ):
71+ def get_pos (self , main_pos = False ):
7272 """
7373 Get the precisest pos for this word.
7474
75+ Args:
76+ main_pos: Use the main pos (cpos or upos) or the minor pos (pos or xpos).
77+
7578 Returns: ``self.pos`` or ``self.cpos``.
7679
7780 """
78- return self .pos or self .cpos
81+ if main_pos :
82+ return self .cpos or self .pos
83+ else :
84+ return self .pos or self .cpos
7985
8086
8187class CoNLLUWord (SerializableDict ):
@@ -155,14 +161,20 @@ def nonempty_fields(self):
155161 [self .form , self .lemma , self .upos , self .xpos , self .feats , self .head , self .deprel , self .deps ,
156162 self .misc ] if f )
157163
158- def get_pos (self ):
164+ def get_pos (self , main_pos = False ):
159165 """
160166 Get the precisest pos for this word.
161167
168+ Args:
169+ main_pos: Use the main pos (cpos or upos) or the minor pos (pos or xpos).
170+
162171 Returns: ``self.xpos`` or ``self.upos``
163172
164173 """
165- return self .xpos or self .upos
174+ if main_pos :
175+ return self .upos or self .xpos
176+ else :
177+ return self .xpos or self .upos
166178
167179
168180class CoNLLSentence (list ):
@@ -283,11 +295,12 @@ def to_markdown(self, headings: Union[str, List[str]] = 'auto') -> str:
283295 text = markdown_table (headings , cells , alignment = alignment )
284296 return text
285297
286- def to_tree (self , extras : List [str ] = None ) -> str :
298+ def to_tree (self , extras : List [str ] = None , main_pos = True ) -> str :
287299 """Convert into a pretty tree string which can be printed to show the tree structure.
288300
289301 Args:
290302 extras: Extra table to be aligned to this tree.
303+ main_pos: Use the main pos (cpos or upos) or the minor pos (pos or xpos).
291304
292305 Returns:
293306 A pretty tree string along with extra table if passed any.
@@ -313,7 +326,7 @@ def to_tree(self, extras: List[str] = None) -> str:
313326 if has_lem :
314327 cell_per_word .append (word .lemma )
315328 if has_pos :
316- cell_per_word .append (word .get_pos ())
329+ cell_per_word .append (word .get_pos (main_pos ))
317330 if extras :
318331 cell_per_word .extend (extras [i + 1 ])
319332 rows .append (cell_per_word )
0 commit comments