InterviewDB Experience

Parse Citations: Extract and Normalize Academic References from Text

Interview Experience

Problem

You are given a block of text containing inline citations in the format [AuthorYear] (e.g., [Smith2019], [LeCun1989]). Extract all unique citations, parse them into structured form, and return them sorted by year then author.

python
import re
from dataclasses import dataclass

@dataclass
class Citation:
    author: str
    year: int
    raw: str

def parse_citations(text: str) -> list[Citation]:
    pass

**Input**:
  "Recent work [Smith2019] builds on [LeCun1989] and [Vaswani2017].
   See also [Smith2019] for further detail."

**Output**: [
  Citation(author='LeCun', year=1989, raw='[LeCun1989]'),
  Citation(author='Vaswani', year=2017, raw='[Vaswani2017]'),
  Citation(author='Smith', year=2019, raw='[Smith2019]'),
]
# Deduplicated, sorted by year.

Follow-ups

  1. How would you extend the regex to handle multi-author citations like [Smith&Jones2020] or [Smith et al. 2020]?
  2. What if the year appears before the author (e.g., [2019Smith])? How do you detect the format?
  3. How would you link each citation back to a list of references at the end of the document?
  4. Extend to extract citation context: the sentence in which each citation appears.

Full Details

Problem

You are given a block of text containing inline citations in the format [AuthorYear] (e.g., [Smith2019], [LeCun1989]). Extract all unique citations, parse them into structured form, and return them sorted by year then author.

python
import re
from dataclasses import dataclass

@dataclass
class Citation:
    author: str
    year: int
    raw: str

def parse_citations(text: str) -> list[Citation]:
    pass

**Input**:
  "Recent work [Smith2019] builds on [LeCun1989] and [Vaswani2017].
   See also [Smith2019] for further detail."

**Output**: [
  Citation(author='LeCun', year=1989, raw='[LeCun1989]'),
  Citation(author='Vaswani', year=2017, raw='[Vaswani2017]'),
  Citation(author='Smith', year=2019, raw='[Smith2019]'),
]
# Deduplicated, sorted by year.

Follow-ups

  1. How would you extend the regex to handle multi-author citations like [Smith&Jones2020] or [Smith et al. 2020]?
  2. What if the year appears before the author (e.g., [2019Smith])? How do you detect the format?
  3. How would you link each citation back to a list of references at the end of the document?
  4. Extend to extract citation context: the sentence in which each citation appears.

About This Question

This is a candidate experience report from a moveworks interview during the phone round.

It covers the following topics: Coding, Phone .