Skip to content
Snippets Groups Projects
Commit 946184be authored by Michał Kaliński's avatar Michał Kaliński
Browse files

New, sane tag_sentence

Adden a new method which can be used as is to tag a sentence and return the
result, without any AnnotatedSentence magic on caller's side
parent aefc58ff
No related merge requests found
...@@ -214,11 +214,7 @@ class Chunker: ...@@ -214,11 +214,7 @@ class Chunker:
sys.stderr.write('done!\n') sys.stderr.write('done!\n')
self.stats.dump() self.stats.dump()
def tag_sentence(self, sent): def _tag_sentence(self, sent, asent):
"""Chunks the given sentence."""
# wrap the sentence as an AnnotatedSentence
asent = corpus2.AnnotatedSentence.wrap_sentence(sent)
# iterate over layers # iterate over layers
for layer_idx, layer in enumerate(self.layers): for layer_idx, layer in enumerate(self.layers):
# get model for current layer # get model for current layer
...@@ -283,6 +279,26 @@ class Chunker: ...@@ -283,6 +279,26 @@ class Chunker:
if self.verbose: if self.verbose:
self.stats.maybe_report() self.stats.maybe_report()
def tag_sentence(self, sent):
"""Chunks the given sentence."""
# wrap the sentence as an AnnotatedSentence
asent = corpus2.AnnotatedSentence.wrap_sentence(sent)
self._tag_sentence(sent, asent)
def tag_sentence_sane(self, sent):
"""
A sane version of tag_sentence, that doesn't require the sentence to be
preprocessed in any way to actually get something sensible out of it.
The way is gleaned from iobber_txt
Ideally this would replace tag_sentence, but first someone has to make
sense of this absurd class
"""
asent = corpus2.AnnotatedSentence.wrap_sentence(sent)
new_sent = corpus2.AnnotatedSentence.cast_as_sentence(asent)
self._tag_sentence(new_sent, asent)
return new_sent
def tag_input(self, in_path, out_path, input_format, output_format, def tag_input(self, in_path, out_path, input_format, output_format,
preserve_pars): preserve_pars):
"""Chunks the input and writes processed input to out_path or stdout if """Chunks the input and writes processed input to out_path or stdout if
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment