@@ -110,10 +110,29 @@ type Framework struct {
110110 Froms map [From ]bool `json:"froms,omitempty"`
111111 Tags []string `json:"tags,omitempty"`
112112 IsFocus bool `json:"is_focus,omitempty"`
113+ Judge * Judgement `json:"judge,omitempty"` // 判定层(fingers/judge)的结论, nil 表示未经判定
113114 MatchDetail * MatchDetail `json:"matcher,omitempty"`
114115 * Attributes `json:"attributes,omitempty"`
115116}
116117
118+ // Judgement is a judgement layer's ruling on the claim that a framework
119+ // produced the response (see github.com/chainreactors/fingers/judge).
120+ // Rejected and duplicate entries are kept so callers can explain them;
121+ // Frameworks.Accepted drops them.
122+ type Judgement struct {
123+ // Option is the claim option the ruling picked, such as "declared"
124+ // (the response names the product in a header or cookie, decided without
125+ // a model), "running", "mentioned" or "unrelated".
126+ Option string `json:"option,omitempty"`
127+ // Outcome is what Option means for the claim: "holds", "refuted" or
128+ // "insufficient" (the evidence decides neither way).
129+ Outcome string `json:"outcome,omitempty"`
130+ Confidence float64 `json:"confidence,omitempty"` // the provider's confidence in Option; 1 for code's rulings
131+ Evidence []string `json:"evidence,omitempty"` // the response excerpts the claim was ruled on
132+ Rejected bool `json:"rejected,omitempty"` // the action taken: not reported (refuted, or insufficient where so configured)
133+ Duplicate bool `json:"duplicate,omitempty"` // another engine's spelling of a product kept under another name
134+ }
135+
117136// MatchDetail describes which rule and matcher produced a hit.
118137type MatchDetail struct {
119138 RuleIndex int `json:"rule_index,omitempty"`
@@ -227,6 +246,9 @@ func (fs Frameworks) Add(other *Framework) bool {
227246 }
228247 frame .Tags = iutils .StringsUnique (append (frame .Tags , other .Tags ... ))
229248 frame .UpdateAttributes (other .Attributes )
249+ if frame .Judge == nil {
250+ frame .Judge = other .Judge
251+ }
230252 return false
231253 } else {
232254 fs [other .Name ] = other
@@ -337,3 +359,15 @@ func (fs Frameworks) HasFrom(from string) bool {
337359 }
338360 return false
339361}
362+
363+ // Accepted returns the frameworks without judged false positives and
364+ // duplicate spellings. Frameworks that were not judged are kept.
365+ func (fs Frameworks ) Accepted () Frameworks {
366+ out := make (Frameworks , len (fs ))
367+ for k , f := range fs {
368+ if f != nil && (f .Judge == nil || ! f .Judge .Rejected && ! f .Judge .Duplicate ) {
369+ out [k ] = f
370+ }
371+ }
372+ return out
373+ }
0 commit comments