當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。