33
44
55class Sentences (BaseWriter ):
6- """A writer of plain-text sentences (one per line).
6+ """A writer of plain-text sentences (one sentence per line).
77
88 Usage:
99 udapy write.Sentences if_missing=empty < my.conllu > my.txt
10+ udapy write.Sentences newdoc=1 newpar=1 < my.conllu > my.txt
1011 """
1112
12- def __init__ (self , if_missing = 'detokenize' , ** kwargs ):
13+ def __init__ (self , if_missing = 'detokenize' , newdoc = None , newpar = None , ** kwargs ):
1314 """Create the Sentences writer block.
1415
1516 Parameters:
@@ -18,9 +19,21 @@ def __init__(self, if_missing='detokenize', **kwargs):
1819 * `empty`: print an empty line
1920 * `warn_detokenize`, `warn_empty`: in addition emit a warning via `logging.warning()`
2021 * `fatal`: raise an exception
22+ newdoc: What to do if `root.newdoc` is not None? (default=None)
23+ * None: ignore it
24+ * True: print an empty_line (except for the first tree, i.e. bundle.number==1)
25+ newpar: What to do if `root.newpar` is not None? (default=None)
26+ * None: ignore it
27+ * True: print an empty_line (except for the first tree, i.e. bundle.number==1)
2128 """
2229 super ().__init__ (** kwargs )
2330 self .if_missing = if_missing
31+ self .newdoc = newdoc
32+ self .newpar = newpar
2433
2534 def process_tree (self , tree ):
35+ if self .newdoc and tree .newdoc and tree .bundle .number > 1 :
36+ print ()
37+ if self .newpar and tree .newpar and tree .bundle .number > 1 :
38+ print ()
2639 print (tree .get_sentence (self .if_missing ))
0 commit comments