def location(inputSTR): global username global apikey articut = Articut(username=username, apikey=apikey) resultDICT = articut.parse(inputSTR, level="lv2") locLIST = articut.getLocationStemLIST(resultDICT) return locLIST
with open("../../account.info", "r") as f: userDICT = json.loads(f.read()) username = userDICT["email"] apikey = userDICT["apikey"] atc = Articut(username=userDICT["email"], apikey=userDICT["apikey"]) except: #使用免費的斷詞額度。 #實體化 Articut() atc = Articut() #載入 Demo 用的文字 with open("./PengHu.txt", encoding="utf-8") as f: contentLIST = [l.replace("\n", "") for l in f.readlines()] resultLIST = [] for c in contentLIST: print("Processing:{}/{} >> {}".format( contentLIST.index(c) + 1, len(contentLIST), c)) resultDICT = atc.parse(c, openDataPlaceAccessBOOL=True) locationLIST = atc.getLocationStemLIST(resultDICT) if locationLIST != None: resultLIST.extend(locationLIST) else: pass print("DetectionResult:\n") pprint(resultLIST) with open("./LocationDetectionResultLIST.json", "w", encoding="utf-8") as f: json.dump(resultLIST, f, ensure_ascii=False)