privyscope-ja 0.1.4__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.
@@ -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
95
+ Derivative 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 [yyyy] [name of copyright owner]
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,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: privyscope-ja
3
+ Version: 0.1.4
4
+ Summary: privyscope-ja — Japanese language pack for the privyscope PII engine
5
+ Author: privyscope Core Team
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/zafrem/privyscope-ja
8
+ Project-URL: Documentation, https://github.com/zafrem/privyscope-ja/blob/main/README.md
9
+ Keywords: pii,ner,redaction,privacy,japanese,onnx
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Text Processing :: Linguistic
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: privyscope>=0.1.3
23
+ Provides-Extra: train
24
+ Requires-Dist: privyscope[train]>=0.1.0; extra == "train"
25
+ Requires-Dist: fugashi>=1.3; extra == "train"
26
+ Requires-Dist: unidic-lite>=1.0.8; extra == "train"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # privyscope-ja
33
+
34
+ **Japanese language pack** for [privyscope](https://github.com/zafrem/privyscope),
35
+ a two-stage hybrid PII detection & masking engine.
36
+
37
+ This is a thin **plugin**: it ships only the Japanese data (`regex_rules.yaml`,
38
+ `entity_config.yaml`) and registers itself with the `privyscope` core via the
39
+ `privyscope.languages` entry point. The engine and the `privyscope` command live
40
+ in the core, which is pulled in automatically.
41
+
42
+ Japanese mixes three scripts — kanji (漢字), hiragana (ひらがな) and katakana
43
+ (カタカナ) — with no inter-word spaces, so the pack advertises all three scripts
44
+ and leaves personal-name detection to the NER stage rather than regex.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install privyscope-ja # pulls in the `privyscope` core automatically
50
+ ```
51
+
52
+ ## Quickstart
53
+
54
+ ```bash
55
+ privyscope redact "田中さんの電話は090-1234-5678、メールは taro@example.co.jp"
56
+ # → "<PER>さんの電話は<PHONE>、メールは <EMAIL>"
57
+ ```
58
+
59
+ ```python
60
+ from privyscope import Privyscope
61
+ eng = Privyscope.from_pretrained(lang="ja")
62
+ eng.redact("田中さんの電話は090-1234-5678").masked_text # "<PER>さんの電話は<PHONE>"
63
+ ```
64
+
65
+ ## How it works
66
+
67
+ A **two-stage hybrid pipeline**, results merged via union:
68
+
69
+ 1. **Regex filter** — structurally obvious PII: Japanese mobile
70
+ (`0[789]0-xxxx-xxxx`, `+81`), landlines, My Number (個人番号, 12-digit with
71
+ check digit), passport, driver's license, Corporate Number (法人番号),
72
+ Japanese bank accounts, email, and credential secrets.
73
+ 2. **ONNX NER** — a BIOES token classifier with a constrained Viterbi decoder for
74
+ contextual PII (names, addresses, private dates). Weights download from
75
+ Hugging Face Hub (`zafrem/privyscope-ja`) on first use.
76
+
77
+ Inference is **ONNX Runtime only — no PyTorch at runtime**. The base encoder
78
+ tokenizes with MeCab, but that dependency is needed only for training/fine-tuning.
79
+
80
+ ## Entities
81
+
82
+ 8 base types — `PER`, `PHONE`, `ID_NUM`, `EMAIL`, `LOC`, `BANK`, `DATE`,
83
+ `SECRET` — plus extended `BIZ_NUM` (Corporate Number 法人番号) and
84
+ `DRIVER_LICENSE`, caught by regex.
85
+
86
+ ## Model & performance
87
+
88
+ - **Base encoder** — `tohoku-nlp/bert-base-japanese-v3` → BIOES head → Viterbi
89
+ decoder.
90
+ - **Runtime artifact** — INT8-quantized ONNX, max sequence length 256, downloaded
91
+ from the Hub with a SHA-256 `checksum.txt` for integrity.
92
+ - **Accuracy** — run `privyscope eval --lang ja your_val.jsonl` on your own
93
+ labelled data; numbers will be published here once the held-out evaluation is
94
+ finalized.
95
+
96
+ ## Limitations
97
+
98
+ - Not an anonymization/compliance guarantee; use as one layer of
99
+ privacy-by-design, with human review for sensitive workflows.
100
+ - Personal names are contextual (NER only): recall depends on the fine-tuned
101
+ model, which is trained across kanji/hiragana/katakana renderings.
102
+
103
+ ## License
104
+
105
+ Apache-2.0. See [LICENSE](LICENSE).
106
+
107
+ Stage-1 regex patterns are compiled from the
108
+ [pii-pattern-engine](https://github.com/zafrem/pii-pattern-engine) ruleset. Most rules carry
109
+ a **verification function** — a checksum or dictionary validator (`jp_my_number_valid`, `luhn`) that a match
110
+ must pass before it is redacted, so a value that merely looks like an ID is left alone.
111
+
112
+ Regex-only extended entities: `BIZ_NUM · DRIVER_LICENSE · CRYPTO · IP · DEVICE · URL`.
113
+
114
+ > `privyscope_ja/regex_rules.yaml` is **generated** by `scripts/gen_regex_rules.py` and is overwritten
115
+ > on every build — edit the mapping in that script, not the YAML. See [CONTRIBUTING](CONTRIBUTING.md).
@@ -0,0 +1,84 @@
1
+ # privyscope-ja
2
+
3
+ **Japanese language pack** for [privyscope](https://github.com/zafrem/privyscope),
4
+ a two-stage hybrid PII detection & masking engine.
5
+
6
+ This is a thin **plugin**: it ships only the Japanese data (`regex_rules.yaml`,
7
+ `entity_config.yaml`) and registers itself with the `privyscope` core via the
8
+ `privyscope.languages` entry point. The engine and the `privyscope` command live
9
+ in the core, which is pulled in automatically.
10
+
11
+ Japanese mixes three scripts — kanji (漢字), hiragana (ひらがな) and katakana
12
+ (カタカナ) — with no inter-word spaces, so the pack advertises all three scripts
13
+ and leaves personal-name detection to the NER stage rather than regex.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install privyscope-ja # pulls in the `privyscope` core automatically
19
+ ```
20
+
21
+ ## Quickstart
22
+
23
+ ```bash
24
+ privyscope redact "田中さんの電話は090-1234-5678、メールは taro@example.co.jp"
25
+ # → "<PER>さんの電話は<PHONE>、メールは <EMAIL>"
26
+ ```
27
+
28
+ ```python
29
+ from privyscope import Privyscope
30
+ eng = Privyscope.from_pretrained(lang="ja")
31
+ eng.redact("田中さんの電話は090-1234-5678").masked_text # "<PER>さんの電話は<PHONE>"
32
+ ```
33
+
34
+ ## How it works
35
+
36
+ A **two-stage hybrid pipeline**, results merged via union:
37
+
38
+ 1. **Regex filter** — structurally obvious PII: Japanese mobile
39
+ (`0[789]0-xxxx-xxxx`, `+81`), landlines, My Number (個人番号, 12-digit with
40
+ check digit), passport, driver's license, Corporate Number (法人番号),
41
+ Japanese bank accounts, email, and credential secrets.
42
+ 2. **ONNX NER** — a BIOES token classifier with a constrained Viterbi decoder for
43
+ contextual PII (names, addresses, private dates). Weights download from
44
+ Hugging Face Hub (`zafrem/privyscope-ja`) on first use.
45
+
46
+ Inference is **ONNX Runtime only — no PyTorch at runtime**. The base encoder
47
+ tokenizes with MeCab, but that dependency is needed only for training/fine-tuning.
48
+
49
+ ## Entities
50
+
51
+ 8 base types — `PER`, `PHONE`, `ID_NUM`, `EMAIL`, `LOC`, `BANK`, `DATE`,
52
+ `SECRET` — plus extended `BIZ_NUM` (Corporate Number 法人番号) and
53
+ `DRIVER_LICENSE`, caught by regex.
54
+
55
+ ## Model & performance
56
+
57
+ - **Base encoder** — `tohoku-nlp/bert-base-japanese-v3` → BIOES head → Viterbi
58
+ decoder.
59
+ - **Runtime artifact** — INT8-quantized ONNX, max sequence length 256, downloaded
60
+ from the Hub with a SHA-256 `checksum.txt` for integrity.
61
+ - **Accuracy** — run `privyscope eval --lang ja your_val.jsonl` on your own
62
+ labelled data; numbers will be published here once the held-out evaluation is
63
+ finalized.
64
+
65
+ ## Limitations
66
+
67
+ - Not an anonymization/compliance guarantee; use as one layer of
68
+ privacy-by-design, with human review for sensitive workflows.
69
+ - Personal names are contextual (NER only): recall depends on the fine-tuned
70
+ model, which is trained across kanji/hiragana/katakana renderings.
71
+
72
+ ## License
73
+
74
+ Apache-2.0. See [LICENSE](LICENSE).
75
+
76
+ Stage-1 regex patterns are compiled from the
77
+ [pii-pattern-engine](https://github.com/zafrem/pii-pattern-engine) ruleset. Most rules carry
78
+ a **verification function** — a checksum or dictionary validator (`jp_my_number_valid`, `luhn`) that a match
79
+ must pass before it is redacted, so a value that merely looks like an ID is left alone.
80
+
81
+ Regex-only extended entities: `BIZ_NUM · DRIVER_LICENSE · CRYPTO · IP · DEVICE · URL`.
82
+
83
+ > `privyscope_ja/regex_rules.yaml` is **generated** by `scripts/gen_regex_rules.py` and is overwritten
84
+ > on every build — edit the mapping in that script, not the YAML. See [CONTRIBUTING](CONTRIBUTING.md).
@@ -0,0 +1,29 @@
1
+ """privyscope-ja — Japanese language pack for the ``privyscope`` engine (Apache-2.0).
2
+
3
+ This is a thin **plugin**: it ships only Japanese data (``regex_rules.yaml``,
4
+ ``entity_config.yaml``) and registers itself with the core via the
5
+ ``privyscope.languages`` entry point. All engine code lives in the ``privyscope``
6
+ core package, which is pulled in as a dependency.
7
+
8
+ from privyscope_ja import Privyscope # re-exported from the core
9
+ engine = Privyscope.from_pretrained(lang="ja")
10
+ engine.redact("田中さんの電話番号は090-1234-5678です").masked_text
11
+ # "<PER>さんの電話番号は<PHONE>です"
12
+
13
+ Japanese is written in a mix of kanji, hiragana and katakana, so ``scripts``
14
+ lists all three (plus ``Latin`` for interleaved ASCII) — the core uses this to
15
+ auto-route text to this pack.
16
+ """
17
+ from privyscope import Privyscope, RedactionResult, DetectedSpan, LanguagePlugin, __version__
18
+
19
+ #: Registered under the ``privyscope.languages`` entry-point group (see pyproject).
20
+ LANG = LanguagePlugin(
21
+ code="ja",
22
+ display_name="Japanese",
23
+ default_repo="zafrem/privyscope-ja",
24
+ package="privyscope_ja",
25
+ scripts=("Han", "Hiragana", "Katakana"),
26
+ default_base_model="tohoku-nlp/bert-base-japanese-v3",
27
+ )
28
+
29
+ __all__ = ["Privyscope", "RedactionResult", "DetectedSpan", "LANG", "__version__"]
@@ -0,0 +1,71 @@
1
+ # privyscope-ja — entity configuration (Japanese / Japan).
2
+ # Base PII taxonomy (SRS §6) plus ja-specific extended entities. Extended
3
+ # entities are detected by regex only unless added to the NER label space via a
4
+ # custom fine-tune (FR-2.6).
5
+ language: ja
6
+
7
+ base_entities:
8
+ - code: PER
9
+ detection: contextual
10
+ regex: null
11
+ - code: PHONE
12
+ detection: structural
13
+ regex: '(?:\+81[-\s]?|0)\d{1,4}[-\s]?\d{1,4}[-\s]?\d{3,4}'
14
+ - code: ID_NUM
15
+ detection: structural
16
+ # My Number (個人番号) — 12 digits, optionally spaced in groups of four.
17
+ regex: '\d{4}[-\s]?\d{4}[-\s]?\d{4}'
18
+ - code: EMAIL
19
+ detection: structural
20
+ regex: '[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}'
21
+ - code: LOC
22
+ detection: contextual
23
+ regex: null
24
+ - code: BANK
25
+ detection: structural
26
+ regex: '\d{7,}'
27
+ - code: DATE
28
+ detection: hybrid
29
+ regex: null
30
+ - code: SECRET
31
+ detection: hybrid
32
+ regex: 'sk-[A-Za-z0-9]{20,}'
33
+
34
+ extended_entities:
35
+ # ja-specific identifiers not in the base label set.
36
+ - code: BIZ_NUM
37
+ detection: structural
38
+ regex: '[1-9]\d{12}'
39
+ description: Corporate Number (法人番号), 13 digits
40
+
41
+ - code: DRIVER_LICENSE
42
+ detection: structural
43
+ regex: '\d{12}'
44
+ description: Driver's license number (運転免許証番号), 12 digits
45
+
46
+ # Regex-only entities (ENTITY_SPEC §3.3), compiled from the pii-pattern-engine
47
+ # ruleset by scripts/gen_regex_rules.py. Detected by the Stage-1 filter; absent from
48
+ # the NER label space unless added via a custom fine-tune (FR-2.6).
49
+ - code: CRYPTO
50
+ detection: structural
51
+ regex: null
52
+ description: Bitcoin / Ethereum wallet address
53
+ - code: DEVICE
54
+ detection: structural
55
+ regex: null
56
+ description: MAC address / IMEI
57
+ - code: IP
58
+ detection: structural
59
+ regex: null
60
+ description: IPv4 / IPv6 address
61
+ - code: URL
62
+ detection: structural
63
+ regex: null
64
+ description: URL
65
+
66
+ # Partial-masking policy; applied by downstream consumers.
67
+ partial_masking:
68
+ ID_NUM: '1234****5678'
69
+ PHONE: '090****5678'
70
+ BANK: '**** **** 3456'
71
+ EMAIL: 'u***@domain.com'
@@ -0,0 +1,240 @@
1
+ # privyscope-ja — Stage 1 Regex Filter rules (SRS §3.4, ENTITY_SPEC §3).
2
+ #
3
+ # GENERATED FILE — do not edit. Compiled from the pii-pattern-engine submodule by
4
+ # scripts/gen_regex_rules.py; change the mapping there and rebuild.
5
+ #
6
+ # Fields:
7
+ # id : upstream pattern id (provenance)
8
+ # label : privyscope entity code
9
+ # pattern : Python `re` pattern
10
+ # priority : overlap-resolution weight, from upstream severity (higher wins)
11
+ # verify : checksum/dictionary validator a match must pass (optional)
12
+ version: 2
13
+ language: ja
14
+ rules:
15
+ - id: credit_card_amex_01
16
+ label: BANK
17
+ pattern: (?<![A-Za-z0-9])(?:3[47][0-9]{13})(?![A-Za-z0-9])
18
+ priority: 100
19
+ - id: credit_card_diners_01
20
+ label: BANK
21
+ pattern: (?<![A-Za-z0-9])(?:3[0689][0-9]{12})(?![A-Za-z0-9])
22
+ priority: 100
23
+ verify: credit_card_bin_valid
24
+ - id: credit_card_discover_01
25
+ label: BANK
26
+ pattern: (?<![A-Za-z0-9])(?:6(?:011|5[0-9]{2})[0-9]{12})(?![A-Za-z0-9])
27
+ priority: 100
28
+ - id: credit_card_jcb_01
29
+ label: BANK
30
+ pattern: (?<![A-Za-z0-9])(?:(?:2131|1800|35\d{3})\d{11})(?![A-Za-z0-9])
31
+ priority: 100
32
+ - id: credit_card_mastercard_01
33
+ label: BANK
34
+ pattern: (?<![A-Za-z0-9])(?:5[1-5][0-9]{14})(?![A-Za-z0-9])
35
+ priority: 100
36
+ - id: credit_card_visa_01
37
+ label: BANK
38
+ pattern: (?<![A-Za-z0-9])(?:4[0-9]{12}(?:[0-9]{3})?)(?![A-Za-z0-9])
39
+ priority: 100
40
+ - id: generic_japanese_bank_account_01
41
+ label: BANK
42
+ pattern: (?<![A-Za-z0-9])(?:[0-9]{4}-?[0-9]{3}-?[0-9]{7})(?![A-Za-z0-9])
43
+ priority: 100
44
+ verify: generic_number_not_timestamp
45
+ - id: local_credit_card_grouped
46
+ label: BANK
47
+ pattern: (?<![0-9])(?:[0-9]{4}[- ]){3}[0-9]{4}(?![0-9])
48
+ priority: 100
49
+ verify: luhn
50
+ - id: mizuho_bank_account_01
51
+ label: BANK
52
+ pattern: (?<![A-Za-z0-9])(?:0001-?[0-9]{3}-?[0-9]{7})(?![A-Za-z0-9])
53
+ priority: 100
54
+ - id: mufg_bank_account_01
55
+ label: BANK
56
+ pattern: (?<![A-Za-z0-9])(?:0005-?[0-9]{3}-?[0-9]{7})(?![A-Za-z0-9])
57
+ priority: 100
58
+ - id: rakuten_bank_account_01
59
+ label: BANK
60
+ pattern: (?<![A-Za-z0-9])(?:0036-?[0-9]{3}-?[0-9]{7})(?![A-Za-z0-9])
61
+ priority: 100
62
+ verify: generic_number_not_timestamp
63
+ - id: resona_bank_account_01
64
+ label: BANK
65
+ pattern: (?<![A-Za-z0-9])(?:0010-?[0-9]{3}-?[0-9]{7})(?![A-Za-z0-9])
66
+ priority: 100
67
+ - id: seven_bank_account_01
68
+ label: BANK
69
+ pattern: (?<![A-Za-z0-9])(?:0034-?[0-9]{3}-?[0-9]{7})(?![A-Za-z0-9])
70
+ priority: 100
71
+ - id: smbc_bank_account_01
72
+ label: BANK
73
+ pattern: (?<![A-Za-z0-9])(?:0009-?[0-9]{3}-?[0-9]{7})(?![A-Za-z0-9])
74
+ priority: 100
75
+ - id: my_number_01
76
+ label: ID_NUM
77
+ pattern: (?<![A-Za-z0-9])(?:[0-9]{4}-?[0-9]{4}-?[0-9]{4})(?![A-Za-z0-9])
78
+ priority: 100
79
+ verify: jp_my_number_valid
80
+ - id: passport_01
81
+ label: ID_NUM
82
+ pattern: (?<![A-Za-z0-9])(?:(?i:[A-Z]{2}[0-9]{7}))(?![A-Za-z0-9])
83
+ priority: 100
84
+ - id: aws_access_key_01
85
+ label: SECRET
86
+ pattern: (?<![A-Za-z0-9])(?:AKIA[0-9A-Z]{16})(?![A-Za-z0-9])
87
+ priority: 100
88
+ - id: aws_secret_key_01
89
+ label: SECRET
90
+ pattern: (?<![A-Za-z0-9])(?:\b[A-Za-z0-9/+=]{40}\b)(?![A-Za-z0-9])
91
+ priority: 100
92
+ verify: high_entropy_token
93
+ - id: generic_api_key_01
94
+ label: SECRET
95
+ pattern: (?<![A-Za-z0-9])(?:[A-Za-z0-9_\-+/=]{32,})(?![A-Za-z0-9])
96
+ priority: 100
97
+ verify: high_entropy_token
98
+ - id: generic_token_01
99
+ label: SECRET
100
+ pattern: (?<![A-Za-z0-9])(?:[A-Za-z0-9_\-+/=.]{20,})(?![A-Za-z0-9])
101
+ priority: 100
102
+ verify: high_entropy_token
103
+ - id: github_token_01
104
+ label: SECRET
105
+ pattern: (?<![A-Za-z0-9])(?:gh[pousr]_[A-Za-z0-9_]{36,})(?![A-Za-z0-9])
106
+ priority: 100
107
+ verify: high_entropy_token
108
+ - id: google_api_key_01
109
+ label: SECRET
110
+ pattern: (?<![A-Za-z0-9])(?:AIza[A-Za-z0-9\-_]{35})(?![A-Za-z0-9])
111
+ priority: 100
112
+ - id: local_env_assignment_secret
113
+ label: SECRET
114
+ pattern: (?:[A-Z][A-Z0-9]*_)*(?:PASS|PASSWORD|SECRET|TOKEN|KEY|APIKEY|CREDENTIAL)[A-Z0-9_]*\s*=\s*\S{6,}
115
+ priority: 100
116
+ - id: private_key_01
117
+ label: SECRET
118
+ pattern: (?<![A-Za-z0-9])(?:-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----)(?![A-Za-z0-9])
119
+ priority: 100
120
+ - id: slack_token_01
121
+ label: SECRET
122
+ pattern: (?<![A-Za-z0-9])(?:xox[bpar]-[A-Za-z0-9\-]{10,})(?![A-Za-z0-9])
123
+ priority: 100
124
+ verify: high_entropy_token
125
+ - id: stripe_key_01
126
+ label: SECRET
127
+ pattern: (?<![A-Za-z0-9])(?:(?:rk|sk|pk)_(live|test|demo)_[A-Za-z0-9]{24,})(?![A-Za-z0-9])
128
+ priority: 100
129
+ verify: high_entropy_token
130
+ - id: iban_01
131
+ label: BANK
132
+ pattern: (?<![A-Za-z0-9])(?:[A-Z]{2}\d{2}[A-Z0-9]{11,30})(?![A-Za-z0-9])
133
+ priority: 75
134
+ verify: iban_mod97
135
+ - id: iban_de_01
136
+ label: BANK
137
+ pattern: (?<![A-Za-z0-9])(?:DE\d{2}[A-Z0-9]{18})(?![A-Za-z0-9])
138
+ priority: 75
139
+ verify: iban_mod97
140
+ - id: iban_fr_01
141
+ label: BANK
142
+ pattern: (?<![A-Za-z0-9])(?:FR\d{2}[A-Z0-9]{23})(?![A-Za-z0-9])
143
+ priority: 75
144
+ verify: iban_mod97
145
+ - id: iban_gb_01
146
+ label: BANK
147
+ pattern: (?<![A-Za-z0-9])(?:GB\d{2}[A-Z0-9]{18})(?![A-Za-z0-9])
148
+ priority: 75
149
+ verify: iban_mod97
150
+ - id: iban_it_01
151
+ label: BANK
152
+ pattern: (?<![A-Za-z0-9])(?:IT\d{2}[A-Z0-9]{23})(?![A-Za-z0-9])
153
+ priority: 75
154
+ verify: iban_mod97
155
+ - id: crypto_btc_p2pkh
156
+ label: CRYPTO
157
+ pattern: (?<![A-Za-z0-9])(?:1[a-km-zA-HJ-NP-Z1-9]{25,34})(?![A-Za-z0-9])
158
+ priority: 75
159
+ verify: crypto_btc_valid
160
+ - id: crypto_eth_01
161
+ label: CRYPTO
162
+ pattern: (?<![A-Za-z0-9])(?:0x[a-fA-F0-9]{40})(?![A-Za-z0-9])
163
+ priority: 75
164
+ verify: crypto_eth_valid
165
+ - id: driver_license_01
166
+ label: DRIVER_LICENSE
167
+ pattern: (?<![A-Za-z0-9])(?:[0-9]{4}-?[0-9]{2}-?[0-9]{6})(?![A-Za-z0-9])
168
+ priority: 75
169
+ verify: jp_driver_license_valid
170
+ - id: address_simple_01
171
+ label: LOC
172
+ pattern: (?<![A-Za-z0-9])(?:(?:北海道|東京都|大阪府|京都府|青森県|岩手県|宮城県|秋田県|山形県|福島県|茨城県|栃木県|群馬県|埼玉県|千葉県|神奈川県|新潟県|富山県|石川県|福井県|山梨県|長野県|岐阜県|静岡県|愛知県|三重県|滋賀県|兵庫県|奈良県|和歌山県|鳥取県|島根県|岡山県|広島県|山口県|徳島県|香川県|愛媛県|高知県|福岡県|佐賀県|長崎県|熊本県|大分県|宮崎県|鹿児島県|沖縄県)[ぁ-ゟ゠-ヿ一-鿿\s]+(?:市|区|町|村)[ぁ-ゟ゠-ヿ一-鿿a-zA-Z0-90-9\s\-−‐]+(?:[0-90-9]+丁目[0-90-9]+番[0-90-9]+号|[0-90-9]+[-−‐][0-90-9]+(?:[-−‐][0-90-9]+)?))(?![A-Za-z0-9])
173
+ priority: 75
174
+ verify: japanese_address_valid
175
+ - id: mobile_01
176
+ label: PHONE
177
+ pattern: (?<![A-Za-z0-9])(?:0[789]0-?[0-9]{4}-?[0-9]{4})(?![A-Za-z0-9])
178
+ priority: 75
179
+ - id: artifactory_token_01
180
+ label: SECRET
181
+ pattern: (?<![A-Za-z0-9])(?:\b(cm|AKC)[a-zA-Z0-9]{10,}\b)(?![A-Za-z0-9])
182
+ priority: 75
183
+ verify: high_entropy_token
184
+ - id: jwt_token_01
185
+ label: SECRET
186
+ pattern: (?<![A-Za-z0-9])(?:eyJ[A-Za-z0-9_\-]+\.eyJ[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+)(?![A-Za-z0-9])
187
+ priority: 75
188
+ - id: jp_corporate_number
189
+ label: BIZ_NUM
190
+ pattern: (?<![A-Za-z0-9])(?:[1-9][0-9]{12})(?![A-Za-z0-9])
191
+ priority: 50
192
+ verify: jp_corporate_number_valid
193
+ - id: imei_01
194
+ label: DEVICE
195
+ pattern: (?<![A-Za-z0-9])(?:\b[0-9]{15}\b)(?![A-Za-z0-9])
196
+ priority: 50
197
+ verify: imei_valid
198
+ - id: email_01
199
+ label: EMAIL
200
+ pattern: (?<![A-Za-z0-9])(?:(?i:[a-zA-Z0-9._%+-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}))(?![A-Za-z0-9])
201
+ priority: 50
202
+ - id: fcm_token_01
203
+ label: SECRET
204
+ pattern: (?<![A-Za-z0-9])(?:[a-zA-Z0-9\-_]{140,200}:[a-zA-Z0-9\-_]{11})(?![A-Za-z0-9])
205
+ priority: 50
206
+ - id: date_iso_01
207
+ label: DATE
208
+ pattern: (?<![A-Za-z0-9])(?:(19|20)\d{2}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))(?![A-Za-z0-9])
209
+ priority: 25
210
+ verify: not_timestamp
211
+ - id: date_slash_01
212
+ label: DATE
213
+ pattern: (?<![A-Za-z0-9])(?:((19|20)\d{2}/(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])|(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])/(19|20)\d{2}))(?![A-Za-z0-9])
214
+ priority: 25
215
+ - id: mac_address_01
216
+ label: DEVICE
217
+ pattern: (?<![A-Za-z0-9])(?:([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}))(?![A-Za-z0-9])
218
+ priority: 25
219
+ verify: mac_address_valid
220
+ - id: ipv4_01
221
+ label: IP
222
+ pattern: (?<![A-Za-z0-9])(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![A-Za-z0-9])
223
+ priority: 25
224
+ - id: ipv6_01
225
+ label: IP
226
+ pattern: (?<![A-Za-z0-9])(?:(?i:(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))))(?![A-Za-z0-9])
227
+ priority: 25
228
+ - id: landline_01
229
+ label: PHONE
230
+ pattern: (?<![A-Za-z0-9])(?:0(?:[1-6][0-9]?|[789][1-9])(?:-?[0-9]{3,4}-?[0-9]{4}))(?![A-Za-z0-9])
231
+ priority: 25
232
+ verify: not_repeating_pattern
233
+ - id: uuid_01
234
+ label: SECRET
235
+ pattern: (?<![A-Za-z0-9])(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})(?![A-Za-z0-9])
236
+ priority: 25
237
+ - id: url_01
238
+ label: URL
239
+ pattern: (?<![A-Za-z0-9])(?:(?i:https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&/=]*)))(?![A-Za-z0-9])
240
+ priority: 25
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: privyscope-ja
3
+ Version: 0.1.4
4
+ Summary: privyscope-ja — Japanese language pack for the privyscope PII engine
5
+ Author: privyscope Core Team
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/zafrem/privyscope-ja
8
+ Project-URL: Documentation, https://github.com/zafrem/privyscope-ja/blob/main/README.md
9
+ Keywords: pii,ner,redaction,privacy,japanese,onnx
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Text Processing :: Linguistic
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: privyscope>=0.1.3
23
+ Provides-Extra: train
24
+ Requires-Dist: privyscope[train]>=0.1.0; extra == "train"
25
+ Requires-Dist: fugashi>=1.3; extra == "train"
26
+ Requires-Dist: unidic-lite>=1.0.8; extra == "train"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # privyscope-ja
33
+
34
+ **Japanese language pack** for [privyscope](https://github.com/zafrem/privyscope),
35
+ a two-stage hybrid PII detection & masking engine.
36
+
37
+ This is a thin **plugin**: it ships only the Japanese data (`regex_rules.yaml`,
38
+ `entity_config.yaml`) and registers itself with the `privyscope` core via the
39
+ `privyscope.languages` entry point. The engine and the `privyscope` command live
40
+ in the core, which is pulled in automatically.
41
+
42
+ Japanese mixes three scripts — kanji (漢字), hiragana (ひらがな) and katakana
43
+ (カタカナ) — with no inter-word spaces, so the pack advertises all three scripts
44
+ and leaves personal-name detection to the NER stage rather than regex.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install privyscope-ja # pulls in the `privyscope` core automatically
50
+ ```
51
+
52
+ ## Quickstart
53
+
54
+ ```bash
55
+ privyscope redact "田中さんの電話は090-1234-5678、メールは taro@example.co.jp"
56
+ # → "<PER>さんの電話は<PHONE>、メールは <EMAIL>"
57
+ ```
58
+
59
+ ```python
60
+ from privyscope import Privyscope
61
+ eng = Privyscope.from_pretrained(lang="ja")
62
+ eng.redact("田中さんの電話は090-1234-5678").masked_text # "<PER>さんの電話は<PHONE>"
63
+ ```
64
+
65
+ ## How it works
66
+
67
+ A **two-stage hybrid pipeline**, results merged via union:
68
+
69
+ 1. **Regex filter** — structurally obvious PII: Japanese mobile
70
+ (`0[789]0-xxxx-xxxx`, `+81`), landlines, My Number (個人番号, 12-digit with
71
+ check digit), passport, driver's license, Corporate Number (法人番号),
72
+ Japanese bank accounts, email, and credential secrets.
73
+ 2. **ONNX NER** — a BIOES token classifier with a constrained Viterbi decoder for
74
+ contextual PII (names, addresses, private dates). Weights download from
75
+ Hugging Face Hub (`zafrem/privyscope-ja`) on first use.
76
+
77
+ Inference is **ONNX Runtime only — no PyTorch at runtime**. The base encoder
78
+ tokenizes with MeCab, but that dependency is needed only for training/fine-tuning.
79
+
80
+ ## Entities
81
+
82
+ 8 base types — `PER`, `PHONE`, `ID_NUM`, `EMAIL`, `LOC`, `BANK`, `DATE`,
83
+ `SECRET` — plus extended `BIZ_NUM` (Corporate Number 法人番号) and
84
+ `DRIVER_LICENSE`, caught by regex.
85
+
86
+ ## Model & performance
87
+
88
+ - **Base encoder** — `tohoku-nlp/bert-base-japanese-v3` → BIOES head → Viterbi
89
+ decoder.
90
+ - **Runtime artifact** — INT8-quantized ONNX, max sequence length 256, downloaded
91
+ from the Hub with a SHA-256 `checksum.txt` for integrity.
92
+ - **Accuracy** — run `privyscope eval --lang ja your_val.jsonl` on your own
93
+ labelled data; numbers will be published here once the held-out evaluation is
94
+ finalized.
95
+
96
+ ## Limitations
97
+
98
+ - Not an anonymization/compliance guarantee; use as one layer of
99
+ privacy-by-design, with human review for sensitive workflows.
100
+ - Personal names are contextual (NER only): recall depends on the fine-tuned
101
+ model, which is trained across kanji/hiragana/katakana renderings.
102
+
103
+ ## License
104
+
105
+ Apache-2.0. See [LICENSE](LICENSE).
106
+
107
+ Stage-1 regex patterns are compiled from the
108
+ [pii-pattern-engine](https://github.com/zafrem/pii-pattern-engine) ruleset. Most rules carry
109
+ a **verification function** — a checksum or dictionary validator (`jp_my_number_valid`, `luhn`) that a match
110
+ must pass before it is redacted, so a value that merely looks like an ID is left alone.
111
+
112
+ Regex-only extended entities: `BIZ_NUM · DRIVER_LICENSE · CRYPTO · IP · DEVICE · URL`.
113
+
114
+ > `privyscope_ja/regex_rules.yaml` is **generated** by `scripts/gen_regex_rules.py` and is overwritten
115
+ > on every build — edit the mapping in that script, not the YAML. See [CONTRIBUTING](CONTRIBUTING.md).
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ privyscope_ja/__init__.py
6
+ privyscope_ja/entity_config.yaml
7
+ privyscope_ja/regex_rules.yaml
8
+ privyscope_ja.egg-info/PKG-INFO
9
+ privyscope_ja.egg-info/SOURCES.txt
10
+ privyscope_ja.egg-info/dependency_links.txt
11
+ privyscope_ja.egg-info/entry_points.txt
12
+ privyscope_ja.egg-info/requires.txt
13
+ privyscope_ja.egg-info/top_level.txt
14
+ tests/test_ja_regex.py
15
+ tests/test_plugin_registered.py
@@ -0,0 +1,2 @@
1
+ [privyscope.languages]
2
+ ja = privyscope_ja:LANG
@@ -0,0 +1,10 @@
1
+ privyscope>=0.1.3
2
+
3
+ [dev]
4
+ pytest>=7.0
5
+ pytest-cov>=4.0
6
+
7
+ [train]
8
+ privyscope[train]>=0.1.0
9
+ fugashi>=1.3
10
+ unidic-lite>=1.0.8
@@ -0,0 +1 @@
1
+ privyscope_ja
@@ -0,0 +1,65 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel", "pyyaml>=6.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "privyscope-ja"
7
+ version = "0.1.4"
8
+ description = "privyscope-ja — Japanese language pack for the privyscope PII engine"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "privyscope Core Team" }]
13
+ keywords = ["pii", "ner", "redaction", "privacy", "japanese", "onnx"]
14
+ classifiers = [
15
+ "License :: OSI Approved :: Apache Software License",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Text Processing :: Linguistic",
24
+ ]
25
+ # The engine lives in the core; this pack only adds Japanese data + registration.
26
+ dependencies = [
27
+ # 0.1.3 added the verification gate; older cores silently ignore the
28
+ # `verify:` key in regex_rules.yaml and run every rule unverified.
29
+ "privyscope>=0.1.3",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ # The Japanese base encoder tokenizes with MeCab (fugashi + a dictionary), needed
34
+ # only for training / fine-tuning — not at ONNX inference time.
35
+ train = ["privyscope[train]>=0.1.0", "fugashi>=1.3", "unidic-lite>=1.0.8"]
36
+ dev = ["pytest>=7.0", "pytest-cov>=4.0"]
37
+
38
+ # Register the Japanese plugin so the core discovers it at runtime. No console
39
+ # script here — the `privyscope` command is owned solely by the core.
40
+ [project.entry-points."privyscope.languages"]
41
+ ja = "privyscope_ja:LANG"
42
+
43
+ [project.urls]
44
+ Homepage = "https://github.com/zafrem/privyscope-ja"
45
+ Documentation = "https://github.com/zafrem/privyscope-ja/blob/main/README.md"
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["."]
49
+ include = ["privyscope_ja*"]
50
+
51
+ [tool.setuptools.package-data]
52
+ privyscope_ja = ["*.yaml"]
53
+
54
+ [tool.pytest.ini_options]
55
+ # Collect only this repo's tests. The pii-pattern-engine submodule ships its own suite
56
+ # (3,500+ cases, and it imports `re2`), which pytest would otherwise pick up from the repo
57
+ # root and fail on. `testpaths` covers a bare `pytest`; `norecursedirs` covers `pytest .`.
58
+ testpaths = ["tests"]
59
+ norecursedirs = ["pii-pattern-engine", ".core", "build", "dist", ".git"]
60
+
61
+ [tool.coverage.run]
62
+ # This pack's CI runs `--cov=privyscope` (the core engine, exercised through these rules).
63
+ # _vendor/ is verbatim upstream code from the pii-pattern-engine submodule, not ours to
64
+ # test — counting its 1,196 statements as uncovered halves the reported total.
65
+ omit = ["*/privyscope/_core/_vendor/*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,41 @@
1
+ """Build shim: compile regex_rules.yaml from the pii-pattern-engine ruleset.
2
+
3
+ Runs at import, before ``setup()`` packages ``privyscope_ja``, so the generated YAML is in
4
+ place to be picked up as package data. Covers every build path — ``pip install .``,
5
+ ``python -m build``, editable installs.
6
+
7
+ Three cases, in order:
8
+ submodule present -> (re)generate, so a build always tracks the checkout
9
+ absent but regex_rules.yaml -> reuse it; this is an sdist, which ships the generated
10
+ present rules but not the submodule
11
+ neither -> fail loudly rather than publish a language pack with no
12
+ Stage-1 rules at all
13
+ """
14
+ from pathlib import Path
15
+
16
+ from setuptools import setup
17
+
18
+ HERE = Path(__file__).parent
19
+ RULES = HERE / "privyscope_ja" / "regex_rules.yaml"
20
+ UPSTREAM = HERE / "pii-pattern-engine"
21
+
22
+
23
+ def _gen_rules() -> None:
24
+ if UPSTREAM.is_dir():
25
+ import subprocess
26
+ import sys
27
+
28
+ subprocess.run(
29
+ [sys.executable, str(HERE / "scripts" / "gen_regex_rules.py")], check=True
30
+ )
31
+ elif not RULES.exists():
32
+ raise SystemExit(
33
+ "privyscope-ja: cannot build — the pii-pattern-engine submodule is missing and\n"
34
+ "no generated regex_rules.yaml is present, so the pack would ship with no\n"
35
+ "Stage-1 regex rules.\n"
36
+ " run: git submodule update --init --recursive"
37
+ )
38
+
39
+
40
+ _gen_rules()
41
+ setup()
@@ -0,0 +1,50 @@
1
+ """Japanese Stage-1 regex rules (over the real ja data)."""
2
+ import pytest
3
+
4
+ from privyscope import installed_languages
5
+ from privyscope._core.regex_filter import RegexFilter
6
+
7
+ from privyscope_ja import LANG, Privyscope
8
+
9
+
10
+ def _filter():
11
+ return RegexFilter.from_yaml(LANG.regex_rules_path())
12
+
13
+
14
+ def test_ja_mobile_and_email():
15
+ rf = _filter()
16
+ text = "電話は090-1234-5678、メールは taro@example.co.jp です"
17
+ spans = {(s.label, text[s.start:s.end]) for s in rf.find(text)}
18
+ assert ("PHONE", "090-1234-5678") in spans
19
+ assert ("EMAIL", "taro@example.co.jp") in spans
20
+
21
+
22
+ def test_ja_my_number():
23
+ rf = _filter()
24
+ # 123456789018 has a valid My Number check digit (jp_my_number_valid).
25
+ text = "マイナンバーは123456789018です"
26
+ spans = {(s.label, text[s.start:s.end]) for s in rf.find(text)}
27
+ assert ("ID_NUM", "123456789018") in spans
28
+
29
+
30
+ def test_ja_secret_token():
31
+ rf = _filter()
32
+ text = "APIキー sk-abcdefghijklmnopqrstuvwxyz012345 を再発行"
33
+ spans = {(s.label, text[s.start:s.end]) for s in rf.find(text)}
34
+ assert ("SECRET", "sk-abcdefghijklmnopqrstuvwxyz012345") in spans
35
+
36
+
37
+ def test_ja_names_left_to_ner():
38
+ # PER is contextual (regex: null) — the Stage-1 filter must NOT emit names.
39
+ rf = _filter()
40
+ spans = {s.label for s in rf.find("担当は田中さんと佐藤さんです")}
41
+ assert "PER" not in spans
42
+
43
+
44
+ def test_ja_engine_regex_only():
45
+ if "ja" not in installed_languages():
46
+ pytest.skip("privyscope-ja not pip-installed; plugin not discoverable")
47
+ engine = Privyscope.regex_only(lang="ja")
48
+ r = engine.redact("電話は090-1234-5678、メールは taro@example.co.jp です")
49
+ assert "<PHONE>" in r.redacted_text
50
+ assert "<EMAIL>" in r.redacted_text
@@ -0,0 +1,21 @@
1
+ """Verify the Japanese pack registers with the core (requires install)."""
2
+ import pytest
3
+
4
+ from privyscope import installed_languages
5
+ from privyscope_ja import LANG
6
+
7
+
8
+ def test_lang_record_shape():
9
+ assert LANG.code == "ja"
10
+ assert LANG.display_name == "Japanese"
11
+ assert LANG.default_repo == "zafrem/privyscope-ja"
12
+ assert LANG.scripts == ("Han", "Hiragana", "Katakana")
13
+ assert LANG.regex_rules_path().exists()
14
+ assert LANG.entity_config_path().exists()
15
+
16
+
17
+ def test_discovered_via_entry_point():
18
+ langs = installed_languages()
19
+ if "ja" not in langs:
20
+ pytest.skip("privyscope-ja not pip-installed; entry point not discoverable")
21
+ assert langs["ja"].display_name == "Japanese"