@@ -144,7 +144,7 @@ class TextModeTrees(BaseWriter):
144144 def __init__ (self , print_sent_id = True , print_text = True , add_empty_line = True , indent = 1 ,
145145 minimize_cross = True , color = 'auto' , attributes = 'form,upos,deprel' ,
146146 print_undef_as = '_' , print_doc_meta = True , print_comments = False , print_empty = True ,
147- mark = '(ToDo|ToDoOrigText|Bug|Mark)' , marked_only = False , hints = True ,
147+ print_mwt = False , mark = '(ToDo|ToDoOrigText|Bug|Mark)' , marked_only = False , hints = True ,
148148 layout = 'classic' , ** kwargs ):
149149 """Create new TextModeTrees block object.
150150
@@ -167,7 +167,8 @@ def __init__(self, print_sent_id=True, print_text=True, add_empty_line=True, ind
167167 print_undef_as: What should be printed instead of undefined attribute values (if any)?
168168 print_doc_meta: Print ``document.meta`` metadata before each document?
169169 print_comments: Print comments (other than ``sent_id`` and ``text``)?
170- print_empty: Print empty nodes?
170+ print_empty: Print empty nodes? Default=True
171+ print_mwt: Print multi-word tokens? Default=False
171172 mark: A regex pattern. If ``re.search(mark + '=', str(node.misc))`` matches, the node is highlighted.
172173 If ``print_comments`` and ``re.search(r'^ %s = ' % mark, root.comment, re.M)`` matches,
173174 the comment is highlighted. Empty string means no highlighting.
@@ -193,6 +194,7 @@ def __init__(self, print_sent_id=True, print_text=True, add_empty_line=True, ind
193194 self .print_doc_meta = print_doc_meta
194195 self .print_comments = print_comments
195196 self .print_empty = print_empty
197+ self .print_mwt = print_mwt
196198 self .mark = mark
197199 self .marked_only = marked_only
198200 self .layout = layout
@@ -250,18 +252,18 @@ def should_print_tree(self, root, allnodes):
250252 def process_tree (self , root , force_print = False ):
251253 """Print the tree to (possibly redirected) sys.stdout."""
252254 if self .print_empty :
253- if root .is_root ():
255+ if root .is_root () and not self . print_mwt :
254256 allnodes = [root ] + root .descendants_and_empty
255257 else :
256- allnodes = root .descendants (add_self = 1 )
258+ allnodes = root .descendants (add_self = 1 , add_mwt = self . print_mwt )
257259 empty = [e for e in root ._root .empty_nodes if e > allnodes [0 ] and e < allnodes [- 1 ]]
258260 allnodes .extend (empty )
259261 allnodes .sort ()
260262 else :
261- allnodes = root .descendants (add_self = 1 )
263+ allnodes = root .descendants (add_self = 1 , add_mwt = self . print_mwt )
262264 if not force_print and not self .should_print_tree (root , allnodes ):
263265 return
264- self ._index_of = {allnodes [i ].ord : i for i in range (len (allnodes ))}
266+ self ._index_of = {allnodes [i ].ord_range if allnodes [ i ]. is_mwt () else allnodes [ i ]. ord : i for i in range (len (allnodes ))}
265267 self .lines = ['' ] * len (allnodes )
266268 self .lengths = [0 ] * len (allnodes )
267269
@@ -288,7 +290,7 @@ def process_tree(self, root, force_print=False):
288290 if self .layout == 'classic' :
289291 self .add_node (idx , node )
290292 else :
291- if idx_node .parent is not node :
293+ if idx_node .is_mwt () or idx_node . parent is not node :
292294 self ._add (idx , self ._vert [self ._ends (idx , '─╭╰╪┡┢' )])
293295 else :
294296 precedes_parent = idx < self ._index_of [node .ord ]
@@ -306,7 +308,7 @@ def process_tree(self, root, force_print=False):
306308
307309 if self .layout == 'classic' :
308310 for idx , node in enumerate (allnodes ):
309- if node .is_empty ():
311+ if node .is_empty () or node . is_mwt () :
310312 self .add_node (idx , node )
311313 else :
312314 columns_attrs = [[a ] for a in self .attrs ] if self .layout == 'align' else [self .attrs ]
@@ -365,7 +367,7 @@ def _add(self, idx, text):
365367
366368 def add_node (self , idx , node ):
367369 """Render a node with its attributes."""
368- if not node .is_root ():
370+ if node . is_mwt () or not node .is_root ():
369371 values = node .get_attrs (self .attrs , undefs = self .print_undef_as )
370372 self .lengths [idx ] += 1 + len (' ' .join (values ))
371373 marked = self .is_marked (node )
0 commit comments