當前位置: 首頁>>代碼示例>>Python>>正文


Python data.load方法代碼示例

本文整理匯總了Python中nltk.data.load方法的典型用法代碼示例。如果您正苦於以下問題:Python data.load方法的具體用法?Python data.load怎麽用?Python data.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nltk.data的用法示例。


在下文中一共展示了data.load方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: demo_sent_subjectivity

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def demo_sent_subjectivity(text):
    """
    Classify a single sentence as subjective or objective using a stored
    SentimentAnalyzer.

    :param text: a sentence whose subjectivity has to be classified.
    """
    from nltk.classify import NaiveBayesClassifier
    from nltk.tokenize import regexp
    word_tokenizer = regexp.WhitespaceTokenizer()
    try:
        sentim_analyzer = load('sa_subjectivity.pickle')
    except LookupError:
        print('Cannot find the sentiment analyzer you want to load.')
        print('Training a new one using NaiveBayesClassifier.')
        sentim_analyzer = demo_subjectivity(NaiveBayesClassifier.train, True)

    # Tokenize and convert to lower case
    tokenized_text = [word.lower() for word in word_tokenizer.tokenize(text)]
    print(sentim_analyzer.classify(tokenized_text)) 
開發者ID:sdoran35,項目名稱:hate-to-hugs,代碼行數:22,代碼來源:util.py

示例2: _load_universal_map

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def _load_universal_map(fileid):
    contents = load(join(_UNIVERSAL_DATA, fileid+'.map'), format="text")

    # When mapping to the Universal Tagset,
    # map unknown inputs to 'X' not 'UNK'
    _MAPPINGS[fileid]['universal'].default_factory = lambda: 'X'

    for line in contents.splitlines():
        line = line.strip()
        if line == '':
            continue
        fine, coarse = line.split('\t')

        assert coarse in _UNIVERSAL_TAGS, 'Unexpected coarse tag: {}'.format(coarse)
        assert fine not in _MAPPINGS[fileid]['universal'], 'Multiple entries for original tag: {}'.format(fine)

        _MAPPINGS[fileid]['universal'][fine] = coarse 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:19,代碼來源:mapping.py

示例3: pos_tag

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def pos_tag(tokens, tagset=None):
    """
    Use NLTK's currently recommended part of speech tagger to
    tag the given list of tokens.

        >>> from nltk.tag import pos_tag # doctest: +SKIP
        >>> from nltk.tokenize import word_tokenize # doctest: +SKIP
        >>> pos_tag(word_tokenize("John's big idea isn't all that bad.")) # doctest: +SKIP
        [('John', 'NNP'), ("'s", 'POS'), ('big', 'JJ'), ('idea', 'NN'), ('is',
        'VBZ'), ("n't", 'RB'), ('all', 'DT'), ('that', 'DT'), ('bad', 'JJ'),
        ('.', '.')]

    :param tokens: Sequence of tokens to be tagged
    :type tokens: list(str)
    :return: The tagged tokens
    :rtype: list(tuple(str, str))
    """
    tagger = load(_POS_TAGGER)
    if tagset:
        return [(token, map_tag('en-ptb', tagset, tag)) for (token, tag) in tagger.tag(tokens)]
    return tagger.tag(tokens) 
開發者ID:EastonLee,項目名稱:FancyWord,代碼行數:23,代碼來源:__init__.py

示例4: __init__

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def __init__(self, language):
        """
        :param str language: ISO 639-1 language code. See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
        """
        self.language = language
        model = self.supported_models.get(language)
        if model:
            self.splitter = load(model)
        else:
            raise ValueError(
                "Invalid or unsupported language: '%s'. Please use one of the currently supported ones: %s" % (
                    language, self.supported_models.keys())) 
開發者ID:Wikidata,項目名稱:StrepHit,代碼行數:14,代碼來源:split_sentences.py

示例5: ne_chunk

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def ne_chunk(tagged_tokens, binary=False):
    """
    Use NLTK's currently recommended named entity chunker to
    chunk the given list of tagged tokens.
    """
    if binary:
        chunker_pickle = _BINARY_NE_CHUNKER
    else:
        chunker_pickle = _MULTICLASS_NE_CHUNKER
    chunker = load(chunker_pickle)
    return chunker.parse(tagged_tokens) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:13,代碼來源:__init__.py

示例6: ne_chunk_sents

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def ne_chunk_sents(tagged_sentences, binary=False):
    """
    Use NLTK's currently recommended named entity chunker to chunk the
    given list of tagged sentences, each consisting of a list of tagged tokens.
    """
    if binary:
        chunker_pickle = _BINARY_NE_CHUNKER
    else:
        chunker_pickle = _MULTICLASS_NE_CHUNKER
    chunker = load(chunker_pickle)
    return chunker.parse_sents(tagged_sentences) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:13,代碼來源:__init__.py

示例7: _format_tagset

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def _format_tagset(tagset, tagpattern=None):
    tagdict = load("help/tagsets/" + tagset + ".pickle")
    if not tagpattern:
        _print_entries(sorted(tagdict), tagdict)
    elif tagpattern in tagdict:
        _print_entries([tagpattern], tagdict)
    else:
        tagpattern = re.compile(tagpattern)
        tags = [tag for tag in sorted(tagdict) if tagpattern.match(tag)]
        if tags:
            _print_entries(tags, tagdict)
        else:
            print("No matching tags found.") 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:15,代碼來源:help.py

示例8: read_rule

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def read_rule (self, filename):
        rules = load('nltk:stemmers/rslp/' + filename, format='raw').decode("utf8")
        lines = rules.split("\n")

        lines = [line for line in lines if line != ""]     # remove blank lines
        lines = [line for line in lines if line[0] != "#"]  # remove comments

        # NOTE: a simple but ugly hack to make this parser happy with double '\t's
        lines = [line.replace("\t\t", "\t") for line in lines]

        # parse rules
        rules = []
        for line in lines:
            rule = []
            tokens = line.split("\t")

            # text to be searched for at the end of the string
            rule.append( tokens[0][1:-1] ) # remove quotes

            # minimum stem size to perform the replacement
            rule.append( int(tokens[1]) )

            # text to be replaced into
            rule.append( tokens[2][1:-1] ) # remove quotes

            # exceptions to this rule
            rule.append( [token[1:-1] for token in tokens[3].split(",")] )

            # append to the results
            rules.append(rule)

        return rules 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:34,代碼來源:rslp.py

示例9: load

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def load(self, path):
        '''Load the pickled model weights.'''
        self.weights = load(path) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:5,代碼來源:perceptron.py

示例10: __init__

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def __init__(self, load=True):
        '''
        :param load: Load the pickled model upon instantiation.
        '''
        self.model = AveragedPerceptron()
        self.tagdict = {}
        self.classes = set()
        if load:
            AP_MODEL_LOC = str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
            self.load(AP_MODEL_LOC) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:12,代碼來源:perceptron.py

示例11: __init__

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def __init__(self, load=True):
        '''
        :param load: Load the pickled model upon instantiation.
        '''
        self.model = AveragedPerceptron()
        self.tagdict = {}
        self.classes = set()
        if load:
            AP_MODEL_LOC = 'file:'+str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
            self.load(AP_MODEL_LOC) 
開發者ID:SignalMedia,項目名稱:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda,代碼行數:12,代碼來源:perceptron.py

示例12: sent_tokenize

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def sent_tokenize(text, language='english'):
    """
    Return a sentence-tokenized copy of *text*,
    using NLTK's recommended sentence tokenizer
    (currently :class:`.PunktSentenceTokenizer`
    for the specified language).

    :param text: text to split into sentences
    :param language: the model name in the Punkt corpus
    """
    tokenizer = load('tokenizers/punkt/{0}.pickle'.format(language))
    return tokenizer.tokenize(text)

# Standard word tokenizer. 
開發者ID:EastonLee,項目名稱:FancyWord,代碼行數:16,代碼來源:__init__.py

示例13: pos_tag_sents

# 需要導入模塊: from nltk import data [as 別名]
# 或者: from nltk.data import load [as 別名]
def pos_tag_sents(sentences):
    """
    Use NLTK's currently recommended part of speech tagger to tag the
    given list of sentences, each consisting of a list of tokens.
    """
    tagger = load(_POS_TAGGER)
    return tagger.tag_sents(sentences) 
開發者ID:EastonLee,項目名稱:FancyWord,代碼行數:9,代碼來源:__init__.py


注:本文中的nltk.data.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。