当前位置: 首页>>代码示例>>Python>>正文


Python Classifier.classify方法代码示例

本文整理汇总了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
开发者ID:superdude264,项目名称:SpamFilter,代码行数:15,代码来源:spamFilter.py

示例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&param=2
            return True
        if len(link.split('.')) == 1: #games
            return True
        else:
            return False
开发者ID:ZiXian92,项目名称:game-price-crawler,代码行数:85,代码来源:Parser.py

示例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]



开发者ID:birndle,项目名称:GTA,代码行数:29,代码来源:Classification.py

示例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))
开发者ID:toshle,项目名称:hyperbole,代码行数:32,代码来源:hyperboler.py


注:本文中的Classifier.Classifier.classify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。