Exemple #1
0
 public void CantRomanizeWithInvalidMethod()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => WanaKana.ToRomaji("つじぎり", new WanaKanaOptions()
     {
         Romanization = (RomanizationType)6
     }));
 }
        /// <summary>
        /// 分句转为罗马音
        /// </summary>
        /// <param name="str"></param>
        /// <param name="isSpace"></param>
        /// <returns></returns>
        public static string UnitToRomaji(string str, bool isSpace)
        {
            var list = _tagger.ParseToNodes(str);

            var result = "";

            foreach (var item in list)
            {
                var nextFeatures = item.Next?.Feature?.Split(',') ?? new string[] { };
                var space        = (!isSpace || nextFeatures.Length <= 6 || new string[] { "記号", "補助記号" }.Contains(nextFeatures[0] ?? "記号")) ? "" : " ";
                if (item.CharType > 0)
                {
                    string[] features;
                    features = item.Feature.Split(',');
                    if (TryCustomConvert(item.Surface, out var customResult))
                    {
                        //用户自定义词典
                        result += customResult;
                    }
                    else if (features.Length > 0 && features[0] != "助詞" && IsJapanese(item.Surface))
                    {
                        //纯假名
                        result += WanaKana.ToRomaji(item.Surface) + space;
                    }
                    else if (features.Length <= 6 || new string[] { "補助記号" }.Contains(features[0]))
                    {
                        //标点符号
                        result += item.Surface;
                    }
                    else if (IsEnglish(item.Surface))
                    {
                        //英文
                        result += item.Surface;
                    }
                    else
                    {
                        //汉字
                        result += WanaKana.ToRomaji(features[ChooseIndexByType(features[0])]) + space;
                    }
                }
                else if (item.Stat != MeCabNodeStat.Bos)
                {
                    result += item.Surface + space;
                }
            }

            if (result.LastIndexOf(' ') == -1)
            {
                return(result);
            }

            if (result.LastIndexOf(' ') == result.Length - 1)
            {
                result = result.Substring(0, result.Length - 1);
            }

            return(result);
        }
Exemple #3
0
        public void ToRomajiWithUppercasing()
        {
            var result = WanaKana.ToRomaji("ワニカニ", new WanaKanaOptions()
            {
                UppercaseKatakana = true
            });

            Assert.Equal("WANIKANI", result);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var words = File.ReadAllLines(args.Length == 0 ? "words.txt" : args[0]);

            var           hepburnConverter = new HepburnConverter();
            List <string> kanaStrings      = new List <string>();
            List <string> romajiStrings    = new List <string>();

            try
            {
                var ifeLang = Activator.CreateInstance(Type.GetTypeFromProgID("MSIME.Japan")) as IFELanguage;
                int hr      = ifeLang.Open();
                if (hr != 0)
                {
                    throw Marshal.GetExceptionForHR(hr);
                }

                foreach (var item in words)
                {
                    hr = ifeLang.GetPhonetic(item, 1, -1, out var yomigana);
                    if (hr != 0)
                    {
                        throw Marshal.GetExceptionForHR(hr);
                    }

                    if (string.IsNullOrWhiteSpace(item))
                    {
                        Console.WriteLine();
                    }
                    else
                    {
                        Console.WriteLine("Origin:" + item);
                        Console.WriteLine("Kana:" + yomigana);
                        var ganaSpace = "";
                        foreach (var word in yomigana)
                        {
                            ganaSpace += word + " ";
                        }
                        Console.WriteLine("Romaji:" + WanaKana.ToRomaji(hepburnConverter, ganaSpace));

                        kanaStrings.Add(yomigana);
                        romajiStrings.Add(WanaKana.ToRomaji(hepburnConverter, ganaSpace));
                    }
                }

                File.AppendAllLines("kana.txt", kanaStrings);
                File.AppendAllLines("romaji.txt", romajiStrings);

                Console.WriteLine("----------------");
                Console.WriteLine("Done!");
                Console.ReadLine();
            }
            catch (COMException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemple #5
0
        public void CustomRomajiMapping()
        {
            var result = WanaKana.ToRomaji("つじぎり", new WanaKanaOptions()
            {
                CustomRomajiMapping = { { "じ", "zi" }, { "つ", "tu" }, { "り", "li" } }
            });

            Assert.Equal("tuzigili", result);
        }
Exemple #6
0
        public void ToRomajiWithUppercasingMixed()
        {
            var result = WanaKana.ToRomaji("ワニカニ が すごい だ", new WanaKanaOptions()
            {
                UppercaseKatakana = true
            });

            Assert.Equal("WANIKANI ga sugoi da", result);
        }
Exemple #7
0
 public void KatakanaToRomaji()
 {
     foreach (var(_, katakana, romaji) in ConversionTables.HiraganaKatakanaToRomaji)
     {
         if (!string.IsNullOrEmpty(katakana))
         {
             var result = WanaKana.ToRomaji(katakana);
             Assert.Equal(romaji, result);
         }
     }
 }
Exemple #8
0
        public void ConvertWithCustomMapping()
        {
            {
                var customMapping = new Trie <char, string>();
                var root          = customMapping.Root;
                root.Insert(('い', "i"));
                root['い'].Insert(('ぬ', "dog"));

                Assert.AreEqual("inu", WanaKana.ToRomaji("いぬ"));
                Assert.AreEqual("dog", WanaKana.ToRomaji("いぬ", customRomajiMapping: customMapping));
            }
        }
Exemple #9
0
 public UOto(Oto oto, UOtoSet set)
 {
     Alias       = oto.Name;
     Set         = set.Name;
     File        = Path.Combine(set.Location, oto.Wav);
     Offset      = oto.Offset;
     Consonant   = oto.Consonant;
     Cutoff      = oto.Cutoff;
     Preutter    = oto.Preutter;
     Overlap     = oto.Overlap;
     SearchTerms = new List <string>();
     SearchTerms.Add(Alias.ToLowerInvariant().Replace(" ", ""));
     SearchTerms.Add(WanaKana.ToRomaji(Alias).ToLowerInvariant().Replace(" ", ""));
 }
Exemple #10
0
        public USinger(Voicebank voicebank, string singersPath)
        {
            Name      = voicebank.Name;
            Author    = voicebank.Author;
            Web       = voicebank.Web;
            OtherInfo = voicebank.OtherInfo;
            Location  = Path.GetDirectoryName(voicebank.File);
            if (!string.IsNullOrEmpty(voicebank.Image))
            {
                Avatar = Path.Combine(Location, voicebank.Image);
                try {
                    using (var stream = new FileStream(Avatar, FileMode.Open)) {
                        using (var memoryStream = new MemoryStream()) {
                            stream.CopyTo(memoryStream);
                            AvatarData = memoryStream.ToArray();
                        }
                    }
                } catch (Exception e) {
                    AvatarData = null;
                    Log.Error(e, "Failed to load avatar data.");
                }
            }
            if (voicebank.PrefixMap != null)
            {
                PrefixMap = voicebank.PrefixMap.Map;
            }
            else
            {
                PrefixMap = new Dictionary <string, Tuple <string, string> >();
            }
            OtoSets = new List <UOtoSet>();
            foreach (var otoSet in voicebank.OtoSets)
            {
                OtoSets.Add(new UOtoSet(otoSet, this, singersPath));
            }
            Id     = voicebank.Id;
            Loaded = true;

            Task.Run(() => {
                OtoSets
                .SelectMany(set => set.Otos.Values)
                .SelectMany(otos => otos)
                .ToList()
                .ForEach(oto => {
                    oto.SearchTerms.Add(oto.Alias.ToLowerInvariant().Replace(" ", ""));
                    oto.SearchTerms.Add(WanaKana.ToRomaji(oto.Alias).ToLowerInvariant().Replace(" ", ""));
                });
            });
        }
Exemple #11
0
        public void ChonpuToLongVowel()
        {
            var result = WanaKana.ToRomaji("スーパー");

            Assert.Equal("suupaa", result);
        }
        public void ProcessDirectory()
        {
            var subDirectories = this._directory.GetDirectories().Where(dir => dir.ContainsSong()).ToList();
            var oszSongs       = this._directory.GetOszFiles();

            if (this._outputDirectory.GetDirectories().Length > 0)
            {
                Console.WriteLine("Cleaning up output directory..");
                foreach (DirectoryInfo directoryInfo in this._outputDirectory.GetDirectories())
                {
                    directoryInfo.Delete(true);
                }
            }

            int total     = subDirectories.Count + oszSongs.Length;
            int id        = this._startId;
            int count     = 1;
            int succesful = 0;

            string format = $"D{total.ToString().Length}";

            Console.WriteLine($"Processing {total} songs!");

            if (oszSongs.Any())
            {
                DirectoryInfo tempDirectory = this._outputDirectory.CreateSubdirectory("temp");

                OsuProcessor osuProcessor = new OsuProcessor(this._categoryId, tempDirectory);
                foreach (FileInfo fileInfo in oszSongs)
                {
                    Console.Write(
                        $"[{count.ToString(format)}/{total.ToString()}] {Path.GetFileNameWithoutExtension(fileInfo.FullName)}..");

                    Song newSong = osuProcessor.Process(fileInfo, id);
                    if (newSong != null)
                    {
                        this._songs.Add(newSong);

                        string outputPath = $"{this._outputDirectory.FullName}{Path.DirectorySeparatorChar}{id}";

                        Directory.CreateDirectory(outputPath);

                        foreach (FileInfo enumerateFile in tempDirectory.EnumerateFiles())
                        {
                            enumerateFile.MoveTo($"{outputPath}{Path.DirectorySeparatorChar}{enumerateFile.Name}");
                        }

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("OK! \n");
                        Console.ResetColor();

                        succesful += 1;
                        id        += 1;
                    }

                    count += 1;
                }

                tempDirectory.Delete(true);
            }



            if (subDirectories.Any())
            {
                TjaProcessor tjaProcessor = new TjaProcessor(this._categoryId);
                foreach (DirectoryInfo subDirectory in subDirectories)
                {
                    FileInfo tjaFile   = subDirectory.GetTjaFile();
                    FileInfo musicFile = subDirectory.GetMusicFile();

                    Console.Write(
                        $"[{count.ToString(format)}/{total.ToString()}] {Path.GetFileNameWithoutExtension(tjaFile.FullName)}..");

                    Song newSong = tjaProcessor.Process(tjaFile, id);

                    if (newSong != null)
                    {
                        this._songs.Add(newSong);


                        string outputPath = $"{this._outputDirectory.FullName}{Path.DirectorySeparatorChar}{id}";

                        Directory.CreateDirectory(outputPath);

#if !DEBUG
                        musicFile.CopyTo($"{outputPath}{Path.DirectorySeparatorChar}main.ogg", true);
#endif

                        tjaFile.CopyTo($"{outputPath}{Path.DirectorySeparatorChar}main.tja", true);

                        if (this._generateMarkers) //behind a switch for now since I don't want to piss off my FTP server (yet)
                        {
                            HepburnConverter hepburn    = new HepburnConverter();
                            string           markerFile =
                                $"{outputPath}{Path.DirectorySeparatorChar}{Path.GetFileNameWithoutExtension(WanaKana.ToRomaji(hepburn, tjaFile.FullName))}";

                            if (!File.Exists(markerFile))
                            {
                                File.Create(
                                    markerFile); //create an empty file with the song name, just to keep shit organised
                            }
                        }

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("OK! \n");
                        Console.ResetColor();

                        succesful += 1;
                        id        += 1;
                    }

                    count += 1;
                }
            }

            Console.WriteLine($"\nSuccesfully processed {succesful} songs out of {total}!");

            string json = JsonSerializer.Serialize(this._songs);
            Console.WriteLine("Exporting json...");
            File.WriteAllText($@"{this._outputDirectory}{Path.DirectorySeparatorChar}songs.json", json, Encoding.GetEncoding(932));

            Console.WriteLine($"\nDone! Enjoy! Don't forget to import songs.json to mongoDB!");
        }
Exemple #13
0
        public void DoubleNsAndDoubleConsonants(string input, string expectedResult)
        {
            var result = WanaKana.ToRomaji(input);

            Assert.Equal(expectedResult, result);
        }
Exemple #14
0
        public void ApostrophesInAmbiguousConsonantVowelCombos(string input, string expectedResult)
        {
            var result = WanaKana.ToRomaji(input);

            Assert.Equal(expectedResult, result);
        }
Exemple #15
0
        public void SmallKana(string input, string expectedResult)
        {
            var result = WanaKana.ToRomaji(input);

            Assert.Equal(expectedResult, result);
        }
Exemple #16
0
 public override string Transform(string lyric)
 {
     return(WanaKana.ToRomaji(lyric));
 }
Exemple #17
0
 public void EmptyResultIsEmpty()
 {
     Assert.Empty(WanaKana.ToRomaji(string.Empty));
 }
Exemple #18
0
        public void ToRomajiPunctuation()
        {
            var result = WanaKana.ToRomaji(string.Join(string.Empty, ConversionTables.JapanesePunctuation));

            Assert.Equal(string.Join(string.Empty, ConversionTables.EnglishPunctuation), result);
        }
Exemple #19
0
        public void ToRomajiBasicTests(string input, string expectedResult)
        {
            var result = WanaKana.ToRomaji(input);

            Assert.Equal(expectedResult, result);
        }
Exemple #20
0
 public string Convert(string input, bool upcaseKatakana = false, Trie <char, string> customRomajiMapping = null) => WanaKana.ToRomaji(input, upcaseKatakana, customRomajiMapping);
Exemple #21
0
        public void KatakanaSpecialOu()
        {
            var result = WanaKana.ToRomaji("缶コーヒー");

            Assert.Equal("缶koohii", result);
        }
Exemple #22
0
        public void SpacesNotAdded()
        {
            var result = WanaKana.ToRomaji("わにかにがすごいだ");

            Assert.NotEqual("wanikani ga sugoi da", result);
        }
Exemple #23
0
        public void DashLikeKanji()
        {
            var result = WanaKana.ToRomaji("一抹げーむ");

            Assert.Equal("一抹ge-mu", result);
        }
Exemple #24
0
        public void ToRomajiLongDashToHyphen()
        {
            var result = WanaKana.ToRomaji("ばつげーむ");

            Assert.Equal("batsuge-mu", result);
        }