Fix some indent.
This commit is contained in:
		
							parent
							
								
									23f4e3a045
								
							
						
					
					
						commit
						dd1ca71957
					
				
					 1 changed files with 43 additions and 47 deletions
				
			
		|  | @ -10,19 +10,17 @@ BASE_URL = "https://api.ce-cotoha.com/api/dev/nlp/" | ||||||
| def auth(client_id, client_secret): | def auth(client_id, client_secret): | ||||||
| 	token_url = "https://api.ce-cotoha.com/v1/oauth/accesstokens" | 	token_url = "https://api.ce-cotoha.com/v1/oauth/accesstokens" | ||||||
| 	headers = { | 	headers = { | ||||||
| 			"Content-Type": "application/json", | 		"Content-Type": "application/json", | ||||||
| 			"charset": "UTF-8" | 		"charset": "UTF-8" | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	data = { | 	data = { | ||||||
| 			"grantType": "client_credentials", | 		"grantType": "client_credentials", | ||||||
| 			"clientId": client_id, | 		"clientId": client_id, | ||||||
| 			"clientSecret": client_secret | 		"clientSecret": client_secret | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	r = requests.post(token_url, | 	r = requests.post(token_url,headers=headers,data=json.dumps(data)) | ||||||
| 										headers=headers, |  | ||||||
| 										data=json.dumps(data)) |  | ||||||
| 
 | 
 | ||||||
| 	return r.json()["access_token"] | 	return r.json()["access_token"] | ||||||
| 
 | 
 | ||||||
|  | @ -33,26 +31,24 @@ def parse(sentence, access_token): | ||||||
| 	base_url = BASE_URL | 	base_url = BASE_URL | ||||||
| 
 | 
 | ||||||
| 	headers = { | 	headers = { | ||||||
| 			"Content-Type": "application/json", | 		"Content-Type": "application/json", | ||||||
| 			"charset": "UTF-8", | 		"charset": "UTF-8", | ||||||
| 			"Authorization": "Bearer {}".format(access_token) | 		"Authorization": "Bearer {}".format(access_token) | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	data = { | 	data = { | ||||||
| 			"sentence": sentence, | 		"sentence": sentence, | ||||||
| 			"type": "default" | 		"type": "default" | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	r = requests.post(base_url + "v1/parse", | 	r = requests.post(base_url + "v1/parse",headers=headers,data=json.dumps(data)) | ||||||
| 										headers=headers, |  | ||||||
| 										data=json.dumps(data)) |  | ||||||
| 	return r.json() | 	return r.json() | ||||||
| 
 | 
 | ||||||
| # ひらがなを削除する関数 | # ひらがなを削除する関数 | ||||||
| # Function to delete hiragana. | # Function to delete hiragana. | ||||||
| # 删除平假名的功能 | # 删除平假名的功能 | ||||||
| def hira_to_blank(str): | def hira_to_blank(str): | ||||||
|     return "".join(["" if ("ぁ" <= ch <= "ん") else ch for ch in str]) |   return "".join(["" if ("ぁ" <= ch <= "ん") else ch for ch in str]) | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
| 	envjson = open('env.json', 'r') | 	envjson = open('env.json', 'r') | ||||||
|  | @ -70,39 +66,39 @@ if __name__ == "__main__": | ||||||
| 	print(parse_document) | 	print(parse_document) | ||||||
| 	result_list = list() | 	result_list = list() | ||||||
| 	for chunks in parse_document['result']: | 	for chunks in parse_document['result']: | ||||||
| 			for token in chunks["tokens"]: | 		for token in chunks["tokens"]: | ||||||
| 					# 形態素解析結果に置き換えルールを適用する | 			# 形態素解析結果に置き換えルールを適用する | ||||||
| 					if (token["pos"] != "連用助詞"  | 			if (token["pos"] != "連用助詞"  | ||||||
| 					and token["pos"] != "引用助詞"  | 			and token["pos"] != "引用助詞"  | ||||||
| 					and token["pos"] != "終助詞"  | 			and token["pos"] != "終助詞"  | ||||||
| 					and token["pos"] != "接続接尾辞"  | 			and token["pos"] != "接続接尾辞"  | ||||||
| 					and token["pos"] != "動詞活用語尾"): | 			and token["pos"] != "動詞活用語尾"): | ||||||
| 							if token["pos"] == "動詞接尾辞" and '終止' in token["features"]: | 				if token["pos"] == "動詞接尾辞" and '終止' in token["features"]: | ||||||
| 									if ("する" in token["lemma"]) or ("ます" in token["lemma"]): | 					if ("する" in token["lemma"]) or ("ます" in token["lemma"]): | ||||||
| 											prime = "也" | 						prime = "也" | ||||||
| 									elif "たい" in token["lemma"]: | 					elif "たい" in token["lemma"]: | ||||||
| 											prime = "希望" | 						prime = "希望" | ||||||
| 									elif token['lemma'] != 'ない': | 					elif token['lemma'] != 'ない': | ||||||
| 											prime = "了" | 						prime = "了" | ||||||
| 									else: | 					else: | ||||||
| 											prime = "実行" | 						prime = "実行" | ||||||
| 							else: | 				else: | ||||||
| 									prime = token["form"] | 					prime = token["form"] | ||||||
| 
 | 
 | ||||||
| 							if token['lemma'] == '私': | 				if token['lemma'] == '私': | ||||||
| 									prime = '我' | 					prime = '我' | ||||||
| 
 | 
 | ||||||
| 							if (token['lemma'] == '君' or token['lemma'] == 'あなた' or token['lemma'] == 'お前'): | 				if (token['lemma'] == '君' or token['lemma'] == 'あなた' or token['lemma'] == 'お前'): | ||||||
| 									prime = '你' | 					prime = '你' | ||||||
| 
 | 
 | ||||||
| 							if len(token["features"]) != 0: | 				if len(token["features"]) != 0: | ||||||
| 									if "SURU" in token["features"][0] : | 					if "SURU" in token["features"][0] : | ||||||
| 											prime = "実行" | 						prime = "実行" | ||||||
| 									elif "連体" in token['features'][0]: | 					elif "連体" in token['features'][0]: | ||||||
| 											prime = "的" | 						prime = "的" | ||||||
| 									elif "疑問符" in token["features"][0]: | 					elif "疑問符" in token["features"][0]: | ||||||
| 											prime = "如何?" | 						prime = "如何?" | ||||||
| 
 | 
 | ||||||
| 							result_list.append(hira_to_blank(prime)) | 				result_list.append(hira_to_blank(prime)) | ||||||
| 
 | 
 | ||||||
| 	print(''.join(result_list)) | 	print(''.join(result_list)) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 k2font
						k2font