Repository navigation
Open
Description
Summary
Borges formats nine styles but its free-text parser (src/lib/free-text-parser.js, parseFreeTextCitation()) reads only Chicago- and APA-like citations. On the tools/markup-value test lists it accepts no Harvard, Vancouver, or OSCOLA entries and almost no IEEE or ABNT ones (docs/free-text-parsing.md, PR #229):
| Style | 12 works: AnyStyle | Borges parser (entries accepted) | 36 works: AnyStyle | Borges parser |
|---|---|---|---|---|
| Harvard | 51 | 0 (0 of 12) | 82 | 0 (0 of 36) |
| IEEE | 59 | 2 (1) | 95 | 7 (16) |
| Vancouver | 46 | 0 (0) | 76 | 0 (0) |
| OSCOLA | 23 | 0 (0) | 55 | 0 (0) |
| ABNT | 53 | 3 (2) | 82 | 31 (9) |
This issue scopes teaching the parser those five styles, and whether it is worth it.
What it is not
- Not the main import path. A pasted citation with a DOI or labelled PMID is resolved at its source before the parser runs; DOIs, PMIDs, ISBNs, arXiv IDs, BibTeX, RIS, and CSL-JSON never reach it. The parser only matters for citations with no identifier: books without ISBNs, chapters, web pages, legal sources, older articles.
- Not a frontend cost. The parser is in the lazy editor chunk loaded when an author first imports (
import( '../lib/parser' )inuse-citation-import-actions.js,build/78.js). Visitors never load it, andview.jsis unaffected.
Size and complexity today
free-text-parser.js807 lines +free-text-authors.js113; about 11.5 KB minified, 2.6 KB gzipped, inside a 43.7 KB (13.9 KB gzipped) lazy chunk.- 17 pattern functions tried in a fixed order; the first match wins. 40 tests in
free-text-parser.test.js.
What each style needs
| Style | Distinguishing patterns | Difficulty |
|---|---|---|
| Harvard | Author-date like APA but Surname, I. without a comma before the year, (2001) not followed by a full stop, titles in ‘single quotes’, Available at: URLs, in Editor (eds) chapters |
Low to medium: close to APA, so the risk is the two stealing each other's inputs |
| IEEE | Optional [n] prefix; I. Surname, initials first; "Title," in double quotes; vol., no., pp., abbreviated journals; [Online]. Available: |
Medium: well labelled, but initials-first names need their own author parser |
| Vancouver | Optional n. prefix; Surname AB with no punctuation; et al.; Journal. 2001;284(5):34-43. compressed block |
Medium: compact and regular, but almost no punctuation around names |
| ABNT | SURNAME, Given. in capitals; title then **bold**/plain container; Disponível em: / Acesso em:; Portuguese month abbreviations |
Medium: Portuguese labels and upper-case surnames |
| OSCOLA | No full stops; ‘Title’ (2001) 284 Journal 34; (Publisher Year); cases R v Smith [2001] UKHL 1, legislation Act 1998, s 3, treaties |
High: secondary sources are tractable, but cases, legislation, and treaties are their own grammar and map to legal_case / legislation / treaty CSL types |
Estimated cost
A rough estimate, to be checked by a spike:
- Code: +800 to +1,500 source lines (about 150 to 300 per style for articles, books, chapters, and web pages, more for OSCOLA's legal types), roughly doubling the parser.
- Bundle: +8 to +12 KB minified, +2 to +3 KB gzipped, in the lazy import chunk only.
- Tests: +100 to +150 cases, plus fixtures for each style from the markup-value corpora.
- Speed: negligible; regular expressions over one pasted entry.
Risks of degrading what works
- Pattern collisions. With first-match-wins, a new Harvard pattern can claim an APA citation (and IEEE a Chicago one) and parse it worse. This is the main risk, not size.
- Wrong records instead of notices. Today an unrecognized entry is declined with a notice. A looser pattern that accepts more can turn a clear refusal into a quietly wrong citation, which is worse.
- Maintenance. Each style adds patterns to keep working as styles and real-world inputs drift.
Mitigations
- Use the block's style as a hint.
parsePastedInput()already receivesstyleKey; pass it toparseFreeTextCitation()and try that style's patterns first, then the rest. An author pasting into an IEEE bibliography most likely has IEEE citations. - Separate modules per style (
free-text/harvard.js, …) behind the same entry point, so a style can be added or removed without touching the others. - Regression gate.
npm run sweepscores both parsers for every style on both corpora; require that no existing style's score drops, and that the existingfree-text-parser.test.jsanddocs/free-text-samples.mdcases still pass. - Keep failing closed. New patterns return
confidence: 'low'and the editor's review flow; anything ambiguous is declined.
Suggested phasing
- Spike: style hint + Harvard. Smallest step, closest to existing APA code, and it tests whether collisions are manageable. Measure with the sweep.
- IEEE and Vancouver together (shared numeric-style prefixes and initials).
- ABNT.
- OSCOLA secondary sources; legal primary sources (cases, legislation, treaties) only if there is demand, as a separate issue.
Stop after any phase where the sweep shows collisions or the gain is small.
Open questions
- How many Borges users paste identifier-less citations in these styles? Without that, phases 3 and 4 may not earn their maintenance.
- Should the parser stay heuristic, or would a small learned model be better? (Probably not: a model would be far larger than the parser and is what
docs/free-text-parsing.mdargues against.) - Is AnyStyle's labelled training data (
anystyle-data) licensed for use as test fixtures?
See docs/free-text-parsing.md and tools/markup-value/results/2026-10-28.md.
Generated by Claude Code
Metadata
Metadata
Assignees
Labels
No labels
Activity
dknauss commentedon Nov 9, 2026
Scoping plan is up in #267 (
docs/planning/free-text-styles-plan.md). What it adds to the outline above:vol. 12, no. 3, pp. 34–43orv. 12, n. 3, p. 34-43) matchesparseSentenceBookCitation()and comes back as a book with the labels in its title, atmediumconfidence. On AnyStyle's 7,846 labelled references, 53% of the IEEE-shaped entries the parser accepts get the wrong title (13% overall).PARSER_BACKENDS.freetextkeeps only.csl, so the existingparseWarningsreview flag is never set for free text.[1]/1.prefixes land in the first author's name; multi-line OSCOLA pastes ending in a page number are joined into one entry.anystyle-datais only a dictionary. The labelled references are in theanystylegem'sres/parser/*.xml, BSD-2-Clause. Lots of IEEE, some ABNT, almost no Vancouver, Harvard, or OSCOLA.Proposed order: a small Phase 0 (fail closed on labelled articles, flag
lowconfidence for review, strip list numbering, add an AnyStyle precision check), then phases 1–4 as above, with a stop-or-go after IEEE and Vancouver. Five decisions for @dknauss are listed at the end of the plan.Generated by Claude Code
Free-text parser: decline misread citations and flag low-confidence p…
Free-text parser: scope more input styles, and fail closed on misread…
Free-text parser: read Harvard citations, with the block's style as a…
Free-text parser: read IEEE and Vancouver citations (#231 Phase 2) (#276