Validate OEIS (On-Line Encyclopedia of Integer Sequences) draft .txt entries against the internal format specification and the OEIS style sheet. Catches formatting errors, missing required fields, contradictory keywords, style violations, and data inconsistencies before submission.
- Single-entry and multi-entry
.txtfiles in OEIS internal format - All 19 field tags:
%I,%S,%T,%U,%N,%D,%H,%F,%Y,%C,%e,%p,%t,%o,%K,%O,%A,%E - Keyword validation (30 recognized keywords)
- Sequence data integrity (integer-only, term count, offset consistency)
- Link/anchor structure for
%Hfields - Style guide patterns in
%Nand%C - Program field conventions (language labels, signatures, dates)
- Non-ASCII detection in core data fields
- Unknown tag detection
- Stdin and file-based input
- Demo mode with built-in good/bad examples
- Coverage table showing which rules are implemented
- Network reachability checks for URLs or links
- Editorial judgment of mathematical correctness or sequence interest
- NLP-based author ordering for
%Dor%H - Chronological ordering verification of
%Centries - Dead code / unused variable detection in program fields
- Binary file or b-file validation
class Issue:
level: str # "ERROR" | "WARNING" | "INFO"
field: str
message: str
def __str__() -> str
class OEISEntry:
raw_lines: list[str]
fields: dict[str, list[str]]
a_number: str | None
sequence_terms: list[str]
sequence_ints: list[int]
name: str | None
offset_a: int | None
offset_b: int | None
keywords: list[str]
author: str | None
parse_entries(text: str) -> list[OEISEntry]
Split text into per-A-number blocks and parse each.
Invariants: text is UTF-8 encoded OEIS internal format.
Returns at least one entry even if no valid tags found.
parse_entry(text: str) -> OEISEntry
Parse a single entry. Delegates to parse_entries and returns the first.
validate(entry: OEISEntry) -> list[Issue]
Run all validation rules against a parsed entry.
Returns a flat list of Issues (errors, warnings, infos).
report(entry: OEISEntry, issues: list[Issue]) -> int
Print human-readable validation report to stdout.
Returns 1 if any errors, 0 otherwise.
print_coverage() -> None
Print the rule coverage table showing which rules are implemented vs missing.
python -m oeis_validator <file.txt> # validate a file
echo '%I A...' | python -m oeis_validator # validate from stdin
python -m oeis_validator --demo # run built-in test suite
python -m oeis_validator --coverage # print rule coverage table
Exit codes:
- 0: validation passed (no errors; warnings/info ok)
- 1: validation failed (one or more errors)
- 2: file not found
Input: OEIS internal format, a line-oriented tagged format. Each line begins with %X, a space, an A-number, a space, and content. Tags are single case-sensitive letters. Example:
%I A000010 M0299 N0111
%S A000010 1,1,2,2,4,2,6,4,6,4
%N A000010 Euler totient function phi(n)
%K A000010 nonn,core,mult
%O A000010 1,3
%A A000010 _N. J. A. Sloane_
Output: Human-readable validation report written to stdout with error/warning/info levels and per-field attribution.
- Empty input — zero-length string produces a single entry with no fields, errors for all required tags.
- Multi-entry file — file with multiple A-number blocks; each is validated independently.
- Malformed lines — lines not matching
%X Annnnnn contentare silently skipped. - No sequence data — missing
%Sreports an error;%T/%Uwithout%Sare not separately required. - Offset b mismatch —
offset_bclaims the first term with |value|≥2 is at position X, but data shows otherwise. - Both
nonnandsign— mutually exclusive keywords; error raised. - Negative data without
signkeyword — error if any term < 0 andsignabsent. - Contradictory keywords —
moreandfullsimultaneously. - Tabs anywhere — tab characters are not valid in the internal format.
- Non-ASCII in core fields — characters > U+007F in
%N,%S,%T,%U,%K,%Oare flagged. - Unknown field tag — any tag not in the known 19-tag set produces a warning.
- Self-closing anchors —
<a href=...></a>with empty title text. - Program without language label —
%olines must start with(LANG). - Wolfram Alpha queries in Mathematica — natural-language patterns like "sum the" in
%t. - Duplicate A-numbers in
%Y— same A-number listed more than once in cross-references.
- Pure stdlib — no third-party dependencies.
- Must handle files up to ~1 MB without excessive memory (streaming line-by-line internally).
- All regex patterns are compiled at module load time.
- Validation must complete in < 1 second for typical single-entry files.