// Convert convert text to yazawanized sentence func Convert(text string, atRandom bool) string { tagger, err := mecab.New(map[string]string{}) if err != nil { panic(err) } defer tagger.Destroy() tagger.Parse("") node, err := tagger.ParseToNode(text) if err != nil { panic(err) } id := findSuitableIndexForReplace(node, atRandom) convertedSentence := []string{} for ; node != (mecab.Node{}); node = node.Next() { if node.Id() == id { feature := strings.Split(node.Feature(), ",") convertedSentence = append(convertedSentence, "『"+strings.ToUpper(kana.KanaToRomaji(feature[len(feature)-2]))+"』") } else { convertedSentence = append(convertedSentence, node.Surface()) } } return strings.Join(convertedSentence, "") }
func main() { if kana.IsLatin(os.Args[1]) { os.Stdout.Write([]byte(kana.RomajiToHiragana(os.Args[1]) + "\n")) } if kana.IsKana(os.Args[1]) { os.Stdout.Write([]byte(kana.KanaToRomaji(os.Args[1]) + "\n")) } }