Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Cutano committed Sep 9, 2020
1 parent 93647e7 commit 05f3797
Showing 1 changed file with 110 additions and 3 deletions.
113 changes: 110 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

Kawazu is a C# library for converting Japanese sentence to Hiragana, Katakana or Romaji with furigana and okurigana modes supported. Inspired by project Kuroshiro.

| Package | NuGet ID | NuGet Status |
| :-----: | :---------------------------------------------: | :----------------------------------------------------------: |
| Kawazu | [Kawazu](https://www.nuget.org/packages/Kawazu) | [![Stat](https://img.shields.io/nuget/v/Kawazu.svg)](https://www.nuget.org/packages/Kawazu) |



## Features

- Japanese Sentence => Hiragana, Katakana or Romaji
Expand All @@ -15,13 +21,17 @@ Kawazu is a C# library for converting Japanese sentence to Hiragana, Katakana or

### Install

The package can be installed by **Nuget**:
The package can be installed by **NuGet**:

`Install-Package Kawazu -Version 1.0.0`
```powershell
Install-Package Kawazu -Version 1.0.0
```

Or reference it in your project:

`<PackageReference Include="Kawazu" Version="1.0.0" />`
```xml
<PackageReference Include="Kawazu" Version="1.0.0" />
```

The package size is **over 50MB** for it contains dictionary file, please take this in to account when you are building a **size-sensitive** project.

Expand Down Expand Up @@ -57,5 +67,102 @@ private static async Task Main(string[] args)
}
```

See the demo [Kawazu-Cli](https://github.com/Cutano/Kawazu/tree/master/Kawazu-Cli) for more details.

### Advanced Usage

#### KawazuConverter Class

Method “**Convert**” accepts six parameters, the last five of which are optional. The **first** parameter is the original Japanese string, the **second** one is the target form of the sentence, the **third** one is the presentation method of the result, the **forth** one is the writing systems of romaji and the **last two** are delimiters. It will return the result string as a async task.

Method “**GetDivisions**” accepts exactly the same six parameters as “Convert”, but returns the raw result from the word Separator.

#### Division Class

Represents the division from the word separator.

#### JapaneseElement Class

A single reading element in a Japanese sentence.
For example, in sentence "今日の映画は面白かった。"
"今日","の","映画","は","面白","か","っ","た" are all JapaneseElement in this condition.
For each of them represents a unit of pronunciation.

#### Utilities Class

Provides several useful Japanese utilities.

### Typical Usage

The code below shows the typical usage of Kawazu converter in a command line application.

*C# language level: 8*

```c#
private static async Task Main(string[] args)
{
Console.WriteLine("Kawazu-Cli Japanese Converter Version 1.0.0");
Console.WriteLine("Type 'exit' to quit");
Console.WriteLine();

var converter = new KawazuConverter();

while (true)
{
Console.WriteLine("Original Japanese Sentence:");
Console.Write("> ");
var str = Console.ReadLine();
if (string.IsNullOrWhiteSpace(str))
{
continue;
}

if (str == "exit")
{
return;
}

Console.WriteLine("Target form ('1':Romaji '2':Hiragana '3':Katakana Default:Hiragana):");
Console.Write("> ");
var toStr = Console.ReadLine();
var to = toStr switch
{
"1" => To.Romaji,
"2" => To.Hiragana,
"3" => To.Katakana,
_ => To.Hiragana
};

Console.WriteLine("Presentation mode ('1':Normal '2':Spaced '3':Okurigana '4':Furigana Default:Okurigana):");
Console.Write("> ");
var modeStr = Console.ReadLine();
var mode = modeStr switch
{
"1" => Mode.Normal,
"2" => Mode.Spaced,
"3" => Mode.Okurigana,
"4" => Mode.Furigana,
_ => Mode.Okurigana
};

var system = RomajiSystem.Hepburn;
if (to == To.Romaji)
{
Console.WriteLine("Romaji system ('1':Nippon '2':Passport '3':Hepburn Default:Hepburn):");
Console.Write("> ");
var systemStr = Console.ReadLine();
system = systemStr switch
{
"1" => RomajiSystem.Nippon,
"2" => RomajiSystem.Passport,
"3" => RomajiSystem.Hepburn,
_ => RomajiSystem.Hepburn
};
}
var result = await converter.Convert(str, to, mode, system, "(", ")");
Console.WriteLine(result);
Console.WriteLine();
}
}
```

0 comments on commit 05f3797

Please sign in to comment.