Plugins¶
helloworld¶
-
kanjidb.builder.plugins.helloworld.run(outputs=None, *, kwargs=None)[source]¶ Write “今日わ” to streams.
Configuration:
run: - helloworld: outputs: - type: stream|var [separator: string] # stream only [encoding: string] # stream only [path: string] # stream only [name: string] # var only
Write to stdout:
run: - helloworld: {}
Python equivalent:
from kanjidb.builder.plugins import helloworld helloworld.run()
Store to result:
run: - helloworld: outputs: - type: var name: result
Python equivalent:
from kanjidb.builder.plugins import helloworld result = helloworld.run()
- Parameters
outputs – output streams
kwargs – context
- Returns
a list containing [“今”, “日”, “わ”]
kanjidic2¶
-
kanjidb.builder.plugins.kanjidic2.run(inputs, outputs=None, *, kd2_file, kwargs=None)[source]¶ Produce a JSON dict containing kanjis data from a Kanjidic2 XML file (download here).
Kanjidic2 contains the whole dictionary, but only kanjis read from input streams are generated.
Configuration:
run: - kanjidic2: kd2_file: string inputs: - type: stream|var [separator: string] # stream only [encoding: string] # stream only [path: string] # stream only [name: string] # var only outputs: - type: stream|var [path: string] # stream only [indent: int] # stream only [name: string] # var only
Generate data for kanjis read from stdin:
run: - kanjidic2: kd2_file: path/to/kanjidic2.xml inputs: - type: stream encoding: utf8 separator: "\n" path: "-" outputs: - type: var name: result
Python equivalent:
from kanjidb.builder.plugins import kanjidic2 result = kanjidic2.run( kd2_file="path/to/kanjidic2.xml", inputs=[{ "type": "stream", "encoding": "utf8", "separator": "\n", "path": "-" }] )
Read kanjis from file and export generated data to file:
run: - kanjidic2: kd2_file: path/to/kanjidic2.xml inputs: - type: stream encoding: utf8 separator: "\n" path: path/to/kanjis.txt outputs: - type: stream indent: 4 path: path/to/db.json
Python equivalent:
from kanjidb.builder.plugins import kanjidic2 kanjidic2.run( kd2_file="path/to/kanjidic2.xml", inputs=[{ "type": "stream", "encoding": "utf8", "separator": "\n", "path": "path/to/kanjis.txt" }], outputs=[{ "type": "stream", "indent": 4, "path": "path/to/db.json" }] )
- Parameters
inputs – input streams
output – output streams
kwargs – context
- Returns
a JSON object with kanjis data
kanjisvg¶
-
kanjidb.builder.plugins.kanjisvg.run(inputs, outputs=None, *, svg_input_dir, base_url, svg_output_dir=None, kwargs=None)[source]¶ Add SVG representation of kanjis to database.
Given a directory containing:
- 04e00.svg - 04e8c.svg - ...
And a JSON kanji database such as:
{ "04e00": {...}, "04e8c": {...} }
This plugin inject SVG URLs into database:
{ "04e00": { "media": { "svg": "base_url/04e00.svg" }, ... }, "04e8c": { "media": { "svg": "base_url/04e8c.svg" }, ... } }
SVG files corresponding to kanjis present in database are copied to svg_output_dir.
Configuration:
run: - kanjisvg: svg_input_dir: string svg_output_dir: string base_url: string inputs: - type: stream|var [separator: string] # stream only [encoding: string] # stream only [path: string] # stream only [name: string] # var only outputs: - type: stream|var [path: string] # stream only [indent: int] # stream only [name: string] # var only
Combine with kanjidic2:
run: - kanjidic2: kd2_file: path/to/kanjidic2.xml inputs: - type: stream encoding: utf8 separator: "\n" path: "-" outputs: - type: var name: result - kanjisvg: svg_input_dir: path/to/svgs/ svg_output_dir: path/to/cdn/ base_url: http://cdn.com/ inputs: - type: var name: result outputs: - type: stream indent: 4 path: path/to/db.json
- Parameters
inputs – input streams
output – output streams
svg_input_dir – directory containing SVG files
svg_output_dir – where to copy SVG files
base_url – base URL to access SVG files
kwargs – context
- Returns
a JSON object with kanjis data
kanjistream¶
-
kanjidb.builder.plugins.kanjistream.run(inputs, outputs=None, *, kwargs=None)[source]¶ Read/write kanjis from/to streams.
Given an input stream containing one unicode encoded kanji per line such as:
U+4E00 U+4E8C ...
This plugin will produce a list containing:
["一", "二", ...]
Configuration:
run: - kanjistream: inputs: - type: stream|var [separator: string] # stream only [encoding: string] # stream only [path: string] # stream only [name: string] # var only outputs: - type: stream|var [separator: string] # stream only [encoding: string] # stream only [path: string] # stream only [name: string] # var only
Read from stdin and store to result:
run: - kanjistream: inputs: - type: stream encoding: utf8 separator: "\n" path: "-" outputs: - type: var name: result
Python equivalent:
from kanjidb.builder.plugins import kanjistream result = kanjistream.run( inputs=[{ "type": "stream", "encoding": "utf8", "separator": "\n", "path": "-" }] )
Get from result and write to stdout:
run: - kanjistream: inputs: - type: var name: result outputs: - type: stream encoding: utf8 separator: "\n" path: "-"
Python equivalent:
from kanjidb.builder.plugins import kanjistream kanjistream.run( inputs=[{ "type": "var", "name": "result" }], outputs=[{ "type": "stream", "encoding": "utf8", "separator": "\n", "path": "-" }], kwargs={"result": ["一", "二"]} )
- Parameters
inputs – input streams
output – output streams
kwargs – context
- Returns
a list of kanjis read from input streams
jsonstream¶
-
kanjidb.builder.plugins.jsonstream.run(inputs, outputs=None, *, kwargs=None)[source]¶ Read/write JSON objects from/to streams.
Configuration:
run: - jsonstream: inputs: - type: stream|var [path: string] # stream only [name: string] # var only outputs: - type: stream|var [path: string] # stream only [indent: int] # stream only [name: string] # var only
Read from stdin and store to result:
run: - jsonstream: inputs: - type: stream path: "-" outputs: - type: var name: result
Python equivalent:
from kanjidb.builder.plugins import jsonstream result = jsonstream.run( inputs=[{ "type": "stream", "path": "-" }] )
Get from result and write to stdout:
run: - jsonstream: inputs: - type: var name: result outputs: - type: stream indent: 4 path: "-"
Python equivalent:
from kanjidb.builder.plugins import jsonstream jsonstream.run( inputs=[{ "type": "var", "name": "result" }], outputs=[{ "type": "stream", "indent": 4, "path": "-" }], kwargs={"result": {...}} )
- Parameters
inputs – input streams
outputs – output streams
kwargs – context
- Returns
a JSON object read from input streams
mergedict¶
-
kanjidb.builder.plugins.mergedict.run(inputs, output=None, *, kwargs=None)[source]¶ Merge multiple JSON dicts to a single one.
Configuration:
run: - mergedict: inputs: - string output: string
Merge dicts from “first” and “second” variables to “result”:
run: - mergedict: inputs: - first - second output: result
Python equivalent:
from kanjidb.builder.plugins import mergedict result = mergedict.run( inputs=["first", "second"], kwargs={"first": {...}, "second": {...}} )
- Parameters
inputs – input vars
output – output var
kwargs – context
- Returns
merged JSON dict