jlawcite 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. jlawcite-2.0.0/LICENSE +201 -0
  2. jlawcite-2.0.0/PKG-INFO +207 -0
  3. jlawcite-2.0.0/README.md +188 -0
  4. jlawcite-2.0.0/pyproject.toml +39 -0
  5. jlawcite-2.0.0/setup.cfg +4 -0
  6. jlawcite-2.0.0/src/jlawcite/__init__.py +13 -0
  7. jlawcite-2.0.0/src/jlawcite/citation.py +668 -0
  8. jlawcite-2.0.0/src/jlawcite/cli.py +57 -0
  9. jlawcite-2.0.0/src/jlawcite/ids/__init__.py +3 -0
  10. jlawcite-2.0.0/src/jlawcite/ids/normalize.py +249 -0
  11. jlawcite-2.0.0/src/jlawcite/jp_abbrev_kit.json +70 -0
  12. jlawcite-2.0.0/src/jlawcite/jp_law_aliases.json +110 -0
  13. jlawcite-2.0.0/src/jlawcite/nta_processor.py +255 -0
  14. jlawcite-2.0.0/src/jlawcite/numerals.py +66 -0
  15. jlawcite-2.0.0/src/jlawcite/parser.py +778 -0
  16. jlawcite-2.0.0/src/jlawcite/pipeline/__init__.py +1 -0
  17. jlawcite-2.0.0/src/jlawcite/pipeline/build_versions.py +71 -0
  18. jlawcite-2.0.0/src/jlawcite/pipeline/eval_search.py +137 -0
  19. jlawcite-2.0.0/src/jlawcite/pipeline/export_release.py +183 -0
  20. jlawcite-2.0.0/src/jlawcite/pipeline/fetch_egov.py +124 -0
  21. jlawcite-2.0.0/src/jlawcite/pipeline/ingest_full.py +1006 -0
  22. jlawcite-2.0.0/src/jlawcite/pipeline/resolve_gold.py +84 -0
  23. jlawcite-2.0.0/src/jlawcite/pipeline/search_cli.py +240 -0
  24. jlawcite-2.0.0/src/jlawcite/pipeline/validate.py +414 -0
  25. jlawcite-2.0.0/src/jlawcite/resolver.py +538 -0
  26. jlawcite-2.0.0/src/jlawcite/schemas.py +289 -0
  27. jlawcite-2.0.0/src/jlawcite/search.py +600 -0
  28. jlawcite-2.0.0/src/jlawcite.egg-info/PKG-INFO +207 -0
  29. jlawcite-2.0.0/src/jlawcite.egg-info/SOURCES.txt +41 -0
  30. jlawcite-2.0.0/src/jlawcite.egg-info/dependency_links.txt +1 -0
  31. jlawcite-2.0.0/src/jlawcite.egg-info/entry_points.txt +2 -0
  32. jlawcite-2.0.0/src/jlawcite.egg-info/requires.txt +8 -0
  33. jlawcite-2.0.0/src/jlawcite.egg-info/top_level.txt +1 -0
  34. jlawcite-2.0.0/tests/test_citation.py +213 -0
  35. jlawcite-2.0.0/tests/test_citation_resolver.py +351 -0
  36. jlawcite-2.0.0/tests/test_ids.py +226 -0
  37. jlawcite-2.0.0/tests/test_ingest_e2e.py +212 -0
  38. jlawcite-2.0.0/tests/test_law_versions.py +70 -0
  39. jlawcite-2.0.0/tests/test_numerals.py +30 -0
  40. jlawcite-2.0.0/tests/test_schemas.py +191 -0
  41. jlawcite-2.0.0/tests/test_search.py +83 -0
  42. jlawcite-2.0.0/tests/test_validate.py +176 -0
  43. jlawcite-2.0.0/tests/test_xml_parser.py +390 -0
jlawcite-2.0.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 The JLaw-CiteGraph authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: jlawcite
3
+ Version: 2.0.0
4
+ Summary: JLaw-CiteGraph: deterministic citation graph and embedding-free search for Japanese statutes (e-Gov 法令)
5
+ Author: yabooung
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/yabooung/jp-law-citation-graph
8
+ Keywords: Japanese law,legal NLP,citation graph,e-Gov,statute,legal information retrieval
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pydantic>=2.5
13
+ Requires-Dist: tqdm>=4.66
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=8.0; extra == "dev"
16
+ Provides-Extra: mcp
17
+ Requires-Dist: mcp>=1.0.0; extra == "mcp"
18
+ Dynamic: license-file
19
+
20
+ # JLaw-CiteGraph 🇯🇵⚖️
21
+
22
+ **English** · [日本語](https://github.com/yabooung/jp-law-citation-graph/blob/main/README.ja.md) · [한국어](https://github.com/yabooung/jp-law-citation-graph/blob/main/README.ko.md)
23
+
24
+ ![code: Apache-2.0](https://img.shields.io/badge/code-Apache--2.0-blue) ![data: CC BY 4.0](https://img.shields.io/badge/data-CC--BY--4.0-green) ![deterministic](https://img.shields.io/badge/pipeline-deterministic%20·%20no%20LLM-brightgreen) ![version](https://img.shields.io/badge/release-v2.0.0-informative)
25
+
26
+ **An open, deterministic citation graph and search index for Japanese statutory law.**
27
+
28
+ Every Japanese law in force is parsed from official [e-Gov](https://laws.e-gov.go.jp/) XML down
29
+ to article (条), paragraph (項) and item (号), and citations in the text are resolved to the provision
30
+ they point at: 92.9% of same-law and 82.2% of cross-law citations, with the unresolved ones listed.
31
+ The result ships as data files, a single-file explorer, a `jlawcite` command-line tool
32
+ that looks up and searches provisions without embeddings, and an MCP server for LLMs.
33
+
34
+ [![JLaw-CiteGraph interactive explorer](https://raw.githubusercontent.com/yabooung/jp-law-citation-graph/main/assets/explorer-screenshot.png)](https://github.com/yabooung/jp-law-citation-graph/blob/main/explorer.html)
35
+
36
+ <sub>[`explorer.html`](https://github.com/yabooung/jp-law-citation-graph/blob/main/explorer.html): pick a law and see what it cites (green) and what cites it (yellow).</sub>
37
+
38
+ ## At a glance (v2.0, e-Gov snapshot 2026-09-27)
39
+
40
+ | | |
41
+ |---|---|
42
+ | **Laws** | 8,998, each at the version in force on 2026-09-29, plus **1,649 upcoming amendments** (施行日 + amending law) |
43
+ | **Graph** | 1.89M nodes (条・項・号・附則・別表) · 1.42M citation edges · 67,666 delegation edges (政令で定める) · 37,377 別表/様式 references |
44
+ | **Law → law network** | 70,577 distinct pairs · 453,390 distinct article-level links between laws |
45
+ | **Citation resolution** | same-law 92.9% · cross-law 82.2% · relative refs (前条/同項/…) 92.2% |
46
+ | **Precision** | ≈98% on hand-checked samples of the rules covering 86% of edges (preliminary, see below) |
47
+ | **Search** | `jlawcite get 民法第七百九条` · BM25 search · on 1,170 real tax questions the citation graph lifts Recall@10 from 0.24 to 0.46 |
48
+ | **Method** | 100% deterministic (rules + dictionaries + document context), no LLM, reproducible from the public e-Gov bulk download |
49
+
50
+ ## What's new in v2
51
+
52
+ | | v1.0 (2026-06) | **v2.0 (2026-09)** |
53
+ |---|---|---|
54
+ | Unit | law → law (article strings) | article / paragraph / item nodes, incl. 附則 and attachments |
55
+ | Edges | cross-law citations | + same-law citations, 前条/同項/前号, delegation, 別表 references |
56
+ | Distinct article-level cross-law links | 173,844 | **453,390** |
57
+ | Law → law pairs | 55,651 | **70,577** |
58
+ | Versions | latest file per law | version in force on a date + upcoming amendments |
59
+ | Search | – | `jlawcite` CLI (lookup, BM25, graph walk) + retrieval benchmark |
60
+ | Precision | 0 errors / 400 (LLM-proposed labels) | per-rule samples with confidence intervals; 5 error classes found and fixed |
61
+
62
+ v1 wrote one line per citation *mention*, so its 1.21M lines hold 173,844 distinct links; v2 counts
63
+ each (source, target) link once. Full list in [CHANGELOG.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/CHANGELOG.md).
64
+
65
+ ## Who is this for?
66
+ | You are… | You use it to… |
67
+ |---|---|
68
+ | a **legal-NLP researcher** | add citation neighbours to statute retrieval / RAG (the benchmark below shows the gain), or reuse the deterministic resolver on your own corpus |
69
+ | a **legal-tech developer** | answer "what cites X?" (amending 個人情報保護法 touches **111** laws) and "what changes when?" (`pending_versions.csv`) |
70
+ | a **network / comparative-law researcher** | study hubs (地方自治法 is cited by 1,250 laws), delegation chains and dependency clusters |
71
+ | building an **LLM legal assistant** | ground citations deterministically via the MCP server: `会社法第737条` → the exact article text |
72
+
73
+ ## Quick start
74
+ ```bash
75
+ git clone https://github.com/yabooung/jp-law-citation-graph && cd jp-law-citation-graph
76
+ pip install -e . # Python 3.11+
77
+
78
+ jlawcite fetch # e-Gov bulk XML (~320 MB) → data/raw/law_xml
79
+ jlawcite build --input data/raw/law_xml \
80
+ --csv data/raw/law_xml/all_law_list.csv --output data/parsed # ~5 min, deterministic
81
+ jlawcite validate --data data/parsed # 11 integrity checks
82
+ jlawcite index # search index (~1.5 min, 2.6 GB)
83
+
84
+ jlawcite get 民法第七百九条 # also: 労働基準法20条1項, 激甚法第三条, node ids
85
+ jlawcite search 解雇 予告 # BM25; --nl for a question sentence
86
+ jlawcite refs 労働基準法第二十条 # what it cites / what cites it
87
+ jlawcite pending --until 20261231 # amendments coming into force
88
+ ```
89
+
90
+ ```text
91
+ $ jlawcite get 民法第七百九条
92
+ 民法 [129AC0000000089, act, 明治二十九年法律第八十九号] 現行 2026-06-24 施行中, 次回改正 2027-06-23
93
+ [129AC0000000089_a709] Article
94
+
95
+ 第七百九条
96
+ 故意又は過失によって他人の権利又は法律上保護される利益を侵害した者は、これによって生じた損害を賠償する責任を負う。
97
+
98
+ 改正予定:
99
+ 2027-06-23 民法 ← 民法等の一部を改正する法律 令和八年法律第四十五号 (公布の日から起算して一年を超えない範囲内において政令で定める日)
100
+ …
101
+ ```
102
+
103
+ Every command takes `--json`. The same functions are available in Python (`jlawcite.search.SearchDB`).
104
+
105
+ ## What's inside (`/data`)
106
+ | File | Content |
107
+ |---|---|
108
+ | `laws.csv` | `law_id, name, type, url` (v1) + `enforcement_date, next_enforcement_date, pending_versions` |
109
+ | `cites_law_to_law.csv` | aggregated `src_law → tgt_law` counts (v1 columns) |
110
+ | `cites_edges.jsonl.gz` | every resolved citation of a named law: v1 fields (`src_article`, `tgt_article`, `via`, `confidence`) + `src_node`, `tgt_node`, `fallback_level` |
111
+ | `cites_all_edges.jsonl.gz` | **every** edge of the graph: CITES (incl. same-law and 前条/同項), DELEGATES_TO, REFERS_TO_ATTACHMENT, AMENDS, each with `extracted_from` |
112
+ | `pending_versions.csv` | upcoming amendments: 施行日, 施行日備考, amending law, e-Gov URL |
113
+ | `release_stats.json` | the counts quoted here |
114
+
115
+ The full node file (1.89M nodes, article and paragraph text included) is attached to the GitHub
116
+ release, or you can rebuild it with the Quick start commands.
117
+
118
+ ```python
119
+ import pandas as pd
120
+ edges = pd.read_csv("data/cites_law_to_law.csv")
121
+ hubs = edges.groupby("tgt_law")["src_law_id"].nunique().sort_values(ascending=False).head(10)
122
+ ```
123
+
124
+ ## Use it from an LLM: MCP server (`mcp/`)
125
+ `resolve_citation`, `what_cites`, `what_law_cites`, `citation_path`, `get_law`, and in v2
126
+ `get_provision` (citation → text), `search_statutes` and `pending_amendments`.
127
+ See [`mcp/README.md`](https://github.com/yabooung/jp-law-citation-graph/blob/main/mcp/README.md).
128
+
129
+ ## Retrieval benchmark
130
+ Each of 1,170 National Tax Agency Q&A cases (質疑応答事例) is a real tax question whose answer cites
131
+ specific articles. The question is the query, and hits are counted at the article level
132
+ (`jlawcite eval`).
133
+
134
+ | method | R@1 | R@5 | R@10 | R@20 | R@50 | MRR@50 | s/query |
135
+ |---|---:|---:|---:|---:|---:|---:|---:|
136
+ | BM25 (character-trigram OR) | 0.086 | 0.192 | 0.244 | 0.326 | 0.437 | 0.140 | 0.11 |
137
+ | BM25 + 1-hop citation graph | **0.256** | **0.403** | **0.459** | **0.500** | **0.550** | **0.325** | 0.11 |
138
+
139
+ <sub>1,170 queries · e-Gov snapshot 2026-09-27 · `eval/v2/nta_retrieval_results.json`</sub>
140
+
141
+ The one-hop expansion adds the articles that the top hits cite. A retrieved 施行令 paragraph pulls
142
+ up the parent-act article it implements. Both rows use no embeddings; they are a baseline for dense
143
+ or hybrid retrievers.
144
+
145
+ ## Quality, honestly
146
+ - **Coverage.** No law is left without body text, the 11 integrity checks pass (no dangling edges),
147
+ and the same input produces the same output.
148
+ - **Resolution rates** leave out citations whose target is not in a current-law corpus: pre-amendment
149
+ text (旧法), amending acts (改正法), and citations inside amending-law 附則 blocks. These are counted
150
+ separately in `jp_cites_stats.json`.
151
+ - **Precision is preliminary.** 180 random edges (10–20 per resolution rule) were checked by hand
152
+ against their source text during development. Five error classes turned up and were fixed. The rules covering 86% of edges now
153
+ measure ≈98%. Samples are small (10/10 still has a 72% lower bound) and were not blind, so treat it
154
+ as indicative. Citations inside amending-law 附則 are about 40% right and are flagged with
155
+ confidence 0.4. Citations of pre-amendment text (「旧○○法第N条」) point at the current version and
156
+ carry `version: "pre_amendment"`. Details: [docs/METHODOLOGY.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/METHODOLOGY.md).
157
+ - **Scope.** National statutes in force only: no case law, 通達, local ordinances, or text of repealed
158
+ and amending acts. イ/ロ/ハ subitems are folded into their item.
159
+
160
+ ## Reproduce
161
+ ```bash
162
+ jlawcite fetch --zip all_xml.zip # re-extract an archived snapshot for an exact rebuild
163
+ jlawcite build … --as-of 20260929 # same snapshot + same as-of date → same graph
164
+ jlawcite export --out data # regenerate the files in /data
165
+ python tools/build_explorer.py # regenerate explorer.html
166
+ python -m pytest # 177 tests
167
+ ```
168
+
169
+ ## Related work
170
+ - **弁護士ドットコム (DDS 2026)** built a citation graph over e-Gov statutes (条・項・号) together with
171
+ books, guidelines and court decisions. It reports P 98.8 / R 92.1 for law-to-law citations; same-law
172
+ references are outside its evaluation, and the graph is not public.
173
+ [paper](https://dbsj.org/wp-content/uploads/2025/11/dds-vol4-no3.pdf)
174
+ - **[DaisukeHori/japan-law](https://github.com/DaisukeHori/japan-law)** publishes about 112k article-level
175
+ cross-references for about 8,000 laws (CC0), without an accuracy evaluation.
176
+ - Reference resolution in Japanese statutes goes back to Tran, Nguyen & Shimazu (ICAIL 2013). Using
177
+ citation structure for statute retrieval has been shown on the Japanese Civil Code (Mizuno & Kano,
178
+ COLIEE 2025; Vuong et al., *Applied Intelligence* 2025) and on Belgian law (Louis et al., EACL 2023).
179
+
180
+ JLaw-CiteGraph adds same-law and relative references (前条・同条・同項・前号・同法), version selection with
181
+ upcoming amendments, per-rule precision, and a retrieval evaluation over the whole corpus, all as open data.
182
+
183
+ ## Documentation
184
+ [CHANGELOG](https://github.com/yabooung/jp-law-citation-graph/blob/main/CHANGELOG.md) · [DATA_CARD](https://github.com/yabooung/jp-law-citation-graph/blob/main/DATA_CARD.md) · [METHODOLOGY](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/METHODOLOGY.md) ·
185
+ [eval protocol](https://github.com/yabooung/jp-law-citation-graph/blob/main/eval/EVAL_PROTOCOL.md) · detailed Korean docs: [dataset](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/DATASET.md),
186
+ [schema & resolution rules](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/GRAPH_SCHEMA.md), [search](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/SEARCH.md),
187
+ [improvement handbook](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/IMPROVING_THE_GRAPH.md)
188
+
189
+ ## Contributing
190
+ Issues and PRs are welcome: [CONTRIBUTING.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/CONTRIBUTING.md). A blind annotation round
191
+ (`eval/`) would turn the preliminary precision into a validated number, and it is the most useful
192
+ single contribution.
193
+
194
+ ## License
195
+ Code: Apache-2.0. Data: CC BY 4.0 (source: e-Gov 法令データ; NTA 質疑応答事例 for `eval/v2/nta_gold.jsonl`).
196
+ See [DATA_LICENSE.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/DATA_LICENSE.md). This is not legal advice; check e-Gov / 官報 for legal decisions.
197
+
198
+ ## Citation
199
+ ```bibtex
200
+ @misc{jlaw_citegraph_2026,
201
+ title = {JLaw-CiteGraph: An open citation graph of Japanese statutory law},
202
+ version = {2.0.0},
203
+ year = {2026},
204
+ note = {e-Gov 2026-09-27 snapshot},
205
+ url = {https://github.com/yabooung/jp-law-citation-graph}
206
+ }
207
+ ```
@@ -0,0 +1,188 @@
1
+ # JLaw-CiteGraph 🇯🇵⚖️
2
+
3
+ **English** · [日本語](https://github.com/yabooung/jp-law-citation-graph/blob/main/README.ja.md) · [한국어](https://github.com/yabooung/jp-law-citation-graph/blob/main/README.ko.md)
4
+
5
+ ![code: Apache-2.0](https://img.shields.io/badge/code-Apache--2.0-blue) ![data: CC BY 4.0](https://img.shields.io/badge/data-CC--BY--4.0-green) ![deterministic](https://img.shields.io/badge/pipeline-deterministic%20·%20no%20LLM-brightgreen) ![version](https://img.shields.io/badge/release-v2.0.0-informative)
6
+
7
+ **An open, deterministic citation graph and search index for Japanese statutory law.**
8
+
9
+ Every Japanese law in force is parsed from official [e-Gov](https://laws.e-gov.go.jp/) XML down
10
+ to article (条), paragraph (項) and item (号), and citations in the text are resolved to the provision
11
+ they point at: 92.9% of same-law and 82.2% of cross-law citations, with the unresolved ones listed.
12
+ The result ships as data files, a single-file explorer, a `jlawcite` command-line tool
13
+ that looks up and searches provisions without embeddings, and an MCP server for LLMs.
14
+
15
+ [![JLaw-CiteGraph interactive explorer](https://raw.githubusercontent.com/yabooung/jp-law-citation-graph/main/assets/explorer-screenshot.png)](https://github.com/yabooung/jp-law-citation-graph/blob/main/explorer.html)
16
+
17
+ <sub>[`explorer.html`](https://github.com/yabooung/jp-law-citation-graph/blob/main/explorer.html): pick a law and see what it cites (green) and what cites it (yellow).</sub>
18
+
19
+ ## At a glance (v2.0, e-Gov snapshot 2026-09-27)
20
+
21
+ | | |
22
+ |---|---|
23
+ | **Laws** | 8,998, each at the version in force on 2026-09-29, plus **1,649 upcoming amendments** (施行日 + amending law) |
24
+ | **Graph** | 1.89M nodes (条・項・号・附則・別表) · 1.42M citation edges · 67,666 delegation edges (政令で定める) · 37,377 別表/様式 references |
25
+ | **Law → law network** | 70,577 distinct pairs · 453,390 distinct article-level links between laws |
26
+ | **Citation resolution** | same-law 92.9% · cross-law 82.2% · relative refs (前条/同項/…) 92.2% |
27
+ | **Precision** | ≈98% on hand-checked samples of the rules covering 86% of edges (preliminary, see below) |
28
+ | **Search** | `jlawcite get 民法第七百九条` · BM25 search · on 1,170 real tax questions the citation graph lifts Recall@10 from 0.24 to 0.46 |
29
+ | **Method** | 100% deterministic (rules + dictionaries + document context), no LLM, reproducible from the public e-Gov bulk download |
30
+
31
+ ## What's new in v2
32
+
33
+ | | v1.0 (2026-06) | **v2.0 (2026-09)** |
34
+ |---|---|---|
35
+ | Unit | law → law (article strings) | article / paragraph / item nodes, incl. 附則 and attachments |
36
+ | Edges | cross-law citations | + same-law citations, 前条/同項/前号, delegation, 別表 references |
37
+ | Distinct article-level cross-law links | 173,844 | **453,390** |
38
+ | Law → law pairs | 55,651 | **70,577** |
39
+ | Versions | latest file per law | version in force on a date + upcoming amendments |
40
+ | Search | – | `jlawcite` CLI (lookup, BM25, graph walk) + retrieval benchmark |
41
+ | Precision | 0 errors / 400 (LLM-proposed labels) | per-rule samples with confidence intervals; 5 error classes found and fixed |
42
+
43
+ v1 wrote one line per citation *mention*, so its 1.21M lines hold 173,844 distinct links; v2 counts
44
+ each (source, target) link once. Full list in [CHANGELOG.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/CHANGELOG.md).
45
+
46
+ ## Who is this for?
47
+ | You are… | You use it to… |
48
+ |---|---|
49
+ | a **legal-NLP researcher** | add citation neighbours to statute retrieval / RAG (the benchmark below shows the gain), or reuse the deterministic resolver on your own corpus |
50
+ | a **legal-tech developer** | answer "what cites X?" (amending 個人情報保護法 touches **111** laws) and "what changes when?" (`pending_versions.csv`) |
51
+ | a **network / comparative-law researcher** | study hubs (地方自治法 is cited by 1,250 laws), delegation chains and dependency clusters |
52
+ | building an **LLM legal assistant** | ground citations deterministically via the MCP server: `会社法第737条` → the exact article text |
53
+
54
+ ## Quick start
55
+ ```bash
56
+ git clone https://github.com/yabooung/jp-law-citation-graph && cd jp-law-citation-graph
57
+ pip install -e . # Python 3.11+
58
+
59
+ jlawcite fetch # e-Gov bulk XML (~320 MB) → data/raw/law_xml
60
+ jlawcite build --input data/raw/law_xml \
61
+ --csv data/raw/law_xml/all_law_list.csv --output data/parsed # ~5 min, deterministic
62
+ jlawcite validate --data data/parsed # 11 integrity checks
63
+ jlawcite index # search index (~1.5 min, 2.6 GB)
64
+
65
+ jlawcite get 民法第七百九条 # also: 労働基準法20条1項, 激甚法第三条, node ids
66
+ jlawcite search 解雇 予告 # BM25; --nl for a question sentence
67
+ jlawcite refs 労働基準法第二十条 # what it cites / what cites it
68
+ jlawcite pending --until 20261231 # amendments coming into force
69
+ ```
70
+
71
+ ```text
72
+ $ jlawcite get 民法第七百九条
73
+ 民法 [129AC0000000089, act, 明治二十九年法律第八十九号] 現行 2026-06-24 施行中, 次回改正 2027-06-23
74
+ [129AC0000000089_a709] Article
75
+
76
+ 第七百九条
77
+ 故意又は過失によって他人の権利又は法律上保護される利益を侵害した者は、これによって生じた損害を賠償する責任を負う。
78
+
79
+ 改正予定:
80
+ 2027-06-23 民法 ← 民法等の一部を改正する法律 令和八年法律第四十五号 (公布の日から起算して一年を超えない範囲内において政令で定める日)
81
+ …
82
+ ```
83
+
84
+ Every command takes `--json`. The same functions are available in Python (`jlawcite.search.SearchDB`).
85
+
86
+ ## What's inside (`/data`)
87
+ | File | Content |
88
+ |---|---|
89
+ | `laws.csv` | `law_id, name, type, url` (v1) + `enforcement_date, next_enforcement_date, pending_versions` |
90
+ | `cites_law_to_law.csv` | aggregated `src_law → tgt_law` counts (v1 columns) |
91
+ | `cites_edges.jsonl.gz` | every resolved citation of a named law: v1 fields (`src_article`, `tgt_article`, `via`, `confidence`) + `src_node`, `tgt_node`, `fallback_level` |
92
+ | `cites_all_edges.jsonl.gz` | **every** edge of the graph: CITES (incl. same-law and 前条/同項), DELEGATES_TO, REFERS_TO_ATTACHMENT, AMENDS, each with `extracted_from` |
93
+ | `pending_versions.csv` | upcoming amendments: 施行日, 施行日備考, amending law, e-Gov URL |
94
+ | `release_stats.json` | the counts quoted here |
95
+
96
+ The full node file (1.89M nodes, article and paragraph text included) is attached to the GitHub
97
+ release, or you can rebuild it with the Quick start commands.
98
+
99
+ ```python
100
+ import pandas as pd
101
+ edges = pd.read_csv("data/cites_law_to_law.csv")
102
+ hubs = edges.groupby("tgt_law")["src_law_id"].nunique().sort_values(ascending=False).head(10)
103
+ ```
104
+
105
+ ## Use it from an LLM: MCP server (`mcp/`)
106
+ `resolve_citation`, `what_cites`, `what_law_cites`, `citation_path`, `get_law`, and in v2
107
+ `get_provision` (citation → text), `search_statutes` and `pending_amendments`.
108
+ See [`mcp/README.md`](https://github.com/yabooung/jp-law-citation-graph/blob/main/mcp/README.md).
109
+
110
+ ## Retrieval benchmark
111
+ Each of 1,170 National Tax Agency Q&A cases (質疑応答事例) is a real tax question whose answer cites
112
+ specific articles. The question is the query, and hits are counted at the article level
113
+ (`jlawcite eval`).
114
+
115
+ | method | R@1 | R@5 | R@10 | R@20 | R@50 | MRR@50 | s/query |
116
+ |---|---:|---:|---:|---:|---:|---:|---:|
117
+ | BM25 (character-trigram OR) | 0.086 | 0.192 | 0.244 | 0.326 | 0.437 | 0.140 | 0.11 |
118
+ | BM25 + 1-hop citation graph | **0.256** | **0.403** | **0.459** | **0.500** | **0.550** | **0.325** | 0.11 |
119
+
120
+ <sub>1,170 queries · e-Gov snapshot 2026-09-27 · `eval/v2/nta_retrieval_results.json`</sub>
121
+
122
+ The one-hop expansion adds the articles that the top hits cite. A retrieved 施行令 paragraph pulls
123
+ up the parent-act article it implements. Both rows use no embeddings; they are a baseline for dense
124
+ or hybrid retrievers.
125
+
126
+ ## Quality, honestly
127
+ - **Coverage.** No law is left without body text, the 11 integrity checks pass (no dangling edges),
128
+ and the same input produces the same output.
129
+ - **Resolution rates** leave out citations whose target is not in a current-law corpus: pre-amendment
130
+ text (旧法), amending acts (改正法), and citations inside amending-law 附則 blocks. These are counted
131
+ separately in `jp_cites_stats.json`.
132
+ - **Precision is preliminary.** 180 random edges (10–20 per resolution rule) were checked by hand
133
+ against their source text during development. Five error classes turned up and were fixed. The rules covering 86% of edges now
134
+ measure ≈98%. Samples are small (10/10 still has a 72% lower bound) and were not blind, so treat it
135
+ as indicative. Citations inside amending-law 附則 are about 40% right and are flagged with
136
+ confidence 0.4. Citations of pre-amendment text (「旧○○法第N条」) point at the current version and
137
+ carry `version: "pre_amendment"`. Details: [docs/METHODOLOGY.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/METHODOLOGY.md).
138
+ - **Scope.** National statutes in force only: no case law, 通達, local ordinances, or text of repealed
139
+ and amending acts. イ/ロ/ハ subitems are folded into their item.
140
+
141
+ ## Reproduce
142
+ ```bash
143
+ jlawcite fetch --zip all_xml.zip # re-extract an archived snapshot for an exact rebuild
144
+ jlawcite build … --as-of 20260929 # same snapshot + same as-of date → same graph
145
+ jlawcite export --out data # regenerate the files in /data
146
+ python tools/build_explorer.py # regenerate explorer.html
147
+ python -m pytest # 177 tests
148
+ ```
149
+
150
+ ## Related work
151
+ - **弁護士ドットコム (DDS 2026)** built a citation graph over e-Gov statutes (条・項・号) together with
152
+ books, guidelines and court decisions. It reports P 98.8 / R 92.1 for law-to-law citations; same-law
153
+ references are outside its evaluation, and the graph is not public.
154
+ [paper](https://dbsj.org/wp-content/uploads/2025/11/dds-vol4-no3.pdf)
155
+ - **[DaisukeHori/japan-law](https://github.com/DaisukeHori/japan-law)** publishes about 112k article-level
156
+ cross-references for about 8,000 laws (CC0), without an accuracy evaluation.
157
+ - Reference resolution in Japanese statutes goes back to Tran, Nguyen & Shimazu (ICAIL 2013). Using
158
+ citation structure for statute retrieval has been shown on the Japanese Civil Code (Mizuno & Kano,
159
+ COLIEE 2025; Vuong et al., *Applied Intelligence* 2025) and on Belgian law (Louis et al., EACL 2023).
160
+
161
+ JLaw-CiteGraph adds same-law and relative references (前条・同条・同項・前号・同法), version selection with
162
+ upcoming amendments, per-rule precision, and a retrieval evaluation over the whole corpus, all as open data.
163
+
164
+ ## Documentation
165
+ [CHANGELOG](https://github.com/yabooung/jp-law-citation-graph/blob/main/CHANGELOG.md) · [DATA_CARD](https://github.com/yabooung/jp-law-citation-graph/blob/main/DATA_CARD.md) · [METHODOLOGY](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/METHODOLOGY.md) ·
166
+ [eval protocol](https://github.com/yabooung/jp-law-citation-graph/blob/main/eval/EVAL_PROTOCOL.md) · detailed Korean docs: [dataset](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/DATASET.md),
167
+ [schema & resolution rules](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/GRAPH_SCHEMA.md), [search](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/SEARCH.md),
168
+ [improvement handbook](https://github.com/yabooung/jp-law-citation-graph/blob/main/docs/ko/IMPROVING_THE_GRAPH.md)
169
+
170
+ ## Contributing
171
+ Issues and PRs are welcome: [CONTRIBUTING.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/CONTRIBUTING.md). A blind annotation round
172
+ (`eval/`) would turn the preliminary precision into a validated number, and it is the most useful
173
+ single contribution.
174
+
175
+ ## License
176
+ Code: Apache-2.0. Data: CC BY 4.0 (source: e-Gov 法令データ; NTA 質疑応答事例 for `eval/v2/nta_gold.jsonl`).
177
+ See [DATA_LICENSE.md](https://github.com/yabooung/jp-law-citation-graph/blob/main/DATA_LICENSE.md). This is not legal advice; check e-Gov / 官報 for legal decisions.
178
+
179
+ ## Citation
180
+ ```bibtex
181
+ @misc{jlaw_citegraph_2026,
182
+ title = {JLaw-CiteGraph: An open citation graph of Japanese statutory law},
183
+ version = {2.0.0},
184
+ year = {2026},
185
+ note = {e-Gov 2026-09-27 snapshot},
186
+ url = {https://github.com/yabooung/jp-law-citation-graph}
187
+ }
188
+ ```
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "jlawcite"
3
+ version = "2.0.0"
4
+ description = "JLaw-CiteGraph: deterministic citation graph and embedding-free search for Japanese statutes (e-Gov 法令)"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = {text = "Apache-2.0"}
8
+ authors = [{name = "yabooung"}]
9
+ keywords = ["Japanese law", "legal NLP", "citation graph", "e-Gov", "statute", "legal information retrieval"]
10
+ dependencies = [
11
+ "pydantic>=2.5",
12
+ "tqdm>=4.66",
13
+ ]
14
+
15
+ [project.optional-dependencies]
16
+ dev = ["pytest>=8.0"]
17
+ mcp = ["mcp>=1.0.0"]
18
+
19
+ [project.urls]
20
+ Homepage = "https://github.com/yabooung/jp-law-citation-graph"
21
+
22
+ [project.scripts]
23
+ jlawcite = "jlawcite.cli:main"
24
+
25
+ [build-system]
26
+ requires = ["setuptools>=61.0"]
27
+ build-backend = "setuptools.build_meta"
28
+
29
+ [tool.setuptools]
30
+ package-dir = {"" = "src"}
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
34
+
35
+ [tool.setuptools.package-data]
36
+ jlawcite = ["*.json"]
37
+
38
+ [tool.pytest.ini_options]
39
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,13 @@
1
+ """jlawcite — deterministic Japanese statutory citation graph and search.
2
+
3
+ Modules (v1 names kept):
4
+ parser e-Gov 法令 XML → Law / Article / Paragraph / Item / Attachment records
5
+ citation rule-based citation extraction (external / internal / referential / …)
6
+ resolver LawNameIndex (promulgation / canonical / 旧法令名 / alias / defined
7
+ abbreviations) and referential resolution (前条・同項・前号 …)
8
+ search SQLite FTS5 search index and SearchDB API
9
+ pipeline fetch → build → validate → export / index / eval (CLI: `jlawcite`)
10
+ """
11
+ from __future__ import annotations
12
+
13
+ __version__ = "2.0.0"