Metadata-Version: 2.4
Name: hkeyecite
Version: 0.1.2
Summary: A library for extracting and parsing legal citations from Hong Kong court judgments
Author: Terracotta
License: BSD 2-Clause License
        
        Copyright (c) 2025, Terracotta
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
        ---
        
        Portions of this software are derived from eyecite
        (https://github.com/freelawproject/eyecite)
        
        Copyright (c) 2020, Free Law Project
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/terracottalabs/hkeyecite
Project-URL: Repository, https://github.com/terracottalabs/hkeyecite
Project-URL: Issues, https://github.com/terracottalabs/hkeyecite/issues
Keywords: legal,citations,hong kong,law,nlp,courts
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Legal Industry
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Text Processing
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Dynamic: license-file

# hkeyecite

A Python library that automatically finds and extracts legal citations from Hong Kong court judgments.

Give it any block of text containing Hong Kong legal references, and it will identify and parse:

- **Neutral citations** -- e.g. `[2024] HKCFA 1`
- **Law report citations** -- e.g. `(2019) 22 HKCFAR 446`
- **Action numbers** -- e.g. `HCAL 1756/2020`

It also extracts case names (e.g. "HKSAR v Harjani") and pinpoint references (e.g. "at [45]") when present.

![Demo](https://raw.githubusercontent.com/terracottalabs/hkeyecite/main/demo.gif)

## Installation

```bash
pip install hkeyecite
```

Requires Python 3.10 or later.

## What it recognises

### Neutral citations

The format used by the Judiciary since 2018: `[Year] Court Number`

| Code | Court |
|---|---|
| `HKCFA` | Court of Final Appeal |
| `HKCA` | Court of Appeal |
| `HKCFI` | Court of First Instance |
| `HKDC` | District Court |
| `HKFC` / `HKFamC` | Family Court |
| `HKLT` / `HKLdT` | Lands Tribunal |
| `HKCT` | Competition Tribunal |
| `HKLBT` / `HKLaT` | Labour Tribunal |
| `HKSCT` | Small Claims Tribunal |
| `HKOAT` | Obscene Articles Tribunal |
| `HKCC` | Coroner's Court |
| `HKMC` / `HKMagC` | Magistrates' Courts |
| `CFA` / `CA` / `CFI` | Older alternate codes |

### Law report citations

References to published law report series: `(Year) Volume Reporter Page`

| Code | Report Series |
|---|---|
| `HKCFAR` | Hong Kong Court of Final Appeal Reports |
| `HKLRD` | Hong Kong Law Reports & Digest |
| `HKC` | Hong Kong Cases |
| `HKPLR` | Hong Kong Public Law Reports |
| `HKLR` | Hong Kong Law Reports (historical) |
| `HKCLR` | Hong Kong Criminal Law Reports |
| `HKCLRT` | Hong Kong Chinese Law Reports & Translations |

Dotted variations (e.g. `H.K.L.R.D.`, `H.K.C.F.A.R.`) are automatically normalised.

### Action numbers

Case filing references: `Prefix Number/Year`

Common prefixes include FACV, FACC (Court of Final Appeal), CACV, CACC (Court of Appeal), HCA, HCAL, HCCC (Court of First Instance), DCCJ, DCCC (District Court), and many more.

### Metadata

When a citation is preceded by a case name like `HKSAR v Harjani` or `Re Something`, it is automatically extracted. Pinpoint references that follow a citation (`at [45]`, `at para 10`, `at p. 5`) are also captured.

## API

### `get_citations(text)`

The main function. Returns a list of citations found in the text, sorted by position.

```python
from hkeyecite import get_citations

citations = get_citations(text)
```

Each citation has:
- `.matched_text` -- the original text that was matched
- `.normalized()` -- a standardised form of the citation
- `.case_name` -- the case name, if one appears before the citation
- `.pin_cite` -- the pinpoint reference (e.g. paragraph number), if one follows
- `.start`, `.end` -- character positions in the source text

Pass `include_action_numbers=False` to skip action number extraction.

### Convenience functions

```python
from hkeyecite.find import extract_neutral_citation, extract_reported_citations, extract_action_numbers

# Extract only one type
neutral = extract_neutral_citation(text)
reported = extract_reported_citations(text)
actions = extract_action_numbers(text)
```

### Court and reporter lookup

```python
from hkeyecite.courts import get_court_by_code, get_court_by_case_prefix
from hkeyecite.reporters import get_reporter

court = get_court_by_code("HKCFA")
court.name      # "Court of Final Appeal"
court.name_zh   # "終審法院"

court = get_court_by_case_prefix("FACV")
court.code      # "HKCFA"

reporter = get_reporter("HKCFAR")
reporter.name   # "Hong Kong Court of Final Appeal Reports"
```

## Limitations

- Only Hong Kong citations are supported -- UK, Australian, and other jurisdictions are not covered
- Case names in Chinese characters are not extracted
- Some older or non-standard citation formats may not be recognised

## Contributing

Pull requests are welcome. If you find a citation format that isn't recognised or have ideas for improvement, feel free to open an issue or PR.

## Acknowledgments

This project is derived from [eyecite](https://github.com/freelawproject/eyecite), a citation extraction library for US legal citations by the Free Law Project. `hkeyecite` adapts eyecite's approach for the Hong Kong jurisdiction, covering HK-specific courts, law reports, action number formats, and neutral citation conventions.

## License

BSD 2-Clause License -- see [LICENSE.txt](LICENSE.txt) for details.
