コード例 #1
0
ファイル: categories.go プロジェクト: soccerties/redwood
// collectRules collects the rules from all the categories and adds
// them to URLRules and phraseRules.
func (cf *config) collectRules() {
	for _, c := range cf.Categories {
		for rule, _ := range c.weights {
			switch rule.t {
			case contentPhrase:
				cf.ContentPhraseList.addPhrase(rule.content)
			case imageHash:
				content := rule.content
				threshold := -1
				if dash := strings.Index(content, "-"); dash != -1 {
					t, err := strconv.Atoi(content[dash+1:])
					if err != nil {
						log.Printf("%v: %v", rule, err)
						continue
					}
					threshold = t
					content = content[:dash]
				}
				h, err := dhash.Parse(content)
				if err != nil {
					log.Printf("%v: %v", rule, err)
					continue
				}
				cf.ImageHashes = append(cf.ImageHashes, dhashWithThreshold{h, threshold})
			default:
				cf.URLRules.AddRule(rule)
			}
		}
	}
	cf.ContentPhraseList.findFallbackNodes(0, nil)
	cf.URLRules.finalize()
}
コード例 #2
0
ファイル: categories.go プロジェクト: vishnuvaradaraj/redwood
// collectRules collects the rules from all the categories and adds
// them to URLRules and phraseRules.
func (cf *config) collectRules() {
	for _, c := range cf.Categories {
		for rule, _ := range c.weights {
			switch rule.t {
			case contentPhrase:
				cf.ContentPhraseList.addPhrase(rule.content)
			case imageHash:
				h, err := dhash.Parse(rule.content)
				if err != nil {
					log.Printf("%v: %v", rule, err)
					continue
				}
				cf.ImageHashes = append(cf.ImageHashes, h)
			default:
				cf.URLRules.AddRule(rule)
			}
		}
	}
	cf.ContentPhraseList.findFallbackNodes(0, nil)
	cf.URLRules.finalize()
}