當前位置: 首頁>>代碼示例>>Python>>正文


Python Preprocessor.preprocessor_main方法代碼示例

本文整理匯總了Python中preprocessor.Preprocessor.preprocessor_main方法的典型用法代碼示例。如果您正苦於以下問題:Python Preprocessor.preprocessor_main方法的具體用法?Python Preprocessor.preprocessor_main怎麽用?Python Preprocessor.preprocessor_main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在preprocessor.Preprocessor的用法示例。


在下文中一共展示了Preprocessor.preprocessor_main方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: classify

# 需要導入模塊: from preprocessor import Preprocessor [as 別名]
# 或者: from preprocessor.Preprocessor import preprocessor_main [as 別名]
 def classify(self) :
     t1 = time.time()
     
     # Schedule a crawl job with the query
     try :        
         crawler = Search(self.search_query)
         crawler.googleSearch()
     except Exception as e :
         print e            
         print "Error in initializing Google search"
     
     t2 = time.time()
     print "Google search done in " + str(t2-t1) + " secs"
     
     # Extract data crawled 
     try :
         crawler.get_crawled_urls()
     except Exception as e :
         print e            
         print "Error in extracting crawl data"
     
     t3 = time.time()
     print "Test data extraction done in " + str(t3-t2) + " secs"
     
     # Preprocess test data
     try :
         preproc_test = Preprocessor(crawler.all_urls)
         preproc_test.preprocessor_main()
     except Exception as e :
         print e
         print "Error in preprocessing crawl data"
         
     t4 = time.time()
     print "Test data preprocessing done in " + str(t4-t3) + " secs"
     
     # Send a search request to Dig server with the query
     dig_search = Dig_Search(self.search_query)
     dig_search.search_request()
     t5 = time.time()
     print "Dig Search done in " + str(t5-t4) + " secs"
     
     # Extract results returned by search query
     dig_search.dig_extraction()
     t6 = time.time()
     print "Dig extraction done in " + str(t6-t5) + " secs"
     
     # Preprocess the search results
     try :        
         preproc_train = Preprocessor(dig_search.urls_dig)
         preproc_train.preprocessor_main()
         dig_search.filter_dig_result(preproc_train.data)
     except Exception as e :
         print e
         print "Error in preprocessing training data"
         
     t7 = time.time()
     print "Training data preprocessing done in " + str(t7-t6) + " secs"
     
     # Compute tfidf vectors of data
     try :        
         tfidf_train = Tfidf_Vectorize(dig_search.urls_dig)
         tfidf_train.tfidf_vectorize_train()
         tfidf_train.tfidf_vectorize_test(preproc_test.data)
     except Exception as e :
         print e
         print "Error in computing tfidf vectorization"
     
     t9 = time.time()
     print "Tfidf computation done in " + str(t9-t7) + " secs"
     
     # Compute similarity of training data with its centroid vector
     try :        
         sim_train = Similarity(tfidf_train.tfidf_centroid_train, tfidf_train.features_train, tfidf_train.tfidf_train)
         similarity_train = sim_train.similarity_main()
     except Exception as e :
         print e
         print "Error in computing cosine similarity"
         
     t10 = time.time()
     print "Training data similarity computation done in " + str(t10-t9) + " secs"
     
     # Compute similarity of test data with training data
     try :        
         sim_test = Similarity(tfidf_train.tfidf_centroid_train, tfidf_train.features_train, tfidf_train.tfidf_test)
         similarity_test = sim_test.similarity_main()
     except Exception as e :
         print e
         print "Error in computing cosine similarity"
         
     t11 = time.time()
     print "Similarity computation done in " + str(t11-t10) + " secs"
     
     print "Total time = " + str(t11-t1)
     
     evaluator = Evaluation(similarity_train, similarity_test)
     urls_classified = evaluator.compare_similarity(preproc_test)
     
     classified_output = self.formatOutput(urls_classified)
     
     return classified_output
開發者ID:usc-isi-i2,項目名稱:dig-classifier,代碼行數:102,代碼來源:classifier.py

示例2: classify

# 需要導入模塊: from preprocessor import Preprocessor [as 別名]
# 或者: from preprocessor.Preprocessor import preprocessor_main [as 別名]
 def classify(self) :
     t1 = time.time()
     
     # Schedule a crawl job with the query
     try :        
         crawler = Search(self.search_query)
         crawler.googleSearch()
     except Exception as e :
         print "Error in initializing Google search"
     
     t2 = time.time()
     print "Google search done in " + str(t2-t1) + " secs"
     
     # Extract data crawled 
     try :
         crawler.get_crawled_urls()
     except Exception as e :
         print "Error in extracting crawl data"
     
     t3 = time.time()
     print "Test data extraction done in " + str(t3-t2) + " secs"
     
     # Preprocess test data
     try :
         preproc_test = Preprocessor(crawler.all_urls)
         preproc_test.preprocessor_main()
     except Exception as e :
         print e
         print "Error in preprocessing crawl data"
         
     t4 = time.time()
     print "Test data preprocessing done in " + str(t4-t3) + " secs"
     
     # Send a search request to Dig server with the query
     dig_search = Dig_Search(self.search_query)
     dig_search.search_request()
     t5 = time.time()
     print "Dig Search done in " + str(t5-t4) + " secs"
     
     # Extract results returned by search query
     dig_search.dig_extraction()
     t6 = time.time()
     print "Dig extraction done in " + str(t6-t5) + " secs"
     
     # Preprocess the search results
     try :        
         preproc_train = Preprocessor(dig_search.urls_dig)
         preproc_train.preprocessor_main()
         dig_search.filter_dig_result(preproc_train.data)
     except Exception as e :
         print e
         print "Error in preprocessing training data"
         
     t7 = time.time()
     print "Training data preprocessing done in " + str(t7-t6) + " secs"
     
     # Compute tfidf vectors of data
     try :        
         tfidf_train = Tfidf_Vectorize(dig_search.urls_dig)
         tfidf_train.tfidf_vectorize_train()
         tfidf_train.tfidf_vectorize_test(preproc_test.data)
     except Exception as e :
         print e
         print "Error in computing tfidf vectorization"
     
     t9 = time.time()
     print "Tfidf computation done in " + str(t9-t7) + " secs"
     
     # Compute similarity of training data with its centroid vector
     try :        
         sim_train = Similarity(tfidf_train.tfidf_centroid_train, tfidf_train.features_train, tfidf_train.tfidf_train)
         similarity_train = sim_train.similarity_main()
     except Exception as e :
         print e
         print "Error in computing cosine similarity"
         
     t10 = time.time()
     print "Training data similarity computation done in " + str(t10-t9) + " secs"
     
     # Compute similarity of test data with training data
     try :        
         sim_test = Similarity(tfidf_train.tfidf_centroid_train, tfidf_train.features_train, tfidf_train.tfidf_test)
         similarity_test = sim_test.similarity_main()
     except Exception as e :
         print e
         print "Error in computing cosine similarity"
         
     t11 = time.time()
     print "Similarity computation done in " + str(t11-t10) + " secs"
     
     print "Total time = " + str(t11-t1)
     
     evaluator = Evaluation(similarity_train, similarity_test)
     similarity_count = evaluator.compare_similarity(preproc_test)
     
     avg_train_similarity = numpy.mean(similarity_train)
     epsilon = 0.4 * avg_train_similarity
     classifier_output = open("output/" + self.search_query.replace(' ','_') + "2.html","w")
     urls_classified = []
     
#.........這裏部分代碼省略.........
開發者ID:usc-isi-i2,項目名稱:dig-classifier,代碼行數:103,代碼來源:classifier_OLD.py


注:本文中的preprocessor.Preprocessor.preprocessor_main方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。