Public Documentation
NKFtool.NKFtool
— ModuleNKFtool
Julia package to guess and convert encodings of Japanese characters. This is a wrapper to Network kanji filter, aka nkf, and provides the interface to use nkf command installed in your system from Julia.
NKFtool requires nkf to be installed in your system. Major Unix-like operating systems offer its precompiled version in their package management systems.
NKF information
NKFtool.nkf_version
— Methodnkf_version()
Print the version message of nkf command. The same as the output of nkf --version
command.
Examples
julia> nkf_version() |> print
Network Kanji Filter Version 2.1.5 (2018-12-15)
Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa).
Copyright (C) 1996-2018, The nkf Project.
NKFtool.nkf_help
— Methodnkf_help()
Print the help message of nkf command. The same as the output of nkf --help
command.
Examples
julia> nkf_help() |> print
Guess an encoding
NKFtool.nkf_guess
— Methodnkf_guess(from::String)
Try to guess the encoding of the input text from
, and return a string representing its encoding, which is just the result of the command line echo <from> | nkf -g
.
Examples
julia> nkf_guess(raw"こんにちわ")
"UTF-8"
julia> nkf_convert( raw"こんにちわ", "-j") |> nkf_guess
"ISO-2022-JP"
julia> nkf_convert( raw"こんにちわ", "-e") |> nkf_guess
"EUC-JP"
julia> nkf_convert( raw"こんにちわ", "-s") |> nkf_guess
"Shift_JIS"
NKFtool.nkf_guess
— Methodnkf_guess(from::IO)
Try to guess the encoding of the input stream from
, and return a string representing its encoding.
Examples
julia> nkf_guess(IOBuffer(raw"こんにちわ"))
"UTF-8"
julia> open("hello_sjis.txt","w") do f
print(f, nkf_convert(raw"こんにちわ", "-s"))
end
#
encoding=open("hello_sjis.txt") do f
nkf_guess(f)
end
"Shift_JIS"
Convert an encoding
NKFtool.nkf_convert
— Functionnkf_convert(from::String, options="-w -m0")
Convert the input string from
to the encoding specified by the option directive options
, and return the output text string, which is just the result of the command line echo <from> | nkf <options>
.
Arguments
from::String
: the input stringoptions::String
: the option directive to be passed to nkf command.- Output encoding
-j
: ISO-2022-JP-s
: Shift_JIS-e
: EUC-JP-w[8[0],{16,32}[{B,L}[0]]]
: UTF with options
- Input encoding
-J
: ISO-2022-JP-S
: Shift_JIS-E
: EUC-JP-W[8,[16,32][B,L]]
: UTF with option
- MIME decode :
-m[BQSN0]
- B:base64
- Q:quoted
- S:strict
- N:nonstrict
- 0:no decode
- MIME encode :
-M[BQ]
- B:base64
- Q:quoted
- Output encoding
Examples
julia> nkf_convert(raw"こんにちわ", "-w -m0")
"こんにちわ"
julia> using Base64
julia> nkf_convert( raw"こんにちわ", "-j") |> base64encode
"GyRCJDMkcyRLJEEkbxsoQg=="
julia> String(base64decode(ans)) |> nkf_convert
"こんにちわ"
NKFtool.nkf_convert
— Functionnkf_convert(from::IO, options="-w -m0")
Convert the input stream from
to the encoding specified by the option directive options
, and return the output text string, which is just the result of the command line cat <from> | nkf <options>
Arguments
text::String
: the input stringoptions::String
: the directibr to be passed to nkf command. Seenkf_convert(from::String, options="-w -m0")
Examples
julia> open("hello_sjis.txt","w") do f
print(f, nkf_convert(raw"こんにちわ", "-s"))
end
#
hello_utf=open("hello_sjis.txt") do f
nkf_convert(f, "-w -m0")
end
"こんにちわ"