From 395527c06bc63ea7ace511f0facd2822b17ca207 Mon Sep 17 00:00:00 2001 From: rovshanmuradov Date: Mon, 12 Oct 2026 21:54:35 +0400 Subject: [PATCH] fix(scoring): don't treat "register" in prose as signup navigation Any "register" counted as a navigation indicator, so algorithm text such as "output register A" was scored as clutter and removed. Only registration prompts ("register now", "register an account") and register links or buttons count now. --- src/removals/scoring.ts | 23 ++++++++++- tests/expected/scoring--algorithm-register.md | 40 +++++++++++++++++++ .../expected/scoring--registration-heading.md | 16 ++++++++ .../fixtures/scoring--algorithm-register.html | 40 +++++++++++++++++++ .../scoring--registration-heading.html | 12 ++++++ 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 tests/expected/scoring--algorithm-register.md create mode 100644 tests/expected/scoring--registration-heading.md create mode 100644 tests/fixtures/scoring--algorithm-register.html create mode 100644 tests/fixtures/scoring--registration-heading.html diff --git a/src/removals/scoring.ts b/src/removals/scoring.ts index 97d2e292c..c1db1d6a9 100644 --- a/src/removals/scoring.ts +++ b/src/removals/scoring.ts @@ -44,7 +44,6 @@ const navigationIndicators = [ 'popular', 'privacy', 'recommended', - 'register', 'related', 'responses', 'share', @@ -69,6 +68,22 @@ const datePattern = /(?:(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z] // Author attribution pattern — case-sensitive "By" + capitalized name const bylinePattern = /\bBy\s+[A-Z]/; +// Bare "register" is also a CPU or quantum register. Count it only as a signup +// prompt that opens a block, or as the label of a link or button. +const registrationPromptPattern = /^\s*(?:please\s+)?register\s+(?:now|today|here|to\s+continue|for\s+(?:free|an?\s+account)|(?:an?|your)\s+account)\b/; +const registrationControlPattern = /^(?:please\s+)?register(?:$|\s+(?:for|to)\b)/; + +function isRegistrationPrompt(element: Element): boolean { + const text = (element.textContent || '').trim().toLowerCase(); + if (!text.includes('register')) return false; + if (registrationPromptPattern.test(text)) return true; + return Array.from(element.querySelectorAll('a[href], button, [role="button"]')).some(control => { + const label = (control.textContent || '').trim().toLowerCase(); + return (registrationControlPattern.test(label) || registrationPromptPattern.test(label)) && + !control.querySelector('code'); + }); +} + // Pre-compiled navigation indicator regexes for scoreNonContentBlock const navigationIndicatorRegexes = navigationIndicators.map( indicator => new RegExp(`\\b${indicator.replace(/\s+/g, '\\s+')}\\b`) @@ -355,6 +370,7 @@ export class ContentScorer { if (headingText && headingText === text.trim()) { const headingLower = headingText.toLowerCase(); if (!navigationHeadingPattern.test(headingLower) && + !isRegistrationPrompt(headingChild) && !tocHeadingPattern.test(headingLower)) { return true; } @@ -369,7 +385,7 @@ export class ContentScorer { let hasNavigationHeading = false; for (let i = 0; i < headings.length; i++) { const headingText = (headings[i].textContent || '').toLowerCase().trim(); - if (navigationHeadingPattern.test(headingText)) { + if (navigationHeadingPattern.test(headingText) || isRegistrationPrompt(headings[i])) { hasNavigationHeading = true; break; } @@ -479,6 +495,9 @@ export class ContentScorer { indicatorMatches++; } } + if (isRegistrationPrompt(element)) { + indicatorMatches++; + } score -= indicatorMatches * 10; // Check for high link density (navigation) diff --git a/tests/expected/scoring--algorithm-register.md b/tests/expected/scoring--algorithm-register.md new file mode 100644 index 000000000..8f74e935d --- /dev/null +++ b/tests/expected/scoring--algorithm-register.md @@ -0,0 +1,40 @@ +```json +{ + "title": "Register operations", + "author": "", + "site": "example.com", + "published": "" +} +``` + +This procedure describes how a receiver processes an encoded state after transmission. The sender prepares a collection of physical systems and applies an encoding operation before delivering the result. The receiver uses a decoding operation to recover the original information. Each operation acts on a specified group of systems rather than on the entire collection. The names attached to these groups distinguish the input from the output and make the instructions precise. Intermediate states may contain errors introduced during transmission. The decoding procedure identifies those errors and corrects them without changing the information that the sender intended to convey. The ordering of the operations is therefore important. + +The steps below describe the final part of that procedure. Read each instruction in order and keep the named systems separate throughout the calculation. An operation written beside a system name applies only to that system. A dagger denotes the inverse operation in this example. After the inverse operations have been applied the receiver can produce the decoded state. The final instruction identifies which system contains that state. These conventions also allow the same procedure to be described in ordinary prose without equations. Both descriptions specify the same sequence of operations and the same final result. + +## Algorithm + +1. Decode the received state. + 1. Apply $D$ and output register $A$. + 2. Apply $U^\dagger P^\dagger$ to the received register $B$. + +### Quantum register operations + +Initialize the register before decoding. + +Use the `register` keyword. + +See the [`register`](https://example.com/reference/register) keyword. + +Check `register_state` before returning. + +Registered values remain unchanged. + +Use the cash register carefully. + +The register now contains output. + +Call `register` to continue. + +We register an account in this example. + +Inspect register [state](https://example.com/state) before returning. \ No newline at end of file diff --git a/tests/expected/scoring--registration-heading.md b/tests/expected/scoring--registration-heading.md new file mode 100644 index 000000000..82e74f309 --- /dev/null +++ b/tests/expected/scoring--registration-heading.md @@ -0,0 +1,16 @@ +```json +{ + "title": "Decoding experiment", + "author": "", + "site": "example.com", + "published": "" +} +``` + +This procedure describes how a receiver processes an encoded state after transmission. The sender prepares a collection of physical systems and applies an encoding operation before delivering the result. The receiver uses a decoding operation to recover the original information. Each operation acts on a specified group of systems rather than on the entire collection. The names attached to these groups distinguish the input from the output and make the instructions precise. Intermediate states may contain errors introduced during transmission. The decoding procedure identifies those errors and corrects them without changing the information that the sender intended to convey. The ordering of the operations is therefore important. + +The steps below describe the final part of that procedure. Read each instruction in order and keep the named systems separate throughout the calculation. An operation written beside a system name applies only to that system. A dagger denotes the inverse operation in this example. After the inverse operations have been applied the receiver can produce the decoded state. The final instruction identifies which system contains that state. These conventions also allow the same procedure to be described in ordinary prose without equations. Both descriptions specify the same sequence of operations and the same final result. + +The experiment compares the recovered information with the original input under several controlled conditions. Each trial uses the same preparation procedure so that differences in the observed result can be attributed to transmission errors rather than to changes in the initial state. Measurements are collected after decoding and evaluated using the same criteria throughout the experiment. The comparison also checks whether the order of the recovery operations affects the outcome. Repeating the trials with different error patterns establishes which aspects of the procedure remain stable. The interpretation of these measurements depends on keeping the preparation and recovery stages distinct and recording the final state consistently. + +This is the last substantive conclusion of our experiment, and it explains the results to our readers. diff --git a/tests/fixtures/scoring--algorithm-register.html b/tests/fixtures/scoring--algorithm-register.html new file mode 100644 index 000000000..3eed0e516 --- /dev/null +++ b/tests/fixtures/scoring--algorithm-register.html @@ -0,0 +1,40 @@ + + + +Register operations + +
+

Register operations

+

This procedure describes how a receiver processes an encoded state after transmission. The sender prepares a collection of physical systems and applies an encoding operation before delivering the result. The receiver uses a decoding operation to recover the original information. Each operation acts on a specified group of systems rather than on the entire collection. The names attached to these groups distinguish the input from the output and make the instructions precise. Intermediate states may contain errors introduced during transmission. The decoding procedure identifies those errors and corrects them without changing the information that the sender intended to convey. The ordering of the operations is therefore important.

+

The steps below describe the final part of that procedure. Read each instruction in order and keep the named systems separate throughout the calculation. An operation written beside a system name applies only to that system. A dagger denotes the inverse operation in this example. After the inverse operations have been applied the receiver can produce the decoded state. The final instruction identifies which system contains that state. These conventions also allow the same procedure to be described in ordinary prose without equations. Both descriptions specify the same sequence of operations and the same final result.

+

Algorithm

+
    +
  1. Decode the received state. +
      +
    1. Apply DD and output register AA.

    2. +
    3. Apply U†P†U^\dagger P^\dagger to the received register BB.

    4. +
    +
  2. +
+

Quantum register operations

+

Initialize the register before decoding.

+

Use the register keyword.

+

See the register keyword.

+

Check register_state before returning.

+

Registered values remain unchanged.

+

Use the cash register carefully.

+

The register now contains output.

+

Call register to continue.

+

We register an account in this example.

+

Inspect register state before returning.

+

Account access Register

+

Register now for free access.

+

Register an account to proceed.

+

Please register to continue.

+

Account access Register now

+

Sign up for updates.

+

Register now for X access.

+ +
+ + diff --git a/tests/fixtures/scoring--registration-heading.html b/tests/fixtures/scoring--registration-heading.html new file mode 100644 index 000000000..0c96aaee6 --- /dev/null +++ b/tests/fixtures/scoring--registration-heading.html @@ -0,0 +1,12 @@ + + + +Decoding experiment +
+

This procedure describes how a receiver processes an encoded state after transmission. The sender prepares a collection of physical systems and applies an encoding operation before delivering the result. The receiver uses a decoding operation to recover the original information. Each operation acts on a specified group of systems rather than on the entire collection. The names attached to these groups distinguish the input from the output and make the instructions precise. Intermediate states may contain errors introduced during transmission. The decoding procedure identifies those errors and corrects them without changing the information that the sender intended to convey. The ordering of the operations is therefore important.

+

The steps below describe the final part of that procedure. Read each instruction in order and keep the named systems separate throughout the calculation. An operation written beside a system name applies only to that system. A dagger denotes the inverse operation in this example. After the inverse operations have been applied the receiver can produce the decoded state. The final instruction identifies which system contains that state. These conventions also allow the same procedure to be described in ordinary prose without equations. Both descriptions specify the same sequence of operations and the same final result.

+

The experiment compares the recovered information with the original input under several controlled conditions. Each trial uses the same preparation procedure so that differences in the observed result can be attributed to transmission errors rather than to changes in the initial state. Measurements are collected after decoding and evaluated using the same criteria throughout the experiment. The comparison also checks whether the order of the recovery operations affects the outcome. Repeating the trials with different error patterns establishes which aspects of the procedure remain stable. The interpretation of these measurements depends on keeping the preparation and recovery stages distinct and recording the final state consistently.

+

Register for updates

+

This is the last substantive conclusion of our experiment, and it explains the results to our readers.

+
+