本文整理匯總了Python中Classifier.Classifier.classify方法的典型用法代碼示例。如果您正苦於以下問題:Python Classifier.classify方法的具體用法?Python Classifier.classify怎麽用?Python Classifier.classify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Classifier.Classifier
的用法示例。
在下文中一共展示了Classifier.classify方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from Classifier import Classifier [as 別名]
# 或者: from Classifier.Classifier import classify [as 別名]
def main():
try:
trainingData, tuningData, testData, priorSpam = buildDataSets()
nbc = Classifier(priorSpam, COUNT_THRESHOLD, SMOOTHING_FACTOR, DEFAULT_PROBABILITY)
# nbc = Classifier2(priorSpam, 0, .01, None)
nbc.train(trainingData)
nbc.classify(testData)
report(testData)
except Exception as e:
print e
return 5
示例2: Parser
# 需要導入模塊: from Classifier import Classifier [as 別名]
# 或者: from Classifier.Classifier import classify [as 別名]
class Parser(object):
def __init__(self):
self.classifier = Classifier()
def parse(self, page, url, time):
try:
links = []
print "Currently parsing: " + url
soup = BeautifulSoup(page, 'html.parser')
data = self.classifier.classify(soup, url)
# get links only when the page is relevant
if data is not None:
links = self.getRelevantUris(soup, url)
print 'No. of links retrieved: ' + str(len(links))
return (links, data, time)
except:
print "Parser: cannot parse page"
return ([], None, time)
# takes in a html page
def getRelevantUris(self, page, url):
# extract domain from url
parsed_uri = urlparse(url)
domain = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
listOfLinks = []
for link in page.find_all('a'):
listOfLinks.append(link.get('href'))
# clean up the links
listOfLinks = self.cleanLinks(listOfLinks, domain)
# remove dups
links = list(set(listOfLinks))
return links
def cleanLinks(self, listOfLinks, domain):
newLinks = []
for link in listOfLinks:
if self.isErroneous(link):
pass
elif self.isRelativeLink(link):
concatLink = self.concatRelativeLink(domain, link)
newLinks.append(concatLink)
else:
newLinks.append(link) # absolute link
return newLinks
def isErroneous(self, link):
if link is None or link.startswith('#') or link.startswith('.'):
return True
if 'mailto' in link or 'javascript' in link:
return True
else:
return False
def concatRelativeLink(self, domain, link):
if link.startswith('/'):
return (domain + link[1:]) # avoid double slashes //
else:
return (domain + link)
def isRelativeLink(self, link):
frontUrl = link.split('?',1)[0]
if link.startswith('/'):
return True
if 'php' in frontUrl and '/' not in frontUrl: #php?param=1¶m=2
return True
if len(link.split('.')) == 1: #games
return True
else:
return False
示例3: cmdline_parser
# 需要導入模塊: from Classifier import Classifier [as 別名]
# 或者: from Classifier.Classifier import classify [as 別名]
dest="queries",
required=False)
parser.add_argument("-c", dest="C", required=False)
return parser
model = None
if __name__ == "__main__":
parser = cmdline_parser()
args = parser.parse_args()
gta = list(SeqIO.parse(args.gta, "fasta"))
viral = list(SeqIO.parse(args.viral, "fasta"))
model = Classifier(gta, viral)
queries = args.queries.split(',')
for query in queries:
query_seqs = list(SeqIO.parse(query, "fasta"))
gene_num = int(query[query.find('orfg')+4])
if not model:
# dist_matrix = parse_dists.get_dist_matrix(gene_num)
model = Classifier(gta, viral)
model.get_training_set()
# model.get_weights()
SVs = model.learn_SVM_model(float(args.C))
print model.classify(query_seqs)[1]
示例4: Classifier
# 需要導入模塊: from Classifier import Classifier [as 別名]
# 或者: from Classifier.Classifier import classify [as 別名]
from Classifier import Classifier
hyp_tweets = [('I am so hungry I could eat a horse', 'hyperbole'),
('I have a million things to do', 'hyperbole'),
('I had to walk 15 miles to school in the snow, uphill', 'hyperbole'),
('She is as heavy as an elephant', 'hyperbole'),
('He is as fat as a whale', 'hyperbole'),
('Like a god', 'hyperbole'),
('They ran like greased lightning', 'hyperbole'),
('My grandmother is as old as the hills', 'hyperbole'),
('I am dying of shame', 'hyperbole'),
('I had a ton of homework', 'hyperbole'),
('If I can’t buy that new game I will die', 'hyperbole')]
nor_tweets = [('I do not like this car', 'normal'),
('I like this car', 'normal'),
('This view is horrible', 'normal'),
('I feel tired this morning', 'normal'),
('I am not looking forward to the concert', 'normal'),
('The door is black', 'normal'),
('I love you', 'normal'),
('He is my enemy', 'normal')]
tweets = hyp_tweets + nor_tweets
classifier = Classifier()
classifier.train(tweets)
for tweet in Fetcher.fetch("hyperbole", 10):
print(classifier.classify(tweet))