예제 #1
0
 def generateBrandClassifier(self, br):
     bc = BrandClassifier()
     bc.account_id = br.account_id
     bc.account_name = br.account_name
     bc.campaign_id = br.campaign_id
     bc.campaign_name = br.campaign_name
     bc.score_threshold = br.score_threshold
     bc.name = {br.name: br.synonyms}
     bc.brand_confidence_clues = self.genClassifierClues(br.keywords)
     for kws in br.keyword_sets:
         if kws.getId():
             bc.brand_confidence_clues.append((kws.getValue(),) + tuple(MongoManager.getKeywordset(id=kws.getId()).getKeywords()))
     if br.rules:
         bc.brand_regexps = [(re.compile(self.getBrandRegexpFromRule(br, rule), re.I|re.U), rule) for rule in br.rules]
     pr_number = 0
     for pr in br.children:
         bc.product_list.append(pr.name)
         bc.products[pr.name] = pr.synonyms
         bc.product_regexps[pr.name] = []
         for rule in pr.rules:
             bc.product_regexps[pr.name].append((re.compile(self.getProductRegexpFromRule(br, pr, pr_number, rule), re.I|re.U), rule))
         if pr.use_brand_id_rules: 
             for rule in br.rules:
                 if rule.find("[P]") >= 0:
                     bc.product_regexps[pr.name].append((re.compile(self.getProductRegexpFromRule(br, pr, pr_number, rule), re.I|re.U), rule))
         pr_number += 1
         bc.product_confidence_clues[pr.name] = self.genClassifierClues(pr.keywords)
     return bc
예제 #2
0
 def generateTopicClassifier(self, topicdoc):
     tc = TopicClassifier()
     tc.topic_name = topicdoc.getName()
     tc.topic_id = str(topicdoc.getId())
     tc.topic_confidence_clues = self.genClassifierClues(topicdoc.getKeywords())
     for kws in topicdoc.getKeywordsets():
         tc.topic_confidence_clues.append((kws.getValue(),) + tuple(MongoManager.getKeywordset(id=kws.getId()).getKeywords()))
     return tc