pubid 2.0.43 → 2.0.44

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c706e42cf47a3be2877764c84b7dc99b58dcccdd5564c53af60ab48119f6614
4
- data.tar.gz: d421067efc31aeedfe63a7437d92751c49f358ec08919fe7f8f48e956a381ff9
3
+ metadata.gz: 6d99cf14909f9fd7fb38dbb49af29ba7af4cc8709185b37d7ce6d93d6c7d5489
4
+ data.tar.gz: a07eb61ebe481ddabc1a757db4959f1e681c76ed8c58a41a2267f90b61cae11d
5
5
  SHA512:
6
- metadata.gz: e846579162aa56c93ce6d332622b25abd2139d637d7d2fc7afb53f7e80e8ef179d2b4fc3786719ed440e94b39cff593536a899b0c8f7c09a67c6b0629420e03d
7
- data.tar.gz: f3ca75ca1732166a3e4837990aa002af0b82ca0967029124375714e090f16822910e559d9063734dffca64ec9c765510984fa9c6b1be64eba3ea6adcb7a21158
6
+ metadata.gz: 47f10de035fea281a9afc3644bc4163ddc28bf7b1bf1a1b5aed2d46e97bc544ad2ab0a560d513609b5228376b684517692e74f8257b24b0e581d0a520b8ad74f
7
+ data.tar.gz: 7615b627d44622f5e5bd247dac8fa7d46741ee537a7f5128c70bd4bbeb0bab7bf9a2954cb8abec971094e1386c1eb09f9fc768036676ed63c69a63d7b4be3b3d
@@ -0,0 +1 @@
1
+ {"bindings":null,"version":"0.1.0","grammar":"PubidArxiv","shape":"parsanol-tree/v2","binding_version":1,"entries":{"identifier":{"root":"identifier","grammar":{"atoms":[{"Entity":{"atom":8}},{"Re":{"pattern":"(?i:arXiv)"}},{"Entity":{"atom":3}},{"Str":{"pattern":":"}},{"Named":{"name":"colon","atom":2}},{"Entity":{"atom":6}},{"Str":{"pattern":" "}},{"Alternative":{"atoms":[4,5]}},{"Sequence":{"atoms":[1,7]}},{"Repetition":{"atom":0,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":21}},{"Entity":{"atom":15}},{"Entity":{"atom":13}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":12,"min":4,"max":4,"tag":"Repetition"}},{"Named":{"name":"yymm","atom":14}},{"Str":{"pattern":"."}},{"Entity":{"atom":20}},{"Entity":{"atom":13}},{"Repetition":{"atom":18,"min":4,"max":5,"tag":"Repetition"}},{"Named":{"name":"number","atom":19}},{"Sequence":{"atoms":[11,16,17]}},{"Entity":{"atom":52}},{"Entity":{"atom":31}},{"Entity":{"atom":25}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Entity":{"atom":25}},{"Str":{"pattern":"-"}},{"Alternative":{"atoms":[26,27]}},{"Repetition":{"atom":28,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[24,29]}},{"Named":{"name":"archive","atom":30}},{"Str":{"pattern":"."}},{"Entity":{"atom":43}},{"Entity":{"atom":37}},{"Re":{"pattern":"[\\x41-\\x5a]"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Alternative":{"atoms":[35,36]}},{"Entity":{"atom":37}},{"Str":{"pattern":"-"}},{"Alternative":{"atoms":[38,39]}},{"Repetition":{"atom":40,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[34,41]}},{"Named":{"name":"subject_class","atom":42}},{"Sequence":{"atoms":[32,33]}},{"Repetition":{"atom":44,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":"/"}},{"Entity":{"atom":15}},{"Entity":{"atom":51}},{"Entity":{"atom":13}},{"Repetition":{"atom":49,"min":3,"max":3,"tag":"Repetition"}},{"Named":{"name":"number","atom":50}},{"Sequence":{"atoms":[23,45,46,47,48]}},{"Alternative":{"atoms":[10,22]}},{"Entity":{"atom":59}},{"Str":{"pattern":"v"}},{"Entity":{"atom":13}},{"Repetition":{"atom":56,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"version","atom":57}},{"Sequence":{"atoms":[55,58]}},{"Repetition":{"atom":54,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[9,53,60]}}],"root":61},"bindings":[{"capture":"archive","path":"archive","type":"string","card":null,"preprocess":null},{"capture":"subject_class","path":"subject_class","type":"string","card":null,"preprocess":null},{"capture":"yymm","path":"yymm","type":"string","card":null,"preprocess":null},{"capture":"number","path":"number","type":"string","card":null,"preprocess":null},{"capture":"version","path":"version","type":"string","card":null,"preprocess":null}]}},"preprocess":{},"tables":{},"lint":{"order_warnings":[]},"default_entry":"identifier","render":{},"derive":{},"tests":[{"entry":"identifier","kind":"accept","input":"arXiv:2301.00001v1","expect":{}},{"entry":"identifier","kind":"accept","input":"arxiv:0704.0001","expect":{}},{"entry":"identifier","kind":"accept","input":"arXiv hep-th/9901001v2","expect":{}},{"entry":"identifier","kind":"accept","input":"math.GT/0309136","expect":{}},{"entry":"identifier","kind":"reject","input":"nonsense","expect":{}},{"entry":"identifier","kind":"reject","input":"2301.001","expect":{}},{"entry":"identifier","kind":"reject","input":"hep-th/99010","expect":{}},{"entry":"identifier","kind":"example","input":"arXiv:2301.00001v1","expect":{"yymm":"2301","number":"00001","version":"1"}},{"entry":"identifier","kind":"example","input":"0704.0001","expect":{"yymm":"0704","number":"0001"}},{"entry":"identifier","kind":"example","input":"hep-th/9901001","expect":{"archive":"hep-th","yymm":"9901","number":"001"}},{"entry":"identifier","kind":"example","input":"math.GT/0309136v2","expect":{"archive":"math","subject_class":"GT","yymm":"0309","number":"136","version":"2"}}],"docs":{},"source":"# arXiv e-print identifiers, per\n# https://info.arxiv.org/help/arxiv_identifier_for_services.html:\n# new form YYMM.NNNN[vN] (0704-1412) and YYMM.NNNNN[vN] (1501 onward)\n# old form archive[.SC]/YYMMNNN[vN] (9108-0703)\n# with an optional, case-insensitive \"arXiv:\" or \"arXiv \" prefix.\n# The date ranges, the month and v0 are checked by the Ruby builder.\n\ngrammar PubidArxiv version \"0.1.0\" edition 2 {\n digit = %x30-39\n lower = %x61-7A\n letter = %x41-5A / %x61-7A\n arxiv_prefix = %i\"arXiv\" (colon / space)\n yymm = (4digit) as yymm\n new_number = (4*5digit) as number\n new_id = yymm \".\" new_number\n archive = (lower *(lower / \"-\")) as archive\n subject_class = (letter *(letter / \"-\")) as subject_class\n old_number = (3digit) as number\n old_id = archive [\".\" subject_class] \"/\" yymm old_number\n version = \"v\" (1*digit) as version\n identifier = [arxiv_prefix] (new_id / old_id) [version]\n space = \" \"\n colon = \":\"\n entry identifier: identifier\n\n # Typed model bindings: every bound capture lands on the\n # consumer model's field of the same name.\n bindings identifier {\n archive -> archive (string)\n subject_class -> subject_class (string)\n yymm -> yymm (string)\n number -> number (string)\n version -> version (string)\n }\n\n\n test {\n accept \"arXiv:2301.00001v1\"\n accept \"arxiv:0704.0001\"\n accept \"arXiv hep-th/9901001v2\"\n accept \"math.GT/0309136\"\n reject \"nonsense\"\n reject \"2301.001\"\n reject \"hep-th/99010\"\n example \"arXiv:2301.00001v1\" { yymm: \"2301\" number: \"00001\" version: \"1\" }\n example \"0704.0001\" { yymm: \"0704\" number: \"0001\" }\n example \"hep-th/9901001\" { archive: \"hep-th\" yymm: \"9901\" number: \"001\" }\n example \"math.GT/0309136v2\" { archive: \"math\" subject_class: \"GT\" yymm: \"0309\" number: \"136\" version: \"2\" }\n }\n}\n","source_hash":"c4b4676d738856a7717100c2a3a0545fa1e5a6b83fbf8b09b08dcbe1c33c4a5e","unicode_tables":"onigmo (Ruby 3.4.10)","compiler_version":"1.5.1.0","edition":2,"semantics_hash":"sha256:a7a76fd8f3dbc2635edef63cbb9451aba802e36dea8c4b616ddfdeed626834d1","checksum":"sha256:ccd0bf40ffcb0469e051ed63f14ce1786c88938ee56f12a3edd4ac45ea894512","validated":{"lint_errors":0,"lint_warnings":0,"tests_total":11,"tests_failures":0,"self_test":true},"byte_checksum":"sha256:b308269a659a039642ab933276733ecb6f71de1c3873b35ac3959dac4681c4ea"}
data/data/parg/eu.json ADDED
@@ -0,0 +1 @@
1
+ {"bindings":null,"version":"0.1.0","grammar":"PubidEu","shape":"parsanol-tree/v2","binding_version":1,"entries":{"identifier":{"root":"identifier","grammar":{"atoms":[{"Entity":{"atom":24}},{"Str":{"pattern":"EU"}},{"Named":{"name":"prefix","atom":1}},{"Str":{"pattern":" "}},{"Entity":{"atom":9}},{"Str":{"pattern":"Regulation"}},{"Str":{"pattern":"Directive"}},{"Str":{"pattern":"Decision"}},{"Alternative":{"atoms":[5,6,7]}},{"Named":{"name":"type_word","atom":8}},{"Str":{"pattern":" No"}},{"Named":{"name":"no","atom":10}},{"Repetition":{"atom":11,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":" "}},{"Entity":{"atom":18}},{"Entity":{"atom":16}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":15,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"first","atom":17}},{"Str":{"pattern":"/"}},{"Entity":{"atom":23}},{"Entity":{"atom":16}},{"Repetition":{"atom":21,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"second","atom":22}},{"Sequence":{"atoms":[2,3,4,12,13,14,19,20]}},{"Entity":{"atom":57}},{"Entity":{"atom":9}},{"Str":{"pattern":" ("}},{"Entity":{"atom":35}},{"Str":{"pattern":"Euratom"}},{"Str":{"pattern":"CFSP"}},{"Str":{"pattern":"EEC"}},{"Str":{"pattern":"EC"}},{"Str":{"pattern":"EU"}},{"Alternative":{"atoms":[29,30,31,32,33]}},{"Named":{"name":"family","atom":34}},{"Str":{"pattern":")"}},{"Sequence":{"atoms":[27,28,36]}},{"Repetition":{"atom":37,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":" No"}},{"Named":{"name":"no","atom":39}},{"Repetition":{"atom":40,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":" "}},{"Entity":{"atom":18}},{"Str":{"pattern":"/"}},{"Entity":{"atom":23}},{"Str":{"pattern":"/"}},{"Entity":{"atom":54}},{"Str":{"pattern":"Euratom"}},{"Str":{"pattern":"CFSP"}},{"Str":{"pattern":"EEC"}},{"Str":{"pattern":"EC"}},{"Str":{"pattern":"EU"}},{"Alternative":{"atoms":[48,49,50,51,52]}},{"Named":{"name":"family_suffix","atom":53}},{"Sequence":{"atoms":[46,47]}},{"Repetition":{"atom":55,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[26,38,41,42,43,44,45,56]}},{"Entity":{"atom":79}},{"Str":{"pattern":"CELEX"}},{"Str":{"pattern":" "}},{"Str":{"pattern":": "}},{"Str":{"pattern":":"}},{"Alternative":{"atoms":[60,61,62]}},{"Sequence":{"atoms":[59,63]}},{"Repetition":{"atom":64,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":"3"}},{"Entity":{"atom":16}},{"Repetition":{"atom":67,"min":4,"max":4,"tag":"Repetition"}},{"Named":{"name":"year","atom":68}},{"Entity":{"atom":75}},{"Str":{"pattern":"R"}},{"Str":{"pattern":"L"}},{"Str":{"pattern":"D"}},{"Alternative":{"atoms":[71,72,73]}},{"Named":{"name":"celex_letter","atom":74}},{"Entity":{"atom":16}},{"Repetition":{"atom":76,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"number","atom":77}},{"Sequence":{"atoms":[65,66,69,70,78]}},{"Entity":{"atom":101}},{"Str":{"pattern":"http"}},{"Str":{"pattern":"s"}},{"Repetition":{"atom":82,"min":0,"max":1,"tag":"Maybe"}},{"Str":{"pattern":"://data.europa.eu/eli/"}},{"Entity":{"atom":90}},{"Str":{"pattern":"reg"}},{"Str":{"pattern":"dir"}},{"Str":{"pattern":"dec"}},{"Alternative":{"atoms":[86,87,88]}},{"Named":{"name":"eli_type","atom":89}},{"Str":{"pattern":"/"}},{"Entity":{"atom":16}},{"Repetition":{"atom":92,"min":4,"max":4,"tag":"Repetition"}},{"Named":{"name":"year","atom":93}},{"Str":{"pattern":"/"}},{"Entity":{"atom":16}},{"Repetition":{"atom":96,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"number","atom":97}},{"Str":{"pattern":"/oj"}},{"Repetition":{"atom":99,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[81,83,84,85,91,94,95,98,100]}},{"Alternative":{"atoms":[0,25,58,80]}}],"root":102},"bindings":[{"capture":"prefix","path":"prefix","type":"string","card":null,"preprocess":null},{"capture":"type_word","path":"type_word","type":"string","card":null,"preprocess":null},{"capture":"family","path":"family","type":"string","card":null,"preprocess":null},{"capture":"family_suffix","path":"family_suffix","type":"string","card":null,"preprocess":null},{"capture":"no","path":"no","type":"string","card":null,"preprocess":null},{"capture":"first","path":"first","type":"string","card":null,"preprocess":null},{"capture":"second","path":"second","type":"string","card":null,"preprocess":null},{"capture":"celex_letter","path":"celex_letter","type":"string","card":null,"preprocess":null},{"capture":"eli_type","path":"eli_type","type":"string","card":null,"preprocess":null},{"capture":"year","path":"year","type":"string","card":null,"preprocess":null},{"capture":"number","path":"number","type":"string","card":null,"preprocess":null}]}},"preprocess":{},"tables":{},"lint":{"order_warnings":[]},"default_entry":"identifier","render":{},"derive":{},"tests":[{"entry":"identifier","kind":"accept","input":"EU Regulation 1227/2011","expect":{}},{"entry":"identifier","kind":"accept","input":"EU Directive 2016/680","expect":{}},{"entry":"identifier","kind":"accept","input":"Regulation (EU) No 1227/2011","expect":{}},{"entry":"identifier","kind":"accept","input":"Directive 2010/75/EU","expect":{}},{"entry":"identifier","kind":"accept","input":"CELEX 32011R1227","expect":{}},{"entry":"identifier","kind":"accept","input":"CELEX: 32011R1227","expect":{}},{"entry":"identifier","kind":"accept","input":"EU Regulation No 2015/2014","expect":{}},{"entry":"identifier","kind":"accept","input":"32016L0680","expect":{}},{"entry":"identifier","kind":"accept","input":"http://data.europa.eu/eli/reg/2011/1227/oj","expect":{}},{"entry":"identifier","kind":"reject","input":"nonsense","expect":{}},{"entry":"identifier","kind":"reject","input":"EU Regulation 1227","expect":{}},{"entry":"identifier","kind":"example","input":"EU Regulation 1227/2011","expect":{"prefix":"EU","type_word":"Regulation","first":"1227","second":"2011"}},{"entry":"identifier","kind":"example","input":"Regulation (EU) No 1227/2011","expect":{"type_word":"Regulation","family":"EU","no":" No","first":"1227","second":"2011"}},{"entry":"identifier","kind":"example","input":"Directive 2010/75/EU","expect":{"type_word":"Directive","first":"2010","second":"75","family_suffix":"EU"}},{"entry":"identifier","kind":"example","input":"EU Regulation No 2015/2014","expect":{"prefix":"EU","type_word":"Regulation","no":" No","first":"2015","second":"2014"}},{"entry":"identifier","kind":"example","input":"CELEX 32016R0679","expect":{"year":"2016","celex_letter":"R","number":"0679"}},{"entry":"identifier","kind":"example","input":"http://data.europa.eu/eli/dir/2016/680/oj","expect":{"eli_type":"dir","year":"2016","number":"680"}}],"docs":{},"source":"# EU legal acts (Regulation / Directive / Decision), four input forms:\n# canonical EU Regulation 1227/2011, EU Directive 2016/680\n# long (OJ) Regulation (EU) No 1227/2011, Directive 2010/75/EU\n# CELEX CELEX 32011R1227, CELEX:32011R1227, 32011R1227\n# ELI http://data.europa.eu/eli/reg/2011/1227/oj\n# The canonical and long forms capture the two numbers as `first` and\n# `second`: which one is the year is not derivable from the grammar\n# (`Regulation (EC) No 2003/2003`), so the Ruby builder decides; an\n# optional `No` (also in the canonical form, where the renderer prints it\n# only to tell two readings apart) marks <number>/<year>. CELEX and ELI fix\n# the order, so they capture `year` and `number` directly. The bracketed\n# and the suffixed family are separate captures, so the builder can reject\n# a conflict (`Regulation (EU) No 1227/2011/EC`).\n\ngrammar PubidEu version \"0.1.0\" edition 2 {\n digit = %x30-39\n type_word = (\"Regulation\" / \"Directive\" / \"Decision\") as type_word\n family = (\"Euratom\" / \"CFSP\" / \"EEC\" / \"EC\" / \"EU\") as family\n family_suffix = (\"Euratom\" / \"CFSP\" / \"EEC\" / \"EC\" / \"EU\") as family_suffix\n first = (1*digit) as first\n second = (1*digit) as second\n canonical = (\"EU\") as prefix \" \" type_word [(\" No\") as no] \" \" first \"/\" second\n long = type_word [\" (\" family \")\"] [(\" No\") as no] \" \" first \"/\" second [\"/\" family_suffix]\n celex_letter = (\"R\" / \"L\" / \"D\") as celex_letter\n celex = [\"CELEX\" (\" \" / \": \" / \":\")] \"3\" (4digit) as year celex_letter (1*digit) as number\n eli_type = (\"reg\" / \"dir\" / \"dec\") as eli_type\n eli = \"http\" [\"s\"] \"://data.europa.eu/eli/\" eli_type \"/\" (4digit) as year \"/\" (1*digit) as number [\"/oj\"]\n identifier = canonical / long / celex / eli\n entry identifier: identifier\n\n bindings identifier {\n prefix -> prefix (string)\n type_word -> type_word (string)\n family -> family (string)\n family_suffix -> family_suffix (string)\n no -> no (string)\n first -> first (string)\n second -> second (string)\n celex_letter -> celex_letter (string)\n eli_type -> eli_type (string)\n year -> year (string)\n number -> number (string)\n }\n\n test {\n accept \"EU Regulation 1227/2011\"\n accept \"EU Directive 2016/680\"\n accept \"Regulation (EU) No 1227/2011\"\n accept \"Directive 2010/75/EU\"\n accept \"CELEX 32011R1227\"\n accept \"CELEX: 32011R1227\"\n accept \"EU Regulation No 2015/2014\"\n accept \"32016L0680\"\n accept \"http://data.europa.eu/eli/reg/2011/1227/oj\"\n reject \"nonsense\"\n reject \"EU Regulation 1227\"\n example \"EU Regulation 1227/2011\" { prefix: \"EU\", type_word: \"Regulation\", first: \"1227\", second: \"2011\" }\n example \"Regulation (EU) No 1227/2011\" { type_word: \"Regulation\", family: \"EU\", no: \" No\", first: \"1227\", second: \"2011\" }\n example \"Directive 2010/75/EU\" { type_word: \"Directive\", first: \"2010\", second: \"75\", family_suffix: \"EU\" }\n example \"EU Regulation No 2015/2014\" { prefix: \"EU\", type_word: \"Regulation\", no: \" No\", first: \"2015\", second: \"2014\" }\n example \"CELEX 32016R0679\" { year: \"2016\", celex_letter: \"R\", number: \"0679\" }\n example \"http://data.europa.eu/eli/dir/2016/680/oj\" { eli_type: \"dir\", year: \"2016\", number: \"680\" }\n }\n}\n","source_hash":"5adb915dde94053a07f7e50e1e24395f39e22cbed6edc0214dfb4254decb5873","unicode_tables":"onigmo (Ruby 3.4.10)","compiler_version":"1.5.1.0","edition":2,"semantics_hash":"sha256:c2fc5391cb50af1cdfff0a2eef224997807fab2f72e8dfddbd09ca9ed5a547b5","checksum":"sha256:d08ac392fbe02c098cda98fbce5c12af0ebca3a96b458d5d5f819181fa1847da","validated":{"lint_errors":0,"lint_warnings":0,"tests_total":17,"tests_failures":0,"self_test":true},"byte_checksum":"sha256:7f04183842abcd8a2a2450c0fbacb175126a92e50ff180bd489e340f999715b9"}
@@ -0,0 +1,58 @@
1
+ # arXiv flavor notes
2
+
3
+ - **Origin (relaton#42)**: relaton's `Relaton::Arxiv` keys its `Db` cache with
4
+ `Pubid::Arxiv::Identifier`, routes by `Pubid::Arxiv.prefixes` (`["arXiv"]`)
5
+ and calls `GET https://export.arxiv.org/api/query?id_list=<id>` with
6
+ `to_s(with_publisher: false)`. Source of the forms:
7
+ https://info.arxiv.org/help/arxiv_identifier_for_services.html
8
+ - **Grammar**: `data/parg/arxiv.json`, baked from `grammars/arxiv.parg` with
9
+ the gem's pinned engine (`bundle exec parsanol parg compile …`). The source
10
+ was written here and handed to pubid-grammar to adopt byte-identical
11
+ (hand-off `metanorma__pubid-grammar__arxiv-grammar`); until it lands there,
12
+ the embedded `source` of the artifact is the only copy. Rebake from the
13
+ pubid-grammar copy once it exists.
14
+ - **The grammar checks shape, the Builder checks ranges.** The grammar takes
15
+ any `YYMM.NNNN[N]` and `archive[.SC]/YYMMNNN`; `Builder` rejects a month
16
+ outside 01–12, a 4-digit number outside 0704–1412, a 5-digit number before
17
+ 1501, an old id outside 9108–0703, `v0` and a version with a leading zero
18
+ (`v01` would render `v1`, so `to_s` would not be exact). It raises
19
+ `ArgumentError`, which `Identifier.build_identifier` turns into
20
+ `Pubid::Errors::ParseError` — the ISBN shape, with the input guards kept
21
+ outside that rescue.
22
+ - **Components**: `archive`/`subject_class` (old ids only), `year` (4 digits;
23
+ old ids 91–99 → 19xx, else 20xx; new ids always 20xx), `month`, `number`
24
+ (the inherited `:string`, sequence only, leading zeros kept: `00001`,
25
+ `001`) and `version` (Integer, nil when absent). `root.number` is the
26
+ sequence number: it is never empty, but it narrows the index less than a
27
+ full `2301.00001` would.
28
+ - **Rendering**: always the canonical colon form `arXiv:<id>`, whatever
29
+ prefix the input used (`arxiv 2301.00001` → `arXiv:2301.00001`; the classify
30
+ run records these as `!input!rendered`). `with_publisher: false` is handled
31
+ in the renderer, not by `Renderers::PublisherStripper`, because the stripper
32
+ cuts only before a space, `-`, `/` or `.`, never before `:`;
33
+ `publisher_prefixes` is `[]` for that reason. No `publisher` component is
34
+ stored: the token is constant and every surface prints it.
35
+ - **Matching**: `subset_strict :archive, :subject_class, :year, :month,
36
+ :number`, so the version is the only `===` wildcard — `arXiv:2301.00001`
37
+ matches `…v1` and `…v2`, a new id never matches an old one, `math/…` does
38
+ not match `math.GT/…`, and an empty hand-built reference matches nothing.
39
+ `==` stays exact.
40
+ - **`year` is identity, not an edition.** The shared `#exclude` treats
41
+ `:year`/`:date` as the edition wildcard, which would turn `2301.00001`
42
+ into `0001.00001` and make `matches?(…, ignore: [:year])` match a paper of
43
+ another month. `Identifier#exclude` therefore ignores `:year`, `:date` and
44
+ `:month`; ignore `:version` to match across versions.
45
+ - **`to_urn` returns `to_pubid_urn`.** arXiv has no official namespace, and
46
+ the base fallback `urn:arxiv:<number>:<year>` collided (`2301.00001` and
47
+ `2302.00001` shared one URN).
48
+ - **Known, left open**: `from_hash`/`parse_urn` do not run the builder's
49
+ range checks (a hand-made `month: 13` renders `2313.…`); the grammar is
50
+ looser than the real archive list (`a/9901001` parses); a new-form id in the
51
+ 2090s is accepted; the MR string is the bare number (ISBN's is empty);
52
+ annotated rendering adds a span only to a version-less new id, because the
53
+ number is glued to `v` or to YYMM.
54
+ - **Routing**: `Pubid.parse` matches prefixes case-sensitively, so it routes
55
+ `arXiv:…` and `arXiv …` only; `Pubid::Arxiv.parse` accepts every spelling,
56
+ and bare ids.
57
+ - **URN**: `#to_pubid_urn` only (`docs/URN-SCHEMES.adoc` `[[urn-arxiv]]`);
58
+ arXiv registers no official URN namespace.
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Arxiv
5
+ # Builds a Pubid::Arxiv::Identifier from the bound parse hash.
6
+ #
7
+ # The grammar checks the shape; this class checks the rules the shape
8
+ # cannot express, and raises ArgumentError (which Identifier.parse turns
9
+ # into Pubid::Errors::ParseError):
10
+ #
11
+ # - the month is 01-12;
12
+ # - a 4-digit new number has a YYMM from 0704 to 1412;
13
+ # - a 5-digit new number has a YYMM from 1501;
14
+ # - an old-form id has a YYMM from 9108 to 0703;
15
+ # - the version is 1 or more, with no leading zero (so `to_s` is exact).
16
+ class Builder
17
+ def self.build(parsed_data)
18
+ new.build(parsed_data)
19
+ end
20
+
21
+ def build(data)
22
+ archive = presence(data[:archive])
23
+ year, month = year_month(data[:yymm].to_s, old: archive)
24
+ number = data[:number].to_s
25
+ validate_range!(year, month, number, old: archive)
26
+
27
+ Identifiers::Eprint.new(
28
+ archive: archive, subject_class: presence(data[:subject_class]),
29
+ year: year, month: month, number: number,
30
+ version: version(data[:version])
31
+ )
32
+ end
33
+
34
+ private
35
+
36
+ # Old-form ids run from 9108 to 0703, so 91-99 is the 1990s; a new id
37
+ # is always in the 2000s.
38
+ def year_month(yymm, old:)
39
+ two_digit = yymm[0, 2].to_i
40
+ month = yymm[2, 2].to_i
41
+ validate_month!(month, yymm)
42
+ century = old && two_digit >= 91 ? 1900 : 2000
43
+ [century + two_digit, month]
44
+ end
45
+
46
+ def validate_range!(year, month, number, old:)
47
+ old ? validate_old!(year, month) : validate_new!(year, month, number)
48
+ end
49
+
50
+ def validate_month!(month, yymm)
51
+ return if month.between?(1, 12)
52
+
53
+ raise ArgumentError, "month out of range in YYMM #{yymm}"
54
+ end
55
+
56
+ def validate_old!(year, month)
57
+ return if ym(year, month).between?(199108, 200703)
58
+
59
+ raise ArgumentError, "an old-form id dates from 9108 to 0703"
60
+ end
61
+
62
+ def validate_new!(year, month, number)
63
+ date = ym(year, month)
64
+ valid = if number.length == 4
65
+ date.between?(200704, 201412)
66
+ else
67
+ date >= 201501
68
+ end
69
+ return if valid
70
+
71
+ raise ArgumentError,
72
+ "a #{number.length}-digit number does not fit YYMM " \
73
+ "#{format('%<y>02d%<m>02d', y: year % 100, m: month)}"
74
+ end
75
+
76
+ def ym(year, month)
77
+ (year * 100) + month
78
+ end
79
+
80
+ def version(value)
81
+ return nil if value.nil? || value.to_s.empty?
82
+
83
+ text = value.to_s
84
+ if text.start_with?("0")
85
+ raise ArgumentError,
86
+ "version v#{text} is not 1 or more without a leading zero"
87
+ end
88
+
89
+ text.to_i
90
+ end
91
+
92
+ def presence(value)
93
+ text = value.to_s
94
+ text.empty? ? nil : text
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ Pubid::Arxiv::Builder.prepend(Pubid::Builder::AllPartsWrap)
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Arxiv
5
+ class Identifier < ::Pubid::Identifier
6
+ # The archive of an old-form id (`hep-th`, `math`); nil for a new id.
7
+ attribute :archive, :string
8
+
9
+ # The subject class of an old-form id (`GT` in `math.GT/0309136`).
10
+ attribute :subject_class, :string
11
+
12
+ # The submission year (4 digits) and month, read from the id's YYMM.
13
+ attribute :year, :integer
14
+ attribute :month, :integer
15
+
16
+ # The e-print version (`v2` -> 2); nil when the id names no version.
17
+ attribute :version, :integer
18
+
19
+ ARXIV_TYPE_MAP = {
20
+ "pubid:arxiv:eprint" => "Pubid::Arxiv::Identifiers::Eprint",
21
+ }.freeze
22
+
23
+ key_value do
24
+ map "_type", to: :_type, polymorphic_map: ARXIV_TYPE_MAP
25
+ map "archive", to: :archive
26
+ map "subject_class", to: :subject_class
27
+ map "year", to: :year
28
+ map "month", to: :month
29
+ map "number", to: :number
30
+ map "version", to: :version
31
+ end
32
+
33
+ # A nil archive or subject class means "this id has none", so a new id
34
+ # never matches an old one and `math/…` never matches `math.GT/…`. The
35
+ # year, month and number are always stated. The version is the only
36
+ # wildcard.
37
+ subset_strict :archive, :subject_class, :year, :month, :number
38
+
39
+ # The year and month name the paper (they are its YYMM), not an
40
+ # edition, so the generic year wildcard must not drop them:
41
+ # `matches?(other, ignore: [:year])` would otherwise match
42
+ # `2301.00001` with `2401.00001`.
43
+ IDENTITY_ATTRIBUTES = %i[year date month].freeze
44
+
45
+ def exclude(*attrs)
46
+ super(*(attrs - IDENTITY_ATTRIBUTES))
47
+ end
48
+
49
+ # arXiv registers no official URN namespace, and the base fallback
50
+ # (`urn:arxiv:<number>:<year>`) maps different papers to one URN, so
51
+ # the official form is the lossless pubid-scheme URN.
52
+ def to_urn
53
+ to_pubid_urn
54
+ end
55
+
56
+ PUBLISHER = "arXiv"
57
+
58
+ # The four-digit YYMM the id prints.
59
+ def yymm
60
+ format("%<yy>02d%<mm>02d", yy: year.to_i % 100, mm: month.to_i)
61
+ end
62
+
63
+ # True for an old-form (archive) id.
64
+ def old_style?
65
+ !archive.nil?
66
+ end
67
+
68
+ def to_s(**opts)
69
+ render(format: :human, **opts)
70
+ end
71
+
72
+ # The renderer prints the `arXiv:` token itself and drops it for
73
+ # `with_publisher: false`. The shared stripper cuts only before a space,
74
+ # `-`, `/` or `.`, never before a colon, so it has nothing to cut here.
75
+ def publisher_prefixes
76
+ []
77
+ end
78
+
79
+ def self.parse(identifier)
80
+ unless identifier.is_a?(String)
81
+ raise Pubid::Errors::InvalidInputError,
82
+ Pubid::INPUT_NOT_A_STRING_MESSAGE
83
+ end
84
+
85
+ if identifier.length > Pubid::MAX_INPUT_LENGTH
86
+ raise Pubid::Errors::InvalidInputError, Pubid::INPUT_TOO_LONG_MESSAGE
87
+ end
88
+
89
+ identifier = ::Pubid.utf8_input(identifier)
90
+
91
+ # The guards above stay OUTSIDE build_identifier, whose ArgumentError
92
+ # rescue would otherwise swallow them (the ISBN lesson).
93
+ build_identifier(identifier)
94
+ end
95
+
96
+ # @raise [Pubid::Errors::ParseError] if the string is not an arXiv id
97
+ def self.build_identifier(identifier)
98
+ parsed = Pubid::Parg::Model.bound(:arxiv, identifier)
99
+ Builder.build(parsed)
100
+ rescue ArgumentError => e
101
+ # The Builder checks the date ranges, the month and the version.
102
+ # Surface that as a parse failure, the class a grammar rejection has.
103
+ raise Pubid::Errors::ParseError.new(
104
+ "invalid arXiv identifier '#{identifier}': #{e.message}",
105
+ input: identifier, flavor: "arxiv",
106
+ )
107
+ end
108
+ private_class_method :build_identifier
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Arxiv
5
+ module Identifiers
6
+ # An arXiv e-print, new form or old form.
7
+ #
8
+ # Examples:
9
+ # arXiv:2301.00001v1
10
+ # arXiv:0704.0001
11
+ # arXiv:hep-th/9901001v2
12
+ # arXiv:math.GT/0309136
13
+ class Eprint < Identifier
14
+ def self.type
15
+ { key: :eprint, title: "arXiv e-print", short: "arXiv" }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Arxiv
5
+ module Identifiers
6
+ autoload :Eprint, "#{__dir__}/identifiers/eprint"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Arxiv
5
+ # Grammar for arXiv identifiers. The parser of record is the baked
6
+ # artifact `data/parg/arxiv.json` (source: pubid-grammar
7
+ # `grammars/arxiv.parg`), run by Pubid::Parg::Model.bound.
8
+ #
9
+ # Accepts:
10
+ # [arXiv(:| )] YYMM.NNNN[vN] | YYMM.NNNNN[vN]
11
+ # [arXiv(:| )] archive[.SC]/YYMMNNN[vN]
12
+ #
13
+ # The prefix is case-insensitive. Date ranges, the month and the version
14
+ # are checked by the Builder.
15
+ class Parser
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Arxiv
5
+ # The pubid-scheme URN of arXiv (docs/URN-SCHEMES.adoc, [[urn-arxiv]]).
6
+ #
7
+ # arXiv:2301.00001v1
8
+ # -> urn:pubid:arxiv:eprint:2023:1:00001:v-1
9
+ # arXiv:math.GT/0309136
10
+ # -> urn:pubid:arxiv:eprint:2003:9:136:archive-math:sc-GT
11
+ #
12
+ # Every e-print has a year, a month and a number, so they are the
13
+ # positional core. The archive and subject class (old ids only) and the
14
+ # version can be absent, so they are atoms. arXiv registers no official
15
+ # URN namespace.
16
+ PubidUrnSchema = Pubid::PubidUrn.define("arxiv") do
17
+ atom "archive", "archive"
18
+ atom "subject_class", "sc"
19
+ atom "version", "v", kind: :int
20
+
21
+ core = [["year", :int], ["month", :int], "number"]
22
+ type "pubid:arxiv:eprint", "eprint", core: core
23
+ type "pubid:arxiv:identifier", "id", core: core
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Arxiv
5
+ # Human-readable renderer for arXiv ids.
6
+ #
7
+ # Prints the canonical colon form `arXiv:<id>` whatever prefix the input
8
+ # used, and the bare id for `with_publisher: false` — the form the arXiv
9
+ # API takes in `id_list`.
10
+ class Renderer < ::Pubid::Renderers::Base
11
+ def render(with_publisher: nil, **_opts)
12
+ bare = "#{body}#{version}"
13
+ with_publisher == false ? bare : "#{Identifier::PUBLISHER}:#{bare}"
14
+ end
15
+
16
+ private
17
+
18
+ def body
19
+ return "#{@id.yymm}.#{@id.number}" unless @id.old_style?
20
+
21
+ archive = [@id.archive, @id.subject_class].compact.join(".")
22
+ "#{archive}/#{@id.yymm}#{@id.number}"
23
+ end
24
+
25
+ def version
26
+ @id.version ? "v#{@id.version}" : ""
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pubid"
4
+ module Pubid
5
+ # arXiv flavor — e-print identifiers per
6
+ # https://info.arxiv.org/help/arxiv_identifier_for_services.html
7
+ #
8
+ # Parses the new form (`2301.00001v1`, `0704.0001`) and the old form
9
+ # (`hep-th/9901001`, `math.GT/0309136`), each with an optional
10
+ # case-insensitive `arXiv:` or `arXiv ` prefix. A missing version is a
11
+ # wildcard under `===`, so `arXiv:2301.00001` matches every version.
12
+ module Arxiv
13
+ extend Pubid::PrefixesSupport
14
+
15
+ PREFIXES = ["arXiv"].freeze
16
+
17
+ autoload :Builder, "#{__dir__}/arxiv/builder"
18
+ autoload :Identifier, "#{__dir__}/arxiv/identifier"
19
+ autoload :Identifiers, "#{__dir__}/arxiv/identifiers"
20
+ autoload :Parser, "#{__dir__}/arxiv/parser"
21
+ autoload :Renderer, "#{__dir__}/arxiv/renderer"
22
+ autoload :PubidUrnSchema, "#{__dir__}/arxiv/pubid_urn_schema"
23
+
24
+ def self.parse(identifier)
25
+ Identifier.parse(identifier)
26
+ end
27
+
28
+ Identifier.format_registry = FormatRegistry.new(parent: Identifier.format_registry)
29
+ Identifier.format_registry.register(:human, renderer: Arxiv::Renderer)
30
+
31
+ def self.identifier_types
32
+ @identifier_types ||= Identifiers.constants
33
+ .filter_map { |c| begin; Identifiers.const_get(c); rescue NameError; nil; end }
34
+ .select { |c| c.is_a?(Class) && c.singleton_methods(false).include?(:type) }
35
+ .select { |c| c.type.is_a?(Hash) }
36
+ end
37
+
38
+ def self.all_typed_stages
39
+ @all_typed_stages ||= identifier_types.flat_map do |klass|
40
+ klass.const_defined?(:TYPED_STAGES) ? klass.const_get(:TYPED_STAGES) : []
41
+ end
42
+ end
43
+
44
+ def self.locate_type(code)
45
+ identifier_types.find { |t| t.type[:key].to_s == code.to_s }
46
+ end
47
+
48
+ def self.locate_stage(abbr)
49
+ abbr_str = abbr.to_s.upcase
50
+ all_typed_stages.find { |s| s.abbr.any? { |a| a.to_s.upcase == abbr_str } }
51
+ end
52
+ end
53
+ end
54
+
55
+ Pubid::Registry.register(:arxiv, Pubid::Arxiv)
@@ -0,0 +1,92 @@
1
+ # EU legal acts (`Pubid::Eu`)
2
+
3
+ Regulations, directives and decisions of the Official Journal (CELEX sector 3,
4
+ type letters R / L / D). Requested by relaton/relaton#44 for the `Relaton::Eu`
5
+ flavor, whose `Relaton::Db` cache keys on this pubid.
6
+
7
+ ## Forms
8
+
9
+ | input | example | `to_s` |
10
+ |---|---|---|
11
+ | canonical (round-trips) | `EU Regulation 1227/2011` | same |
12
+ | Official Journal long form | `Regulation (EU) No 1227/2011`, `Directive 2010/75/EU` | canonical; sets `family` |
13
+ | CELEX | `32011R1227`, `CELEX 32011R1227`, `CELEX:32011R1227` | canonical |
14
+ | ELI | `http(s)://data.europa.eu/eli/reg/2011/1227[/oj]` | canonical |
15
+
16
+ `#to_celex` and `#to_eli` give the two official identifiers back. `to_urn`
17
+ (`urn:eu:reg:2011:1227`) is pubid-invented: the EU has no URN namespace.
18
+
19
+ `Pubid.parse` routes only the canonical form (the prefix `EU`). The other
20
+ forms do not start with `EU` and do not round-trip, and prefix routing lets
21
+ only a prefix owner give a non-exact parse, so call `Pubid::Eu.parse` for
22
+ them. relaton queries with the canonical form only.
23
+
24
+ ## The number order is spelling, kept in `number_first`
25
+
26
+ The order of the two numbers is not derivable from the string:
27
+ `Regulation (EC) No 2003/2003` exists, and a pre-2015 number can look like a
28
+ year. Before 2015 a regulation printed `<number>/<year>`; directives printed
29
+ `<year>/<number>`; **decisions used both** (`Decision No 1082/2013/EU`, an
30
+ act of the Parliament and the Council, and `Decision 2010/87/EU`, a
31
+ Commission act). From 2015 every act prints `<year>/<number>`.
32
+
33
+ - **Render rule** (`Identifier#default_number_first?`): a regulation with a
34
+ year before 2015 prints `<number>/<year>`; everything else prints
35
+ `<year>/<number>`. The builder stores `number_first` **only when the input
36
+ order differs from this rule** (`EU Decision 1082/2013` → `true`), so a
37
+ normal index row carries no flag. It is `equality_ignored` and a URN facet:
38
+ the order is spelling, and `EU Decision 1082/2013` equals `32013D1082`.
39
+ - **Parse rule** (`Builder.number_first_for`), for every form: `No` marks
40
+ `<number>/<year>` (the Official Journal convention, exact for the long
41
+ form). Without `No`, a value is a plausible year when it has 4 digits in
42
+ 1952..2099; one plausible value is the year; with two, a first value from
43
+ 2015 is the year, else a regulation reads `<number>/<year>` and another act
44
+ `<year>/<number>`; none raises `Pubid::Errors::ParseError` (from the
45
+ builder, not the grammar). The long form uses the same rule, so
46
+ `to_s(with_publisher: false)` (`Regulation 1227/2011`) parses back.
47
+ - **Two acts can share one plain print**: `32015R2014` and `32014R2015` both
48
+ print `2015/2014`. The renderer asks the parse rule how the plain pair
49
+ reads back; when that is another act it prints `EU Regulation No 2015/2014`
50
+ instead. So `parse(id.to_s) == id` for every act, in both orders and without
51
+ the publisher; `spec/pubid/eu/identifier_spec.rb` sweeps a year × number
52
+ grid to lock it. A canonical input always reads back as itself, so it
53
+ never gains a `No`.
54
+ - CELEX and ELI years are checked against the same range, and a number of
55
+ 0 is rejected. The bracketed family and the suffixed one are separate
56
+ captures; two different ones (`Regulation (EU) No 1227/2011/EC`) raise.
57
+
58
+ ## Identity and matching
59
+
60
+ Identity is the leaf class, `date` (year) and `number` (leading CELEX zeros
61
+ stripped). `family` is part of identity but nil on a canonical reference, so
62
+ `EU Regulation 1227/2011 === parse("Regulation (EU) No 1227/2011")` is true
63
+ (the default SubsetMatch wildcard), and the reverse is false. Every reference
64
+ states the year, so the `partial_ref_spec` entry is `omits: []`.
65
+
66
+ ## Known gaps
67
+
68
+ - Two-digit years (`Directive 95/46/EC`, `Regulation (EEC) No 1408/71`) are
69
+ rejected. They need a century rule, and relaton did not ask for them.
70
+ - Joint families (`(EU, Euratom)`) and the CELEX suffixes `(01)` for colliding
71
+ numbers are not parsed.
72
+ - The author words of the Official Journal title (`Commission Implementing
73
+ Regulation (EU) 2019/947`, `Council Directive …`) are not parsed; strip
74
+ them first. They name no other act, so they would not be identity.
75
+ - Other CELEX sectors (treaties, case law) are out of scope.
76
+
77
+ ## The grammar is baked here ahead of pubid-grammar
78
+
79
+ `data/parg/eu.json` was compiled in this repo at parsanol **1.5.1.0** (the
80
+ Gemfile pin), because `pubid-grammar` had no `grammars/eu.parg` yet. Hand-off
81
+ `pubid__pubid-grammar__eu-flavor-grammar` carries the source. To change the
82
+ grammar, extract the source with `jq -j .source data/parg/eu.json`, edit,
83
+ then:
84
+
85
+ ```bash
86
+ bundle exec parsanol parg compile eu.parg -o data/parg/eu.json
87
+ bundle exec parsanol parg test data/parg/eu.json
88
+ ```
89
+
90
+ Use raw `"/"` and `" "` literals, not `slash`/`space` rule references: a rule
91
+ reference makes a tree node, and the alternatives then warn about duplicate
92
+ `slash` subtrees (the same note sits in the UN grammar).
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ # Bound captures (data/parg/eu.json) → an EU identifier.
6
+ #
7
+ # CELEX and ELI give the year and the number by position. The canonical
8
+ # and the long forms give two numbers, +first+ and +second+, and the
9
+ # order is not in the grammar: `Regulation (EC) No 2003/2003` exists, and
10
+ # a pre-2015 number can look like a year. See .number_first_for.
11
+ class Builder
12
+ TYPES_BY_WORD = {
13
+ "Regulation" => :Regulation,
14
+ "Directive" => :Directive,
15
+ "Decision" => :Decision,
16
+ }.freeze
17
+ TYPES_BY_CELEX = {
18
+ "R" => :Regulation, "L" => :Directive, "D" => :Decision
19
+ }.freeze
20
+ TYPES_BY_ELI = {
21
+ "reg" => :Regulation, "dir" => :Directive, "dec" => :Decision
22
+ }.freeze
23
+
24
+ # The first Official Journal acts (ECSC) date from 1952.
25
+ YEARS = (1952..2099)
26
+
27
+ # One parsed act before it becomes an identifier.
28
+ Act = Struct.new(:klass, :year, :number, :number_first)
29
+
30
+ def self.build(data, input = nil)
31
+ new(input).build(data)
32
+ end
33
+
34
+ def initialize(input)
35
+ @input = input
36
+ end
37
+
38
+ # Which of two printed numbers is the year, when the input has no
39
+ # "No". Only one plausible year: that one. Both: a first value from
40
+ # 2015 is the year (every act prints <year>/<number> from 2015);
41
+ # otherwise a regulation prints <number>/<year> and other acts
42
+ # <year>/<number>. Neither: nil. The renderer calls this too, to know
43
+ # when a plain print would read back as another act.
44
+ def self.number_first_for(klass, first, second)
45
+ first_year = year?(first)
46
+ second_year = year?(second)
47
+ return nil unless first_year || second_year
48
+ return !first_year if first_year != second_year
49
+ return false if first.to_i >= Identifier::FIXED_ORDER_YEAR
50
+
51
+ klass == :Regulation
52
+ end
53
+
54
+ def self.year?(value)
55
+ value.length == 4 && YEARS.cover?(value.to_i)
56
+ end
57
+
58
+ def build(data)
59
+ act = positional(data) || from_pair(data)
60
+ fail!("#{act.year} is not a year") unless self.class.year?(act.year)
61
+ number = strip_zeros(act.number)
62
+ fail!("number 0") if number == "0"
63
+
64
+ id = Identifiers.const_get(act.klass).new(
65
+ number: number,
66
+ date: ::Pubid::Components::Date.new(year: act.year),
67
+ family: family(data),
68
+ )
69
+ keep_order(id, act.number_first)
70
+ end
71
+
72
+ private
73
+
74
+ # CELEX and ELI: the year and the number have fixed places.
75
+ def positional(data)
76
+ klass = if data[:celex_letter]
77
+ TYPES_BY_CELEX.fetch(data[:celex_letter])
78
+ elsif data[:eli_type]
79
+ TYPES_BY_ELI.fetch(data[:eli_type])
80
+ end
81
+ klass && Act.new(klass, data[:year], data[:number], nil)
82
+ end
83
+
84
+ def from_pair(data)
85
+ klass = TYPES_BY_WORD.fetch(data[:type_word])
86
+ first = data[:first]
87
+ second = data[:second]
88
+ # "No" marks <number>/<year> (Regulation (EU) No 1227/2011,
89
+ # Decision No 1082/2013/EU); every other pair reads by the rule.
90
+ number_first = !data[:no].nil? ||
91
+ self.class.number_first_for(klass, first, second)
92
+ fail!("no year in #{first}/#{second}") if number_first.nil?
93
+
94
+ year, number = number_first ? [second, first] : [first, second]
95
+ Act.new(klass, year, number, number_first)
96
+ end
97
+
98
+ # Keep the order only when it is not what the render rule prints.
99
+ def keep_order(id, number_first)
100
+ unless number_first.nil? || number_first == id.default_number_first?
101
+ id.number_first = number_first
102
+ end
103
+ id
104
+ end
105
+
106
+ def family(data)
107
+ bracket = data[:family]
108
+ suffix = data[:family_suffix]
109
+ if bracket && suffix && bracket != suffix
110
+ fail!("two families, #{bracket} and #{suffix}")
111
+ end
112
+
113
+ bracket || suffix
114
+ end
115
+
116
+ def strip_zeros(number)
117
+ number.sub(/\A0+(?=\d)/, "")
118
+ end
119
+
120
+ def fail!(message)
121
+ raise Pubid::Errors::ParseError.new(
122
+ "EU legal act: #{message}", nil, input: @input, flavor: "eu"
123
+ )
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ Pubid::Eu::Builder.prepend(Pubid::Builder::AllPartsWrap)
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ # Base class for every EU legal act AND the flavor's parse entry point.
6
+ #
7
+ # Identity is the type (the leaf class), the year (+date+) and the
8
+ # +number+ — the three parts of a CELEX number. +family+ is the bracketed
9
+ # legal family of the Official Journal form (`(EU)`, `(EC)` …); the
10
+ # canonical reference omits it, so a reference with no family matches a
11
+ # row that has one (`===`).
12
+ class Identifier < ::Pubid::Identifier
13
+ # The legal family: EU, EC, EEC, Euratom or CFSP.
14
+ attribute :family, :string
15
+
16
+ # The print order of the two numbers. nil applies the default rule
17
+ # (#default_number_first?); the builder sets it only when the input
18
+ # used the other order, so the flag is rare in an index row.
19
+ attribute :number_first, :boolean
20
+
21
+ # The order is spelling, not identity: "EU Decision 1082/2013" and the
22
+ # CELEX number 32013D1082 name one act.
23
+ equality_ignored :number_first
24
+
25
+ EU_TYPE_MAP = {
26
+ "pubid:eu:regulation" => "Pubid::Eu::Identifiers::Regulation",
27
+ "pubid:eu:directive" => "Pubid::Eu::Identifiers::Directive",
28
+ "pubid:eu:decision" => "Pubid::Eu::Identifiers::Decision",
29
+ }.freeze
30
+
31
+ key_value do
32
+ map "_type", to: :_type, polymorphic_map: EU_TYPE_MAP
33
+ map "number", to: :number
34
+ map "date", to: :date
35
+ map "family", to: :family
36
+ map "number_first", to: :number_first
37
+ end
38
+
39
+ PUBLISHER = "EU"
40
+
41
+ # From 2015 every act prints <year>/<number>. Before 2015 a regulation
42
+ # printed <number>/<year>; other acts used both orders, so they default
43
+ # to <year>/<number> and keep the input order in +number_first+.
44
+ FIXED_ORDER_YEAR = 2015
45
+
46
+ def self.type
47
+ { key: :identifier, title: "", celex: nil, eli: nil }
48
+ end
49
+
50
+ # The year is identity, not an edition: 1227/2011 and 1227/2012 are two
51
+ # acts. So an all-parts wrapper keeps the date (the default drops it,
52
+ # which printed "EU Regulation 1227/ (all parts)").
53
+ def self.all_parts_edition_keys
54
+ super - %i[date year]
55
+ end
56
+
57
+ def default_number_first?
58
+ is_a?(Identifiers::Regulation) && year.to_i < FIXED_ORDER_YEAR
59
+ end
60
+
61
+ def number_first?
62
+ number_first.nil? ? default_number_first? : number_first
63
+ end
64
+
65
+ def to_s(**opts)
66
+ render(format: :human, **opts)
67
+ end
68
+
69
+ # EU keeps its publisher in the PUBLISHER constant, not the attribute.
70
+ def publisher_prefixes
71
+ [PUBLISHER]
72
+ end
73
+
74
+ # The CELEX number: sector 3, year, type letter, number padded to 4.
75
+ def to_celex
76
+ "3#{year}#{self.class.type[:celex]}#{number.rjust(4, '0')}"
77
+ end
78
+
79
+ # The ELI of the act as published in the Official Journal.
80
+ def to_eli
81
+ "http://data.europa.eu/eli/#{self.class.type[:eli]}/#{year}/#{number}/oj"
82
+ end
83
+
84
+ # The EU has no registered URN namespace (the ELI is its official
85
+ # identifier, #to_eli). This pubid-invented form keeps the act type,
86
+ # so a regulation and a decision with the same numbers do not collide.
87
+ def to_urn
88
+ "urn:eu:#{self.class.type[:eli]}:#{year}:#{number}"
89
+ end
90
+
91
+ # MR string: eu.<eli type>.<number>.<year>, e.g. eu.reg.1227.2011.
92
+ def mr_publisher
93
+ PUBLISHER.downcase
94
+ end
95
+
96
+ def mr_type
97
+ self.class.type[:eli]
98
+ end
99
+
100
+ def self.parse(identifier)
101
+ unless identifier.is_a?(String)
102
+ raise Pubid::Errors::InvalidInputError,
103
+ Pubid::INPUT_NOT_A_STRING_MESSAGE
104
+ end
105
+
106
+ if identifier.length > Pubid::MAX_INPUT_LENGTH
107
+ raise Pubid::Errors::InvalidInputError, Pubid::INPUT_TOO_LONG_MESSAGE
108
+ end
109
+
110
+ identifier = ::Pubid.utf8_input(identifier)
111
+
112
+ parsed = Pubid::Parg::Model.bound(:eu, identifier)
113
+ Builder.build(parsed, identifier)
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ module Identifiers
6
+ # An EU decision (CELEX sector 3, letter D; ELI segment "dec").
7
+ class Decision < Identifier
8
+ def self.type
9
+ { key: :decision, title: "Decision", celex: "D", eli: "dec" }
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ module Identifiers
6
+ # An EU directive (CELEX sector 3, letter L; ELI segment "dir").
7
+ class Directive < Identifier
8
+ def self.type
9
+ { key: :directive, title: "Directive", celex: "L", eli: "dir" }
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ module Identifiers
6
+ # An EU regulation (CELEX sector 3, letter R; ELI segment "reg").
7
+ class Regulation < Identifier
8
+ def self.type
9
+ { key: :regulation, title: "Regulation", celex: "R", eli: "reg" }
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ module Identifiers
6
+ autoload :Regulation, "#{__dir__}/identifiers/regulation"
7
+ autoload :Directive, "#{__dir__}/identifiers/directive"
8
+ autoload :Decision, "#{__dir__}/identifiers/decision"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ # The grammar is the baked artifact data/parg/eu.json; Identifier.parse
6
+ # calls it through Pubid::Parg::Model.bound(:eu, ...).
7
+ class Parser
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ # The pubid-scheme URN of EU legal acts (docs/URN-SCHEMES.adoc, [[urn-eu]]).
6
+ #
7
+ # EU Regulation 1227/2011 -> urn:pubid:eu:reg:2011:1227
8
+ # EU Decision 1082/2013 ->
9
+ # urn:pubid:eu:dec:2013:1082:f:0.numberfirst-true
10
+ #
11
+ # Every act has a year and a number, so both are the positional core,
12
+ # year first (the CELEX and ELI order). The legal family is an atom; the
13
+ # number-order flag records only the spelling, so it is a facet.
14
+ PubidUrnSchema = Pubid::PubidUrn.define("eu") do
15
+ atom "family", "family"
16
+ facet "number_first", "numberfirst", kind: :bool
17
+
18
+ type "pubid:eu:regulation", "reg", core: %w[year number]
19
+ type "pubid:eu:directive", "dir", core: %w[year number]
20
+ type "pubid:eu:decision", "dec", core: %w[year number]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubid
4
+ module Eu
5
+ # The canonical form: "EU <Type> <a>/<b>", the order from
6
+ # Identifier#number_first?.
7
+ #
8
+ # Two acts can share one plain print: 32015R2014 and 32014R2015 both give
9
+ # "2015/2014". The parser reads the plain pair by
10
+ # Builder.number_first_for, so when that reading is not this act, the
11
+ # renderer prints "No <number>/<year>" instead — "No" always marks
12
+ # <number>/<year>, so every print parses back to the act that made it.
13
+ class Renderer < ::Pubid::Renderers::Base
14
+ def render(**_opts)
15
+ "#{Identifier::PUBLISHER} #{@id.class.type[:title]} #{numbers}"
16
+ end
17
+
18
+ private
19
+
20
+ def numbers
21
+ number = @id.number
22
+ year = @id.year
23
+ return number.to_s if year.nil?
24
+
25
+ number_first = @id.number_first?
26
+ pair = number_first ? [number, year] : [year, number]
27
+ return pair.join("/") if reads_back?(pair, number_first)
28
+
29
+ "No #{number}/#{year}"
30
+ end
31
+
32
+ def reads_back?(pair, number_first)
33
+ klass = @id.class.name.split("::").last.to_sym
34
+ Builder.number_first_for(klass, *pair) == number_first
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/pubid/eu.rb ADDED
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pubid"
4
+ module Pubid
5
+ # EU legal acts: regulations, directives and decisions (CELEX sector 3).
6
+ #
7
+ # EU Regulation 1227/2011 canonical, pre-2015 regulation: number/year
8
+ # EU Regulation 2016/679 canonical, from 2015: year/number
9
+ # EU Directive 2016/680 canonical, directives: year/number
10
+ #
11
+ # Parse-only alternates: the Official Journal long form
12
+ # (`Regulation (EU) No 1227/2011`), CELEX (`32011R1227`) and ELI
13
+ # (`http://data.europa.eu/eli/reg/2011/1227/oj`). See lib/pubid/eu/CLAUDE.md.
14
+ module Eu
15
+ extend Pubid::PrefixesSupport
16
+
17
+ PREFIXES = ["EU"].freeze
18
+
19
+ autoload :Builder, "#{__dir__}/eu/builder"
20
+ autoload :Identifier, "#{__dir__}/eu/identifier"
21
+ autoload :Identifiers, "#{__dir__}/eu/identifiers"
22
+ autoload :Parser, "#{__dir__}/eu/parser"
23
+ autoload :Renderer, "#{__dir__}/eu/renderer"
24
+ autoload :PubidUrnSchema, "#{__dir__}/eu/pubid_urn_schema"
25
+
26
+ def self.parse(identifier)
27
+ Identifier.parse(identifier)
28
+ end
29
+
30
+ Identifier.format_registry =
31
+ FormatRegistry.new(parent: Identifier.format_registry)
32
+ Identifier.format_registry.register(:human, renderer: Eu::Renderer)
33
+
34
+ def self.identifier_types
35
+ [Identifiers::Regulation, Identifiers::Directive, Identifiers::Decision]
36
+ end
37
+
38
+ def self.all_typed_stages
39
+ []
40
+ end
41
+
42
+ def self.locate_type(code)
43
+ identifier_types.find { |t| t.type[:key].to_s == code.to_s }
44
+ end
45
+
46
+ def self.locate_stage(_abbr)
47
+ nil
48
+ end
49
+ end
50
+ end
51
+
52
+ Pubid::Registry.register(:eu, Pubid::Eu)
data/lib/pubid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pubid
4
- VERSION = "2.0.43"
4
+ VERSION = "2.0.44"
5
5
  end
data/lib/pubid.rb CHANGED
@@ -221,6 +221,7 @@ module Pubid
221
221
  autoload :Amca, "pubid/amca"
222
222
  autoload :Ansi, "pubid/ansi"
223
223
  autoload :Api, "pubid/api"
224
+ autoload :Arxiv, "pubid/arxiv"
224
225
  autoload :Ashrae, "pubid/ashrae"
225
226
  autoload :Asme, "pubid/asme"
226
227
  autoload :Doi, "pubid/doi"
@@ -258,6 +259,7 @@ module Pubid
258
259
  # beside the coded flavor, never routed by Pubid.parse (registry keys
259
260
  # sort "etsi" first).
260
261
  autoload :EtsiPfs, "pubid/etsi_pfs"
262
+ autoload :Eu, "pubid/eu"
261
263
  autoload :Evs, "pubid/evs"
262
264
  autoload :Gost, "pubid/gost"
263
265
  autoload :Gb, "pubid/gb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.43
4
+ version: 2.0.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -83,6 +83,7 @@ files:
83
83
  - data/parg/amca.json
84
84
  - data/parg/ansi.json
85
85
  - data/parg/api.json
86
+ - data/parg/arxiv.json
86
87
  - data/parg/ashrae.json
87
88
  - data/parg/asme.json
88
89
  - data/parg/astm.json
@@ -104,6 +105,7 @@ files:
104
105
  - data/parg/ecma.json
105
106
  - data/parg/etsi.json
106
107
  - data/parg/etsi_pfs.json
108
+ - data/parg/eu.json
107
109
  - data/parg/evs.json
108
110
  - data/parg/gb.json
109
111
  - data/parg/gost.json
@@ -219,6 +221,15 @@ files:
219
221
  - lib/pubid/api/single_identifier.rb
220
222
  - lib/pubid/api/urn_generator.rb
221
223
  - lib/pubid/api/urn_parser.rb
224
+ - lib/pubid/arxiv.rb
225
+ - lib/pubid/arxiv/CLAUDE.md
226
+ - lib/pubid/arxiv/builder.rb
227
+ - lib/pubid/arxiv/identifier.rb
228
+ - lib/pubid/arxiv/identifiers.rb
229
+ - lib/pubid/arxiv/identifiers/eprint.rb
230
+ - lib/pubid/arxiv/parser.rb
231
+ - lib/pubid/arxiv/pubid_urn_schema.rb
232
+ - lib/pubid/arxiv/renderer.rb
222
233
  - lib/pubid/ashrae.rb
223
234
  - lib/pubid/ashrae/CLAUDE.md
224
235
  - lib/pubid/ashrae/builder.rb
@@ -594,6 +605,17 @@ files:
594
605
  - lib/pubid/etsi_pfs/pubid_urn_schema.rb
595
606
  - lib/pubid/etsi_pfs/renderer.rb
596
607
  - lib/pubid/etsi_pfs/urn_generator.rb
608
+ - lib/pubid/eu.rb
609
+ - lib/pubid/eu/CLAUDE.md
610
+ - lib/pubid/eu/builder.rb
611
+ - lib/pubid/eu/identifier.rb
612
+ - lib/pubid/eu/identifiers.rb
613
+ - lib/pubid/eu/identifiers/decision.rb
614
+ - lib/pubid/eu/identifiers/directive.rb
615
+ - lib/pubid/eu/identifiers/regulation.rb
616
+ - lib/pubid/eu/parser.rb
617
+ - lib/pubid/eu/pubid_urn_schema.rb
618
+ - lib/pubid/eu/renderer.rb
597
619
  - lib/pubid/evs.rb
598
620
  - lib/pubid/evs/CLAUDE.md
599
621
  - lib/pubid/evs/builder.rb