def search(self, text, qid=None, related_docs=None): query = Query() if (not self.free_search): if qid == None: for q in self.preprocessor.get_representation_query(): if (q.text == text): query = q break else: qtmp = self.source.read_query(qid) query.text = qtmp.text query.docs_relevant = qtmp.docs_relevant query.docs_retrieval = [] if self.free_search or query.text == '': query.text = text self.query_processor.execute(query) documents = self.search_model.retrieval(query, related_docs) if len(documents) == 2: query.docs_retrieval = documents[0] query.docs_scores = documents[1] else: query.docs_retrieval = documents query.docs_scores = [] self.query = query return query
def read_querys(self): if (not self.__querys): files = open(self.local_file_q, 'r', encoding="utf-8").read().split('.I') self.__querys = dict() for line in files: if line: match = re.match(self._pattern, line, re.DOTALL) if match: new_line = match.groupdict() self.__querys[int(new_line['id'])] = Query( id=int(new_line['id']), text=str(new_line['text'].strip())) relevants_resume = dict() relevants = open(self.path + '/ARTIGOS.rel', 'r', encoding="utf-8").readlines() for i in relevants: line = np.array(i.split(' ')).tolist() key = int(line[0]) try: self.__querys[key].docs_relevant.append(int(line[2])) except: continue return self.__querys.values()
def read_querys(self): if (not self.__querys): files = open(self.local_file_q, 'r').read().split('.I') self.__querys = dict() for line in files: if line: match = re.match(self._pattern_qry, line, re.DOTALL) if match: new_line = match.groupdict() self.__querys[int(new_line['id'])] = Query( id=int(new_line['id']), text=str(new_line['text'].strip())) relevants = open(self.path + '/ADI.REL', 'r').readlines() for i in relevants: line = np.array(i.split()).tolist() key = int(line[0]) if key in self.__querys: self.__querys[int(key)].docs_relevant.append(int(line[1])) for k in list(self.__querys.keys()): if not self.__querys[k].docs_relevant: del self.__querys[k] return self.__querys.values()
def main(): print(""" Welcome to Zendesk Search! Type 'quit' to exit the program at any time. Start by selecting a category to search by: - Type 1 for users - Type 2 for organisations - Type 3 for tickets Then search by term and value When prompted for a term type 'terms' to view a list of terms you can search by for each category. """) #Instantiate search and query object search = Search() query = Query(None, None, None) #Ask the user which category they want to search by command = getUserInput(CATEGORY_SELECTION) #Quit is the command to exit out of the program while command != "quit": #Validate the user input selectionResult = validateCategorySelection(query, command) if (not selectionResult): #Repeat the search until user quits command = getUserInput(CATEGORY_SELECTION) continue #Ask the user what term to search by command = getUserInput(SEARCH_TERM) query.setTerm(command) #Find the data for the search result = searchEngine(search, query) if (result != None): print(result) #Repeat the search until user quits command = getUserInput(CATEGORY_SELECTION) try: exit(0) except: exit(1) raise
def home(): ''' Default Route : invokes models and forms module ''' try: c = request.headers.get('clientid') s = request.headers.get('secret') print(f"clientid : {c} | secret {s}") print(f"clientid type : {type(c)} | secret {type(s)}") print(request.headers.keys) o = Authorize() access = o.verify(c, s) if access: # if ((c=='sparkey') and (s=='qpalzmwiskxn')): if request.is_json: q = Query() q.show() else: return 'Incorrect json format', 400 else: return 'Incorrect credentials', 400 except Exception as err: return str(err)
def read_querys(self): if(not self.__querys): files = open(self.local_file_q, 'r').read().split('/') self.__querys = dict() for line in files: match = re.match(self._pattern, line, re.DOTALL) if match: new_line = match.groupdict() if(new_line['id']): self.__querys[int(new_line['id'])] = Query(id=int(new_line['id']),text=str(new_line['text'].strip())) relevants = open(self.path+'/rlv-ass', 'r').read().split('/') for line in relevants: match = re.match(self._pattern, line, re.DOTALL) if match: new_line = match.groupdict() if (new_line['id']): key = int(new_line['id']) self.__querys[int(key)].docs_relevant = list(map(int,new_line['text'].split())) return self.__querys.values()
def noDataQuery(): from engine.query import Query noDataQuery = Query('users', '_id', '123') yield noDataQuery
def invalidQuery(): from engine.query import Query invalidQuery = Query('users', 'testing', '123456') yield invalidQuery
def orgQuery(): from engine.query import Query orgQuery = Query('organisations', '_id', '122') yield orgQuery
def ticketQuery(): from engine.query import Query ticketQuery = Query('tickets', 'organization_id', '122') yield ticketQuery
def ticketSelectedQuery(): from engine.query import Query ticketSelectedQuery = Query('tickets', 'organization_id', None) yield ticketSelectedQuery
def userQuery(): from engine.query import Query userQuery = Query('users', '_id', '1') yield userQuery
def lookup_querys(self, text): return [ Query(id=i, text=q, docs_relevant=docs) for (i, (q, docs)) in enumerate(self.local_file_q) if text in q ]
def emptyQuery(): from engine.query import Query query = Query(None, None, None) yield query
def usersTermQuery(): from engine.query import Query usersTermQuery = Query('users', 'terms', 'None') yield usersTermQuery
def read_query(self, id): (q, docs) = self.local_file_q[int(id)] return Query(id=id, text=q, docs_relevant=docs)
def read_querys(self): return [ Query(id=i, text=q, docs_relevant=docs) for (i, (q, docs)) in enumerate(self.local_file_q) ]
def orgsTermQuery(): from engine.query import Query orgsTermQuery = Query('organisations', 'terms', 'None') yield orgsTermQuery
def userSelectedQuery(): from engine.query import Query userSelectedQuery = Query('users', '_id', None) yield userSelectedQuery
def ticketsTermQuery(): from engine.query import Query ticketsTermQuery = Query('tickets', 'terms', 'None') yield ticketsTermQuery
def orgSelectedQuery(): from engine.query import Query orgSelectedQuery = Query('organisations', '_id', None) yield orgSelectedQuery