├── 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 の WebAPI の動作確認ページです。
42 | 43 |変換 ボタンを押すとこのブラウザから実際に WebAPI を実行して結果を表示します
45 |現在表示されている URL に POST メソッドを使って法人番号文字列 または JSON を送信すると変換結果の JSON が出力されます。
法人番号文字列を変換する場合には Content-Type: text/plain を指定して POST します
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 します
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 | 法人番号文字列を変換する場合には Content-Type: text/plain を指定して POST します
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 します
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 |