Commit c79bc6d7 by Steven Bird

Merge pull request #683 from heatherleaf/develop

Added `parse` method to malt.py, fixes #682
parents 6015262a b3e948d5
...@@ -284,7 +284,7 @@ class DependencyGraph(object): ...@@ -284,7 +284,7 @@ class DependencyGraph(object):
elif style == 4: elif style == 4:
lines.append('%s\t%s\t%s\t%s\n' % (word, tag, head, rel)) lines.append('%s\t%s\t%s\t%s\n' % (word, tag, head, rel))
elif style == 10: elif style == 10:
lines.append('%s\t%s\t%s\t%s\t%s\%s\t%s\t%s\t_\t_\n' % (i+1, word, lemma, ctag, tag, feats, head, rel)) lines.append('%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t_\t_\n' % (i+1, word, lemma, ctag, tag, feats, head, rel))
else: else:
raise ValueError('Number of tab-delimited fields (%d) not supported by CoNLL(10) or Malt-Tab(4) format' % (style)) raise ValueError('Number of tab-delimited fields (%d) not supported by CoNLL(10) or Malt-Tab(4) format' % (style))
return ''.join(lines) return ''.join(lines)
......
...@@ -113,6 +113,18 @@ class MaltParser(ParserI): ...@@ -113,6 +113,18 @@ class MaltParser(ParserI):
tagged_sentences = [self.tagger.tag(sentence) for sentence in sentences] tagged_sentences = [self.tagger.tag(sentence) for sentence in sentences]
return self.tagged_parse_sents(tagged_sentences, verbose) return self.tagged_parse_sents(tagged_sentences, verbose)
def parse(self, sentence, verbose=False):
"""
Use MaltParser to parse a sentence. Takes a sentence as a list of words.
The sentence will be automatically tagged with this MaltParser instance's
tagger.
:param sentence: Input sentence to parse
:type sentence: list(str)
:return: ``DependencyGraph`` the dependency graph representation of the sentence
"""
return self.parse_sents([sentence], verbose)[0]
def raw_parse(self, sentence, verbose=False): def raw_parse(self, sentence, verbose=False):
""" """
Use MaltParser to parse a sentence. Takes a sentence as a string; Use MaltParser to parse a sentence. Takes a sentence as a string;
......
Markdown is supported
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