def getExpansions(self, sentence): self.getCredentials() self.AuthClient = Authentication(self.username, self.password) self.logger.info('In getExpansions function of UMLSExpander') # get TGT for our session self.tgt = self.AuthClient.gettgt() self.uri = "https://uts-ws.nlm.nih.gov" self.cache = SingletonUMLSCache.Instance().cache synonyms = [] synonyms = sentence.strip().split() metaConcepts = self.getMetaConcepts(sentence) for mconcept in metaConcepts: try: for el in self.cache[mconcept]: synonyms.append(el) self.logger.info('Found UMLS Cached Concept: ' + str(mconcept.cui)) except: try: termSyns = [] self.logger.info('Getting concept expansions from UMLS') # metamap has direct mapping with UMLS based on Concept Unique Identification (CUI) cui = mconcept.cui content_endpoint = "/rest/content/" + str( self.version) + "/CUI/" + str(cui) query = {'ticket': self.AuthClient.getst(self.tgt)} r = requests.get(self.uri + content_endpoint, params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] try: query = {'ticket': self.AuthClient.getst(self.tgt)} # THE REST API returns a json object that includes other concepts with different relations r = requests.get(jsonData["relations"], params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] for el in jsonData: ''' This is how to access differennt relations in UMLS #if el['relationLabel'] == 'RL' or el['relationLabel'] == 'RQ': ''' termSyns.append(el['relatedIdName']) synonyms.append(el['relatedIdName']) self.cache[mconcept] = termSyns self.logger.info( 'Parsed the JSON object returned from UMLS') except Exception as e: self.logger.debug('Exception in UMLS Expansion ' + str(e)) pass except: pass # class method of Expander that stops the metamap # self.stopMetaMap() listSynonyms = list(set(synonyms)) ExpandedSentence = ' '.join(listSynonyms) return ExpandedSentence
def get_atoms(cuis, tgt=None): auth = Authentication.Authentication(apikeyfile) if not tgt: tgt = auth.get_ticket_granting_ticket() atoms = {} params = {'language': language} for cui in cuis: #print("In CUI loop") #print(cui) params['ticket'] = auth.get_service_ticket(tgt) request = requests.get(base_uri + all_atoms.format(cui), params=params) if request.status_code != 404: #dataform = str(request).strip("'<>() ").replace('\'', '\"') #results = json.loads(dataform) #request = requests.get(base_uri + all_atoms.format(cui), params=params).json() #print(request.text) results = simplejson.loads(request.text) #print(results) atoms[cui] = [] for atom in results['result']: atoms[cui].append(atom['name']) else: atoms[cui] = [] return atoms
def get_category(string): apikey = "" version = "current" uri = "https://uts-ws.nlm.nih.gov" content_endpoint = "/rest/search/" + version string = string AuthClient = Authentication(apikey) tgt = AuthClient.gettgt() pageNumber = 0 ticket = AuthClient.getst(tgt) pageNumber += 1 query = {'string': string, 'ticket': ticket, 'pageNumber': pageNumber} r = requests.get(uri + content_endpoint, params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] result = jsonData["results"][0] try: uri = result["uri"].replace("2020AA", "current") # 根据得到的uri进行再一次的查找 ticket = AuthClient.getst(tgt) query = {"ticket": ticket} r = requests.get(uri, params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] category = jsonData["semanticTypes"][0]["name"] # print(string, " ", category) return category except Exception as e: # print(string, " ", "error") return "error"
def __init__(self, searchlist=[], searchtype="word"): # self.username=username # self.password=password self.searchlist = searchlist # "[ 'Therapeutic', 'fever' ]" self.searchtype = searchtype # "word" self.sabs = "NANDA-I" self.AuthClient = Authentication(apikey) self.tgt = self.AuthClient.gettgt()
def concept_lookup(apikey,version,string): name_l=[] uri = "https://uts-ws.nlm.nih.gov" content_endpoint = "/rest/search/"+version ##get at ticket granting ticket for the session AuthClient = Authentication(apikey) tgt = AuthClient.gettgt() pageNumber=0 while True: ##generate a new service ticket for each page if needed ticket = AuthClient.getst(tgt) pageNumber += 1 query = {'string':string,'ticket':ticket, 'pageNumber':pageNumber} #query['includeObsolete'] = 'true' #query['includeSuppressible'] = 'true' #query['returnIdType'] = "sourceConcept" #query['sabs'] = "SNOMEDCT_US" query['searchType']='exact' r = requests.get(uri+content_endpoint,params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] #print (json.dumps(items, indent = 4)) print("Results for page " + str(pageNumber)+"\n") for result in jsonData["results"]: try: print("ui: " + result["ui"]) except: NameError try: print("uri: " + result["uri"]) except: NameError try: print("name: " + result["name"]) name_l.append(result["name"]) except: NameError try: print("Source Vocabulary: " + result["rootSource"]) except: NameError print("\n") ##Either our search returned nothing, or we're at the end if jsonData["results"][0]["ui"] == "NONE": break print("*********") return name_l
def retrieve_from_api_by_source(endpoint,apikey): AuthClient = Authentication(apikey) tgt = AuthClient.gettgt() query = {'ticket':AuthClient.getst(tgt), "language":"ENG", "pageNumber":1, "pageSize":1000} r = requests.get(endpoint, params = query) r.encoding = "utf-8" try: items = json.loads(r.text) return items except ValueError: print("Decode failed...")
def goto_authentication(self): if not self.opened_dialog: self.opened_dialog = True # Instantiate window, bind focus change to func, set focus self.window = Authentication.Authentication(Toplevel(self.parent), self) self.window.parent.bind("<FocusOut>", self.focus_out) self.window.parent.focus_set() # Open window and make main window wait self.parent.wait_window(self.window.parent) self.opened_dialog = False else: self.window.parent.focus_set()
def save_atoms(filename, atomfile='split_atoms.pickle'): tree = ET.parse(filename) root = tree.getroot() auth = Authentication.Authentication(apikeyfile) tgt = auth.get_ticket_granting_ticket() qno_atoms = {} for topic in root: number = topic.attrib['number'] disease = clean(topic.find('disease').text) gene = clean(topic.find('gene').text) demographic = clean(topic.find('demographic').text) if topic.find('other'): other = clean(topic.find('other').text) else: other = '' text = { 'disease': disease, 'gene': gene, 'demographic': demographic, 'other': other } qno_atoms[number] = {} fn = 'tempfile' fnout = fn + '.txt' fnin = fn + '.mmi' for key, value in text.items(): with open(fnout, 'w') as fout: fout.write(value) subprocess.run(mm_lite + [fnout]) cuis = [] with open(fnin, 'r') as fin: for line in fin: tokens = line.strip().split('|') cuis.append(tokens[4]) atoms = get_atoms(cuis, tgt) qno_atoms[number][key] = atoms with open(atomfile, 'wb') as outfile: pickle.dump(qno_atoms, outfile)
def getValue(cui, concept): try: apikey = "86a68870-ddd3-40d5-8454-de804bffd1b3" identifier = cui AuthClient = Authentication(apikey) tgt = AuthClient.gettgt() uri = "https://uts-ws.nlm.nih.gov" content_endpoint = "/rest/content/current/CUI/" + str( identifier) + "/" + concept query = {'ticket': AuthClient.getst(tgt)} r = requests.get(uri + content_endpoint, params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] return jsonData except: return {}
def search_term(string, page_limit=2, check=False): #apikey = '6119ca85-39ff-4649-aa79-6c1b1d281a02' #TP# apikey = 'b30cd58c-9d49-40fe-99ca-5b4807458c37' #version = '2018AA' version = 'current' string = string uri = "https://uts-ws.nlm.nih.gov" content_endpoint = "/rest/search/" + version ##get at ticket granting ticket for the session AuthClient = Authentication(apikey) tgt = AuthClient.gettgt() pageNumber = 0 res = [] while True: ##generate a new service ticket for each page if needed ticket = AuthClient.getst(tgt) pageNumber += 1 query = {'string': string, 'ticket': ticket, 'pageNumber': pageNumber} r = requests.get(uri + content_endpoint, params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] #print (json.dumps(items, indent = 4))s #print("Results for page " + str(pageNumber)+"\n") if jsonData["results"][0]["ui"] == "NONE" or pageNumber > page_limit: break for result in jsonData["results"]: if check: try: res.append((result["ui"], result["name"])) except: NameError else: try: res.append(result["ui"]) except: NameError ##Either our search returned nothing, or we're at the end return res
def init_authentication(api_key): global last_auth_time, last_auth_client global auth_client now_time = time.time() ## Re-authorize every thirty minutes if (last_auth_time is None or (now_time - last_auth_time) > 30 * 60): if (last_auth_time is None): log.debug('Authenticating with the UTS server') else: log.debug('Re-authenticating with the UTS server') last_auth_time = time.time() auth_client = Authentication(api_key) last_auth_client = auth_client else: auth_client = last_auth_client ################################### #get TGT for our session ################################### return auth_client
def get_atoms_from_str(disease): auth = Authentication.Authentication(apikeyfile) tgt = auth.get_ticket_granting_ticket() fn = 'tempfile' fnout = fn + '.txt' fnin = fn + '.mmi' with open(fnout, 'w') as fout: fout.write(disease) subprocess.run(mm_lite + [fnout]) cuis = [] with open(fnin, 'r') as fin: for line in fin: tokens = line.strip().split('|') cuis.append(tokens[4]) #print("In getatoms method") #print(cuis) atoms = get_atoms(cuis, tgt) return atoms
############################################# global gen_dir, cache, cuilist, username, password, version, AuthClient, tgt, uri gen_dir = "generatedSummaries" cache = {} #{cui:jsonData} cuilist=[] #umls authentication username = "******" password = "******" #apikey = args.apikey version = "2016AB" #identifier = args.identifier #source = args.source AuthClient = Authentication(username,password) #get TGT for our session tgt = AuthClient.gettgt() uri = "https://uts-ws.nlm.nih.gov" #initializing lucene parameters lucene.initVM() analyzer = StandardAnalyzer() reader_first = DirectoryReader.open(SimpleFSDirectory(Paths.get("/home/khyathi/Projects/bioasq/medline17n-lucene1/"))) searcher = IndexSearcher(reader_first) ############################################# app = Flask(__name__)
def uri_setup(): apikey = config.api_key AuthClient = Authentication(apikey) return [uri, AuthClient]
import Authentication import diagnosis import Patient auth = Authentication.Authentication() db = Authentication.Database() diag = diagnosis.Diagnosis() patient = Patient.PatientInfo() class Hrm: email = "" password = "" doctor_details = { "doctors_name": " ", "doctors_specialization": " ", "hospital_name": " ", } def greet(self): print("Hello Doctor!!!!") def ask_for_user_choice(self): print("Do you want to login or register ?") choice = input("Enter: \n 1 : Login \n 2 : Register \n ") if int(choice) == 1: self.ask_for_user_data() self.login_user() elif int(choice) == 2:
def retrieve_by_cui(self, cui): apikey = "bc854b26-2a47-4b7e-b4f2-7b324d54804f" identifier = cui AuthClient = Authentication(apikey) version = "current" tgt = AuthClient.gettgt() uri = "https://uts-ws.nlm.nih.gov" content_endpoint = "/rest/content/" + str(version) + "/CUI/" + str(identifier) query = {'ticket': AuthClient.getst(tgt)} if (self.cnt + 1) % 4500 == 0: time.sleep(120) self.cnt += 1 try: r = requests.get(uri + content_endpoint, params=query) r.encoding = 'utf-8' items = json.loads(r.text) jsonData = items["result"] name = jsonData["name"] return name except: return 'UNK' # if __name__ == '__main__': # print retrieve_by_cui("C0001964") # parser = argparse.ArgumentParser(description='process user given parameters') # # parser.add_argument("-u", "--username", required = True, dest="username", help = "enter username") # # parser.add_argument("-p", "--password", required = True, dest="password", help = "enter passowrd") # parser.add_argument("-k", "--apikey", required=True, dest="apikey", help="enter api key from your UTS Profile") # parser.add_argument("-v", "--version", required=False, dest="version", default="current", # help="enter version example-2015AA") # parser.add_argument("-i", "--identifier", required=True, dest="identifier", help="enter identifier example-C0018787") # parser.add_argument("-s", "--source", required=False, dest="source", help="enter source name if known") # # args = parser.parse_args() # # # username = args.username # # password = args.password # apikey = args.apikey # version = args.version # identifier = args.identifier # source = args.source # AuthClient = Authentication(apikey) # # ################################### # # get TGT for our session # ################################### # # tgt = AuthClient.gettgt() # uri = "https://uts-ws.nlm.nih.gov" # # try: # source # except NameError: # source = None # # ##if we don't specify a source vocabulary, assume we're retrieving UMLS CUIs # if source is None: # content_endpoint = "/rest/content/" + str(version) + "/CUI/" + str(identifier) # # else: # content_endpoint = "/rest/content/" + str(version) + "/source/" + str(source) + "/" + str(identifier) # # ##ticket is the only parameter needed for this call - paging does not come into play because we're only asking for one Json object # query = {'ticket': AuthClient.getst(tgt)} # r = requests.get(uri + content_endpoint, params=query) # r.encoding = 'utf-8' # items = json.loads(r.text) # jsonData = items["result"] # # ##uncomment the print statment if you want the raw json output, or you can just look at the documentation :=) # # https://documentation.uts.nlm.nih.gov/rest/concept/index.html#sample-output # # https://documentation.uts.nlm.nih.gov/rest/source-asserted-identifiers/index.html#sample-output # # print (json.dumps(items, indent = 4)) # # ############################ # ### Print out fields #### # # classType = jsonData["classType"] # name = jsonData["name"] # ui = jsonData["ui"] # AtomCount = jsonData["atomCount"] # Definitions = jsonData["definitions"] # Atoms = jsonData["atoms"] # DefaultPreferredAtom = jsonData["defaultPreferredAtom"] # # ## print out the shared data elements that are common to both the 'Concept' and 'SourceAtomCluster' class # print ("classType: " + classType) # print ("ui: " + ui) # print ("Name: " + name) # print ("AtomCount: " + str(AtomCount)) # print ("Atoms: " + Atoms) # print ("Default Preferred Atom: " + DefaultPreferredAtom) # # ## These data elements may or may not exist depending on what class ('Concept' or 'SourceAtomCluster') you're dealing with so we check for each one. # try: # jsonData["definitions"] # print ("definitions: " + jsonData["definitions"]) # except: # pass # # try: # jsonData["parents"] # print ("parents: " + jsonData["parents"]) # except: # pass # # try: # jsonData["children"] # print ("children: " + jsonData["children"]) # except: # pass # # try: # jsonData["relations"] # print ("relations: " + jsonData["relations"]) # except: # pass # # try: # jsonData["descendants"] # print ("descendants: " + jsonData["descendants"]) # except: # pass # # try: # jsonData["semanticTypes"] # print("Semantic Types:") # for stys in jsonData["semanticTypes"]: # print("uri: " + stys["uri"]) # print("name: " + stys["name"]) # # except: # pass
# on the /search endpoint ################################################################################# from __future__ import print_function from Authentication import * import requests import json import argparse from collections import defaultdict version = "current" #string = "diabetic foot" uri = "https://uts-ws.nlm.nih.gov" content_endpoint = "/rest/search/" + version ##get at ticket granting ticket for the session AuthClient = Authentication("", " ", " ") cuiList = [] dicConcept = defaultdict(list) def searchTerm(term, key): pageNumber = 0 print("term is", term) while True: ticket = AuthClient.getst(key) pageNumber += 1 query = { 'string': term,
def get_cid(search_term, dicSemanticType): username = '******' password = '******' version = '2018AB' url = "https://uts-ws.nlm.nih.gov" content_endpoint = "/rest/search/" + version ##get at ticket granting ticket for the session tries = 0 while 1: try: AuthClient = Authentication(username, password) tgt = AuthClient.gettgt() except requests.exceptions.ConnectionError: print("ConnectionError1") time.sleep(120) tries += 1 print("retring: ", tries) continue except IndexError: print("IndexError1") time.sleep(120) tries += 1 print("retring: ", tries) continue except requests.exceptions.SSLError: print("SSLError1") time.sleep(120) tries += 1 print("retring: ", tries) continue break listResult = [] listSearchType = ['exact'] for searchType in listSearchType: boolNextPage = True pageNumber = 0 # iterating through each page while boolNextPage & (pageNumber < 2): ##generate a new service ticket for each page if needed tries = 0 while 1: try: ticket = AuthClient.getst(tgt) except requests.exceptions.ConnectionError: print("ConnectionError2") time.sleep(120) tries += 1 print("retring: ", tries) continue except IndexError: print("IndexError2") time.sleep(120) tries += 1 print("retring: ", tries) continue except requests.exceptions.SSLError: print("SSLError2") time.sleep(120) tries += 1 print("retring: ", tries) continue break pageNumber += 1 query = {'string': search_term, 'ticket': ticket, 'pageNumber': pageNumber, 'searchType': searchType} # https://stackoverflow.com/questions/23013220/max-retries-exceeded-with-url-in-requests session = requests.Session() retry = Retry(connect=300, backoff_factor=15) adapter = HTTPAdapter(max_retries=retry) session.mount('http://', adapter) session.mount('https://', adapter) # https://stackoverflow.com/questions/16573332/jsondecodeerror-expecting-value-line-1-column-1-char-0 tries = 0 while 1: try: items = session.get(url + content_endpoint, params=query).json() # items = requests.get(url + content_endpoint, params=query).json() except json.decoder.JSONDecodeError: print("JSONDecodeError3") time.sleep(120) tries += 1 print("retring: ", tries) continue except requests.exceptions.SSLError: print("SSLError3") time.sleep(120) tries += 1 print("retring: ", tries) continue break jsonData = items["result"] for result in jsonData["results"]: try: # print("ui: " + result["ui"]) if (result["ui"] != 'NONE') & (result["ui"] in dicSemanticType) & (not 'wt Allele' in result["name"]): listResult.append(result["ui"] + "\t" + result["name"] + "\t" + dicSemanticType[result["ui"]]) # print(string + "\t" + result["ui"] + "\t" + result["name"] + "\t" + dicSemanticType[result["ui"]]) except: print("Name Error: ", search_term) NameError # if either our search returned nothing, or we're at the end if jsonData["results"][0]["ui"] == "NONE": boolNextPage = False # if more exact search result is available if len(listResult) != 0: break # if the results from all search types are not available if len(listResult) == 0: listResult = ["NA\tNA\tNA"] listReturn = [] for i in range(len(listResult)): if "T087" in listResult[i]: listReturn.append(listResult[i]) if len(listReturn) == 0: listReturn = listResult listTemp = sorted(listReturn)[0].split("\t") if not len(listTemp): print(search_term, listTemp, searchType) return "\t".join([listTemp[1], listTemp[0], listTemp[2]])
class ProcessRequests: auth = Authentication() question = ['how are you', 'how are you doing'] var3 = ['time'] cmdjokes = ['joke', 'funny'] cmd2 = ['music', 'songs', 'song'] jokes = [ "can a kangaroo jump higher than a house? of course, a house doesn’t jump at all.", 'my dog used to chase people on a bike a lot. it got so bad, finally i had to take his bike away.', 'doctor: im sorry but you suffer from a terminal illness and have only 10 to live.patient: what do you mean, 10? 10 what? months? weeks?!"doctor: nine.' ] cmd4 = ['open youtube', 'i want to watch a video'] cmd5 = ['weather'] exitCmd = ['exit', 'close', 'goodbye', 'nothing'] cmd7 = [ 'what is your color', 'what is your colour', 'your color', 'your color?' ] colrep = [ 'right now its rainbow', 'right now its transparent', 'right now its non chromatic' ] cmd8 = ['what is you favourite colour', 'what is your favourite color'] cmd9 = ['thank you'] rep9 = ["you're welcome", 'glad i could help you'] webSearch: List[str] = ['firefox', 'internet', 'browser'] sound = ['volume', 'sound'] txtEdit = ['notepad'] says = ['tell', 'say'] newsText = ['news', 'headlines'] posAnswers = ['yes', 'ok', 'yop'] negAnswers = ['no', 'never', 'nope'] mailCmd = ['mail', 'email'] mypc = ['pc', 'laptop', 'system', 'computer'] logoutCmd = ['log', 'sign', 'logout', 'signout'] def validateCommand(self, query, givenList): for word in query: for gword in givenList: if (word == gword): return True return False def processRequests(self, query): queryx = query.split() queryx = [ word for word in queryx if not word in set(stopwords.words('english')) ] if (self.validateCommand(queryx, self.webSearch) and (self.auth.permissions["internet_access"] == 1 or self.auth.permissions["master_access"] == 1)): if (r'search' in query): self.getInfoWebSearch(query) elif (r'go to'): comp = regex.compile(r'(go\s*to)\s*([\w\s\.]*)') match = regex.search(comp, query) try: squery = match.group(2) except AttributeError: squery = '' url = 'https://' + squery self.openFirefox(url) elif ('change your password' == query): self.auth.setPassword() elif (self.validateCommand(queryx, self.says) and (r'something' in query) and (self.auth.permissions["internet_access"] == 1 or self.auth.permissions["master_access"] == 1)): self.tellInfoFromWiki(query) elif self.validateCommand(queryx, self.var3): self.getTime() elif self.validateCommand(queryx, self.mailCmd) and self.validateCommand( queryx, ['send']): self.sendEmail() elif query in self.question: self.auth.speak('I am fine') elif query in self.cmd9: self.auth.speak(random.choice(self.rep9)) elif query in self.cmd7: self.auth.speak('It keeps changing every second') elif query in self.cmd8: self.auth.speak(random.choice(self.colrep)) self.auth.speak('It keeps changing every second') elif self.validateCommand(queryx, self.cmd5): self.getWeatherInfo() elif self.validateCommand(queryx, self.cmd2): self.playMusic() elif (r'open' in query): # open [foldername] inside [name of drive] drive in file explorer if (r'file explorer' in query): self.openFileExplorer(query) else: openApp = self.openAnyApplication(query) if (openApp == 'notepad'): self.openNotepad() else: self.auth.speak('app not found') elif (self.validateCommand(queryx, self.newsText) and (self.auth.permissions["internet_access"] == 1 or self.auth.permissions["master_access"] == 1)): self.auth.speak("fetching headlines from IndiaToday") url = 'https://www.indiatoday.in/top-stories' self.getHeadines(url) elif self.validateCommand(queryx, self.cmdjokes): self.auth.speak(random.choice(self.jokes)) elif (query == 'who are you' or query == 'what is your name'): self.auth.speak('I am covia, your personal assistant') elif ('who is your developer' in query) or (r'who made you' in query): self.auth.speak('Mriganka Goswami developed me.') elif (r'shutdown' in query) and self.validateCommand( queryx, self.mypc): os.system("shutdown /s /t 1") elif (r'restart' in query) and self.validateCommand( queryx, self.mypc) and self.auth.permissions["master_access"] == 1: os.system("shutdown /r /t 1") elif (r'lock' in query) and self.validateCommand(queryx, self.mypc): ctypes.windll.user32.LockWorkStation() elif (self.validateCommand(queryx, self.logoutCmd) or (r'out' in query)) and self.validateCommand( queryx, self.mypc) and self.auth.permissions["master_access"] == 1: os.system("shutdown -l") elif (query in self.exitCmd): self.auth.speak('Good bye!') sys.exit() else: self.auth.speak("sorry....invalid voice command...say again") def openAnyApplication(self, query): app = regex.compile(r'(open)\s*([\w\s]*)') match = regex.search(app, query) try: openApp = match.group(2) except: self.auth.speak('unable to open the application') self.auth.sp.logger.exception("Error in opening application") openApp = '' return openApp def openFileExplorer(self, query): comp = regex.compile(r'(open)\s*([\w\s]*)\s*inside\s*([\w])\s') match = regex.search(comp, query) try: drivePath = match.group(3) folderPath = match.group(2) except: self.auth.speak("Drive name is missing.....try again") self.auth.sp.logger.exception("Drive name missing in 'open drive'") path = drivePath + ":/" + folderPath + "/" path = os.path.realpath(path) os.startfile(path) def getInfoWebSearch(self, query): comp = regex.compile(r'(search)\s*([\w\s]*)') match = regex.search(comp, query) try: squery = match.group(2) except AttributeError: squery = '' squery = squery.replace('about', '').replace(' ', '+') url = 'https://www.google.com/search?q=' + squery self.openFirefox(url) def tellInfoFromWiki(self, query): comp = regex.compile(r'(something\s*about)\s*([\w\s]+)') match = regex.search(comp, query) try: self.getDataFromWiki(match) except AttributeError: self.auth.speak('unable to process your request now') self.auth.sp.logger.exception("Exception in 'say something'") def playMusic(self): path = 'X://Covia//' folder = path for the_file in os.listdir(folder): file_path = os.path.join(folder, the_file) try: if os.path.isfile(file_path): os.unlink(file_path) except Exception as e: self.auth.sp.logger.exception("Unable to find directory") self.auth.speak('unable to find music directory') self.auth.speak('Which song shall I play?') mysong = self.listenAudio() if mysong: flag = 0 url = "https://www.youtube.com/results?search_query=" + \ mysong.replace(' ', '+') response = urlopen(url) html = response.read() soup1 = BeautifulSoup(html, "lxml") url_list = [] for vid in soup1.findAll(attrs={'class': 'yt-uix-tile-link'}): if ('https://www.youtube.com' + vid['href'] ).startswith("https://www.youtube.com/watch?v="): flag = 1 final_url = 'https://www.youtube.com' + vid['href'] url_list.append(final_url) if flag == 1: url = url_list[0] ydl_opts = {} os.chdir(path) with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) for the_file in os.listdir(folder): path = os.path.join(folder, the_file) player = vlc.MediaPlayer(path) player.play() duration = player.get_length() / 1000 duration = time.time() + duration while True: exitQuery = self.listenAudio() if exitQuery != None: exitQuery = exitQuery.split() if self.validateCommand(exitQuery, self.exitCmd): player.stop() break continue if flag == 0: self.auth.speak('I have not found anything in Youtube ') def getWeatherInfo(self): owm = pyowm.OWM('57a134899fde0edebadf307061e9fd23') observation = owm.weather_at_place('Barpeta, IN') w = observation.get_weather() self.auth.speak(w.get_wind()) self.auth.speak('humidity') self.auth.speak(w.get_humidity()) self.auth.speak('temperature') self.auth.speak(w.get_temperature('celsius')) def openNotepad(self): path = 'C:\\Windows\\notepad.exe' os.startfile(path) def getHeadines(self, url): response = rq.get(url) status_code = response.status_code if (status_code == 200): self.topNewsHeadlines(response) else: self.auth.speak("Error in fetching data from internet") self.auth.sp.logger.error("error in fetching data") def topNewsHeadlines(self, response): elems = [] soup = BeautifulSoup(response.text, 'html.parser') for i in range(1, 11): selector = '#content > div.view.view-category-wise-content-list.view-id-category_wise_content_list.view-display-id-section_wise_content_listing.view-dom-id-.custom > div.view-content > div:nth-child(' + str( i) + ') > div.detail > h2 > a' selected = soup.select(selector) if (len(selected) and selected[0].text != '\n'): selected = selected[0].text elems.append(selected) for i in range(len(elems)): news = str(i + 1) + '..........' + elems[i] self.auth.speak(news) def getDataFromWiki(self, match): squery = match.group(2) gotText = wikipedia.summary(squery) gotText = regex.sub('(\/[\w]+\/)', '', gotText) gotText = regex.sub('(\[[\d]+\])', '', gotText) gotText = regex.sub('[^A-Za-z0-9\s\(\)\-\,\.]+', '', gotText) gotText = gotText.replace('\n', '') self.auth.speak(gotText) time.sleep(2) self.auth.speak('Do you want to save this information?') answer = self.listenAudio() answer = answer.split() if self.validateCommand(answer, self.posAnswers): raNum = squery + str(random.randint(1, 1000)) drive = 'X:\\Docs\\' + raNum + ".txt" file = open(drive, 'w+') file.write(gotText) file.close() self.auth.speak('information saved in docs folder with ' + raNum + ' name.') elif self.validateCommand(answer, self.negAnswers): self.auth.speak('As your wish!') def openFirefox(self, url): browser = self.initializeBrowser(url) xquery = 'running' while (xquery != 'close browser'): xquery = self.listenAudio() if (xquery == 'close browser'): browser.close() def sendEmail(self): self.auth.speak('Who is the recipient?') recipient = self.listenAudio() recipient = recipient.replace(' ', '') if (recipient != None and (self.auth.permissions["master_access"] == 1 or self.auth.permissions["email_access"] == 1)): SqlQueryRecipient = 'SELECT email_id FROM email_list WHERE shortname = "' + recipient + '"' EmailIdList = self.getDatafromDb(SqlQueryRecipient) if (len(EmailIdList)): emailId = EmailIdList[0][0] self.auth.speak('What should I say to him?') content = self.listenAudioLong() if (content == None): content = "Hii there" self.auth.speak('can i send the message?') resp = self.listenAudio() if (resp == None): resp = "yes" if (resp == 'yes'): userSql = 'SELECT email, epass FROM email_auth WHERE cred_id=(SELECT cred_id FROM credentials WHERE username= "******")' userEmailCred = self.getDatafromDb(userSql) username = userEmailCred[0][0] password = userEmailCred[0][1] mail = smtplib.SMTP('smtp.gmail.com', 587) mail.ehlo() mail.starttls() mail.login(username, password) mail.sendmail(username, emailId, content) mail.close() self.auth.speak('Email has been sent successfully') else: self.auth.speak('Email sending cancelled') else: self.auth.speak('no recipients found') def initializeBrowser(self, url): browser = Firefox() browser.get(url) return browser def getTime(self): now = datetime.now() self.speak(now.strftime("The time is %H:%M")) def quit(self): sys.exit()
def __init__(self): self.auth = Authentication().authenticateTwitterApi()
################################################################################################# from Authentication import * import requests import json import sys #query = sys.argv[1] query = "C0301559" # username = args.username # password = args.password apikey = "" # enter api key from your UTS Profile version = "current" identifier = query # enter version example-2015AA # source = source #enter source name if known AuthClient = Authentication(apikey) ################################### # get TGT for our session ################################### tgt = AuthClient.gettgt() uri = "https://uts-ws.nlm.nih.gov" try: source except NameError: source = None #print(source) ##if we don't specify a source vocabulary, assume we're retrieving UMLS CUIs
print("") print(medicallist) print(termdic) print("*********") for ttt in value: if len(termdic[ttt]) > 0: print(ttt, ": \t ", MaxConcept(termdic[ttt])) if __name__ == '__main__': #value=readTextFile("Clinical Notes/Partnter Annoted.txt") # this was for unstructured value = process_content() print('value', value) auth = Authentication("username", "password", "key") # put credential used for UMLS Browser apikey = auth.gettgt() print("main class", apikey) # Search Concept for w in value: print("value is", w) t.searchTerm(w, apikey) # Search Semantic Type for cui in t.cuiList: st.searchSemanticType(cui, apikey) extractConcept() # Search Entity Type
def __init__(self): self.__authentication = Authentication.Authentication() self.__user = self.__class__.userclass()