def test_analyze_entities(): result = analyze.analyze_entities('Tom Sawyer is a book written by a guy known as Mark Twain..') print (result) assert result['language'] == 'en' entities = result['entities'] assert len(entities) subject = entities[0] assert subject['type'] == 'PERSON' assert subject['name'].startswith('Tom')
def test_analyze_entities(): result = analyze.analyze_entities( 'Tom Sawyer is a book written by a guy known as Mark Twain.') assert result['language'] == 'en' entities = result['entities'] assert len(entities) subject = entities[0] assert subject['type'] == 'PERSON' assert subject['name'].startswith('Tom')
def test_analyze_entities(): result = analyze.analyze_entities( "Tom Sawyer is a book written by a guy known as Mark Twain.") assert result["language"] == "en" entities = result["entities"] assert len(entities) subject = entities[0] assert subject["type"] == "PERSON" assert subject["name"].startswith("Tom")
def get_named_entities(sentence): import analyze as an response = an.analyze_entities(sentence) named_entities = [] for entity in response['entities']: #print(entity['type']) if entity['type'] != 'COMMON': #print(entity['name']) named_entities.append(entity['name']) #named_entities.append(ent.text) return named_entities #named_entities
def add_task(text): global eve_name # イベント名 # usertask = analyze.get_or_insert('task1') result = analyze.analyze_entities(text, analyze.get_native_encoding_type()) datetimes = pars_datetime(text) entities = json.dumps(result.values()) # メタ情報表示 print "ADD_TASK_META++++++++" print type(entities) print type(result) print(result.keys()) print(result.values()) print(result.items()) print "ADD_TASK_META++++++++" for entitie in result['entities']: # エンティティタイプ表示 print "ENTITE_TYPE+++++++" print entitie['type'] print entitie['name'].encode('utf8') print "ENTITE_TYPE+++++++" if entitie['type'] == "EVENT": eve_name = entitie['name'] for mention in entitie['mentions']: # その他の固有表現表示 print "ALL_MENTIONS+++++++" print mention['type'].encode('utf8') print mention['text']['content'].encode('utf8') print "ALL_MENTIONS+++++++" date = json.loads(datetime.content)rlfetch.fetch(url='https://labs.goo.ne.jp/api/chrono', payload=json.dumps(payloads), method=urlfetch.POST, headers=header) return resu for dt in date['datetime_list']: print dt[1] print type(dt[1]) print type(str(dt[1])) # usertask.tag_date = dtime t = datetime.strptime('2014/01/01', '%Y/%m/%d') print t
def getEntities(text): result = analyze_entities(text, get_native_encoding_type()) entitiesList = [Payload(ent) for ent in result['entities']] filteredEntitiesList = list( filter(lambda x: x.type == 'OTHER', entitiesList)) return set([x.name for x in filteredEntitiesList])
def reg2(reply_token, text, userdata): global org_name, und_name, dep_name org_name = u"見つかりません" und_name = u"見つかりません" dep_name = u"見つかりません" rip1 = text.replace(" ", u"、") rip2 = rip1.replace(u" ", u"、") rip3 = u"私はねー!、" + rip2 + u"なんだよー。" print "TEXT_STRIP" print rip3.encode('utf8') print "TEXT_STRIP" result = analyze.analyze_entities(rip3, analyze.get_native_encoding_type()) entities = json.dumps(result.values()) print type(entities) print type(result) print(result.keys()) print(result.values()) print(result.items()) for entitie in result['entities']: print "=====" print entitie['type'] print entitie['name'].encode('utf8') print "=====" if entitie['type'] == "ORGANIZATION" and u"大学" in entitie['name']: org_name = entitie['name'] for mention in entitie['mentions']: if entitie['type'] == "ORGANIZATION" and mention[ 'type'] == "COMMON": print "=====" print "GAKUBU" print mention['text']['content'].encode('utf8') print "======" und_name = mention['text']['content'] elif entitie['type'] == "OTHER": print "=====" print "GAKKA" print mention['text']['content'].encode('utf8') print "======" dep_name = mention['text']['content'] print "ALL_MENTIONS" print mention['type'].encode('utf8') print mention['text']['content'].encode('utf8') print "ALL_MENTIONS" parse = u"学校名: " + org_name + u"\n学部名: " + und_name + u"\n学科名: " + dep_name + u"\nよろしいですか?" payloads = { "replyToken": reply_token, "messages": [{ "type": "template", "altText": parse, "template": { "type": "confirm", "text": parse, "actions": [{ "type": "message", "label": u"はい", "text": u"はい" }, { "type": "message", "label": u"修正", "text": u"修正" }] } }] } Massage.reply(payloads) userdata.flag = "reg3" if org_name != u"見つかりません": userdata.school = org_name if und_name != u"見つかりません": userdata.undergraduate = und_name if dep_name != u"見つかりません": userdata.department = dep_name userdata.put()