├── tools ├── setup.sh ├── setup.js └── format.js ├── test ├── test-main.js ├── test-server.js ├── test-util.js └── test-cli.js ├── package.json ├── LICENSE ├── lib └── util.js ├── .gitignore ├── main.js ├── bin ├── server.js ├── cli.js └── server.html ├── spec ├── 003-misc.json ├── 002-nest.json ├── 001-io.json ├── 005-closed.json └── 004-conflict.json └── README.md /tools/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 準備: https://www.houjin-bangou.nta.go.jp/download/zenken/ から CSV 形式・Unicode を全48ファイルダウンロードして cache ファルダに保存 4 | 5 | SCRIPT_DIR=$(cd $(dirname $0); pwd) 6 | CACHE_DIR=${SCRIPT_DIR}/../cache 7 | DATABASE_DIR=${SCRIPT_DIR}/../db 8 | 9 | #(find ${CACHE_DIR}/*.zip -exec unzip -p {} '*.csv' \;) | node ${SCRIPT_DIR}/c2j.js | gzip > ${OUTPUT_DIR}/data.txt.gz 10 | 11 | rm -fR ${DATABASE_DIR} 12 | mkdir ${DATABASE_DIR} 13 | 14 | for zip in `find ${CACHE_DIR}/*.zip ` ; do 15 | echo ${zip} 16 | unzip -p ${zip} '*.csv' | node ${SCRIPT_DIR}/setup.js ${DATABASE_DIR} 17 | done 18 | 19 | # (find ${CACHE_DIR}/*.zip -exec unzip -p {} '*.csv' \;) | node ${SCRIPT_DIR}/c2j.js ${DATABASE_DIR} 20 | # (find ${CACHE_DIR}/13_*.zip -exec unzip -p {} '*.csv' \;) | node ${SCRIPT_DIR}/c2j.js ${DATABASE_DIR} 21 | -------------------------------------------------------------------------------- /test/test-main.js: -------------------------------------------------------------------------------- 1 | const enrich = require("../main"); 2 | const expect = require('chai').expect; 3 | const fs = require("fs"); 4 | const spec = __dirname + "/../spec"; 5 | 6 | describe('imi-enrichment-hojin', function() { 7 | 8 | describe("spec", function() { 9 | fs.readdirSync(spec).filter(file => file.match(/json$/)).forEach(file => { 10 | describe(file, function() { 11 | const json = JSON.parse(fs.readFileSync(`${spec}/${file}`, "UTF-8")) 12 | json.forEach(a => { 13 | it(a.name, function(done) { 14 | enrich(a.input).then(json => { 15 | try { 16 | expect(json).deep.equal(a.output); 17 | done(); 18 | } catch (e) { 19 | done(e); 20 | } 21 | }).catch(e2 => { 22 | done(e2); 23 | }); 24 | }); 25 | }); 26 | }); 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "imi-enrichment-hojin", 3 | "version": "2.0.0", 4 | "description": "ic:法人型の補完と検証", 5 | "main": "main.js", 6 | "scripts": { 7 | "test": "mocha", 8 | "setup": "bash tools/setup.sh", 9 | "start": "node bin/server.js 8080" 10 | }, 11 | "bin": "bin/cli.js", 12 | "files": [ 13 | "bin", 14 | "lib", 15 | "db" 16 | ], 17 | "keywords": [ 18 | "imi" 19 | ], 20 | "author": "IMI Tool Project", 21 | "license": "MIT", 22 | "devDependencies": { 23 | "chai": "^4.2.0", 24 | "mocha": "^8.2.1", 25 | "node-fetch": "^2.6.1", 26 | "papaparse": "^5.2.0" 27 | }, 28 | "dependencies": { 29 | "command-line-args": "^5.1.1", 30 | "command-line-usage": "^6.1.0", 31 | "leveldown": "^5.4.1", 32 | "levelup": "^4.3.2" 33 | }, 34 | "repository": { 35 | "type": "git", 36 | "url": "git+https://github.com/IMI-Tool-Project/imi-enrichment-hojin.git" 37 | }, 38 | "bugs": { 39 | "url": "https://github.com/IMI-Tool-Project/imi-enrichment-hojin/issues" 40 | }, 41 | "homepage": "https://github.com/IMI-Tool-Project/imi-enrichment-hojin#readme" 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 IMI Tool Project 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/util.js: -------------------------------------------------------------------------------- 1 | const deepStrictEqual = function(expected, actual) { 2 | if (typeof expected !== typeof actual) return false; 3 | 4 | if (Array.isArray(expected)) { 5 | if (!Array.isArray(actual)) return false; 6 | if (expected.length !== actual.length) return false; 7 | if (expected.find((x, i) => !deepStrictEqual(x, actual[i]))) return false; 8 | return true; 9 | } 10 | 11 | if (typeof expected === 'object') { 12 | const k1 = Object.keys(expected); 13 | const k2 = Object.keys(actual); 14 | if (k1.length !== k2.length) return false; 15 | if (k1.find(k => k2.indexOf(k) === -1)) return false; 16 | if (k1.find(k => !deepStrictEqual(expected[k], actual[k]))) return false; 17 | return true; 18 | } 19 | return expected === actual; 20 | }; 21 | 22 | module.exports = { 23 | isValidHoujinBangou: function(bangou) { 24 | return !!(bangou.match(/^([1-9])([0-9]{12})$/)); 25 | }, 26 | isValidCheckDigit: function(bangou) { 27 | const expected = this.calcCheckDigit(bangou); 28 | const actual = this.getCheckDigit(bangou); 29 | return !isNaN(expected) && !isNaN(actual) && expected === actual; 30 | }, 31 | getCheckDigit: function(bangou) { 32 | if (!this.isValidHoujinBangou(bangou)) return NaN; 33 | return parseInt(bangou.substring(0, 1)); 34 | }, 35 | calcCheckDigit: function(bangou) { 36 | if (!this.isValidHoujinBangou(bangou)) return NaN; 37 | let s = 0; 38 | bangou.substring(1).split("").map(a => parseInt(a)).forEach((v, i) => { 39 | s += (i % 2 === 0 ? v * 2 : v); 40 | }); 41 | return 9 - (s % 9); 42 | }, 43 | deepStrictEqual: deepStrictEqual, 44 | put: function(s, p, o) { 45 | if (s[p] === undefined) { 46 | s[p] = o; 47 | } else if (Array.isArray(s[p])) { 48 | if (s[p].find(x => deepStrictEqual(x, o)) === undefined) 49 | s[p].push(o); 50 | } else if (!deepStrictEqual(s[p], o)) { 51 | s[p] = [s[p], o]; 52 | } 53 | return s; 54 | } 55 | }; 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | cache 107 | db 108 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | const levelup = require('levelup'); 2 | const leveldown = require('leveldown'); 3 | const util = require("./lib/util"); 4 | 5 | const DATABASE = __dirname + "/db"; 6 | 7 | module.exports = function(src) { 8 | 9 | const dst = typeof src === 'string' ? { 10 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 11 | "@type": "法人型", 12 | "ID": { 13 | "@type": "ID型", 14 | "体系": { 15 | "@type": "ID体系型", 16 | "表記": "法人番号" 17 | }, 18 | "識別値": src 19 | } 20 | } : JSON.parse(JSON.stringify(src)); 21 | 22 | const targets = []; 23 | 24 | const dig = function(focus) { 25 | if (Array.isArray(focus)) { 26 | focus.forEach(a => dig(a)); 27 | } else if (typeof focus === 'object') { 28 | if (focus["@type"] === "法人型" && focus["ID"] && focus["ID"]["識別値"]) { 29 | const key = focus["ID"]["識別値"]; 30 | if (!util.isValidHoujinBangou(key)) { 31 | util.put(focus, "メタデータ", { 32 | "@type": "文書型", 33 | "説明": "法人番号は1~9ではじまる13桁の数字でなければなりません" 34 | }); 35 | } else if (!util.isValidCheckDigit(key)) { 36 | util.put(focus, "メタデータ", { 37 | "@type": "文書型", 38 | "説明": "法人番号のチェックデジットが不正です" 39 | }); 40 | } else { 41 | targets.push(focus); 42 | } 43 | } 44 | Object.keys(focus).forEach(key => { 45 | dig(focus[key]); 46 | }); 47 | } 48 | }; 49 | 50 | dig(dst); 51 | 52 | if (targets.length === 0) { 53 | return Promise.resolve(dst); 54 | } 55 | 56 | const db = levelup(leveldown(DATABASE)); 57 | const promises = targets.map(target => { 58 | return db.get(target["ID"]["識別値"], { 59 | asBuffer: false 60 | }).then(str => { 61 | const json = JSON.parse(str); 62 | delete json["@context"]; 63 | delete target["ID"]; 64 | Object.keys(json).forEach(key => { 65 | util.put(target, key, json[key]); 66 | }); 67 | return true; 68 | }).catch(e => { 69 | util.put(target, "メタデータ", { 70 | "@type": "文書型", 71 | "説明": "該当する法人番号がありません" 72 | }); 73 | return true; 74 | }); 75 | }); 76 | return Promise.all(promises).then(() => db.close()).then(() => dst); 77 | }; 78 | -------------------------------------------------------------------------------- /bin/server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const enrichment = require("../main"); 4 | const http = require("http"); 5 | 6 | if (process.argv.length < 3 || !process.argv[2].match(/^[1-9][0-9]*$/)) { 7 | console.error("Usage: node server.js [port number]"); 8 | process.exit(1); 9 | } 10 | 11 | const port = parseInt(process.argv[2]); 12 | 13 | const server = http.createServer((req, res) => { 14 | if (req.method === "GET") { 15 | res.writeHead(200, { 16 | "Content-Type": "text/html; charset=utf-8", 17 | "Access-Control-Allow-Origin": "*" 18 | }); 19 | res.end(require('fs').readFileSync(__dirname + "/server.html", "utf-8")); 20 | return; 21 | } 22 | 23 | if (req.method !== "POST") { 24 | res.writeHead(405, { 25 | "Content-Type": "text/plain", 26 | "Allow": "POST", 27 | "Access-Control-Allow-Origin": "*" 28 | }); 29 | res.end("405 Method Not Allowed, only POST method is supported"); 30 | return; 31 | } 32 | 33 | const isJSON = req.headers["content-type"] && req.headers["content-type"].indexOf("json") !== -1; 34 | 35 | new Promise(resolve => { 36 | let data = ""; 37 | req.on("data", (chunk) => { 38 | data += chunk; 39 | }).on("end", () => { 40 | resolve(data); 41 | }); 42 | }).then(data => { 43 | let input = data; 44 | if (isJSON) { 45 | try { 46 | input = JSON.parse(data); 47 | } catch (e) { 48 | res.writeHead(400, { 49 | "Content-Type": "text/plain", 50 | "Access-Control-Allow-Origin": "*" 51 | }); 52 | res.end(`400 Bad Request, exception occurred during parsing POST body as JSON\n\n${e.toString()}`); 53 | return; 54 | } 55 | } 56 | enrichment(input).then(json => { 57 | res.writeHead(200, { 58 | "Content-Type": "application/json", 59 | "Access-Control-Allow-Origin": "*" 60 | }); 61 | res.end(JSON.stringify(json, null, 2)); 62 | 63 | }).catch(e => { 64 | res.writeHead(500, { 65 | "Content-Type": "text/plain", 66 | "Access-Control-Allow-Origin": "*" 67 | }); 68 | res.end(`500 Internal Server Error\n\n${e.toString()}`); 69 | }); 70 | }); 71 | 72 | }); 73 | server.listen(port, () => { 74 | console.log(`imi-enrichment-hojin-server is running on port ${port}`); 75 | }); 76 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const fs = require('fs'); 4 | const commandLineArgs = require('command-line-args'); 5 | const commandLineUsage = require('command-line-usage'); 6 | const enrichment = require("../main"); 7 | 8 | const optionDefinitions = [{ 9 | name: 'help', 10 | alias: 'h', 11 | type: Boolean, 12 | description: 'このヘルプを表示します' 13 | }, { 14 | name: 'file', 15 | alias: 'f', 16 | type: String, 17 | defaultOption: true, 18 | typeLabel: '{underline file}', 19 | description: '変換対象とする JSON ファイル' 20 | }, { 21 | name: 'string', 22 | alias: 's', 23 | type: String, 24 | typeLabel: '{underline string}', 25 | description: '変換対象とする法人番号文字列', 26 | }, { 27 | name: 'indent', 28 | alias: 'i', 29 | type: Number, 30 | typeLabel: '{underline number}', 31 | description: '出力する JSON のインデント (default 2)', 32 | defaultValue: 2 33 | }]; 34 | 35 | const options = commandLineArgs(optionDefinitions); 36 | 37 | if (options.help) { 38 | const usage = commandLineUsage([{ 39 | header: 'imi-enrichment-hojin', 40 | content: '法人番号をもとに法人型の情報を補完します' 41 | }, { 42 | header: 'オプション', 43 | optionList: optionDefinitions 44 | }, { 45 | header: '実行例', 46 | content: [{ 47 | desc: 'ヘルプの表示', 48 | example: '$ imi-enrichment-hojin -h' 49 | }, 50 | { 51 | desc: '文字列の処理', 52 | example: '$ imi-enrichment-hojin -s 4000012090001' 53 | }, 54 | { 55 | desc: 'ファイルの処理', 56 | example: '$ imi-enrichment-hojin input.json' 57 | }, 58 | { 59 | desc: '標準入力の処理', 60 | example: '$ cat input.json | imi-enrichment-hojin' 61 | } 62 | ] 63 | }]); 64 | console.log(usage) 65 | } else if (options.string) { 66 | enrichment(options.string).then(json => { 67 | console.log(JSON.stringify(json, null, options.indent)); 68 | }); 69 | } else if (options.file) { 70 | const input = JSON.parse(fs.readFileSync(options.file, "UTF-8")); 71 | enrichment(input).then(json => { 72 | console.log(JSON.stringify(json, null, options.indent)); 73 | }); 74 | } else { 75 | let buffer = ""; 76 | process.stdin.setEncoding('utf-8'); 77 | process.stdin.on('data', chunk => { 78 | buffer += chunk; 79 | }).on('end', () => { 80 | const input = JSON.parse(buffer); 81 | enrichment(input).then(json => { 82 | console.log(JSON.stringify(json, null, options.indent)); 83 | }); 84 | }); 85 | } 86 | -------------------------------------------------------------------------------- /spec/003-misc.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "桁数が不足した法人番号", 3 | "input": "100000000", 4 | "output": { 5 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 6 | "@type": "法人型", 7 | "ID": { 8 | "@type": "ID型", 9 | "体系": { 10 | "@type": "ID体系型", 11 | "表記": "法人番号" 12 | }, 13 | "識別値": "100000000" 14 | }, 15 | "メタデータ": { 16 | "@type": "文書型", 17 | "説明": "法人番号は1~9ではじまる13桁の数字でなければなりません" 18 | } 19 | } 20 | }, 21 | { 22 | "name": "桁数が過剰な法人番号", 23 | "input": "10000000000000000", 24 | "output": { 25 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 26 | "@type": "法人型", 27 | "ID": { 28 | "@type": "ID型", 29 | "体系": { 30 | "@type": "ID体系型", 31 | "表記": "法人番号" 32 | }, 33 | "識別値": "10000000000000000" 34 | }, 35 | "メタデータ": { 36 | "@type": "文書型", 37 | "説明": "法人番号は1~9ではじまる13桁の数字でなければなりません" 38 | } 39 | } 40 | }, 41 | { 42 | "name": "0からはじまる法人番号", 43 | "input": "0123456789012", 44 | "output": { 45 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 46 | "@type": "法人型", 47 | "ID": { 48 | "@type": "ID型", 49 | "体系": { 50 | "@type": "ID体系型", 51 | "表記": "法人番号" 52 | }, 53 | "識別値": "0123456789012" 54 | }, 55 | "メタデータ": { 56 | "@type": "文書型", 57 | "説明": "法人番号は1~9ではじまる13桁の数字でなければなりません" 58 | } 59 | } 60 | }, 61 | { 62 | "name": "チェックデジットの異常", 63 | "input": "9000012090004", 64 | "output": { 65 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 66 | "@type": "法人型", 67 | "ID": { 68 | "@type": "ID型", 69 | "体系": { 70 | "@type": "ID体系型", 71 | "表記": "法人番号" 72 | }, 73 | "識別値": "9000012090004" 74 | }, 75 | "メタデータ": { 76 | "@type": "文書型", 77 | "説明": "法人番号のチェックデジットが不正です" 78 | } 79 | } 80 | }, 81 | { 82 | "name": "存在しない法人番号", 83 | "input": "2876543210987", 84 | "output": { 85 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 86 | "@type": "法人型", 87 | "ID": { 88 | "@type": "ID型", 89 | "体系": { 90 | "@type": "ID体系型", 91 | "表記": "法人番号" 92 | }, 93 | "識別値": "2876543210987" 94 | }, 95 | "メタデータ": { 96 | "@type": "文書型", 97 | "説明": "該当する法人番号がありません" 98 | } 99 | } 100 | } 101 | 102 | ] 103 | -------------------------------------------------------------------------------- /tools/setup.js: -------------------------------------------------------------------------------- 1 | const Papa = require("papaparse"); 2 | const format = require("./format"); 3 | 4 | const levelup = require('levelup'); 5 | const leveldown = require('leveldown'); 6 | 7 | const DATABASE = process.argv[2]; 8 | 9 | const db = levelup(leveldown(DATABASE)); 10 | 11 | /* 12 | db.open().then(() => { 13 | console.log("database opened"); 14 | const promises = []; 15 | process.stdin.pipe(Papa.parse(Papa.NODE_STREAM_INPUT, { 16 | encoding: "UTF-8" 17 | })).on("data", function(f) { 18 | const data = format(f); 19 | if (!data) return; 20 | 21 | const key = data["ID"]["識別値"]; 22 | promises.push(db.put(key, JSON.stringify(data))); 23 | 24 | if (promises.length % 10000 === 0) 25 | console.log(promises.length); 26 | }).on("end", function() { 27 | Promise.all(promises).then(() => { 28 | console.log("end of input"); 29 | return db.close(); 30 | }).then(() => { 31 | console.log("database closed") 32 | }); 33 | }); 34 | });*/ 35 | 36 | 37 | /* 38 | real 10m3.038s 39 | user 5m20.063s 40 | sys 3m14.156s 41 | 42 | const promises = []; 43 | 44 | process.stdin.pipe(Papa.parse(Papa.NODE_STREAM_INPUT, { 45 | encoding: "UTF-8" 46 | })).on("data", function(f) { 47 | const data = format(f); 48 | if (!data) return; 49 | 50 | const key = data["ID"]["識別値"]; 51 | promises.push(db.put(key, JSON.stringify(data))); 52 | 53 | if (promises.length % 10000 === 0) 54 | console.error(promises.length); 55 | }).on("end", function() { 56 | 57 | Promise.all(promises).then(a => { 58 | console.error("end of input"); 59 | }); 60 | }); 61 | */ 62 | 63 | const SIZE = 100000; 64 | // 10000 : 6m37.628s 65 | // 100000 : 3m48.405s 66 | 67 | let chain = null; 68 | const promises = []; 69 | let count = 0; 70 | 71 | function flash() { 72 | console.log("flash " + count); 73 | promises.push(chain.write()); 74 | chain = null; 75 | } 76 | 77 | db.open().then(() => { 78 | console.log("database opened"); 79 | process.stdin.pipe(Papa.parse(Papa.NODE_STREAM_INPUT, { 80 | encoding: "UTF-8" 81 | })).on("data", function(f) { 82 | const data = format(f); 83 | if (!data) return; 84 | 85 | const key = data["ID"]["識別値"]; 86 | 87 | if (chain === null) { 88 | chain = db.batch(); 89 | } 90 | chain.put(key, JSON.stringify(data)); 91 | count++; 92 | 93 | if (count % SIZE === 0) { 94 | flash(); 95 | } 96 | 97 | }).on("end", function() { 98 | 99 | if (chain !== null) { 100 | flash(); 101 | } 102 | 103 | Promise.all(promises).then(() => { 104 | console.error("done"); 105 | db.close().then(a => { 106 | console.log("database closed"); 107 | }); 108 | }); 109 | }); 110 | 111 | }); 112 | -------------------------------------------------------------------------------- /spec/002-nest.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "ネスト", 3 | "input": { 4 | "@type": "法人型", 5 | "ID": { 6 | "識別値": "4000012090001" 7 | }, 8 | "関与": { 9 | "@type": "関与型", 10 | "役割": "外局", 11 | "関与者": { 12 | "@type": "法人型", 13 | "ID": { 14 | "識別値": "1000012090004" 15 | } 16 | } 17 | } 18 | }, 19 | "output": { 20 | "@type": "法人型", 21 | "組織種別": { 22 | "@type": "コード型", 23 | "コード種別": { 24 | "@type": "コードリスト型", 25 | "表記": "法人種別" 26 | }, 27 | "識別値": "101", 28 | "表記": "国の機関" 29 | }, 30 | "ID": { 31 | "@type": "ID型", 32 | "体系": { 33 | "@type": "ID体系型", 34 | "表記": "法人番号" 35 | }, 36 | "識別値": "4000012090001" 37 | }, 38 | "表記": "経済産業省", 39 | "名称": { 40 | "@type": "名称型", 41 | "表記": "経済産業省", 42 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 43 | "カナ表記": "ケイザイサンギョウショウ" 44 | }, 45 | "住所": [{ 46 | "@type": "住所型", 47 | "種別": "国内所在地", 48 | "表記": "東京都 千代田区 霞が関1丁目3-1", 49 | "郵便番号": "1000013", 50 | "都道府県": "東京都", 51 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 52 | "市区町村": "千代田区", 53 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 54 | }, { 55 | "@type": "住所型", 56 | "種別": "国内所在地(英語表記)", 57 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 58 | "都道府県": "Tokyo" 59 | }], 60 | "関与": { 61 | "@type": "関与型", 62 | "役割": "外局", 63 | "関与者": { 64 | "@type": "法人型", 65 | "ID": { 66 | "@type": "ID型", 67 | "体系": { 68 | "@type": "ID体系型", 69 | "表記": "法人番号" 70 | }, 71 | "識別値": "1000012090004" 72 | }, 73 | "組織種別": { 74 | "@type": "コード型", 75 | "コード種別": { 76 | "@type": "コードリスト型", 77 | "表記": "法人種別" 78 | }, 79 | "識別値": "101", 80 | "表記": "国の機関" 81 | }, 82 | "表記": "中小企業庁", 83 | "名称": { 84 | "@type": "名称型", 85 | "表記": "中小企業庁", 86 | "ローマ字表記": "Small and Medium Enterprise Agency", 87 | "カナ表記": "チュウショウキギョウチョウ" 88 | }, 89 | "住所": [{ 90 | "@type": "住所型", 91 | "種別": "国内所在地", 92 | "表記": "東京都 千代田区 霞が関1丁目3-1", 93 | "郵便番号": "1000013", 94 | "都道府県": "東京都", 95 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 96 | "市区町村": "千代田区", 97 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 98 | }, 99 | { 100 | "@type": "住所型", 101 | "種別": "国内所在地(英語表記)", 102 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 103 | "都道府県": "Tokyo" 104 | } 105 | ] 106 | } 107 | } 108 | } 109 | }] 110 | -------------------------------------------------------------------------------- /tools/format.js: -------------------------------------------------------------------------------- 1 | const PROCESS = { 2 | "01": "新規", 3 | "11": "商号又は名称の変更", 4 | "12": "国内所在地の変更", 5 | "13": "国外所在地の変更", 6 | "21": "登記記録の閉鎖等", 7 | "22": "登記記録の復活等", 8 | "71": "吸収合併", 9 | "72": "吸収合併無効", 10 | "81": "商号の登記の抹消", 11 | "99": "削除" 12 | }; 13 | 14 | const KIND = { 15 | "101": "国の機関", 16 | "201": "地方公共団体", 17 | "301": "株式会社", 18 | "302": "有限会社", 19 | "303": "合名会社", 20 | "304": "合資会社", 21 | "305": "合同会社", 22 | "399": "その他の設立登記法人", 23 | "401": "外国会社等", 24 | "499": "その他" 25 | }; 26 | 27 | const CLOSE = { 28 | "01": "清算の結了等", 29 | "11": "合併による解散等", 30 | "21": "登記官による閉鎖", 31 | "31": "その他の清算の結了等" 32 | }; 33 | 34 | module.exports = function(f) { 35 | if (!f || f[1] === undefined) return null; 36 | 37 | const data = { 38 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 39 | "@type": "法人型", 40 | "組織種別": { 41 | "@type": "コード型", 42 | "コード種別": { 43 | "@type": "コードリスト型", 44 | "表記": "法人種別" 45 | }, 46 | "識別値": f[8], 47 | "表記": KIND[f[8]] 48 | }, 49 | "ID": { 50 | "@type": "ID型", 51 | "体系": { 52 | "@type": "ID体系型", 53 | "表記": "法人番号" 54 | }, 55 | "識別値": f[1], 56 | }, 57 | "表記": f[6], 58 | "名称": { 59 | "@type": "名称型", 60 | "表記": f[6] 61 | }, 62 | "住所": [] 63 | }; 64 | 65 | if (f[24] !== "") 66 | data["名称"]["ローマ字表記"] = f[24]; 67 | 68 | if (f[28] !== "") 69 | data["名称"]["カナ表記"] = f[28]; 70 | 71 | if (f[7] !== "") 72 | data["名称"]["画像"] = `https://www.houjin-bangou.nta.go.jp/image?imageid=${f[7]}`; 73 | 74 | 75 | if (f[9] !== "") { 76 | const a = { 77 | "@type": "住所型", 78 | "種別": "国内所在地", 79 | "表記": `${f[9]} ${f[10]} ${f[11]}`, 80 | "郵便番号": f[15], 81 | "都道府県": f[9], 82 | "都道府県コード": `http://data.e-stat.go.jp/lod/sac/C${f[13]}000`, 83 | "市区町村": f[10], 84 | "市区町村コード": `http://data.e-stat.go.jp/lod/sac/C${f[13]}${f[14]}` 85 | }; 86 | if (f[12].length > 0) a["画像"] = `https://www.houjin-bangou.nta.go.jp/image?imageid=${f[12]}`; 87 | data["住所"].push(a); 88 | } 89 | 90 | if (f[25] !== "") { 91 | const a = { 92 | "@type": "住所型", 93 | "種別": "国内所在地(英語表記)", 94 | "表記": `${f[26]}, ${f[25]}`, 95 | "都道府県": f[25] 96 | }; 97 | if (f[12].length > 0) a["画像"] = `https://www.houjin-bangou.nta.go.jp/image?imageid=${f[12]}`; 98 | data["住所"].push(a); 99 | } 100 | 101 | if (f[16] !== "") { 102 | const a = { 103 | "@type": "住所型", 104 | "種別": "国外所在地", 105 | "表記": f[16] 106 | }; 107 | if (f[17].length > 0) a["画像"] = `https://www.houjin-bangou.nta.go.jp/image?imageid=${f[17]}`; 108 | data["住所"].push(a); 109 | } 110 | 111 | if (f[27] !== "") { 112 | const a = { 113 | "@type": "住所型", 114 | "種別": "国外所在地(英語表記)", 115 | "表記": f[27] 116 | }; 117 | if (f[17].length > 0) a["画像"] = `https://www.houjin-bangou.nta.go.jp/image?imageid=${f[17]}`; 118 | data["住所"].push(a); 119 | } 120 | 121 | if (data["住所"].length === 0) delete data["住所"]; 122 | else if (data["住所"].length === 1) data["住所"] = data["住所"][0]; 123 | 124 | 125 | if (f[19] !== "") { 126 | const a = { 127 | "@type": "状況型", 128 | "種別コード": { 129 | "@type": "コード型", 130 | "コード種別": { 131 | "@type": "コードリスト型", 132 | "表記": "登記記録の閉鎖等の事由" 133 | }, 134 | "識別値": f[19], 135 | "表記": CLOSE[f[19]] 136 | }, 137 | "日時": { 138 | "@type": "日時型", 139 | "標準型日時": f[18] 140 | } 141 | }; 142 | if (f[20] !== "") 143 | a["関与"] = { 144 | "@type": "関与型", 145 | "役割": "継承先法人", 146 | "関与者": { 147 | "@type": "法人型", 148 | "ID": { 149 | "@type": "ID型", 150 | "体系": { 151 | "@type": "ID体系型", 152 | "表記": "法人番号" 153 | }, 154 | "識別値": f[20] 155 | } 156 | } 157 | } 158 | data["活動状況"] = a; 159 | } 160 | 161 | return data; 162 | }; 163 | -------------------------------------------------------------------------------- /test/test-server.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect; 2 | const spawn = require('child_process').spawn; 3 | const fetch = require("node-fetch"); 4 | 5 | const fs = require("fs"); 6 | const spec = __dirname + "/../spec"; 7 | 8 | const PORT = "37564"; 9 | const ENDPOINT = `http://localhost:${PORT}`; 10 | 11 | describe('imi-enrichment-hojin#server', () => { 12 | 13 | let server = null; 14 | 15 | before((done) => { 16 | server = spawn("node", ["bin/server.js", PORT]); 17 | let initialized = false; 18 | server.stdout.on('data', (data) => { 19 | if (!initialized) { 20 | initialized = true; 21 | done(); 22 | } 23 | }); 24 | }); 25 | 26 | after(() => { 27 | server.kill(); 28 | }); 29 | 30 | describe('server', () => { 31 | it("GET リクエストに対して 200 OK を返すこと", (done) => { 32 | try { 33 | fetch(ENDPOINT).then(res => { 34 | try { 35 | expect(res.status).to.equal(200); 36 | expect(res.headers.get("Access-Control-Allow-Origin")).to.equal("*"); 37 | done(); 38 | } catch (e) { 39 | done(e); 40 | } 41 | }).catch(e => { 42 | done(e); 43 | }); 44 | } catch (e) { 45 | done(e); 46 | } 47 | }); 48 | 49 | it("HEAD リクエストを 405 Request Not Allowed でリジェクトすること", (done) => { 50 | try { 51 | fetch(ENDPOINT, { 52 | method: "HEAD" 53 | }).then(res => { 54 | try { 55 | expect(res.status).to.equal(405); 56 | expect(res.headers.get("Access-Control-Allow-Origin")).to.equal("*"); 57 | done(); 58 | } catch (e) { 59 | done(e); 60 | } 61 | }).catch(e => { 62 | done(e); 63 | }); 64 | } catch (e) { 65 | done(e); 66 | } 67 | }); 68 | 69 | it("JSON でないリクエストを 400 Bad Request でリジェクトすること", (done) => { 70 | fetch(ENDPOINT, { 71 | method: "POST", 72 | body: "hello, world", 73 | headers: { 74 | 'Accept': 'application/json', 75 | 'Content-Type': 'application/json' 76 | } 77 | }).then(res => { 78 | try { 79 | expect(res.status).to.equal(400); 80 | expect(res.headers.get("Access-Control-Allow-Origin")).to.equal("*"); 81 | done(); 82 | } catch (e) { 83 | done(e); 84 | } 85 | }); 86 | }); 87 | 88 | it("正常なクエストに 200 OK を返すこと", (done) => { 89 | fetch(ENDPOINT, { 90 | method: "POST", 91 | body: "{}", 92 | headers: { 93 | 'Accept': 'application/json', 94 | 'Content-Type': 'application/json' 95 | } 96 | }).then(res => { 97 | try { 98 | expect(res.status).to.equal(200); 99 | expect(res.headers.get("Access-Control-Allow-Origin")).to.equal("*"); 100 | done(); 101 | } catch (e) { 102 | done(e); 103 | } 104 | }); 105 | }); 106 | }); 107 | 108 | describe("spec", function() { 109 | fs.readdirSync(spec).filter(file => file.match(/json$/)).forEach(file => { 110 | describe(file, function() { 111 | const json = JSON.parse(fs.readFileSync(`${spec}/${file}`, "UTF-8")); 112 | json.forEach(a => { 113 | it(a.name, done => { 114 | const body = typeof a.input === 'object' ? JSON.stringify(a.input) : a.input; 115 | 116 | fetch(ENDPOINT, { 117 | method: "POST", 118 | body: body, 119 | headers: { 120 | 'Accept': 'application/json', 121 | 'Content-Type': typeof a.input === 'object' ? 'application/json' : 'text/plain' 122 | } 123 | }).then(res => res.json()).then(json => { 124 | try { 125 | expect(json).deep.equal(a.output); 126 | done(); 127 | } catch (e) { 128 | done(e); 129 | } 130 | }); 131 | }); 132 | }); 133 | }); 134 | }); 135 | }); 136 | 137 | }); 138 | -------------------------------------------------------------------------------- /test/test-util.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect; 2 | const util = require("../lib/util.js"); 3 | 4 | describe('imi-enrichment-hojin#util', () => { 5 | 6 | it("getCheckDigit", () => { 7 | expect(util.getCheckDigit("8700110005901")).to.equal(8); 8 | expect(util.getCheckDigit("4000012090001")).to.equal(4); 9 | expect(util.getCheckDigit("400001209000")).to.be.NaN; 10 | expect(util.getCheckDigit("40000120900000")).to.be.NaN; 11 | }); 12 | 13 | it("calcCheckDigit", () => { 14 | expect(util.calcCheckDigit("8700110005901")).to.equal(8); 15 | expect(util.calcCheckDigit("4000012090001")).to.equal(4); 16 | expect(util.calcCheckDigit("400001209000")).to.be.NaN; 17 | expect(util.calcCheckDigit("40000120900000")).to.be.NaN; 18 | }); 19 | 20 | it("isValidHoujinBangou", () => { 21 | expect(util.isValidHoujinBangou("8700110005901")).to.be.true; 22 | expect(util.isValidHoujinBangou("4000012090001")).to.be.true; 23 | expect(util.isValidHoujinBangou("400001209000")).to.be.false; 24 | expect(util.isValidHoujinBangou("40000120900000")).to.be.false; 25 | }); 26 | 27 | it("isValidCheckDigit", () => { 28 | expect(util.isValidCheckDigit("8700110005901")).to.be.true; 29 | expect(util.isValidCheckDigit("4000012090001")).to.be.true; 30 | expect(util.isValidCheckDigit("5000012090001")).to.be.false; 31 | expect(util.isValidCheckDigit("6000012090001")).to.be.false; 32 | expect(util.isValidCheckDigit("600001209000")).to.be.false; 33 | expect(util.isValidCheckDigit("60000120900000")).to.be.false; 34 | }); 35 | 36 | it("deepStrictEqual", () => { 37 | expect(util.deepStrictEqual(0, 0)).to.be.true; 38 | expect(util.deepStrictEqual(1, 1)).to.be.true; 39 | expect(util.deepStrictEqual(true, true)).to.be.true; 40 | expect(util.deepStrictEqual(false, false)).to.be.true; 41 | expect(util.deepStrictEqual("hello", "hello")).to.be.true; 42 | expect(util.deepStrictEqual([0, "hello", true], [0, "hello", true])).to.be.true; 43 | expect(util.deepStrictEqual({ 44 | a: 1, 45 | b: 2 46 | }, { 47 | b: 2, 48 | a: 1 49 | })).to.be.true; 50 | 51 | expect(util.deepStrictEqual("hello", "world")).to.be.false; 52 | expect(util.deepStrictEqual([0, "hello", true], [0, "hello", false])).to.be.false; 53 | expect(util.deepStrictEqual([0, "hello", true], [0, true, "hello"])).to.be.false; 54 | expect(util.deepStrictEqual({ 55 | a: 1, 56 | b: 2 57 | }, { 58 | b: 2 59 | })).to.be.false; 60 | }); 61 | 62 | it("put", () => { 63 | expect(util.put({}, "name", "Alice")).deep.equal({ 64 | "name": "Alice" 65 | }); 66 | expect(util.put({ 67 | "name": "Alice" 68 | }, "name", "Alice")).deep.equal({ 69 | "name": "Alice" 70 | }); 71 | expect(util.put({ 72 | "name": "Bob" 73 | }, "name", "Alice")).deep.equal({ 74 | "name": ["Bob", "Alice"] 75 | }); 76 | expect(util.put({ 77 | "name": ["Bob", "Cate"], 78 | }, "name", "Alice")).deep.equal({ 79 | "name": ["Bob", "Cate", "Alice"] 80 | }); 81 | expect(util.put({}, "is", { 82 | "@type": "Cat" 83 | })).deep.equal({ 84 | "is": { 85 | "@type": "Cat" 86 | } 87 | }); 88 | expect(util.put({ 89 | "is": { 90 | "@type": "Cat" 91 | } 92 | }, "is", { 93 | "@type": "Cat" 94 | })).deep.equal({ 95 | "is": { 96 | "@type": "Cat" 97 | } 98 | }); 99 | expect(util.put({ 100 | "is": { 101 | "@type": "Dog" 102 | } 103 | }, "is", { 104 | "@type": "Cat" 105 | })).deep.equal({ 106 | "is": [{ 107 | "@type": "Dog" 108 | }, { 109 | "@type": "Cat" 110 | }] 111 | }); 112 | expect(util.put({ 113 | "is": [{ 114 | "@type": "Dog" 115 | }, { 116 | "@type": "Animal" 117 | }] 118 | }, "is", { 119 | "@type": "Cat" 120 | })).deep.equal({ 121 | "is": [{ 122 | "@type": "Dog" 123 | }, { 124 | "@type": "Animal" 125 | }, { 126 | "@type": "Cat" 127 | }] 128 | }); 129 | }); 130 | }); 131 | -------------------------------------------------------------------------------- /test/test-cli.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect; 2 | const spawn = require('child_process').spawn; 3 | const fs = require("fs"); 4 | const spec = __dirname + "/../spec"; 5 | 6 | function cli(options, stdin) { 7 | let res = ""; 8 | const cmd = ["bin/cli.js"].concat(options || []); 9 | return new Promise(resolve => { 10 | const child = spawn("node", cmd); 11 | child.stdout.setEncoding('utf-8'); 12 | child.stdout.on('data', (data) => { 13 | res += data; 14 | }); 15 | child.on('close', (code) => { 16 | resolve(res); 17 | }); 18 | if (stdin) { 19 | child.stdin.setEncoding('utf-8'); 20 | child.stdin.write(stdin); 21 | child.stdin.end(); 22 | } 23 | }); 24 | } 25 | 26 | const samples = JSON.parse(fs.readFileSync(`${spec}/001-io.json`, "UTF-8")); 27 | 28 | describe('imi-enrichment-hojin#cli', () => { 29 | 30 | const tempfile = `tmp.${(new Date()).getTime()}.json`; 31 | 32 | before((done) => { 33 | fs.writeFileSync(tempfile, JSON.stringify(samples[1].input), "UTF-8"); 34 | done(); 35 | }); 36 | 37 | after(() => { 38 | fs.unlinkSync(tempfile); 39 | }); 40 | 41 | describe('options', () => { 42 | 43 | it("-h", (done) => { 44 | cli(["-h"]).then(res => { 45 | try { 46 | expect(res).to.have.string("imi-enrichment-hojin"); 47 | done(); 48 | } catch (e) { 49 | done(e); 50 | } 51 | }); 52 | }); 53 | 54 | it("--help", (done) => { 55 | cli(["--help"]).then(res => { 56 | try { 57 | expect(res).to.have.string("imi-enrichment-hojin"); 58 | done(); 59 | } catch (e) { 60 | done(e); 61 | } 62 | }); 63 | }); 64 | 65 | it("-s", (done) => { 66 | cli(["-s", samples[0].input]).then(res => { 67 | try { 68 | expect(JSON.parse(res)).deep.equal(samples[0].output); 69 | done(); 70 | } catch (e) { 71 | done(e); 72 | } 73 | }); 74 | }); 75 | 76 | it("--string", (done) => { 77 | cli(["--string", samples[0].input]).then(res => { 78 | try { 79 | expect(JSON.parse(res)).deep.equal(samples[0].output); 80 | done(); 81 | } catch (e) { 82 | done(e); 83 | } 84 | }); 85 | }); 86 | 87 | it("-f", (done) => { 88 | cli(["-f", tempfile]).then(res => { 89 | try { 90 | expect(JSON.parse(res)).deep.equal(samples[1].output); 91 | done(); 92 | } catch (e) { 93 | done(e); 94 | } 95 | }); 96 | }); 97 | 98 | it("--file", (done) => { 99 | cli(["--file", tempfile]).then(res => { 100 | try { 101 | expect(JSON.parse(res)).deep.equal(samples[1].output); 102 | done(); 103 | } catch (e) { 104 | done(e); 105 | } 106 | }); 107 | }); 108 | 109 | it("filename only", (done) => { 110 | cli([tempfile]).then(res => { 111 | try { 112 | expect(JSON.parse(res)).deep.equal(samples[1].output); 113 | done(); 114 | } catch (e) { 115 | done(e); 116 | } 117 | }); 118 | }); 119 | 120 | it("stdin", (done) => { 121 | cli(null, JSON.stringify(samples[1].input)).then(res => { 122 | try { 123 | expect(JSON.parse(res)).deep.equal(samples[1].output); 124 | done(); 125 | } catch (e) { 126 | done(e); 127 | } 128 | }); 129 | }); 130 | }); 131 | 132 | describe("spec", function() { 133 | fs.readdirSync(spec).filter(file => file.match(/json$/)).forEach(file => { 134 | describe(file, function() { 135 | const json = JSON.parse(fs.readFileSync(`${spec}/${file}`, "UTF-8")); 136 | json.forEach(a => { 137 | it(a.name, done => { 138 | const promise = typeof a.input === 'string' ? cli(["-s", a.input]) : cli(null, JSON.stringify(a.input)); 139 | promise.then(res => { 140 | try { 141 | expect(JSON.parse(res)).deep.equal(a.output); 142 | done(); 143 | } catch (e) { 144 | done(e); 145 | } 146 | }); 147 | }); 148 | }); 149 | }); 150 | }); 151 | }); 152 | 153 | }); 154 | -------------------------------------------------------------------------------- /spec/001-io.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "文字列入力 (@context を付与する)", 3 | "input": "4000012090001", 4 | "output": { 5 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 6 | "@type": "法人型", 7 | "組織種別": { 8 | "@type": "コード型", 9 | "コード種別": { 10 | "@type": "コードリスト型", 11 | "表記": "法人種別" 12 | }, 13 | "識別値": "101", 14 | "表記": "国の機関" 15 | }, 16 | "ID": { 17 | "@type": "ID型", 18 | "体系": { 19 | "@type": "ID体系型", 20 | "表記": "法人番号" 21 | }, 22 | "識別値": "4000012090001" 23 | }, 24 | "表記": "経済産業省", 25 | "名称": { 26 | "@type": "名称型", 27 | "表記": "経済産業省", 28 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 29 | "カナ表記": "ケイザイサンギョウショウ" 30 | }, 31 | "住所": [{ 32 | "@type": "住所型", 33 | "種別": "国内所在地", 34 | "表記": "東京都 千代田区 霞が関1丁目3-1", 35 | "郵便番号": "1000013", 36 | "都道府県": "東京都", 37 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 38 | "市区町村": "千代田区", 39 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 40 | }, { 41 | "@type": "住所型", 42 | "種別": "国内所在地(英語表記)", 43 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 44 | "都道府県": "Tokyo" 45 | }] 46 | } 47 | }, { 48 | "name": "オブジェクト入力 (@context は付与しない)", 49 | "input": { 50 | "@type": "法人型", 51 | "ID": { 52 | "識別値": "4000012090001" 53 | } 54 | }, 55 | "output": { 56 | "@type": "法人型", 57 | "組織種別": { 58 | "@type": "コード型", 59 | "コード種別": { 60 | "@type": "コードリスト型", 61 | "表記": "法人種別" 62 | }, 63 | "識別値": "101", 64 | "表記": "国の機関" 65 | }, 66 | "ID": { 67 | "@type": "ID型", 68 | "体系": { 69 | "@type": "ID体系型", 70 | "表記": "法人番号" 71 | }, 72 | "識別値": "4000012090001" 73 | }, 74 | "表記": "経済産業省", 75 | "名称": { 76 | "@type": "名称型", 77 | "表記": "経済産業省", 78 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 79 | "カナ表記": "ケイザイサンギョウショウ" 80 | }, 81 | "住所": [{ 82 | "@type": "住所型", 83 | "種別": "国内所在地", 84 | "表記": "東京都 千代田区 霞が関1丁目3-1", 85 | "郵便番号": "1000013", 86 | "都道府県": "東京都", 87 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 88 | "市区町村": "千代田区", 89 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 90 | }, { 91 | "@type": "住所型", 92 | "種別": "国内所在地(英語表記)", 93 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 94 | "都道府県": "Tokyo" 95 | }] 96 | } 97 | }, { 98 | "name": "配列入力 (@context は付与しない)", 99 | "input": [{ 100 | "@type": "法人型", 101 | "ID": { 102 | "識別値": "4000012090001" 103 | } 104 | }, { 105 | "@type": "法人型", 106 | "ID": { 107 | "識別値": "2000012100001" 108 | } 109 | }], 110 | "output": [{ 111 | "@type": "法人型", 112 | "組織種別": { 113 | "@type": "コード型", 114 | "コード種別": { 115 | "@type": "コードリスト型", 116 | "表記": "法人種別" 117 | }, 118 | "識別値": "101", 119 | "表記": "国の機関" 120 | }, 121 | "ID": { 122 | "@type": "ID型", 123 | "体系": { 124 | "@type": "ID体系型", 125 | "表記": "法人番号" 126 | }, 127 | "識別値": "4000012090001" 128 | }, 129 | "表記": "経済産業省", 130 | "名称": { 131 | "@type": "名称型", 132 | "表記": "経済産業省", 133 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 134 | "カナ表記": "ケイザイサンギョウショウ" 135 | }, 136 | "住所": [{ 137 | "@type": "住所型", 138 | "種別": "国内所在地", 139 | "表記": "東京都 千代田区 霞が関1丁目3-1", 140 | "郵便番号": "1000013", 141 | "都道府県": "東京都", 142 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 143 | "市区町村": "千代田区", 144 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 145 | }, { 146 | "@type": "住所型", 147 | "種別": "国内所在地(英語表記)", 148 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 149 | "都道府県": "Tokyo" 150 | }] 151 | }, { 152 | "@type": "法人型", 153 | "ID": { 154 | "@type": "ID型", 155 | "体系": { 156 | "@type": "ID体系型", 157 | "表記": "法人番号" 158 | }, 159 | "識別値": "2000012100001" 160 | }, 161 | "住所": [{ 162 | "@type": "住所型", 163 | "市区町村": "千代田区", 164 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101", 165 | "種別": "国内所在地", 166 | "表記": "東京都 千代田区 霞が関2丁目1-3", 167 | "郵便番号": "1000013", 168 | "都道府県": "東京都", 169 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000" 170 | }, 171 | { 172 | "@type": "住所型", 173 | "種別": "国内所在地(英語表記)", 174 | "表記": "2-1-3 kasumigaseki, Chiyoda-ku, Tokyo", 175 | "都道府県": "Tokyo" 176 | } 177 | ], 178 | "名称": { 179 | "@type": "名称型", 180 | "カナ表記": "コクドコウツウショウ", 181 | "ローマ字表記": "Ministry of Land, Infrastructure, Transport and Tourism", 182 | "表記": "国土交通省" 183 | }, 184 | "組織種別": { 185 | "@type": "コード型", 186 | "コード種別": { 187 | "@type": "コードリスト型", 188 | "表記": "法人種別" 189 | }, 190 | "表記": "国の機関", 191 | "識別値": "101" 192 | }, 193 | "表記": "国土交通省" 194 | }] 195 | }] 196 | -------------------------------------------------------------------------------- /bin/server.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | imi-enrichment-hojin 6 | 35 | 36 | 37 | 38 |
39 |

imi-enrichment-hojin

40 | 41 |

このページは imi-enrichment-hojin の WebAPI の動作確認ページです。

42 | 43 |

動作確認

44 |

変換 ボタンを押すとこのブラウザから実際に WebAPI を実行して結果を表示します

45 |
46 |
法人番号(2~9ではじまる13桁数字)
47 |
48 |
JSON
49 |
50 |
実行結果
51 |
52 | 53 |
54 |
55 | 56 |

使用方法

57 | 58 |

現在表示されている URL に POST メソッドを使って法人番号文字列 または JSON を送信すると変換結果の JSON が出力されます。

59 | 60 |

curl

61 |

法人番号文字列を変換する場合には Content-Type: text/plain を指定して POST します

62 |
 63 | $ curl -X POST -H 'Content-Type: text/plain' -d '4000012090001' __ENDPOINT__
 64 | {
 65 |   "@context": "https://imi.go.jp/ns/core/context.jsonld",
 66 |   "@type": "法人型",
 67 |   "組織種別": {
 68 |     "@type": "コード型",
 69 |     "コード種別": {
 70 |       "@type": "コードリスト型",
 71 |       "表記": "法人種別"
 72 |     },
 73 |     "識別値": "101",
 74 |     "表記": "国の機関"
 75 |   },
 76 |   "ID": {
 77 |     "@type": "ID型",
 78 |     "体系": {
 79 |       "@type": "ID体系型",
 80 |       "表記": "法人番号"
 81 |     },
 82 |     "識別値": "4000012090001"
 83 |   },
 84 |   "表記": "経済産業省",
 85 |   "名称": {
 86 |     "@type": "名称型",
 87 |     "表記": "経済産業省",
 88 |     "ローマ字表記": "Ministry of Economy, Trade and Industry",
 89 |     "カナ表記": "ケイザイサンギョウショウ"
 90 |   },
 91 |   "住所": [
 92 |     {
 93 |       "@type": "住所型",
 94 |       "種別": "国内所在地",
 95 |       "表記": "東京都 千代田区 霞が関1丁目3-1",
 96 |       "郵便番号": "1000013",
 97 |       "都道府県": "東京都",
 98 |       "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000",
 99 |       "市区町村": "千代田区",
100 |       "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101"
101 |     },
102 |     {
103 |       "@type": "住所型",
104 |       "種別": "国内所在地(英語表記)",
105 |       "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo",
106 |       "都道府県": "Tokyo"
107 |     }
108 |   ]
109 | }
110 | 
111 | 112 |

JSON を変換する場合には Content-Type: application/json を指定して POST します

113 |
114 | $ curl -X POST -H 'Content-Type: application/json' -d '{"@type":"法人型","ID":{"識別値":"4000012090001"}}' __ENDPOINT__
115 | {
116 |   "@type": "法人型",
117 |   "組織種別": {
118 |     "@type": "コード型",
119 |     "コード種別": {
120 |       "@type": "コードリスト型",
121 |       "表記": "法人種別"
122 |     },
123 |     "識別値": "101",
124 |     "表記": "国の機関"
125 |   },
126 |   "ID": {
127 |     "@type": "ID型",
128 |     "体系": {
129 |       "@type": "ID体系型",
130 |       "表記": "法人番号"
131 |     },
132 |     "識別値": "4000012090001"
133 |   },
134 |   "表記": "経済産業省",
135 |   "名称": {
136 |     "@type": "名称型",
137 |     "表記": "経済産業省",
138 |     "ローマ字表記": "Ministry of Economy, Trade and Industry",
139 |     "カナ表記": "ケイザイサンギョウショウ"
140 |   },
141 |   "住所": [
142 |     {
143 |       "@type": "住所型",
144 |       "種別": "国内所在地",
145 |       "表記": "東京都 千代田区 霞が関1丁目3-1",
146 |       "郵便番号": "1000013",
147 |       "都道府県": "東京都",
148 |       "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000",
149 |       "市区町村": "千代田区",
150 |       "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101"
151 |     },
152 |     {
153 |       "@type": "住所型",
154 |       "種別": "国内所在地(英語表記)",
155 |       "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo",
156 |       "都道府県": "Tokyo"
157 |     }
158 |   ]
159 | }
160 | 
161 | 162 |

browser

163 |

法人番号文字列を変換する場合には Content-Type: text/plain を指定して POST します

164 |
165 | fetch("__ENDPOINT__", {
166 |   method: "POST",
167 |   headers: {
168 |     "Content-Type": "text/plain"
169 |   },
170 |   body: "4000012090001"
171 | }).then(function(response) {
172 |   return response.ok ? response.json() : response.text();
173 | }).then(function(result) {
174 |   console.log(result);
175 | });
176 | 
177 | 178 |

JSON を変換する場合には Content-Type: application/json を指定して POST します

179 | 180 |
181 | fetch("__ENDPOINT__", {
182 |   method: "POST",
183 |   headers: {
184 |     "Content-Type": "application/json"
185 |   },
186 |   body: '{"@type":"法人型","ID":{"識別値":"4000012090001"}}'
187 | }).then(function(response) {
188 |   return response.ok ? response.json() : response.text();
189 | }).then(function(result) {
190 |   console.log(result);
191 | });
192 | 
193 |
194 | 225 | 226 | 227 | 228 | -------------------------------------------------------------------------------- /spec/005-closed.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "01清算の結了等", 3 | "input": "1010001164098", 4 | "output": { 5 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 6 | "@type": "法人型", 7 | "組織種別": { 8 | "@type": "コード型", 9 | "コード種別": { 10 | "@type": "コードリスト型", 11 | "表記": "法人種別" 12 | }, 13 | "識別値": "301", 14 | "表記": "株式会社" 15 | }, 16 | "ID": { 17 | "@type": "ID型", 18 | "体系": { 19 | "@type": "ID体系型", 20 | "表記": "法人番号" 21 | }, 22 | "識別値": "1010001164098" 23 | }, 24 | "表記": "日高エナジー株式会社", 25 | "名称": { 26 | "@type": "名称型", 27 | "表記": "日高エナジー株式会社", 28 | "カナ表記": "ヒダカエナジー" 29 | }, 30 | "住所": { 31 | "@type": "住所型", 32 | "種別": "国内所在地", 33 | "表記": "北海道 様似郡様似町 大通3丁目26番地", 34 | "郵便番号": "0580014", 35 | "都道府県": "北海道", 36 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C01000", 37 | "市区町村": "様似郡様似町", 38 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C01608" 39 | }, 40 | "活動状況": { 41 | "@type": "状況型", 42 | "種別コード": { 43 | "@type": "コード型", 44 | "コード種別": { 45 | "@type": "コードリスト型", 46 | "表記": "登記記録の閉鎖等の事由" 47 | }, 48 | "識別値": "01", 49 | "表記": "清算の結了等" 50 | }, 51 | "日時": { 52 | "@type": "日時型", 53 | "標準型日時": "2019-06-14" 54 | } 55 | } 56 | } 57 | }, { 58 | "name": "11合併による解散等(継承先あり)", 59 | "input": "1430001000814", 60 | "output": { 61 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 62 | "@type": "法人型", 63 | "組織種別": { 64 | "@type": "コード型", 65 | "コード種別": { 66 | "@type": "コードリスト型", 67 | "表記": "法人種別" 68 | }, 69 | "識別値": "301", 70 | "表記": "株式会社" 71 | }, 72 | "ID": { 73 | "@type": "ID型", 74 | "体系": { 75 | "@type": "ID体系型", 76 | "表記": "法人番号" 77 | }, 78 | "識別値": "1430001000814" 79 | }, 80 | "表記": "アテネ店舗企画株式会社", 81 | "名称": { 82 | "@type": "名称型", 83 | "表記": "アテネ店舗企画株式会社" 84 | }, 85 | "住所": { 86 | "@type": "住所型", 87 | "種別": "国内所在地", 88 | "表記": "北海道 札幌市中央区 宮の森四条12丁目2番10号", 89 | "郵便番号": "0640954", 90 | "都道府県": "北海道", 91 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C01000", 92 | "市区町村": "札幌市中央区", 93 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C01101" 94 | }, 95 | "活動状況": { 96 | "@type": "状況型", 97 | "種別コード": { 98 | "@type": "コード型", 99 | "コード種別": { 100 | "@type": "コードリスト型", 101 | "表記": "登記記録の閉鎖等の事由" 102 | }, 103 | "識別値": "11", 104 | "表記": "合併による解散等" 105 | }, 106 | "日時": { 107 | "@type": "日時型", 108 | "標準型日時": "2017-03-02" 109 | }, 110 | "関与": { 111 | "@type": "関与型", 112 | "役割": "継承先法人", 113 | "関与者": { 114 | "@type": "法人型", 115 | "ID": { 116 | "@type": "ID型", 117 | "体系": { 118 | "@type": "ID体系型", 119 | "表記": "法人番号" 120 | }, 121 | "識別値": "2430001000813" 122 | } 123 | } 124 | } 125 | } 126 | } 127 | }, { 128 | "name": "21登記官による閉鎖", 129 | "input": "1430001000343", 130 | "output": { 131 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 132 | "@type": "法人型", 133 | "組織種別": { 134 | "@type": "コード型", 135 | "コード種別": { 136 | "@type": "コードリスト型", 137 | "表記": "法人種別" 138 | }, 139 | "識別値": "301", 140 | "表記": "株式会社" 141 | }, 142 | "ID": { 143 | "@type": "ID型", 144 | "体系": { 145 | "@type": "ID体系型", 146 | "表記": "法人番号" 147 | }, 148 | "識別値": "1430001000343" 149 | }, 150 | "表記": "亜光測量株式会社", 151 | "名称": { 152 | "@type": "名称型", 153 | "表記": "亜光測量株式会社" 154 | }, 155 | "住所": { 156 | "@type": "住所型", 157 | "種別": "国内所在地", 158 | "表記": "北海道 札幌市西区 山の手五条9丁目3番25号", 159 | "郵便番号": "0630005", 160 | "都道府県": "北海道", 161 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C01000", 162 | "市区町村": "札幌市西区", 163 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C01107" 164 | }, 165 | "活動状況": { 166 | "@type": "状況型", 167 | "種別コード": { 168 | "@type": "コード型", 169 | "コード種別": { 170 | "@type": "コードリスト型", 171 | "表記": "登記記録の閉鎖等の事由" 172 | }, 173 | "識別値": "21", 174 | "表記": "登記官による閉鎖" 175 | }, 176 | "日時": { 177 | "@type": "日時型", 178 | "標準型日時": "2019-01-17" 179 | } 180 | } 181 | } 182 | }, { 183 | "name": "31その他の清算の結了等", 184 | "input": "1700150032564", 185 | "output": { 186 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 187 | "@type": "法人型", 188 | "組織種別": { 189 | "@type": "コード型", 190 | "コード種別": { 191 | "@type": "コードリスト型", 192 | "表記": "法人種別" 193 | }, 194 | "識別値": "499", 195 | "表記": "その他" 196 | }, 197 | "ID": { 198 | "@type": "ID型", 199 | "体系": { 200 | "@type": "ID体系型", 201 | "表記": "法人番号" 202 | }, 203 | "識別値": "1700150032564" 204 | }, 205 | "表記": "大丸藤井企業年金基金", 206 | "名称": { 207 | "@type": "名称型", 208 | "表記": "大丸藤井企業年金基金", 209 | "カナ表記": "ダイマルフジイキギヨウネンキンキキン" 210 | }, 211 | "住所": { 212 | "@type": "住所型", 213 | "種別": "国内所在地", 214 | "表記": "北海道 札幌市白石区 菊水三条1丁目8-20", 215 | "郵便番号": "0030803", 216 | "都道府県": "北海道", 217 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C01000", 218 | "市区町村": "札幌市白石区", 219 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C01104" 220 | }, 221 | "活動状況": { 222 | "@type": "状況型", 223 | "種別コード": { 224 | "@type": "コード型", 225 | "コード種別": { 226 | "@type": "コードリスト型", 227 | "表記": "登記記録の閉鎖等の事由" 228 | }, 229 | "識別値": "31", 230 | "表記": "その他の清算の結了等" 231 | }, 232 | "日時": { 233 | "@type": "日時型", 234 | "標準型日時": "2016-11-22" 235 | } 236 | } 237 | } 238 | }, { 239 | "name": "31その他の清算の結了等(継承先あり)", 240 | "input": "8700150031972", 241 | "output": { 242 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 243 | "@type": "法人型", 244 | "組織種別": { 245 | "@type": "コード型", 246 | "コード種別": { 247 | "@type": "コードリスト型", 248 | "表記": "法人種別" 249 | }, 250 | "識別値": "499", 251 | "表記": "その他" 252 | }, 253 | "ID": { 254 | "@type": "ID型", 255 | "体系": { 256 | "@type": "ID体系型", 257 | "表記": "法人番号" 258 | }, 259 | "識別値": "8700150031972" 260 | }, 261 | "表記": "北海道農業会議", 262 | "名称": { 263 | "@type": "名称型", 264 | "表記": "北海道農業会議" 265 | }, 266 | "住所": { 267 | "@type": "住所型", 268 | "種別": "国内所在地", 269 | "表記": "北海道 札幌市中央区 北五条西6丁目1-23北海道通信ビル5F", 270 | "郵便番号": "0600005", 271 | "都道府県": "北海道", 272 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C01000", 273 | "市区町村": "札幌市中央区", 274 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C01101" 275 | }, 276 | "活動状況": { 277 | "@type": "状況型", 278 | "種別コード": { 279 | "@type": "コード型", 280 | "コード種別": { 281 | "@type": "コードリスト型", 282 | "表記": "登記記録の閉鎖等の事由" 283 | }, 284 | "識別値": "31", 285 | "表記": "その他の清算の結了等" 286 | }, 287 | "日時": { 288 | "@type": "日時型", 289 | "標準型日時": "2016-03-31" 290 | }, 291 | "関与": { 292 | "@type": "関与型", 293 | "役割": "継承先法人", 294 | "関与者": { 295 | "@type": "法人型", 296 | "ID": { 297 | "@type": "ID型", 298 | "体系": { 299 | "@type": "ID体系型", 300 | "表記": "法人番号" 301 | }, 302 | "識別値": "1430005012772" 303 | } 304 | } 305 | } 306 | } 307 | } 308 | }] 309 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # imi-enrichment-hojin 2 | 3 | 入力となる JSON-LD に含まれる `ID>識別値 をもつ 法人型` に対して各種のプロパティを補完して返します。 4 | 5 | **input.json** 6 | 7 | ```input.json 8 | { 9 | "@type": "法人型", 10 | "ID" : { 11 | "@type": "ID型", 12 | "識別値" : "4000012090001" 13 | } 14 | } 15 | ``` 16 | 17 | **output.json** 18 | 19 | ```output.json 20 | { 21 | "@type": "法人型", 22 | "組織種別": { 23 | "@type": "コード型", 24 | "コード種別": { 25 | "@type": "コードリスト型", 26 | "表記": "法人種別" 27 | }, 28 | "識別値": "101", 29 | "表記": "国の機関" 30 | }, 31 | "ID": { 32 | "@type": "ID型", 33 | "体系": { 34 | "@type": "ID体系型", 35 | "表記": "法人番号" 36 | }, 37 | "識別値": "4000012090001" 38 | }, 39 | "表記": "経済産業省", 40 | "名称": { 41 | "@type": "名称型", 42 | "表記": "経済産業省", 43 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 44 | "カナ表記": "ケイザイサンギョウショウ" 45 | }, 46 | "住所": [ 47 | { 48 | "@type": "住所型", 49 | "種別": "国内所在地", 50 | "表記": "東京都 千代田区 霞が関1丁目3-1", 51 | "郵便番号": "1000013", 52 | "都道府県": "東京都", 53 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 54 | "市区町村": "千代田区", 55 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 56 | }, 57 | { 58 | "@type": "住所型", 59 | "種別": "国内所在地(英語表記)", 60 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 61 | "都道府県": "Tokyo" 62 | } 63 | ] 64 | } 65 | ``` 66 | 67 | - 補完される情報は [国税庁法人番号公表サイト](https://www.houjin-bangou.nta.go.jp/) で公開されている情報を `法人型` にマッピングしたものとなります 68 | - データソースは [国税庁法人番号公表サイト・基本3情報](https://www.houjin-bangou.nta.go.jp/download/) をダウンロードしたものです 69 | - 本パッケージに添付されているデータは 令和元年12月27日更新 のものになります 70 | - 所与の法人番号に問題がある場合には `メタデータ` プロパティにメッセージが記述されます 71 | 72 | **output_with_error.json** 73 | 74 | ``` 75 | { 76 | "@context": "https://imi.go.jp/ns/core/context.jsonld", 77 | "@type": "法人型", 78 | "ID": { 79 | "@type": "ID型", 80 | "体系": { 81 | "@type": "ID体系型", 82 | "表記": "法人番号" 83 | }, 84 | "識別値": "2876543210987" 85 | }, 86 | "メタデータ": { 87 | "@type": "文書型", 88 | "説明": "該当する法人番号がありません" 89 | } 90 | } 91 | ``` 92 | 93 | 以下のエラーが検出されます 94 | 95 | - 法人番号が 13桁の数字でない場合 96 | - 法人番号の先頭が 2~9 でない場合 97 | - 法人番号のチェックデジットが不正な場合 98 | - 指定された法人番号が存在しない場合 99 | 100 | # 利用者向け情報 101 | 102 | `imi-enrichment-hojin` は node.js のモジュールですが、 103 | 動作のためには後述の環境構築の手順によってバンドルデータベースを構築する必要があります。 104 | 105 | 簡便な動作確認のために、バンドルデータベースを同梱したパッケージアーカイブが 106 | [gBizInfo: IMI コンポーネントツール](https://info.gbiz.go.jp/tools/imi_tools/index.html) のページにて公開されています。 107 | 108 | 以下の手順は同ページで公開されているパッケージアーカイブ `imi-enrichment-hojin-2.0.0.tgz` を用いて実行します。 109 | 110 | ## インストール 111 | 112 | 以下の手順でインストールします。 113 | 114 | ``` 115 | $ npm install https://info.gbiz.go.jp/tools/imi_tools/resource/imi-enrichment-hojin/imi-enrichment-hojin-2.0.0.tgz 116 | ``` 117 | 118 | ## コマンドラインインターフェイス 119 | 120 | `imi-enrichment-hojin-2.0.0.tgz` にはコマンドラインインターフェイスが同梱されており、 121 | 通常はインストールすると `imi-enrichment-hojin` コマンドが使用できるようになります。 122 | 123 | コマンドラインインターフェイスのファイルの実体は `bin/cli.js` です。 124 | 125 | ``` 126 | $ npm install https://info.gbiz.go.jp/tools/imi_tools/resource/imi-enrichment-hojin/imi-enrichment-hojin-2.0.0.tgz 127 | 128 | # ヘルプの表示 129 | $ imi-enrichment-hojin -h 130 | 131 | # JSON ファイルの変換 132 | $ imi-enrichment-hojin input.json > output.json 133 | 134 | # 標準入力からの変換 135 | $ cat input.json | imi-enrichment-hojin > output.json 136 | 137 | # 文字列からの変換 138 | $ imi-enrichment-hojin -s 4000012090001 > output.json 139 | 140 | ``` 141 | 142 | または `npx` を使って以下のようにインストールせずに実行することも可能です。 143 | 144 | ``` 145 | $ npx https://info.gbiz.go.jp/tools/imi_tools/resource/imi-enrichment-hojin/imi-enrichment-hojin-2.0.0.tgz -s 4000012090001 146 | ``` 147 | 148 | ## Web API 149 | 150 | `imi-enrichment-hojin-2.0.0.tgz` には Web API を提供するサーバプログラムが同梱されています。 151 | 152 | ### サーバの起動方法 153 | 154 | `bin/server.js` がサーバの実体です。 155 | 以下のように `bin/server.js` を実行することで起動できます。 156 | 157 | ``` 158 | $ npm install https://info.gbiz.go.jp/tools/imi_tools/resource/imi-enrichment-hojin/imi-enrichment-hojin-2.0.0.tgz 159 | $ node node_modules/imi-enrichment-hojin/bin/server.js 160 | Usage: node server.js [port number] 161 | 162 | $ node node_modules/imi-enrichment-hojin/bin/server.js 8080 163 | imi-enrichment-hojin-server is running on port 8080 164 | ``` 165 | 166 | なお、実行時にはポート番号の指定が必要です。指定しなかった場合にはエラーが表示されて終了します。 167 | サーバを停止するには `Ctrl-C` を入力してください。 168 | 169 | ### 利用方法 170 | 171 | WebAPI は POST された JSON または テキストを入力として JSON を返します。 172 | 173 | ``` 174 | $ curl -X POST -H 'Content-Type: application/json' -d '{"@type":"法人型","ID":{"識別値":"4000012090001"}}' localhost:8080 175 | { 176 | "@type": "法人型", 177 | "組織種別": { 178 | "@type": "コード型", 179 | "コード種別": { 180 | "@type": "コードリスト型", 181 | "表記": "法人種別" 182 | }, 183 | "識別値": "101", 184 | "表記": "国の機関" 185 | }, 186 | "ID": { 187 | "@type": "ID型", 188 | "体系": { 189 | "@type": "ID体系型", 190 | "表記": "法人番号" 191 | }, 192 | "識別値": "4000012090001" 193 | }, 194 | "表記": "経済産業省", 195 | "名称": { 196 | "@type": "名称型", 197 | "表記": "経済産業省", 198 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 199 | "カナ表記": "ケイザイサンギョウショウ" 200 | }, 201 | "住所": [ 202 | { 203 | "@type": "住所型", 204 | "種別": "国内所在地", 205 | "表記": "東京都 千代田区 霞が関1丁目3-1", 206 | "郵便番号": "1000013", 207 | "都道府県": "東京都", 208 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 209 | "市区町村": "千代田区", 210 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 211 | }, 212 | { 213 | "@type": "住所型", 214 | "種別": "国内所在地(英語表記)", 215 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 216 | "都道府県": "Tokyo" 217 | } 218 | ] 219 | } 220 | ``` 221 | 222 | ``` 223 | $ curl -X POST -H 'Content-Type: text/plain' -d '4000012090001' localhost:8080 224 | { 225 | "@type": "法人型", 226 | "組織種別": { 227 | "@type": "コード型", 228 | "コード種別": { 229 | "@type": "コードリスト型", 230 | "表記": "法人種別" 231 | }, 232 | "識別値": "101", 233 | "表記": "国の機関" 234 | }, 235 | "ID": { 236 | "@type": "ID型", 237 | "体系": { 238 | "@type": "ID体系型", 239 | "表記": "法人番号" 240 | }, 241 | "識別値": "4000012090001" 242 | }, 243 | "表記": "経済産業省", 244 | "名称": { 245 | "@type": "名称型", 246 | "表記": "経済産業省", 247 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 248 | "カナ表記": "ケイザイサンギョウショウ" 249 | }, 250 | "住所": [ 251 | { 252 | "@type": "住所型", 253 | "種別": "国内所在地", 254 | "表記": "東京都 千代田区 霞が関1丁目3-1", 255 | "郵便番号": "1000013", 256 | "都道府県": "東京都", 257 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 258 | "市区町村": "千代田区", 259 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 260 | }, 261 | { 262 | "@type": "住所型", 263 | "種別": "国内所在地(英語表記)", 264 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 265 | "都道府県": "Tokyo" 266 | } 267 | ] 268 | } 269 | ``` 270 | 271 | - WebAPI の URL に GET メソッドでアクセスした場合には HTML ページが表示され、WebAPI の動作を確認することができます 272 | - POST,GET 以外のメソッドでアクセスした場合には `405 Method Not Allowed` エラーが返されます 273 | - `Content-Type: application/json` ヘッダが設定されている場合は、POST Body を JSON として扱い、JSON に対しての変換結果を返します 274 | - `Content-Type: application/json` ヘッダが設定されているが POST Body が JSON としてパースできない場合は `400 Bad Request` エラーが返されます 275 | - `Content-Type: application/json` ヘッダが設定されていない場合は、POST Body を法人番号文字列として扱い、法人番号をもとに情報の補完された法人型を返します 276 | 277 | ## API (Node.js) 278 | 279 | モジュール `imi-enrichment-hojin` は以下のような API の関数を提供します。 280 | 281 | ``` 282 | module.exports = function(input) {..} 283 | ``` 284 | 285 | - 入力 (input) : 変換対象となる JSON または法人番号文字列(1~9から始まる13桁の数字) 286 | - 出力 : 変換結果の JSON-LD オブジェクトを返却する Promise ※ 変換は非同期で行うために Promise が返されます 287 | 288 | ``` 289 | const convert = require('imi-enrichment-hojin'); 290 | convert("4000012090001").then(json=>{ 291 | console.log(json); 292 | }); 293 | ``` 294 | 295 | # 開発者向け情報 296 | 297 | ## 準備 298 | 299 | [国税庁法人番号公表サイト・全件データのダウンロード(各都道府県別)](https://www.houjin-bangou.nta.go.jp/download/zenken/) から 300 | **CSV 形式・Unicode** をダウンロードします(47都道府県+国外の全48ファイル)。 301 | ダウンロードしたファイルは `01_hokkaido_all_20191227.zip` のような zip ファイルで、 302 | これらのファイルを `/tmp/zenken/` フォルダに保存するものとします。 303 | 304 | ## 環境構築 305 | 306 | 以下の手順で環境を構築します。 307 | 308 | ``` 309 | $ git clone https://github.com/IMI-Tool-Project/imi-enrichment-hojin.git 310 | $ cd imi-enrichment-hojin 311 | $ npm install 312 | $ mkdir cache 313 | $ cp /tmp/zenken/*.zip cache 314 | $ npm run setup 315 | ``` 316 | 317 | ## テスト 318 | 319 | 以下の手順でテストを実行します 320 | 321 | ``` 322 | $ cd imi-enrichment-hojin 323 | $ npm test 324 | ``` 325 | 326 | 327 | ## ブラウザビルド(参考情報) 328 | 329 | `imi-enrichment-hojin` はブラウザ上での直接動作をサポートしていません。 330 | WebAPI を使用してください。 331 | -------------------------------------------------------------------------------- /spec/004-conflict.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "衝突しないプロパティは維持される", 3 | "input": { 4 | "@type": "法人型", 5 | "略称アルファベット": "METI", 6 | "ID": { 7 | "@type": "ID型", 8 | "体系": { 9 | "@type": "ID体系型", 10 | "表記": "法人番号" 11 | }, 12 | "識別値": "4000012090001" 13 | } 14 | }, 15 | "output": { 16 | "@type": "法人型", 17 | "略称アルファベット": "METI", 18 | "組織種別": { 19 | "@type": "コード型", 20 | "コード種別": { 21 | "@type": "コードリスト型", 22 | "表記": "法人種別" 23 | }, 24 | "識別値": "101", 25 | "表記": "国の機関" 26 | }, 27 | "ID": { 28 | "@type": "ID型", 29 | "体系": { 30 | "@type": "ID体系型", 31 | "表記": "法人番号" 32 | }, 33 | "識別値": "4000012090001" 34 | }, 35 | "表記": "経済産業省", 36 | "名称": { 37 | "@type": "名称型", 38 | "表記": "経済産業省", 39 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 40 | "カナ表記": "ケイザイサンギョウショウ" 41 | }, 42 | "住所": [{ 43 | "@type": "住所型", 44 | "種別": "国内所在地", 45 | "表記": "東京都 千代田区 霞が関1丁目3-1", 46 | "郵便番号": "1000013", 47 | "都道府県": "東京都", 48 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 49 | "市区町村": "千代田区", 50 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 51 | }, { 52 | "@type": "住所型", 53 | "種別": "国内所在地(英語表記)", 54 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 55 | "都道府県": "Tokyo" 56 | }] 57 | } 58 | }, { 59 | "name": "単一リテラル:既存の単一リテラルが所与のリテラルと一致する場合は現状維持", 60 | "input": { 61 | "@type": "法人型", 62 | "表記": "経済産業省", 63 | "ID": { 64 | "@type": "ID型", 65 | "体系": { 66 | "@type": "ID体系型", 67 | "表記": "法人番号" 68 | }, 69 | "識別値": "4000012090001" 70 | } 71 | }, 72 | "output": { 73 | "@type": "法人型", 74 | "組織種別": { 75 | "@type": "コード型", 76 | "コード種別": { 77 | "@type": "コードリスト型", 78 | "表記": "法人種別" 79 | }, 80 | "識別値": "101", 81 | "表記": "国の機関" 82 | }, 83 | "ID": { 84 | "@type": "ID型", 85 | "体系": { 86 | "@type": "ID体系型", 87 | "表記": "法人番号" 88 | }, 89 | "識別値": "4000012090001" 90 | }, 91 | "表記": "経済産業省", 92 | "名称": { 93 | "@type": "名称型", 94 | "表記": "経済産業省", 95 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 96 | "カナ表記": "ケイザイサンギョウショウ" 97 | }, 98 | "住所": [{ 99 | "@type": "住所型", 100 | "種別": "国内所在地", 101 | "表記": "東京都 千代田区 霞が関1丁目3-1", 102 | "郵便番号": "1000013", 103 | "都道府県": "東京都", 104 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 105 | "市区町村": "千代田区", 106 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 107 | }, { 108 | "@type": "住所型", 109 | "種別": "国内所在地(英語表記)", 110 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 111 | "都道府県": "Tokyo" 112 | }] 113 | } 114 | }, { 115 | "name": "単一リテラル:既存の単一リテラルが所与のリテラルと一致しない場合は複数保持", 116 | "input": { 117 | "@type": "法人型", 118 | "表記": "経産省", 119 | "ID": { 120 | "@type": "ID型", 121 | "体系": { 122 | "@type": "ID体系型", 123 | "表記": "法人番号" 124 | }, 125 | "識別値": "4000012090001" 126 | } 127 | }, 128 | "output": { 129 | "@type": "法人型", 130 | "組織種別": { 131 | "@type": "コード型", 132 | "コード種別": { 133 | "@type": "コードリスト型", 134 | "表記": "法人種別" 135 | }, 136 | "識別値": "101", 137 | "表記": "国の機関" 138 | }, 139 | "ID": { 140 | "@type": "ID型", 141 | "体系": { 142 | "@type": "ID体系型", 143 | "表記": "法人番号" 144 | }, 145 | "識別値": "4000012090001" 146 | }, 147 | "表記": ["経産省", "経済産業省"], 148 | "名称": { 149 | "@type": "名称型", 150 | "表記": "経済産業省", 151 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 152 | "カナ表記": "ケイザイサンギョウショウ" 153 | }, 154 | "住所": [{ 155 | "@type": "住所型", 156 | "種別": "国内所在地", 157 | "表記": "東京都 千代田区 霞が関1丁目3-1", 158 | "郵便番号": "1000013", 159 | "都道府県": "東京都", 160 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 161 | "市区町村": "千代田区", 162 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 163 | }, { 164 | "@type": "住所型", 165 | "種別": "国内所在地(英語表記)", 166 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 167 | "都道府県": "Tokyo" 168 | }] 169 | } 170 | }, { 171 | "name": "リテラル配列:既存のリテラル配列に所与のリテラルを含む場合は複数保持", 172 | "input": { 173 | "@type": "法人型", 174 | "表記": ["経済産業省", "METI"], 175 | "ID": { 176 | "@type": "ID型", 177 | "体系": { 178 | "@type": "ID体系型", 179 | "表記": "法人番号" 180 | }, 181 | "識別値": "4000012090001" 182 | } 183 | }, 184 | "output": { 185 | "@type": "法人型", 186 | "組織種別": { 187 | "@type": "コード型", 188 | "コード種別": { 189 | "@type": "コードリスト型", 190 | "表記": "法人種別" 191 | }, 192 | "識別値": "101", 193 | "表記": "国の機関" 194 | }, 195 | "ID": { 196 | "@type": "ID型", 197 | "体系": { 198 | "@type": "ID体系型", 199 | "表記": "法人番号" 200 | }, 201 | "識別値": "4000012090001" 202 | }, 203 | "表記": ["経済産業省", "METI"], 204 | "名称": { 205 | "@type": "名称型", 206 | "表記": "経済産業省", 207 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 208 | "カナ表記": "ケイザイサンギョウショウ" 209 | }, 210 | "住所": [{ 211 | "@type": "住所型", 212 | "種別": "国内所在地", 213 | "表記": "東京都 千代田区 霞が関1丁目3-1", 214 | "郵便番号": "1000013", 215 | "都道府県": "東京都", 216 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 217 | "市区町村": "千代田区", 218 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 219 | }, { 220 | "@type": "住所型", 221 | "種別": "国内所在地(英語表記)", 222 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 223 | "都道府県": "Tokyo" 224 | }] 225 | } 226 | }, { 227 | "name": "リテラル配列:既存のリテラル配列に所与のリテラルを含まない場合は末尾に追加", 228 | "input": { 229 | "@type": "法人型", 230 | "表記": ["経産省", "METI"], 231 | "ID": { 232 | "@type": "ID型", 233 | "体系": { 234 | "@type": "ID体系型", 235 | "表記": "法人番号" 236 | }, 237 | "識別値": "4000012090001" 238 | } 239 | }, 240 | "output": { 241 | "@type": "法人型", 242 | "組織種別": { 243 | "@type": "コード型", 244 | "コード種別": { 245 | "@type": "コードリスト型", 246 | "表記": "法人種別" 247 | }, 248 | "識別値": "101", 249 | "表記": "国の機関" 250 | }, 251 | "ID": { 252 | "@type": "ID型", 253 | "体系": { 254 | "@type": "ID体系型", 255 | "表記": "法人番号" 256 | }, 257 | "識別値": "4000012090001" 258 | }, 259 | "表記": ["経産省", "METI", "経済産業省"], 260 | "名称": { 261 | "@type": "名称型", 262 | "表記": "経済産業省", 263 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 264 | "カナ表記": "ケイザイサンギョウショウ" 265 | }, 266 | "住所": [{ 267 | "@type": "住所型", 268 | "種別": "国内所在地", 269 | "表記": "東京都 千代田区 霞が関1丁目3-1", 270 | "郵便番号": "1000013", 271 | "都道府県": "東京都", 272 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 273 | "市区町村": "千代田区", 274 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 275 | }, { 276 | "@type": "住所型", 277 | "種別": "国内所在地(英語表記)", 278 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 279 | "都道府県": "Tokyo" 280 | }] 281 | } 282 | }, { 283 | "name": "単一オブジェクト:既存のオブジェクトが所与のオブジェクトと完全一致する場合は現状維持", 284 | "input": { 285 | "@type": "法人型", 286 | "名称": { 287 | "@type": "名称型", 288 | "表記": "経済産業省", 289 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 290 | "カナ表記": "ケイザイサンギョウショウ" 291 | }, 292 | "ID": { 293 | "@type": "ID型", 294 | "体系": { 295 | "@type": "ID体系型", 296 | "表記": "法人番号" 297 | }, 298 | "識別値": "4000012090001" 299 | } 300 | }, 301 | "output": { 302 | "@type": "法人型", 303 | "組織種別": { 304 | "@type": "コード型", 305 | "コード種別": { 306 | "@type": "コードリスト型", 307 | "表記": "法人種別" 308 | }, 309 | "識別値": "101", 310 | "表記": "国の機関" 311 | }, 312 | "ID": { 313 | "@type": "ID型", 314 | "体系": { 315 | "@type": "ID体系型", 316 | "表記": "法人番号" 317 | }, 318 | "識別値": "4000012090001" 319 | }, 320 | "表記": "経済産業省", 321 | "名称": { 322 | "@type": "名称型", 323 | "表記": "経済産業省", 324 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 325 | "カナ表記": "ケイザイサンギョウショウ" 326 | }, 327 | "住所": [{ 328 | "@type": "住所型", 329 | "種別": "国内所在地", 330 | "表記": "東京都 千代田区 霞が関1丁目3-1", 331 | "郵便番号": "1000013", 332 | "都道府県": "東京都", 333 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 334 | "市区町村": "千代田区", 335 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 336 | }, { 337 | "@type": "住所型", 338 | "種別": "国内所在地(英語表記)", 339 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 340 | "都道府県": "Tokyo" 341 | }] 342 | } 343 | }, { 344 | "name": "単一オブジェクト:既存のオブジェクトが所与のオブジェクトと完全一致しない場合は現状維持", 345 | "input": { 346 | "@type": "法人型", 347 | "名称": { 348 | "@type": "名称型", 349 | "表記": "経済産業省", 350 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 351 | "カナ表記": "ケイザイサンギョウショウ" 352 | }, 353 | "ID": { 354 | "@type": "ID型", 355 | "体系": { 356 | "@type": "ID体系型", 357 | "表記": "法人番号" 358 | }, 359 | "識別値": "4000012090001" 360 | } 361 | }, 362 | "output": { 363 | "@type": "法人型", 364 | "組織種別": { 365 | "@type": "コード型", 366 | "コード種別": { 367 | "@type": "コードリスト型", 368 | "表記": "法人種別" 369 | }, 370 | "識別値": "101", 371 | "表記": "国の機関" 372 | }, 373 | "ID": { 374 | "@type": "ID型", 375 | "体系": { 376 | "@type": "ID体系型", 377 | "表記": "法人番号" 378 | }, 379 | "識別値": "4000012090001" 380 | }, 381 | "表記": "経済産業省", 382 | "名称": { 383 | "@type": "名称型", 384 | "表記": "経済産業省", 385 | "ローマ字表記": "Ministry of Economy, Trade and Industry", 386 | "カナ表記": "ケイザイサンギョウショウ" 387 | }, 388 | "住所": [{ 389 | "@type": "住所型", 390 | "種別": "国内所在地", 391 | "表記": "東京都 千代田区 霞が関1丁目3-1", 392 | "郵便番号": "1000013", 393 | "都道府県": "東京都", 394 | "都道府県コード": "http://data.e-stat.go.jp/lod/sac/C13000", 395 | "市区町村": "千代田区", 396 | "市区町村コード": "http://data.e-stat.go.jp/lod/sac/C13101" 397 | }, { 398 | "@type": "住所型", 399 | "種別": "国内所在地(英語表記)", 400 | "表記": "1-3-1, Kasumigaseki, Chiyoda ku, Tokyo", 401 | "都道府県": "Tokyo" 402 | }] 403 | } 404 | }] 405 | --------------------------------------------------------------------------------