当前位置: 首页>>代码示例>>Python>>正文


Python tag.StanfordPOSTagger方法代码示例

本文整理汇总了Python中nltk.tag.StanfordPOSTagger方法的典型用法代码示例。如果您正苦于以下问题:Python tag.StanfordPOSTagger方法的具体用法?Python tag.StanfordPOSTagger怎么用?Python tag.StanfordPOSTagger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.tag的用法示例。


在下文中一共展示了tag.StanfordPOSTagger方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_postag_with_record

# 需要导入模块: from nltk import tag [as 别名]
# 或者: from nltk.tag import StanfordPOSTagger [as 别名]
def get_postag_with_record(records, pairs):
    path = os.path.dirname(__file__)
    path = path[:path.rfind(os.sep, 0, len(path)-10)+1] + 'stanford-postagger/'
    print(path)
    # jar = '/Users/memray/Project/stanford/stanford-postagger/stanford-postagger.jar'
    jar = path + '/stanford-postagger.jar'
    model = path + '/models/english-bidirectional-distsim.tagger'
    pos_tagger = StanfordPOSTagger(model, jar)
    # model = '/Users/memray/Project/stanford/stanford-postagger/models/english-left3words-distsim.tagger'
    # model = '/Users/memray/Project/stanford/stanford-postagger/models/english-bidirectional-distsim.tagger'

    stanford_dir = jar.rpartition('/')[0]
    stanford_jars = find_jars_within_path(stanford_dir)
    pos_tagger._stanford_jar = ':'.join(stanford_jars)

    tagged_source = []
    # Predict on testing data
    for idx, (record, pair) in enumerate(zip(records, pairs)):  # len(test_data_plain)
        print('*' * 100)
        print('File: '  + record['name'])
        print('Input: ' + str(pair[0]))
        text = pos_tagger.tag(pair[0])
        print('[%d/%d][%d] : %s' % (idx, len(records) , len(pair[0]), str(text)))
        tagged_source.append(text)

    return tagged_source 
开发者ID:memray,项目名称:seq2seq-keyphrase,代码行数:28,代码来源:keyphrase_test_dataset.py

示例2: get_postag_with_index

# 需要导入模块: from nltk import tag [as 别名]
# 或者: from nltk.tag import StanfordPOSTagger [as 别名]
def get_postag_with_index(sources, idx2word, word2idx):
    path = os.path.dirname(__file__)
    path = path[:path.rfind(os.sep, 0, len(path)-10)+1] + 'stanford-postagger/'
    print(path)
    # jar = '/Users/memray/Project/stanford/stanford-postagger/stanford-postagger.jar'
    jar = path + '/stanford-postagger.jar'
    model = path + '/models/english-bidirectional-distsim.tagger'
    pos_tagger = StanfordPOSTagger(model, jar)
    # model = '/Users/memray/Project/stanford/stanford-postagger/models/english-left3words-distsim.tagger'
    # model = '/Users/memray/Project/stanford/stanford-postagger/models/english-bidirectional-distsim.tagger'

    stanford_dir = jar.rpartition('/')[0]
    stanford_jars = find_jars_within_path(stanford_dir)
    pos_tagger._stanford_jar = ':'.join(stanford_jars)

    tagged_source = []
    # Predict on testing data
    for idx in xrange(len(sources)):  # len(test_data_plain)
        test_s_o = sources[idx]
        source_text = keyphrase_utils.cut_zero(test_s_o, idx2word)
        text = pos_tagger.tag(source_text)
        print('[%d/%d] : %s' % (idx, len(sources), str(text)))

        tagged_source.append(text)

    return tagged_source 
开发者ID:memray,项目名称:seq2seq-keyphrase,代码行数:28,代码来源:keyphrase_test_dataset.py

示例3: load_pos_tagger

# 需要导入模块: from nltk import tag [as 别名]
# 或者: from nltk.tag import StanfordPOSTagger [as 别名]
def load_pos_tagger():
    path = os.path.dirname(__file__)
    path =  os.path.join(file_dir[: file_dir.rfind('pykp') + 4], 'stanford-postagger')
    print(path)
    # jar = '/Users/memray/Project/stanford/stanford-postagger/stanford-postagger.jar'
    jar = path + '/stanford-postagger.jar'
    model = path + '/models/english-bidirectional-distsim.tagger'
    pos_tagger = StanfordPOSTagger(model, jar)

    stanford_dir = jar.rpartition('/')[0]
    stanford_jars = find_jars_within_path(stanford_dir)
    pos_tagger._stanford_jar = ':'.join(stanford_jars)

    return pos_tagger 
开发者ID:memray,项目名称:seq2seq-keyphrase-pytorch,代码行数:16,代码来源:test_dataset_producer.py

示例4: __init__

# 需要导入模块: from nltk import tag [as 别名]
# 或者: from nltk.tag import StanfordPOSTagger [as 别名]
def __init__(self, model_type='english-bidirectional-distsim.tagger'):
        """
        Args:
            model:  model available in $STANFORD_MODELS:
                english-bidirectional-distsim.tagger
                english-caseless-left3words-distsim.tagger
                english-left3words-distsim.tagger
        """
        #self.eng_tagger = StanfordPOSTagger(model_type, java_options='-mx16000m')
        self.eng_tagger = PerceptronTagger() 
开发者ID:microsoft,项目名称:NeuronBlocks,代码行数:12,代码来源:EnglishPOSTagger.py

示例5: load_pos_tagger

# 需要导入模块: from nltk import tag [as 别名]
# 或者: from nltk.tag import StanfordPOSTagger [as 别名]
def load_pos_tagger(stanford_base_dir):
    # path = os.path.dirname(__file__)
    # path = os.path.join(file_dir[: file_dir.rfind('pykp') + 4], 'stanford-postagger')
    # print(path)
    # jar = '/Users/memray/Project/stanford/stanford-postagger/stanford-postagger.jar'
    jar = stanford_base_dir + '/stanford-postagger.jar'
    model = stanford_base_dir + '/models/english-bidirectional-distsim.tagger'
    pos_tagger = StanfordPOSTagger(model_filename=model, path_to_jar=jar)

    stanford_base_dir = jar.rpartition('/')[0]
    stanford_jars = find_jars_within_path(stanford_base_dir)
    pos_tagger._stanford_jar = ':'.join(stanford_jars)

    return pos_tagger 
开发者ID:memray,项目名称:OpenNMT-kpg-release,代码行数:16,代码来源:export_dataset.py

示例6: check_postag

# 需要导入模块: from nltk import tag [as 别名]
# 或者: from nltk.tag import StanfordPOSTagger [as 别名]
def check_postag(config):
    train_set, validation_set, test_set, idx2word, word2idx = deserialize_from_file(config['dataset'])

    path = os.path.dirname(__file__)
    path = path[:path.rfind(os.sep, 0, len(path)-10)+1] + 'stanford-postagger/'
    jar = path + '/stanford-postagger.jar'
    model = path + '/models/english-bidirectional-distsim.tagger'
    pos_tagger = StanfordPOSTagger(model, jar)

    for dataset_name in config['testing_datasets']:
        # override the original test_set
        # test_set = load_testing_data(dataset_name, kwargs=dict(basedir=config['path']))(idx2word, word2idx, config['preprocess_type'])

        test_sets = load_additional_testing_data(config['testing_datasets'], idx2word, word2idx, config)
        test_set = test_sets[dataset_name]

        # print(dataset_name)
        # print('Avg length=%d, Max length=%d' % (np.average([len(s) for s in test_set['source']]), np.max([len(s) for s in test_set['source']])))
        test_data_plain = zip(*(test_set['source'], test_set['target']))

        test_size = len(test_data_plain)

        # Alternatively to setting the CLASSPATH add the jar and model via their path:
        jar = '/Users/memray/Project/stanford/stanford-postagger/stanford-postagger.jar'
        # model = '/Users/memray/Project/stanford/stanford-postagger/models/english-left3words-distsim.tagger'
        model = '/Users/memray/Project/stanford/stanford-postagger/models/english-bidirectional-distsim.tagger'
        pos_tagger = StanfordPOSTagger(model, jar)

        for idx in xrange(len(test_data_plain)):  # len(test_data_plain)
            test_s_o, test_t_o = test_data_plain[idx]

            source = keyphrase_utils.cut_zero(test_s_o, idx2word)

            print(source)

            # Add other jars from Stanford directory
            stanford_dir = jar.rpartition('/')[0]
            stanford_jars = find_jars_within_path(stanford_dir)
            pos_tagger._stanford_jar = ':'.join(stanford_jars)

            text = pos_tagger.tag(source)
            print(text) 
开发者ID:memray,项目名称:seq2seq-keyphrase,代码行数:44,代码来源:keyphrase_test_dataset.py


注:本文中的nltk.tag.StanfordPOSTagger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。