3
3
4
4
5
5
class Sentences (BaseWriter ):
6
- """A writer of plain-text sentences (one per line).
6
+ """A writer of plain-text sentences (one sentence per line).
7
7
8
8
Usage:
9
9
udapy write.Sentences if_missing=empty < my.conllu > my.txt
10
+ udapy write.Sentences newdoc=1 newpar=1 < my.conllu > my.txt
10
11
"""
11
12
12
- def __init__ (self , if_missing = 'detokenize' , ** kwargs ):
13
+ def __init__ (self , if_missing = 'detokenize' , newdoc = None , newpar = None , ** kwargs ):
13
14
"""Create the Sentences writer block.
14
15
15
16
Parameters:
@@ -18,9 +19,21 @@ def __init__(self, if_missing='detokenize', **kwargs):
18
19
* `empty`: print an empty line
19
20
* `warn_detokenize`, `warn_empty`: in addition emit a warning via `logging.warning()`
20
21
* `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)
21
28
"""
22
29
super ().__init__ (** kwargs )
23
30
self .if_missing = if_missing
31
+ self .newdoc = newdoc
32
+ self .newpar = newpar
24
33
25
34
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 ()
26
39
print (tree .get_sentence (self .if_missing ))
0 commit comments