本文整理匯總了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