nx_source_tier.nx source
↩ module page · 218 lines · 11550 B
1// nx_source_tier.nx -- the research-established ranking rule, bits-up.
2//
3// module: nishi-core.search.bench.source_tier
4// depends: fx.nx (Q16.16 tier scores), nx_str.nx (substring matching)
5// capability: CORE_COMPUTE
6// wired_status: FULLY_WIRED
7//
8// Operationalizes the operator's principle: FIRST-HAND source material (the
9// actual film / official photo / canonical record / direct interview) ranks
10// ABOVE derivative commentary (reaction videos, "top 10" listicles, SEO
11// aggregators, tier-lists). This is the anti-Google ranking thesis from
12// docs/00-VISION + the five-tier taxonomy from docs/04-DEDUP.
13//
14// Two-stage, data-driven (Rule #11 -- the tables ARE the policy):
15// 1. domain -> base tier (primary/editorial/platform/archive/community)
16// 2. title/url "derivative" signals DEMOTE a result to commentary even on
17// a high-tier domain (a YouTube reaction video is platform AND
18// derivative; the same channel's official trailer is not).
19//
20// A result is_primary (first-hand) iff base tier == PRIMARY and no derivative
21// signal fired. That boolean feeds nx_bench_primary_precision_at_k; the gain
22// (tier score, zeroed when derivative) feeds nx_bench_dcg/ndcg.
23//
24// Tier scores from docs/04-DEDUP: primary 1.0, editorial 0.9, platform 0.7,
25// archive 0.6, community 0.5, unknown 0.3 (Q16.16).
26
27import "fx.nx"
28import "nx_str.nx"
29
30const NX_TIER_PRIMARY: i64 = 1
31const NX_TIER_EDITORIAL: i64 = 2
32const NX_TIER_PLATFORM: i64 = 3
33const NX_TIER_ARCHIVE: i64 = 4
34const NX_TIER_COMMUNITY: i64 = 5
35const NX_TIER_UNKNOWN: i64 = 6
36
37struct NxTierVerdict {
38 tier: i64,
39 score: i64, // Q16.16 tier score
40 is_primary: i64, // 1 iff first-hand source
41 is_derivative: i64, // 1 iff commentary/aggregation about the work
42}
43
44const NX_TIER_VERDICT_BYTES: i64 = 32
45
46// Q16.16 tier score for a tier id.
47func nx_tier_score(tier: i64) -> i64 {
48 if tier == NX_TIER_PRIMARY { return FX_ONE }
49 if tier == NX_TIER_EDITORIAL { return fx_from_frac(9, 10) }
50 if tier == NX_TIER_PLATFORM { return fx_from_frac(7, 10) }
51 if tier == NX_TIER_ARCHIVE { return fx_from_frac(6, 10) }
52 if tier == NX_TIER_COMMUNITY { return fx_from_frac(1, 2) }
53 return fx_from_frac(3, 10)
54}
55
56// ASCII lowercase of a single byte value.
57func nx_tier_lc(c: i64) -> i64 {
58 if c >= 0x41 {
59 if c <= 0x5A { return c + 0x20 }
60 }
61 return c
62}
63
64// Case-insensitive "does hay contain needle". needle must be lowercase.
65// No scratch buffer / no byte-store cast: folds case during comparison.
66func nx_tier_ci_contains(hay: *u8, needle: *u8) -> i64 {
67 let hn: i64 = nx_str_len(hay)
68 let nn: i64 = nx_str_len(needle)
69 if nn == 0 { return 1 }
70 if nn > hn { return 0 }
71 var i: i64 = 0
72 while i <= hn - nn {
73 var j: i64 = 0
74 var ok: i64 = 1
75 while j < nn {
76 if nx_tier_lc(hay[i + j] as i64) != nx_tier_lc(needle[j] as i64) {
77 ok = 0
78 j = nn
79 } else {
80 j = j + 1
81 }
82 }
83 if ok == 1 { return 1 }
84 i = i + 1
85 }
86 return 0
87}
88
89// host substring test (domains are lowercase in URLs -> case-sensitive ok).
90func nx_tier_host_has(url: *u8, domain: *u8) -> i64 {
91 if nx_str_str(url, domain) >= 0 { return 1 }
92 return 0
93}
94
95// domain -> base tier. One line per domain (Rule #11 data-driven). Archive
96// checked before generic so web.archive.org is archive, not unknown.
97func nx_tier_of_url(url: *u8) -> i64 {
98 // primary: the canonical record / official / the work or photo itself
99 if nx_tier_host_has(url, "imdb.com") == 1 { return NX_TIER_PRIMARY }
100 if nx_tier_host_has(url, "wikipedia.org") == 1 { return NX_TIER_PRIMARY }
101 if nx_tier_host_has(url, "wikidata.org") == 1 { return NX_TIER_PRIMARY }
102 if nx_tier_host_has(url, "wikimedia.org") == 1 { return NX_TIER_PRIMARY }
103 if nx_tier_host_has(url, "gettyimages.com") == 1 { return NX_TIER_PRIMARY }
104 if nx_tier_host_has(url, "apimages.com") == 1 { return NX_TIER_PRIMARY }
105 if nx_tier_host_has(url, "arxiv.org") == 1 { return NX_TIER_PRIMARY }
106 if nx_tier_host_has(url, "openreview.net") == 1 { return NX_TIER_PRIMARY }
107 // NOTE (verified 2026-05-29, design workflow): IMDb + Wikipedia are the
108 // only reliable PRIMARY anchors for a celebrity query. Rotten Tomatoes,
109 // TMDB and Box Office Mojo are derivative aggregator CATALOGS that
110 // dominate mainstream SERPs -- they are secondary, not first-hand. Tiered
111 // editorial below so they never earn primary gain.
112 // archive: Wayback / dead-host recovery
113 if nx_tier_host_has(url, "web.archive.org") == 1 { return NX_TIER_ARCHIVE }
114 if nx_tier_host_has(url, "archive.org") == 1 { return NX_TIER_ARCHIVE }
115 if nx_tier_host_has(url, "archive.ph") == 1 { return NX_TIER_ARCHIVE }
116 // editorial: professional press + derivative aggregator catalogs
117 if nx_tier_host_has(url, "themoviedb.org") == 1 { return NX_TIER_EDITORIAL }
118 if nx_tier_host_has(url, "rottentomatoes.com") == 1 { return NX_TIER_EDITORIAL }
119 if nx_tier_host_has(url, "boxofficemojo.com") == 1 { return NX_TIER_EDITORIAL }
120 if nx_tier_host_has(url, "filmaffinity.com") == 1 { return NX_TIER_EDITORIAL }
121 if nx_tier_host_has(url, "tvguide.com") == 1 { return NX_TIER_EDITORIAL }
122 if nx_tier_host_has(url, "variety.com") == 1 { return NX_TIER_EDITORIAL }
123 if nx_tier_host_has(url, "hollywoodreporter.com") == 1 { return NX_TIER_EDITORIAL }
124 if nx_tier_host_has(url, "ew.com") == 1 { return NX_TIER_EDITORIAL }
125 if nx_tier_host_has(url, "people.com") == 1 { return NX_TIER_EDITORIAL }
126 if nx_tier_host_has(url, "nytimes.com") == 1 { return NX_TIER_EDITORIAL }
127 if nx_tier_host_has(url, "vanityfair.com") == 1 { return NX_TIER_EDITORIAL }
128 if nx_tier_host_has(url, "maxim.com") == 1 { return NX_TIER_EDITORIAL }
129 if nx_tier_host_has(url, "deadline.com") == 1 { return NX_TIER_EDITORIAL }
130 if nx_tier_host_has(url, "screenrant.com") == 1 { return NX_TIER_EDITORIAL }
131 if nx_tier_host_has(url, "collider.com") == 1 { return NX_TIER_EDITORIAL }
132 if nx_tier_host_has(url, "cbr.com") == 1 { return NX_TIER_EDITORIAL }
133 // verified-real editorial/press + first-hand-interview outlets (2026-05-29):
134 // these are genuine publications, not SEO bio-spam, so they belong in the
135 // editorial table (Rule #11) -- a person query's interviews/press facets
136 // live here, not in "unknown".
137 if nx_tier_host_has(url, "advocate.com") == 1 { return NX_TIER_EDITORIAL }
138 if nx_tier_host_has(url, "losangelesblade.com") == 1 { return NX_TIER_EDITORIAL }
139 if nx_tier_host_has(url, "sbs.com.au") == 1 { return NX_TIER_EDITORIAL }
140 if nx_tier_host_has(url, "bloody-disgusting.com") == 1 { return NX_TIER_EDITORIAL }
141 if nx_tier_host_has(url, "naludamagazine.com") == 1 { return NX_TIER_EDITORIAL }
142 if nx_tier_host_has(url, "pop-culturalist.com") == 1 { return NX_TIER_EDITORIAL }
143 if nx_tier_host_has(url, "afterbuzztv.com") == 1 { return NX_TIER_EDITORIAL }
144 if nx_tier_host_has(url, "dontgooutthere.com") == 1 { return NX_TIER_EDITORIAL }
145 // platform: user-content platforms
146 if nx_tier_host_has(url, "youtube.com") == 1 { return NX_TIER_PLATFORM }
147 if nx_tier_host_has(url, "youtu.be") == 1 { return NX_TIER_PLATFORM }
148 if nx_tier_host_has(url, "reddit.com") == 1 { return NX_TIER_PLATFORM }
149 if nx_tier_host_has(url, "twitter.com") == 1 { return NX_TIER_PLATFORM }
150 if nx_tier_host_has(url, "instagram.com") == 1 { return NX_TIER_PLATFORM }
151 if nx_tier_host_has(url, "tumblr.com") == 1 { return NX_TIER_PLATFORM }
152 if nx_tier_host_has(url, "tiktok.com") == 1 { return NX_TIER_PLATFORM }
153 if nx_tier_host_has(url, "facebook.com") == 1 { return NX_TIER_PLATFORM }
154 if nx_tier_host_has(url, "pinterest.com") == 1 { return NX_TIER_PLATFORM }
155 if nx_tier_host_has(url, "imgur.com") == 1 { return NX_TIER_PLATFORM }
156 if nx_tier_host_has(url, "github.com") == 1 { return NX_TIER_PLATFORM }
157 if nx_tier_host_has(url, "huggingface.co") == 1 { return NX_TIER_PLATFORM }
158 // community: fan wikis / forums
159 if nx_tier_host_has(url, "fandom.com") == 1 { return NX_TIER_COMMUNITY }
160 if nx_tier_host_has(url, "wikia.com") == 1 { return NX_TIER_COMMUNITY }
161 if nx_tier_host_has(url, "proboards.com") == 1 { return NX_TIER_COMMUNITY }
162 return NX_TIER_UNKNOWN
163}
164
165// derivative-commentary signal in title OR url path (lowercase needles).
166func nx_tier_is_derivative(url: *u8, title: *u8) -> i64 {
167 if nx_tier_ci_contains(title, "reaction") == 1 { return 1 }
168 if nx_tier_ci_contains(title, "reacts") == 1 { return 1 }
169 if nx_tier_ci_contains(title, "review") == 1 { return 1 }
170 if nx_tier_ci_contains(title, "breakdown") == 1 { return 1 }
171 if nx_tier_ci_contains(title, "explained") == 1 { return 1 }
172 if nx_tier_ci_contains(title, "top 10") == 1 { return 1 }
173 if nx_tier_ci_contains(title, "top 5") == 1 { return 1 }
174 if nx_tier_ci_contains(title, "ranked") == 1 { return 1 }
175 if nx_tier_ci_contains(title, "ranking") == 1 { return 1 }
176 if nx_tier_ci_contains(title, "tier list") == 1 { return 1 }
177 if nx_tier_ci_contains(title, "compilation") == 1 { return 1 }
178 if nx_tier_ci_contains(title, "hottest") == 1 { return 1 }
179 if nx_tier_ci_contains(title, "sexiest") == 1 { return 1 }
180 if nx_tier_ci_contains(title, "net worth") == 1 { return 1 }
181 if nx_tier_ci_contains(title, "things you") == 1 { return 1 }
182 if nx_tier_ci_contains(title, "facts about") == 1 { return 1 }
183 if nx_tier_ci_contains(url, "ranked") == 1 { return 1 }
184 if nx_tier_ci_contains(url, "-best-") == 1 { return 1 }
185 // NOTE (operator cardinal 2026-05-29): this flag is METADATA ONLY -- a
186 // "looks like commentary/aggregation" hint. It MUST NOT be used to zero a
187 // result's value or prejudge it: a commentary/gallery/compilation page can
188 // carry UNIQUE content (Comic-Con pics, rare footage, original reporting)
189 // and our mission is to DELIVER that information, not suppress it. Earned
190 // demotion of genuinely non-additive duplicates is the novelty/dedup
191 // kernel's job, measured -- never assumed from a title keyword.
192 return 0
193}
194
195// Full classification into a caller-supplied verdict slot.
196func nx_tier_classify(url: *u8, title: *u8, out: *NxTierVerdict) -> i64 {
197 let t: i64 = nx_tier_of_url(url)
198 let deriv: i64 = nx_tier_is_derivative(url, title)
199 out.tier = t
200 out.score = nx_tier_score(t)
201 out.is_derivative = deriv
202 var prim: i64 = 0
203 if t == NX_TIER_PRIMARY {
204 if deriv == 0 { prim = 1 }
205 }
206 out.is_primary = prim
207 return 0
208}
209
210// Ranking-prior gain for a verdict = the tier score. We do NOT zero
211// "derivative" results (operator cardinal 2026-05-29: deliver information, do
212// not prejudge -- a commentary/aggregation/gallery page can carry unique
213// content). is_derivative stays on the verdict as METADATA only; genuine
214// non-additive duplicates are demoted later by the novelty/dedup mechanism,
215// measured. The primary-source PRIOR still ranks first-hand sources highest.
216func nx_tier_gain(v: *NxTierVerdict) -> i64 {
217 return v.score
218}