Skip to content

Free-text parser: Harvard, IEEE, Vancouver, OSCOLA, and ABNT input (scope) #231

Open

Description

@dknauss

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' ) in use-citation-import-actions.js, build/78.js). Visitors never load it, and view.js is unaffected.

Size and complexity today

  • free-text-parser.js 807 lines + free-text-authors.js 113; 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 receives styleKey; pass it to parseFreeTextCitation() 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 sweep scores both parsers for every style on both corpora; require that no existing style's score drops, and that the existing free-text-parser.test.js and docs/free-text-samples.md cases still pass.
  • Keep failing closed. New patterns return confidence: 'low' and the editor's review flow; anything ambiguous is declined.

Suggested phasing

  1. Spike: style hint + Harvard. Smallest step, closest to existing APA code, and it tests whether collisions are manageable. Measure with the sweep.
  2. IEEE and Vancouver together (shared numeric-style prefixes and initials).
  3. ABNT.
  4. 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.md argues 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

Activity

  1. dknauss commented on Nov 9, 2026

    @dknauss
    OwnerAuthor

    Scoping plan is up in #267 (docs/planning/free-text-styles-plan.md). What it adds to the outline above:

    • IEEE and ABNT don't fail closed today. A labelled journal article (vol. 12, no. 3, pp. 34–43 or v. 12, n. 3, p. 34-43) matches parseSentenceBookCitation() and comes back as a book with the labels in its title, at medium confidence. On AnyStyle's 7,846 labelled references, 53% of the IEEE-shaped entries the parser accepts get the wrong title (13% overall).
    • Confidence never reaches the editor. PARSER_BACKENDS.freetext keeps only .csl, so the existing parseWarnings review flag is never set for free text.
    • Segmentation: [1] / 1. prefixes land in the first author's name; multi-line OSCOLA pastes ending in a page number are joined into one entry.
    • Licence question answered: anystyle-data is only a dictionary. The labelled references are in the anystyle gem's res/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 low confidence 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions