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, 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 # Toolkit self.analyse = AnalyseManager() self.localRE = TaiwanAddressAnalizer(locale="TW") try: self.graphQL = GraphQL() except: pass
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