本文整理汇总了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)
示例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)
示例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
示例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)
示例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()]
示例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