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


Python pycorenlp.StanfordCoreNLP方法代码示例

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


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

示例1: main

# 需要导入模块: import pycorenlp [as 别名]
# 或者: from pycorenlp import StanfordCoreNLP [as 别名]
def main():
    args = parse_args()
    parser = RstParser()
    parser.load('../data/model')
    with gzip.open('../data/resources/bc3200.pickle.gz') as fin:
        print('Load Brown clusters for creating features ...')
        brown_clusters = pickle.load(fin)
    core_nlp = StanfordCoreNLP('http://localhost:9000')
    annotate = lambda x: core_nlp.annotate(x, properties={
        'annotators': 'tokenize,ssplit,pos,lemma,parse,depparse',
        'outputFormat': 'json',
        'ssplit.isOneSentence': True
    })
    edu_file_list = [os.path.join(args.edu_file_dir, fname) for fname in os.listdir(args.edu_file_dir) if fname.endswith('.edu.txt')]
    for edu_file in edu_file_list:
        print('Parsing {}...'.format(edu_file))
        doc = create_doc_from_edu_file(edu_file, annotate_func=annotate)
        pred_rst = parser.sr_parse(doc, brown_clusters)
        tree_str = pred_rst.get_parse()
        pprint_tree_str = Tree.fromstring(tree_str).pformat(margin=150)
        with open(os.path.join(args.output_dir, os.path.basename(edu_file) + '.parse'), 'w') as fout:
            fout.write(pprint_tree_str) 
开发者ID:yizhongw,项目名称:StageDP,代码行数:24,代码来源:parse.py

示例2: __init__

# 需要导入模块: import pycorenlp [as 别名]
# 或者: from pycorenlp import StanfordCoreNLP [as 别名]
def __init__ (self, retokenize=False, span=True, compound_map_file=None):
        """
        the defualt settings are for development only
        for testing, span must be set to False
        """
        if retokenize:
            nlp = StanfordCoreNLP('http://localhost:9000')
            nlp_properties = {
                'annotators': "tokenize,ssplit",
                "tokenize.options": "splitHyphenated=true,normalizeParentheses=false",
                "tokenize.whitespace": False,
                'ssplit.isOneSentence': True,
                'outputFormat': 'json'
            }
            self.stanford_tokenize = lambda text : [x['word'] for x in nlp.annotate(text, nlp_properties)['sentences'][0]['tokens']]
        self.retokenize = retokenize
        self.span = span
        self.compound_map = self.load_compound_map(compound_map_file) 
开发者ID:jcyk,项目名称:gtos,代码行数:20,代码来源:postprocess.py

示例3: __init__

# 需要导入模块: import pycorenlp [as 别名]
# 或者: from pycorenlp import StanfordCoreNLP [as 别名]
def __init__(self):
        self.webparser = StanfordCoreNLP('http://localhost:9020')
        self.load_pickle_file()
        #To use this parser an instance has to be started in parallel:
        #Download Stanford CoreNLP from: https://stanfordnlp.github.io/CoreNLP/index.html
        #Extract anywhere and execute following command: java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9020 
开发者ID:UKPLab,项目名称:coling2018_fake-news-challenge,代码行数:8,代码来源:stanford_parser.py

示例4: __init__

# 需要导入模块: import pycorenlp [as 别名]
# 或者: from pycorenlp import StanfordCoreNLP [as 别名]
def __init__(self, url, compound_map_file):
        self.nlp = StanfordCoreNLP(url)
        self.nlp_properties = {
            'annotators': "tokenize,ssplit,pos,lemma,ner",
            "tokenize.options": "splitHyphenated=true,normalizeParentheses=false",
            "tokenize.whitespace": False,
            'ssplit.isOneSentence': True,
            'outputFormat': 'json'
        }
        self.compound_map = self.load_compound_map(compound_map_file) 
开发者ID:jcyk,项目名称:gtos,代码行数:12,代码来源:feature_annotator.py

示例5: __init__

# 需要导入模块: import pycorenlp [as 别名]
# 或者: from pycorenlp import StanfordCoreNLP [as 别名]
def __init__(self, properties=None):
        self.__properties = properties if properties is not None else \
            {'annotators': 'tokenize,ssplit,pos,lemma,ner,depparse,mention,dcoref,natlog,openie',
             'depparse.model': 'edu/stanford/nlp/models/parser/nndep/english_SD.gz',
             'outputFormat': 'json'}
        self.__nlp = StanfordCoreNLP('http://localhost:9000')
        self.__instance = None

        self.__stopwords = stopwords.words('english')
        with open('./data/pronouns.txt') as f:
            self.__pronouns = [word.strip() for word in f.readlines()] 
开发者ID:IsaacChanghau,项目名称:AmusingPythonCodes,代码行数:13,代码来源:stanford_corenlp.py

示例6: __init__

# 需要导入模块: import pycorenlp [as 别名]
# 或者: from pycorenlp import StanfordCoreNLP [as 别名]
def __init__(self, host='localhost', port=9000, properties={}):
        url = 'http://{0}:{1}'.format(host, port)
        self.nlp = StanfordCoreNLP(url)

        if not properties:
            self.properties = {
                'annotators': 'parse',
                'outputFormat': 'json',
            }
        else:
            self.properties = properties 
开发者ID:ayoungprogrammer,项目名称:Lango,代码行数:13,代码来源:parser.py


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