# \[ANN\] NKFtool - a Julia package for converting encodings in Japanese texts using nkf

**URL:** https://discourse.julialang.org/t/ann-nkftool-a-julia-package-for-converting-encodings-in-japanese-texts-using-nkf/36383
**Category:** Package Announcements
**Tags:** announcement, data
**Created:** [March 23, 2020, 9:55am UTC](https://discourse.julialang.org/t/ann-nkftool-a-julia-package-for-converting-encodings-in-japanese-texts-using-nkf/36383 "2020-03-23T09:55:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hiroharu\_Sugawara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hiroharu_sugawara/32/9400_2.png) [@Hiroharu\_Sugawara](https://discourse.julialang.org/u/Hiroharu_Sugawara)
#### Post date: [March 23, 2020, 9:55am UTC](https://discourse.julialang.org/t/ann-nkftool-a-julia-package-for-converting-encodings-in-japanese-texts-using-nkf/36383/1 "2020-03-23T09:55:10Z")

</div>

I am happy to announce the release of my first package “NKFtool.” which is a wrapper for a command-line tool called network kanji filter, aka, nkf ([nkf Network Kanji Filter Project Top Page - OSDN](https://osdn.net/projects/nkf/)), having been developed over three decades. This package allows you to guess the encoding of Japanese texts and convert them to each other.

This package offers two functions: nkf\_guess and nkf\_convert.

![NKFtool-overview](https://global.discourse-cdn.com/julialang/original/3X/6/0/60fdedf2196f35cca9b71166f4db0103622cbf7a.png)

Use nkf\_guess to guess the encoding of a string:

> julia\> use NKFtool
> 
> julia\> nkf\_guess(raw"こんにちわ")  
> “UTF-8”

Use “nkf\_convert” to convert the encodings. It takes two parameters: the first one is the input string, and the second one is the directive of the conversion. You don’t have to specify the input encoding because “nkf” can guess it.

> julia\> nkf\_convert( raw"こんにちわ", “-s”) |\> nkf\_guess  
> “Shift\_JIS”

Use “nkf\_convert” function without the second argument to convert to UTF-8 because the default second parameter is “-w -m0” (to UTF-8, no MIME decode).  
The “nkf\_guess” and “nkf\_convert” functions also accept an input stream for the first argument, where the inputs may come from an input stream, such as a file

See the following example:

> 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”
> 
> julia\> hello\_utf=open(“hello\_sjis.txt”) do f  
> nkf\_convert(f) # ⇐ Convert to UTF-8  
> end  
> “こんにちわ”

This package requires “nkf” installed in your system.  
Consult the documentation:  
In English → [Guide · NKFtool.jl](https://hsugawa8651.github.io/NKFtool.jl/dev/man/guide/)  
In Japanese → [手引き · NKFtool.jl](https://hsugawa8651.github.io/NKFtool.jl/dev/man/guideja/)

I welcome your feedback, bug reports, suggestions, and PRs.

GitHub → [GitHub - hsugawa8651/NKFtool.jl: NKFtool: Julia package for converting encodings in Japanese texts using nkf](https://github.com/hsugawa8651/NKFtool.jl)
