def __init__(self, username="", apikey="", version="latest", level="lv2"): ''' username = "" # 你註冊時的 email。若留空,則會使用每小時更新 2000 字的公用帳號。 apikey = "" # 您完成付費後取得的 apikey 值。若留空,則會使用每小時更新 2000 字的公用帳號。 ''' try: with open("./account.info", "r") as f: userDICT = json.loads(f.read()) self.username = userDICT["email"] self.apikey = userDICT["apikey"] except: self.username = username self.apikey = apikey self.url = "https://api.droidtown.co" self.version = version self.level = level self.userDefinedDictFILE = None self.openDataPlaceAccessBOOL = False self.chemicalBOOL = True self.fileSizeLimit = 1024 * 1024 * 10 # 10 MB # Toolkit self.analyse = AnalyseManager() self.localRE = TaiwanAddressAnalizer(locale="TW")
def __init__(self, url="http://127.0.0.1", port="8964", bulkSize=20, userDefinedDictFILE=None): self.port = port if "http" not in url: self.url = "http://{}:{}".format(url, port) else: self.url = "{}:{}".format(url, port) self.bulkSize = bulkSize self.processes = cpu_count() if self.processes > 8: self.processes = 8 self.userDefinedDictFILE = None self.openDataPlaceAccessBOOL=False self.fileSizeLimit = 1024 * 1024 * 10 # 10 MB self.userDefinedDICT = {} if userDefinedDictFILE: try: if os.path.getsize(userDefinedDictFILE) <= self.fileSizeLimit: userDefinedFile = json.load(open(userDefinedDictFILE, "r", encoding="utf8")) if type(userDefinedFile) == dict: self.userDefinedDICT = userDefinedFile else: print("User Defined File must be dict type.") return {"status": False, "msg": "UserDefinedDICT Parsing ERROR. Please check your the format and encoding."} else: print("Maximum file size limit is 10 MB.") except Exception as e: print("User Defined File Loading Error.") print(str(e)) return {"status": False, "msg": "UserDefinedDICT Parsing ERROR. Please check your the format and encoding."} # Toolkit self.analyse = AnalyseManager() self.localRE = TaiwanAddressAnalizer(locale="TW")
def __init__(self, username="", apikey="", version="latest", level="lv2"): ''' username = "" # 你註冊時的 email。若留空,則會使用每日 1 萬字的公用帳號。 apikey = "" # 您完成付費後取得的 apikey 值。若留空,則會使用每日 1 萬字的公用帳號。 ''' try: with open("./account.info", "r") as f: userDICT = json.loads(f.read()) self.username = userDICT["email"] self.apikey = userDICT["apikey"] except: self.username = username self.apikey = apikey self.url = "https://api.droidtown.co" self.version = version self.level = level self.userDefinedDictFILE = None self.openDataPlaceAccessBOOL = False self.fileSizeLimit = 1024 * 1024 * 10 # 10 MB self.verbPPat = re.compile("(?<=<VerbP>)[^<]*?(?=.</VerbP>)") self.verbPat = re.compile("(?<=<ACTION_verb>)[^<]*?(?=</ACTION_verb>)") self.nounPat = re.compile( "(?<=<ENTITY_nounHead>)[^<]*?(?=</ENTITY_nounHead>)|(?<=<ENTITY_nouny>)[^<]*?(?=</ENTITY_nouny>)|(?<=<ENTITY_noun>)[^<]*?(?=</ENTITY_noun>)|(?<=<ENTITY_oov>)[^<]*?(?=</ENTITY_oov>)" ) self.modifierPat = re.compile("(?<=<MODIFIER>)[^<]*?(?=</MODIFIER>)") self.funcPat = re.compile( "(?<=<AUX>)[^<]*?(?=</AUX>)|(?<=<FUNC_in[nt]er>)[^<]*?(?=</FUNC_in[nt]er>)|(?<=<RANGE_locality>)[^<]*?(?=</RANGE_locality>)|(?<=<RANGE_period>)[^<]*?(?=</RANGE_period>)" ) self.personPat = re.compile( "(?<=<ENTITY_person>)[^<]*?(?=</ENTITY_person>)") self.pronounPat = re.compile( "(?<=<ENTITY_pronoun>)[^<]*?(?=</ENTITY_pronoun>)") self.locationPat = re.compile("(?<=<LOCATION>)[^<]*?(?=</LOCATION>)") self.placePat = re.compile( "(?<=<KNOWLEDGE_place>)[^<]*?(?=</KNOWLEDGE_place>)") self.timePat = re.compile( "(?<=<TIME_decade>)[^<]*?(?=</TIME_decade>)|(?<=<TIME_year>)[^<]*?(?=</TIME_year>)|(?<=<TIME_season>)[^<]*?(?=</TIME_season>)|(?<=<TIME_month>)[^<]*?(?=</TIME_month>)|(?<=<TIME_week>)[^<]*?(?=</TIME_week>)|(?<=<TIME_day>)[^<]*?(?=</TIME_day>)|(?<=<TIME_justtime>)[^<]*?(?=</TIME_justtime>)" ) self.eventPat = re.compile( "<ACTION_lightVerb>[^<]</ACTION_lightVerb>((?<!</LOCATION>)<ENTITY_nouny>[^<]</ENTITY_nouny>)?((<ACTION_verb>[^<]*?</ACTION_verb>)|(<ENTITY_nouny?>[^<]*?</ENTITY_nouny?>$))|<ACTION_verb>.?[有現到見道]</ACTION_verb>(<ENTITY_nouny?>[^<]*?</ENTITY_nouny?>|<ENTITY_person>[^<]*?</ENTITY_person>)$|(?<=[有現到見道]</ACTION_verb>)((?<!</LOCATION>)<ENTITY_nouny?>[^<]*?</ENTITY_nouny?>)?<ACTION_verb>[^<有現到見道]{1,2}</ACTION_verb>$|((?<!</LOCATION>)<ENTITY_nouny?>[^<]*?</ENTITY_nouny?>)?<ACTION_verb>[^<有現到見道]{1,2}</ACTION_verb>(?!<ACTION)(?!<LOCATION)(?!<KNOWLEDGE)(?!<MODIFIER>)(?!<ENTITY_classifier)(?!<ENTITY_pronoun>)(<ENTITY_nouny?>[^<]*?</ENTITY_nouny?>|<ENTITY_person>[^<]*?</ENTITY_person>)?|<ACTION_lightVerb>.</ACTION_lightVerb><VerbP>[^<]*?</VerbP>|<ACTION_verb>[^<]*?</ACTION_verb>($|(?=<ACTION_verb>))" ) self.addTWPat = re.compile( "(?<=<KNOWLEDGE_addTW>)[^<]*?(?=</KNOWLEDGE_addTW>)") self.stripPat = re.compile("(?<=>).*?(?=<)") self.clausePat = re.compile("\<CLAUSE_.*?Q\>") self.contentPat = re.compile("|".join([ self.verbPat.pattern, self.nounPat.pattern, self.modifierPat.pattern, self.verbPPat.pattern ])) # Toolkit self.analyse = AnalyseManager() self.localRE = TaiwanAddressAnalizer(locale="TW") try: self.graphQL = GraphQL() except: pass
def __init__(self, url="ws://127.0.0.1", port="8964", bulkSize=20, userDefinedDictFILE=None): self.port = port if url.startswith("ws"): self.ws_url = "{}:{}/Articut/WebSocket".format(url, port) self.url = "{}:{}".format(url.replace("ws", "http"), port) elif url.startswith("http"): self.ws_url = "{}:{}/Articut/WebSocket".format( url.replace("http", "ws"), port) self.url = "{}:{}".format(url, port) else: self.ws_url = "ws://{}:{}/Articut/WebSocket".format(url, port) self.url = "http://{}:{}".format(url, port) #enableTrace(True) self.ws = create_connection("{}/API/".format(self.ws_url)) self.ws_bulk = create_connection("{}/BulkAPI/".format(self.ws_url)) self.bulkSize = bulkSize self.userDefinedDictFILE = None self.openDataPlaceAccessBOOL = False self.fileSizeLimit = 1024 * 1024 * 10 # 10 MB self.userDefinedDICT = {} if userDefinedDictFILE: try: if os.path.getsize(userDefinedDictFILE) <= self.fileSizeLimit: userDefinedFile = json.load( open(userDefinedDictFILE, "r", encoding="utf8")) if type(userDefinedFile) == dict: self.userDefinedDICT = userDefinedFile else: print("User Defined File must be dict type.") return { "status": False, "msg": "UserDefinedDICT Parsing ERROR. Please check your the format and encoding." } else: print("Maximum file size limit is 10 MB.") except Exception as e: print("User Defined File Loading Error.") print(str(e)) return { "status": False, "msg": "UserDefinedDICT Parsing ERROR. Please check your the format and encoding." } # Toolkit self.analyse = AnalyseManager() self.localRE = TaiwanAddressAnalizer(locale="TW") self.LawsToolkit = LawsToolkit() self.NER = GenericNER() self.POS = ArticutPOS()
def __init__(self, username="", apikey="", version="latest", level="lv2"): ''' username = "" # 你註冊時的 email。若留空,則會使用每小時更新 2000 字的公用帳號。 apikey = "" # 您完成付費後取得的 apikey 值。若留空,則會使用每小時更新 2000 字的公用帳號。 ''' try: with open("./account.info", "r") as f: userDICT = json.loads(f.read()) self.username = userDICT["email"] self.apikey = userDICT["apikey"] except: self.username = username self.apikey = apikey self.url = "https://api.droidtown.co" self.version = version self.level = level self.userDefinedDictFILE = None self.openDataPlaceAccessBOOL = False self.fileSizeLimit = 1024 * 1024 * 10 # 10 MB # Regex Pattern self.verbPPat = re.compile("(?<=<VerbP>)[^<]*?(?=.</VerbP>)") self.verbPat = re.compile("(?<=<ACTION_verb>)[^<]*?(?=</ACTION_verb>)") self.nounPat = re.compile( "(?<=<ENTITY_nounHead>)[^<]*?(?=</ENTITY_nounHead>)|(?<=<ENTITY_nouny>)[^<]*?(?=</ENTITY_nouny>)|(?<=<ENTITY_noun>)[^<]*?(?=</ENTITY_noun>)|(?<=<ENTITY_oov>)[^<]*?(?=</ENTITY_oov>)" ) self.modifierPat = re.compile("(?<=<MODIFIER>)[^<]*?(?=</MODIFIER>)") self.modifierPPat = re.compile( "(?<=<DegreeP>)[^<]*?(?=</DegreeP>)|(?<=<ModifierP>)[^<]*?(?=</ModifierP>)" ) self.funcPat = re.compile( "(?<=<AUX>)[^<]*?(?=</AUX>)|(?<=<FUNC_in[nt]er>)[^<]*?(?=</FUNC_in[nt]er>)|(?<=<RANGE_locality>)[^<]*?(?=</RANGE_locality>)|(?<=<RANGE_period>)[^<]*?(?=</RANGE_period>)" ) self.personPat = re.compile( "(?<=<ENTITY_person>)[^<]*?(?=</ENTITY_person>)") self.pronounPat = re.compile( "(?<=<ENTITY_pronoun>)[^<]*?(?=</ENTITY_pronoun>)") self.locationPat = re.compile( "(?<=<LOCATION>)[^<]*?(?=</LOCATION>)|(?<=<KNOWLEDGE_addTW>)[^<]*?(?=</KNOWLEDGE_addTW>)|(?<=<KNOWLEDGE_routeTW>)[^<]*?(?=</KNOWLEDGE_routeTW>)" ) self.userDefinedPat = re.compile( "(?<=<UserDefined>)[^<]*?(?=</UserDefined>)") self.placePat = re.compile( "(?<=<KNOWLEDGE_place>)[^<]*?(?=</KNOWLEDGE_place>)") self.timePat = re.compile( "(?<=<TIME_decade>)[^<]*?(?=</TIME_decade>)|(?<=<TIME_year>)[^<]*?(?=</TIME_year>)|(?<=<TIME_season>)[^<]*?(?=</TIME_season>)|(?<=<TIME_month>)[^<]*?(?=</TIME_month>)|(?<=<TIME_week>)[^<]*?(?=</TIME_week>)|(?<=<TIME_day>)[^<]*?(?=</TIME_day>)|(?<=<TIME_justtime>)[^<]*?(?=</TIME_justtime>)" ) self.addTWPat = re.compile( "(?<=<KNOWLEDGE_addTW>)[^<]*?(?=</KNOWLEDGE_addTW>)") self.currencyPat = re.compile( "(?<=<KNOWLEDGE_currency>)[^<]*?(?=</KNOWLEDGE_currency>)") self.currencyGreedyPat = re.compile( "(?<=[元金幣圜圓比布索鎊盾銖令朗郎]</ENTITY_noun><ENTITY_num>)[^<]*?(?=</ENTITY_num>)" ) self.currencyGreedyGapPat = re.compile( "(?<=^<ENTITY_num>)[^<]*?(?=</ENTITY_num>)") self.wikiDataPat = re.compile( "(?<=<KNOWLEDGE_wikiData>)[^<]*?(?=</KNOWLEDGE_wikiData>)") self.stripPat = re.compile("(?<=>).*?(?=<)") self.clausePat = re.compile("\<CLAUSE_.*?Q\>") self.contentPat = re.compile("|".join([ self.verbPPat.pattern, self.verbPat.pattern, self.nounPat.pattern, self.modifierPat.pattern, self.modifierPPat.pattern, self.userDefinedPat.pattern ])) # Toolkit self.analyse = AnalyseManager() self.localRE = TaiwanAddressAnalizer(locale="TW") try: self.graphQL = GraphQL() except: pass