Introducing a new way to review your PRs.

Read the announcement

freelawproject / courtlistener

A fully-searchable and accessible archive of court data including growing repositories of opinions, oral arguments, judges, judicial financial records, and federal filings.

View on GitHub

19 documents · Updated Nov 24, 2026

docs / citation-analysis

Citation analysis

Citation analysis turns legal text into links and relationships. It finds case citations in opinions and RECAP documents, matches them to known opinions when possible, and uses the results for citation counts, authority views, parenthetical summaries, search, and lookup interfaces. See Case law data for the wider case-law model.

Citation analysis model

Citation sources

An analyzed source is an opinion or a RECAP document. The system selects the best available marked-up text or plain text, splits long text into manageable sections when needed, extracts legal citations, and treats each citation as a possible reference to an opinion. An opinion cluster groups the opinion versions for one case. A RECAP document is a filing or other docket document that can cite an opinion.

The same analysis supports two related products:

  • Opinion analysis adds links to the opinion text and records opinion-to-opinion relationships.
  • RECAP analysis records the opinions cited by a filing and supports authority searches.

References: cl/…/utils.py• L204-268 cl/…/tasks.py• L241-271 cl/…/recap_citations.py• L23-50

Citation matching

Citation matching maps text found by the citation parser to a known opinion. Full case citations use normalized reporter, volume, and page data. Date, court, and case-name clues narrow the result when the citation alone does not identify one opinion.

Short citations and supra citations use a full citation that was already resolved in the same document. The system accepts a result only when one candidate remains or when the citation's case-name clue selects one candidate. It excludes a citing opinion from its own citation results. Journal and law citations are recognized as citation types but do not create opinion matches.

The main outcomes are:

OutcomeMeaningDownstream use
Matched opinionOne known opinion is the targetCreate a link and a relationship
No matchNo known opinion fits the citationKeep the text visible and track it for later work
Ambiguous matchMore than one opinion fitsKeep the citation unresolved and offer lookup where appropriate

Reporter input is normalized before matching. The lookup path can search known canonical reporters for a variation and reports not-found and multiple-match results separately.

References: cl/…/match_citations.py• L45-69 cl/…/match_citations.py• L72-150 cl/…/match_citations.py• L153-234 cl/…/match_citations_queries.py• L147-229 cl/…/utils.py• L23-64

Citation annotation

Matched citations are added to stored opinion HTML as links to the cited opinion. A page reference can become a page anchor on that opinion. Unmatched text remains visible without a case link. An ambiguous citation can link to a citation lookup page instead of choosing a case without enough evidence.

Annotation keeps existing source markup when it can do so safely. It uses the citation span from the source text so that a reader can move from the cited text to the target without changing nearby content. Short and supra citations use their full span when needed to keep the resulting HTML valid.

References: cl/…/annotate_citations.py• L22-98 cl/…/annotate_citations.py• L101-160 cl/…/tasks.py• L252-301

Citation relationships

Opinion relationships

An opinion relationship points from the citing opinion to the cited opinion. Its depth records how many references the citing opinion makes to that cited opinion. One relationship represents one pair of opinions, so repeated references increase depth instead of creating duplicate relationship rows.

The relationship stays at the opinion level because one case can have several opinion documents. Case-level views combine relationships across the two opinion clusters. A cluster's citation count increases only when a new citing opinion adds a relationship to that cluster. Repair work can recompute the count from the stored opinion relationships.

Search stores related citation data separately from the database relationship. If a direct database change or a batch option leaves the search document out of sync, a targeted reindex can refresh either cluster citeCount values or opinion cites values over an ID range.

References: cl/…/models.py• L3664-3693 cl/…/tasks.py• L333-375 cl/…/utils.py• L271-298 cl/…/count_citations.py• L102-139 cl/…/reindex_es_cite_fields.py• L20-28 cl/…/reindex_es_cite_fields.py• L56-92

RECAP relationships

A RECAP relationship points from a RECAP document to each cited opinion. Its depth records the number of references in that filing. This supports views of filings that rely on an opinion and authority ranking by both the number of citing filings and the total number of references.

After the relationship is saved, related search fields are refreshed. Search can then expose cited opinion IDs through a RECAP document's cites field and use those IDs for authority queries.

References: cl/…/models.py• L3696-3744 cl/…/recap_citations.py• L52-86 cl/…/tasks.py• L94-119

Unmatched citation tracking

The system keeps unresolved full case citations with the document that cited them. Separate records support opinions and RECAP documents. Their status shows whether citation data was not yet present, later became available, resolved successfully, or still failed because of no match or ambiguity.

Malformed full citations and self-citations are not stored as unresolved case citations. This keeps the repair set focused on citations that may become resolvable as citation data or matching rules improve. A later retry can process citations whose data is now available and can include prior failed cases when requested.

References: cl/…/models.py• L13-66 cl/…/unmatched_citations_utils.py• L21-58 cl/…/unmatched_citations_utils.py• L61-103 cl/…/unmatched_citations_utils.py• L151-218 cl/…/update_unmatched_citations.py• L32-51

Parenthetical analysis

Descriptive parentheticals

A parenthetical is the short description that follows a case citation. The system keeps descriptions that explain the cited case and removes text that only names a judge or opinion type, identifies a document, reports citation edits, or adds another non-substantive label.

Each kept parenthetical connects the opinion that wrote the description to the opinion that it describes. Parallel citations and repeated text from the same source opinion do not create duplicate descriptions.

References: cl/…/filter_parentheticals.py• L21-97 cl/…/tasks.py• L306-332 cl/…/models.py• L120-220

Parenthetical scores

The parenthetical score estimates how useful a description is to a reader. It favors language that states a holding or starts with a clear action phrase. It also rewards descriptions near a practical length and gives a small boost to descriptions written by often-cited cases.

The score is normalized from 0 to 1. It ranks descriptions within a group. It is not a legal judgment about the cited case or the quality of its holding.

References: cl/…/score_parentheticals.py• L15-70 cl/…/tasks.py• L316-331

Parenthetical groups

Parenthetical groups combine descriptions that express substantially the same idea about one cited opinion. Each stored group has a representative description, a size, and a group score. Presentation and search can show one useful summary instead of repeating near-duplicate descriptions.

The grouping process connects descriptions that are textually similar. It chooses a representative that is both strong and central to the group. The group score combines the best description's score with the share of descriptions in that group. Groups are ordered by this score, so a clear idea that appears often can rise above a rare description.

Groups are rebuilt when new descriptions arrive. Batch work can delay group creation and its search updates, so a later rebuild is required before those derived views are complete.

References: cl/…/group_parentheticals.py• L67-95 cl/…/group_parentheticals.py• L202-263 cl/…/parenthetical_utils.py• L16-58 cl/…/tasks.py• L377-387

Citation processing flow

Citation processing extracts references, resolves them, stores relationships, and refreshes the fields used by search and presentation. Opinion processing also creates linked HTML and parenthetical data. RECAP processing stores cited-opinion relationships without changing the filing text.

This diagram shows how an opinion or RECAP document becomes linked text and searchable relationships.

flowchart LR
    A[Opinion or RECAP document] --> B[Extract case citations]
    B --> C[Match citation targets]
    C --> D{Match result}
    D -->|Matched| E[Store relationship]
    D -->|No match or ambiguous| F[Store unresolved record]
    E --> G[Refresh counts and search fields]
    E --> H[Analyze parentheticals]
    H --> I[Score and group descriptions]
    C --> J[Annotate opinion text]
    J --> K[Present linked citation]

The processing jobs rebuild derived citation data for the source document. Improved reporter data or matching rules can therefore repair old unresolved records on a later run. Bulk commands can queue opinion or RECAP work, import known cluster citations from a CSV file, recompute cluster counts, and repair search fields when database rows and indexes differ. The citation-field repair command updates one search field at a time over a required ID range. It targets non-zero cluster counts or opinions with cited relationships and sends the updates in batches.

References: cl/…/tasks.py• L57-220 cl/…/tasks.py• L222-404 cl/…/recap_citations.py• L23-86 cl/…/find_citations.py• L125-287 cl/…/find_citations_recap.py• L102-182 cl/…/import_citations_csv.py• L37-182 cl/…/reindex_es_cite_fields.py• L29-168

Citation interfaces

Opinion presentation

Opinion pages expose citation analysis through linked opinion text and case-level citation views. The page flow uses stored opinion and parenthetical relationships to show cited-by information and useful descriptions. Lookup pages provide a destination when a citation cannot be narrowed to one opinion.

See Opinion pages and publishing for the wider page flow and Opinion corpus ingestion for the source text that enters citation analysis. See RECAP case records for the wider filing and docket-document model.

References: cl/…/views.py• L1039-1054 cl/…/views.py• L1663-1724 cl/…/annotate_citations.py• L33-87

Citation lookup API

The citation lookup API accepts either text containing citations or one reporter, volume, and page. Text results include the citation text, source offsets, normalized forms, a status, and any matching opinion clusters. Reporter variations are normalized before lookup.

The API requires an authorized request and applies a citation-count limit. It reports not found and multiple-match results as distinct statuses. Clients can therefore show missing data and ask a user to choose when more than one opinion matches.

References: cl/…/api_serializers.py• L9-84 cl/…/api_views.py• L32-121 cl/…/api_views.py• L145-204 cl/…/api_views.py• L244-273

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to citation matching must preserve the distinction between matched, unmatched, and ambiguous results because annotation and repair records use those outcomes differently.
  • Changes to opinion relationships must keep opinion-level depth, cluster citation counts, and indexed citation fields aligned.
  • Changes to RECAP relationship storage must keep the database relationship and the indexed cites field in sync so authority search does not use stale links.
  • Changes to parenthetical filtering, scoring, or grouping can change representative text and group order. Rebuild groups after changing those rules.
  • Changes to reporter normalization must remain consistent across matching, citation redirects, and the lookup API.
  • Changes to citation text chunking must preserve citation spans and source offsets so matching and annotation refer to the same text.
  • Changes to CSV citation imports must preserve the cluster-and-citation mapping and use reindexing when existing indexed citation data must change.
  • Changes to bulk options that disable count or group updates require a later count, group, or search-field repair pass.
  • Changes to citation-field repair must keep the selected target aligned with its source IDs: cluster ranges repair citeCount, while opinion ranges repair cites.

Important failure modes

TriggerConsequenceGuard
A citation maps to more than one opinion clusterThe text cannot link to one case and no definite relationship is createdKeep it ambiguous and use the lookup path
Citation data is missing for a valid reporter citationThe text stays unlinked and the citation waits for later resolutionStore the unresolved record and retry after citation data changes
A citing opinion is matched to itselfA false authority link or inflated citation count can resultExclude self-citations during matching and unresolved-record creation
Relationship storage succeeds but search indexing does not runSearch and API results show stale cited IDs or countsRun the related-citation indexing task or a targeted reindex
A direct database update bypasses citation signalsThe database has new citation data but search still shows old valuesRun the citation-field repair for the affected ID range and target
A parenthetical is only a filing, judge, or editorial noteCase pages can show noise as legal meaningFilter non-descriptive parentheticals before scoring
Source text is split without preserving its citation offsetsA citation can be missed or an annotation can wrap the wrong textUse the same source segments and offsets for extraction and annotation
A CSV row names a missing opinion clusterThat citation is skipped and the cluster does not gain the imported citationValidate the target cluster before import and review skipped rows
Batch work disables count or group updates without a repair passCounts, groups, or search fields remain staleReconcile counts and rebuild groups or indexed fields after the batch

Key files

FileWhy to read it
cl/…/tasks.pyMain opinion and RECAP processing lifecycle
cl/…/utils.pySource text selection, chunking, reporter normalization, and count updates
cl/…/match_citations.pyMatching outcomes and citation-type handling
cl/…/match_citations_queries.pySearch rules for citation, date, court, and case-name clues
cl/…/annotate_citations.pyConversion of resolved citations into links in opinion text
cl/…/recap_citations.pyRECAP relationship storage and search refresh
cl/…/models.pyStates for citations that cannot yet resolve
cl/…/filter_parentheticals.pyRules for keeping descriptive parentheticals
cl/…/score_parentheticals.pyRanking signal for parenthetical descriptions
cl/…/group_parentheticals.pySimilarity grouping and representative selection
cl/…/import_citations_csv.pyBatch import of known citations into opinion clusters
cl/…/reindex_es_cite_fields.pyTargeted repair of indexed citation counts and cited-opinion fields
cl/…/models.pyOpinion and RECAP citation relationship records
cl/…/api_views.pyAuthorized citation lookup behavior
cl/…/views.pyWeb citation lookup and opinion-page exposure