def parse(self, sent, *args, **kwargs): ''' :param sent: list(str) :param args: :param kwargs: :return:An iterator that generates parse for the sentence. ''' if overridden(self.parse_sents): return next(self.parse_sents([sent], *args, **kwargs)) elif overridden(self.parse_one): return (tree for tree in [self.parse_one(sent, *args, **kwargs)] if tree is not None) elif overridden(self.parse_all): return iter(self.parse_all(sent, *args, **kwargs)) else: raise NotImplementedError()
def parse(self, sent, *args, **kwargs): """ :return: An iterator that generates parse trees for the sentence. When possible this list is sorted from most likely to least likely. :param sent: The sentence to be parsed :type sent: list(str) :rtype: iter(Tree) """ if overridden(self.parse_sents): return next(self.parse_sents([sent], *args, **kwargs)) elif overridden(self.parse_one): return (tree for tree in [self.parse_one(sent, *args, **kwargs)] if tree is not None) elif overridden(self.parse_all): return iter(self.parse_all(sent, *args, **kwargs)) else: raise NotImplementedError()
def tokenize(self, s): """ Return a tokenized copy of *s*. :rtype: list of str """ if overridden(self.tokenize_sents): return self.tokenize_sents([s])[0]
def tokenize(self, s: str) -> List[str]: """ Return a tokenized copy of *s*. :rtype: List[str] """ if overridden(self.tokenize_sents): return self.tokenize_sents([s])[0]
def classify(self, featureset): """ :return: the most appropriate set of labels for the given featureset. :rtype: set(label) """ if overridden(self.classify_many): return self.classify_many([featureset])[0] else: raise NotImplementedError()
def classify(self, featureset): """ @return: the most appropriate set of labels for the given featureset. @rtype: C{set} of I{label} """ if overridden(self.batch_classify): return self.batch_classify([featureset])[0] else: raise NotImplementedError()
def classify(self, featureset): """ :return: the most appropriate label for the given featureset. :rtype: label """ if overridden(self.batch_classify): return self.batch_classify([featureset])[0] else: raise NotImplementedError()
def classify(self, featureset): """ @return: the most appropriate label for the given featureset. @rtype: label """ if overridden(self.batch_classify): return self.batch_classify([featureset])[0] else: raise NotImplementedError()
def tag(self, tokens): ''' 标注单个句子 :param tokens:list :return:list(tuple(str,str)) ''' if overridden(self.tag_sents): return self.tag_sents([tokens])[0] else: raise NotImplementedError()
def prob_classify(self, featureset): """ :return: a probability distribution over labels for the given featureset. :rtype: ProbDistI """ if overridden(self.batch_prob_classify): return self.batch_prob_classify([featureset])[0] else: raise NotImplementedError()
def prob_classify(self, featureset): """ @return: a probability distribution over sets of labels for the given featureset. @rtype: L{ProbDistI <nltk.probability.ProbDistI>} """ if overridden(self.batch_prob_classify): return self.batch_prob_classify([featureset])[0] else: raise NotImplementedError()
def parse(self, sent, *args, **kwargs): ''' 解析单个句子 :param tokens:list :return:list(tuple(str,str)) ''' if overridden(self.parse_sents): return self.parse_sents([sent])[0] else: raise NotImplementedError()
def tokenize(self, s): """ Divide the given string into a list of substrings. @return: C{list} of C{str} """ if overridden(self.batch_tokenize): return self.batch_tokenize([s])[0] else: raise NotImplementedError()
def tag(self, tokens): """ Determine the most appropriate tag sequence for the given token sequence, and return a corresponding list of tagged tokens. A tagged token is encoded as a tuple ``(token, tag)``. :rtype: list(tuple(str, str)) """ if overridden(self.tag_sents): return self.tag_sents([tokens])[0]
def tokenize(self, s): """ Return a tokenized copy of *s*. :rtype: list of str """ if overridden(self.batch_tokenize): return self.batch_tokenize([s])[0] else: raise NotImplementedError()
def prob_classify(self, featureset): """ @return: a probability distribution over labels for the given featureset. @rtype: L{ProbDistI <nltk.probability.ProbDistI>} """ if overridden(self.batch_prob_classify): return self.batch_prob_classify([featureset])[0] else: raise NotImplementedError()
def tokenize(self, s): """ Return a tokenized copy of *s*. :rtype: list of str """ if overridden(self.tokenize_sents): return self.tokenize_sents([s])[0] else: raise NotImplementedError()
def prob_classify(self, featureset): """ :return: a probability distribution over labels for the given featureset. :rtype: ProbDistI """ if overridden(self.prob_classify_many): return self.prob_classify_many([featureset])[0] else: raise NotImplementedError()
def iter_parse(self, sent): """ @return: An iterator that generates parse trees that represent possible structures for the given sentence. When possible, this list is sorted from most likely to least likely. @param sent: The sentence to be parsed @type sent: L{list} of L{string} @rtype: C{iterator} of L{Tree} """ if overridden(self.batch_iter_parse): return self.batch_iter_parse([sent])[0] elif overridden(self.nbest_parse) or overridden(self.batch_nbest_parse): return iter(self.nbest_parse(sent)) elif overridden(self.parse) or overridden(self.batch_parse): tree = self.parse(sent) if tree: return iter([tree]) else: return iter([]) else: raise NotImplementedError()
def iter_parse(self, sent): """ :return: An iterator that generates parse trees that represent possible structures for the given sentence. When possible, this list is sorted from most likely to least likely. :param sent: The sentence to be parsed :type sent: list(str) :rtype: iter(Tree) """ if overridden(self.batch_iter_parse): return self.batch_iter_parse([sent])[0] elif overridden(self.nbest_parse) or overridden(self.batch_nbest_parse): return iter(self.nbest_parse(sent)) elif overridden(self.parse) or overridden(self.batch_parse): tree = self.parse(sent) if tree: return iter([tree]) else: return iter([]) else: raise NotImplementedError()
def tag(self, tokens): ''' Determine the most appropriate tag sequence for the given token sequence, and return a corresponding list of tagged tokens :param tokens: list of tokens ['我','爱','北京','天安门'] :return: list(tuple(str,str) ''' if overridden(self.tag_sents): return self.tag_sents([tokens])[0] else: raise NotImplementedError()
def iter_parse(self, sent): """ :return: An iterator that generates parse trees that represent possible structures for the given sentence. When possible, this list is sorted from most likely to least likely. :param sent: The sentence to be parsed :type sent: list(str) :rtype: iter(Tree) """ if overridden(self.iter_parse_sents): return self.iter_parse_sents([sent])[0] elif overridden(self.nbest_parse) or overridden(self.nbest_parse_sents): return iter(self.nbest_parse(sent)) elif overridden(self.parse) or overridden(self.parse_sents): tree = self.parse(sent) if tree: return iter([tree]) else: return iter([]) else: raise NotImplementedError()
def tag(self, tokens): """ Determine the most appropriate tag sequence for the given token sequence, and return a corresponding list of tagged tokens. A tagged token is encoded as a tuple C{(token, tag)}. @rtype: C{list} of C{(token, tag)} """ if overridden(self.batch_tag): return self.batch_tag([tokens])[0] else: raise NotImplementedError()
def nbest_parse(self, sent, n=None): """ @return: A list of parse trees that represent possible structures for the given sentence. When possible, this list is sorted from most likely to least likely. If C{n} is specified, then the returned list will contain at most C{n} parse trees. @param sent: The sentence to be parsed @type sent: L{list} of L{string} @param n: The maximum number of trees to return. @type n: C{int} @rtype: C{list} of L{Tree} """ if overridden(self.batch_nbest_parse): return self.batch_nbest_parse([sent],n)[0] elif overridden(self.parse) or overridden(self.batch_parse): tree = self.parse(sent) if tree: return [tree] else: return [] else: return list(itertools.islice(self.iter_parse(sent), n))
def nbest_parse(self, sent, n=None): """ :return: A list of parse trees that represent possible structures for the given sentence. When possible, this list is sorted from most likely to least likely. If ``n`` is specified, then the returned list will contain at most ``n`` parse trees. :param sent: The sentence to be parsed :type sent: list(str) :param n: The maximum number of trees to return. :type n: int :rtype: list(Tree) """ if overridden(self.batch_nbest_parse): return self.batch_nbest_parse([sent],n)[0] elif overridden(self.parse) or overridden(self.batch_parse): tree = self.parse(sent) if tree: return [tree] else: return [] else: return list(itertools.islice(self.iter_parse(sent), n))
def nbest_parse(self, sent, n=None): """ :return: A list of parse trees that represent possible structures for the given sentence. When possible, this list is sorted from most likely to least likely. If ``n`` is specified, then the returned list will contain at most ``n`` parse trees. :param sent: The sentence to be parsed :type sent: list(str) :param n: The maximum number of trees to return. :type n: int :rtype: list(Tree) """ if overridden(self.batch_nbest_parse): return self.batch_nbest_parse([sent], n)[0] elif overridden(self.parse) or overridden(self.batch_parse): tree = self.parse(sent) if tree: return [tree] else: return [] else: return list(itertools.islice(self.iter_parse(sent), n))
def prob_parse(self, sent): """ :return: A probability distribution over the possible parse trees for the given sentence. If there are no possible parse trees for the given sentence, return a probability distribution that assigns a probability of 1.0 to None. :param sent: The sentence to be parsed :type sent: list(str) :rtype: ProbDistI(Tree) """ if overridden(self.batch_prob_parse): return self.batch_prob_parse([sent])[0] else: raise NotImplementedError
def prob_parse(self, sent): """ @return: A probability distribution over the possible parse trees for the given sentence. If there are no possible parse trees for the given sentence, return a probability distribution that assigns a probability of 1.0 to C{None}. @param sent: The sentence to be parsed @type sent: L{list} of L{string} @rtype: L{ProbDistI} of L{Tree} """ if overridden(self.batch_prob_parse): return self.batch_prob_parse([sent])[0] else: raise NotImplementedError
def parse(self, sent): """ :return: A parse tree that represents the structure of the given sentence, or None if no parse tree is found. If multiple parses are found, then return the best parse. :param sent: The sentence to be parsed :type sent: list(str) :rtype: Tree """ if overridden(self.batch_parse): return self.batch_parse([sent])[0] else: trees = self.nbest_parse(sent, 1) if trees: return trees[0] else: return None
def parse(self, sent): """ @return: A parse tree that represents the structure of the given sentence, or C{None} if no parse tree is found. If multiple parses are found, then return the best parse. @param sent: The sentence to be parsed @type sent: L{list} of L{string} @rtype: L{Tree} """ if overridden(self.batch_parse): return self.batch_parse([sent])[0] else: trees = self.nbest_parse(sent, 1) if trees: return trees[0] else: return None
def align(self, source_text_sections, target_text_sections): """ @return: the alignment of the two texts. @rtype: a C{list} of C{tuple} pairs where 1. the first element is a section of source text 2. the second element is the aligned section(s) of target text or 1. the first element is an identifier of a section of source text 2. the second element is identifier(s) of aligned section(s) of target text The second option is necessary for cases where crossing alignments are permitted, as in word alignment implementations. Both elements of the returned tuples are lists - either empty lists, (in the case of ommitted/deleted text) or single or multiple element lists """ if overridden(self.batch_align): return self.batch_align([source_text_sections], [target_text_sections]) else: raise NotImplementedError()
def tag(self, tokens): if overridden(self.tag_sents): return self.tag_sents([tokens])[0]