Example #1
0
        public static List <Word> GetPhonemeRhymes(Syllable syllable, int maxSyllables = 0)
        {
            var rhymes = new Dictionary <string, Word>();

            foreach (var word in English.GetWords())
            {
                // todo:  Temporary hack, this should be removed
                //if (word.Syllables.Count <= 0) {
                //    continue;
                //}

                if (rhymes.ContainsKey(word.Text))
                {
                    continue;
                }

                if (maxSyllables > 0 && word.Syllables.Count > maxSyllables)
                {
                    continue;
                }

                if (word.Text.Trim().Length <= 1 || word.Text.Contains("."))
                {
                    continue;
                }

                if (IsRhyme(syllable, word.Syllables.Last()))
                {
                    rhymes.Add(word.Text, word);
                }
            }

            //return rhymes.GroupBy(each => each.Value).SelectMany(each => each.ToList()).OrderByDescending(each => each.Value).Select(each => each.Key).ToList();
            return(rhymes.Values.ToList());
        }
Example #2
0
 public Language(Inventory inventory, Syllable syllable, Rules rules, Affixes affixes)
 {
     this.inventory = inventory;
     this.syllable  = syllable;
     this.rules     = rules;
     this.affixes   = affixes;
 }
Example #3
0
        public List <Syllable> ReadSyllables()
        {
            List <string> syllableIds;

            using (var dc = ChatbotEntities.GetDataContext())
            {
                syllableIds = dc.chatbot_syllable.Select(p => p.id).ToList();
            }

            WebClient webClient = new WebClient();

            List <Syllable> syllables = new List <Syllable>();

            foreach (string syllableId in syllableIds)
            {
                Syllable syllable = new Syllable();
                string   url      = m_urlSoundTemplate.Replace("{syllable}", syllableId);
                string   filename = Path.GetFileName(url);
                string   filepath = Path.Combine(m_path, "Sound", Source.ykyi.ToString(), filename);
                filepath           = Path.GetFullPath(filepath);
                syllable.Name      = syllableId;
                syllable.SoundPath = filepath;

                if (!File.Exists(filepath))
                {
                    webClient.DownloadFile(url, filepath);
                }
                syllables.Add(syllable);
            }
            return(syllables);
        }
    public void UpdateSymbol1()
    {
        Sign s = databaseManager.GetSign(ID);

        if (s == null)
        {
            SetSyllables(null, null, null);
            Image1.color = Color.clear;
            Image2.color = Color.clear;
            Image3.color = Color.clear;
            isMade       = false;
        }
        else if (s.SyllableSequence.Count == 2)
        {
            Syllable s1 = databaseManager.GetSyllable(s.SyllableSequence[0]);
            Syllable s2 = databaseManager.GetSyllable(s.SyllableSequence[1]);
            SetSyllables(s1.ImageName, s2.ImageName);
            //   transform.parent.GetComponent<Image>().color = new Color32(94, 40, 40, 106);
            isMade = true;
        }
        else if (s.SyllableSequence.Count == 3)
        {
            Syllable s1 = databaseManager.GetSyllable(s.SyllableSequence[0]);
            Syllable s2 = databaseManager.GetSyllable(s.SyllableSequence[1]);
            Syllable s3 = databaseManager.GetSyllable(s.SyllableSequence[2]);
            SetSyllables(s1.ImageName, s2.ImageName, s3.ImageName);
            //   transform.parent.GetComponent<Image>().color = new Color32(94, 40, 40, 106);
            isMade = true;
        }
    }
        public void ParseSyllableTest_Exception()
        {
            // Arrange
            Parser sut      = new Parser(null);
            string syllable = "[]";

            // Act
            Syllable result = sut.ParseSyllable(syllable);
        }
        private void DoParseSyllableTest(string s, Syllable expectedSyllable)
        {
            // Arrange
            Parser sut = new Parser(null);

            // Act
            Syllable result = sut.ParseSyllable(s);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedSyllable?.Chord?.Text, result?.Chord?.Text);
            Assert.AreEqual(expectedSyllable?.Text, result?.Text);
        }
Example #7
0
        public static bool IsRhyme(Syllable syllable1, Syllable syllable2, out string reason)
        {
            var phonemes1 = syllable1.FromNucleus().ToList();
            var phonemes2 = syllable2.FromNucleus().ToList();

            if (phonemes1.Count == 0 || phonemes2.Count == 0)
            {
                reason = "No phonemes found.";
                return(false);
            }

            List <Phoneme> mostPhonemes;
            List <Phoneme> lessPhonemes;

            if (phonemes1.Count > phonemes2.Count)
            {
                mostPhonemes = phonemes1;
                lessPhonemes = phonemes2;
            }
            else
            {
                mostPhonemes = phonemes2;
                lessPhonemes = phonemes1;
            }

            var limit = lessPhonemes.Count - 1;

            for (var index = 0; index < mostPhonemes.Count; index++)
            {
                var phoneme1 = mostPhonemes[index];
                var phoneme2 = lessPhonemes[index > limit ? limit : index];

                if (lessPhonemes.Count < index + 1)
                {
                    if (mostPhonemes[index - 1].Id != phoneme2.Id)
                    {
                        reason = "Invalid number of phonemes";
                        return(false);
                    }
                }

                if (!phoneme1.SoundsLike(phoneme2))
                {
                    reason = "Phonemes do not sound alike.";
                    return(false);
                }
            }

            reason = string.Empty;
            return(true);
        }
Example #8
0
    private static int syllableIndices(string text)
    {
        int mask = 0;

        text = Syllable.Syllabify(text);

        int i = text.IndexOf('∙');

        while (i != -1)
        {
            mask |= (1 << (i));
            i     = text.IndexOf('∙', i + 1);
        }

        return(mask);
    }
        public Document GetDocument(string Text)
        {
            var Document1 = new Document();
            var KoreanText1 = new KoreanText();
            var NonKoreanText1 = new NonKoreanText();

            foreach (var Character in Text)
            {
                if (Syllable.IsSyllable(Character))
                {
                    var Syllable = new Syllable(Character);

                    if (NonKoreanText1.Content != "")
                    {
                        Document1.Text.Add(NonKoreanText1);
                        NonKoreanText1 = new NonKoreanText();
                    }

                    KoreanText1.Syllables.Add(Syllable);
                }
                else
                {
                    if (KoreanText1.Syllables.Any())
                    {
                        Document1.Text.Add(KoreanText1);
                        KoreanText1 = new KoreanText();
                    }

                    NonKoreanText1.Content += Character;
                }
            }

            if (NonKoreanText1.Content != "")
            {
                Document1.Text.Add(NonKoreanText1);
                NonKoreanText1 = new NonKoreanText();
            }

            if (KoreanText1.Syllables.Any())
            {
                Document1.Text.Add(KoreanText1);
                KoreanText1 = new KoreanText();
            }

            return Document1;
        }
Example #10
0
 void SetLang()
 {
     if (Atlas.ExampleWord != null && Atlas.Dict.Has(Atlas.ExampleWord))
     {
         string word     = $" ({Atlas.ExampleWord}).";
         string phonemes = $" ({Syllable.ToString(Atlas.Dict.Get(Atlas.ExampleWord))}).";
         labelWord.Text     = Lang.Get("addword_word_example_word") + word;
         labelPhonemes.Text = Lang.Get("addword_phonemes_example_word") + phonemes;
     }
     else
     {
         labelWord.Text     = Lang.Get("addword_word");
         labelPhonemes.Text = Lang.Get("addword_phonemes");
     }
     Text              = Lang.Get("addword_title");
     buttonOk.Text     = Lang.Get("button_ok");
     buttonCancel.Text = Lang.Get("button_cancel");
 }
Example #11
0
        public static List <Word> GetRhymes(Syllable match, int maxSyllables = 0)
        {
            var results = new List <Word>();

            return(GetPhonemeRhymes(match, maxSyllables));

            /*SyllableMapper.Syllables.Values.ForEachParallel(syllable => {
             *  if (IsRhyme(match, syllable)) {
             *      foreach (var rhymeWord in syllable.Words) {
             *          if ((maxSyllables == 0 || rhymeWord.Syllables.Count <= maxSyllables) && rhymeWord.Syllables.Last() == syllable) {
             *              lock (results) {
             *                  results.Add(rhymeWord);
             *              }
             *          }
             *      }
             *  }
             * });*/

            return(results);
        }
Example #12
0
        public void ReadSyllableLink(WebClient wc, string link)
        {
            string data = wc.DownloadString(link);

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(data);

            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//tr");

            foreach (HtmlNode node in nodes)
            {
                HtmlNode           syllableNode = node.SelectSingleNode("./td[1]");
                HtmlNode           soundNode    = node.SelectSingleNode("./td[2]/a");
                HtmlNodeCollection symbolNodes  = node.SelectNodes("./td[3]/a");

                if (syllableNode != null && soundNode != null &&
                    symbolNodes.Count > 0)
                {
                    string soundPattern = @"sound.php\?s=(\w+)";
                    Match  match        = Regex.Match(soundNode.Attributes["href"].Value, soundPattern);
                    string syllableName = match.Groups[1].Value;
                    string soundUrl     = m_soundUrlTemplate.Replace("{syllable}", syllableName);
                    string filename     = Path.GetFileName(soundUrl);
                    string soundPath    = Path.Combine(m_folder, "Sound", Source.cuhk.ToString(), filename);
                    soundPath = Path.GetFullPath(soundPath);
                    if (!File.Exists(soundPath))
                    {
                        wc.DownloadFile(soundUrl, soundPath);
                    }
                    Syllable syllable = new Syllable();
                    syllable.Name      = syllableName;
                    syllable.SoundPath = soundPath;
                    foreach (HtmlNode symbolNode in symbolNodes)
                    {
                        syllable.Symbols.Add(symbolNode.InnerText);
                    }
                    m_syllables.Add(syllable);
                }
            }
        }
        public static GameObject Instantiate(string name, Syllable syllable, bool keepInvisible = false)
        {
            var go = GameObject.Instantiate(Prefab_s);

            go.name = name;
            go.SetActive(false);

            var goText = go.GetComponentInChildren <TextMesh>();

            goText.text = syllable.Text;

            // Calculate scales for appropriate text display
            float textScale = goText.characterSize;
            float maxXScale = 1.5f;

            float totalCharacterSpace = goText.text.Length / 5.0f;
            float xScale = (totalCharacterSpace > textScale * 5) ? totalCharacterSpace / (textScale * 5) : 1; // Assumes five characters can comfortably fit within the space originally granted
            float yScale = (xScale > maxXScale) ? xScale / maxXScale : 1;

            if (yScale > 1)
            {
                xScale = (int)((xScale / yScale) + 1) * maxXScale;
            }

            // Set scales
            go.transform.localScale = new Vector3(xScale, yScale, go.transform.localScale.z);
            //goText.characterSize = totalCharacterSpace;

            // Register information for the syllable plane script
            var plane = go.GetComponentInChildren <SyllablePlane>();

            plane.Register(syllable, plane.gameObject);

            if (!keepInvisible)
            {
                go.SetActive(true);
            }

            return(go);
        }
        public override string Romanise(Syllable Syllable1, Syllable? PrecedingSyllable = null, Syllable? SucceedingSyllable = null)
        {
            var StringBuilder1 = new StringBuilder();

            StringBuilder1.Append(RomaniseInitial(Syllable1, PrecedingSyllable, SucceedingSyllable));
            StringBuilder1.Append(RomaniseMedial(Syllable1, PrecedingSyllable, SucceedingSyllable));
            StringBuilder1.Append(RomaniseFinal(Syllable1, PrecedingSyllable, SucceedingSyllable));

            return StringBuilder1.ToString();
        }
        private string RomaniseFinal(Syllable Syllable1, Syllable? PrecedingSyllable, Syllable? SucceedingSyllable)
        {
            if (Syllable1.HasFinal)
            {

                if (SucceedingSyllable != null)
                {
                    if (FinalPronunciationChangesRomanisationRules.Any(c => c.Final == Syllable1.Final && c.SucceedingInitial == SucceedingSyllable.Value.Initial))
                    {
                        return FinalPronunciationChangesRomanisationRules.First(c => c.Final == Syllable1.Final && c.SucceedingInitial == SucceedingSyllable.Value.Initial).Romanisation;

                    }
                }

                return FinalRomanisationRules.First(f => f.Final == Syllable1.Final).Romanisation;
            }

            return "";
        }
 public SyllableContext(List <Phoneme> phonemes)
 {
     CurrentSyllable = new Syllable();
     Syllables       = new List <Syllable>();
     Phonemes        = new SteppableList <Phoneme>(phonemes);
 }
Example #17
0
 public static bool IsRhyme(Syllable syllable1, Syllable syllable2)
 {
     return(IsRhyme(syllable1, syllable2, out _));
 }
 private string RomaniseMedial(Syllable Syllable1)
 {
     return MedialRomanisationRules.First(m => m.Jamo == Syllable1.Medial).Romanisation;
 }
        private string RomaniseMedial(Syllable Syllable1, Syllable? PrecedingSyllable, Syllable? SucceedingSyllable)
        {
            if (PrecedingSyllable != null && (PrecedingSyllable.Value.Medial == Jamo.A || PrecedingSyllable.Value.Medial == Jamo.O) && !PrecedingSyllable.Value.HasFinal && Syllable1.Initial == Jamo.Ieung && Syllable1.Medial == Jamo.E)
            {
                return "ë";
            }

            return MedialRomanisationRules.First(m => m.Jamo == Syllable1.Medial).Romanisation;
        }
Example #20
0
 public Element(Syllable syllable)
 {
     Syllable = syllable;
 }
Example #21
0
        public static string GenerateName(Genders gender, int seed)
        {
            //Basic idea: Take a bunch of syllables and smash 'em together.
            //Every syllable has a beginning and ending letter.
            //These beginnings and endings can be split into three groups:
            //    1. Vowels -- can follow any consonant, but should usually not follow a vowel
            //    2. Ending consonant -- shouldn't follow an ending consonant, MIGHT follow a continuing consonant, can follow any vowel
            //    3. Continuing consonant -- can follow any continuing consonants or vowels, but not ending consonants.
            //These syllables are hard-coded and stored in the below "syllables" collection.

            PRNG rng = new PRNG(seed);

            const int minSyllables          = 2,
                      maxSyllables          = 4;
            const float chance_VowelToVowel = 0.05f,
                        chance_ContinuingConsonantToEndingConsonant = 0.5f;

            int nSyllables = rng.NextInt(minSyllables, maxSyllables + 1);

            //Start with a completely random syllable.
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            Syllable firstSyllable       = syllables.ElementAt(rng.NextInt(0, syllables.Count));

            sb.Append(firstSyllable.Value);

            //Add successive syllables making sure they don't conflict with what came before.
            HashSet <Syllable> acceptableSyllables = new HashSet <Syllable>();
            Syllable           lastSyllable        = firstSyllable;

            for (int i = 1; i < nSyllables; ++i)
            {
                //Get all acceptable syllables.
                acceptableSyllables.Clear();
                foreach (Syllable syllable in syllables)
                {
                    float chanceOfAccepting;

                    switch (syllable.StartType)
                    {
                    case Syllable.Types.Vowel:
                        switch (lastSyllable.EndType)
                        {
                        case Syllable.Types.Vowel:
                            chanceOfAccepting = chance_VowelToVowel;
                            break;

                        case Syllable.Types.ContinuingConsonant:
                        case Syllable.Types.EndingConsonant:
                            chanceOfAccepting = 1.0f;
                            break;

                        default: throw new NotImplementedException(lastSyllable.EndType.ToString());
                        }
                        break;

                    case Syllable.Types.EndingConsonant:
                        switch (lastSyllable.EndType)
                        {
                        case Syllable.Types.Vowel:
                            chanceOfAccepting = 1.0f;
                            break;

                        case Syllable.Types.ContinuingConsonant:
                            chanceOfAccepting = chance_ContinuingConsonantToEndingConsonant;
                            break;

                        case Syllable.Types.EndingConsonant:
                            chanceOfAccepting = 0.0f;
                            break;

                        default: throw new NotImplementedException(lastSyllable.EndType.ToString());
                        }
                        break;

                    case Syllable.Types.ContinuingConsonant:
                        switch (lastSyllable.EndType)
                        {
                        case Syllable.Types.Vowel:
                        case Syllable.Types.ContinuingConsonant:
                            chanceOfAccepting = 1.0f;
                            break;

                        case Syllable.Types.EndingConsonant:
                            chanceOfAccepting = 0.0f;
                            break;

                        default: throw new NotImplementedException(lastSyllable.EndType.ToString());
                        }
                        break;

                    default: throw new NotImplementedException(syllable.StartType.ToString());
                    }

                    if (chanceOfAccepting <= 0.0f || syllable == lastSyllable)
                    {
                        continue;
                    }
                    if (chanceOfAccepting >= 1.0f || rng.NextFloat() < chanceOfAccepting)
                    {
                        acceptableSyllables.Add(syllable);
                    }
                }

                //Pick one randomly.
                var nextSyllable = acceptableSyllables.ElementAt(rng.NextInt(0, acceptableSyllables.Count));
                lastSyllable = nextSyllable;
                sb.Append(nextSyllable.Value);
            }

            sb[0] = char.ToUpper(sb[0]);
            return(sb.ToString());
        }
Example #22
0
        public static new List <string> SelectPattern(string[] args)
        {
            try
            {
                bool no_pattern = true;

                Regex wifi    = new Regex(@"sfr|livebox-sagem");
                Regex hex     = new Regex(@"^hex.{6,6}$");
                Regex numeric = new Regex(@"^numeric.{0,6}$");
                Regex symbols = new Regex(@"^symbols.{0,10}$");

                Regex usyllable   = new Regex(@"^usyllable.{0,23}$");
                Regex lsyllable   = new Regex(@"^lsyllable.{0,23}$");
                Regex mixsyllable = new Regex(@"^mixsyllable.{0,23}$");

                Regex ualpha   = new Regex(@"^ualpha.{0,23}$");
                Regex lalpha   = new Regex(@"^lalpha.{0,23}$");
                Regex mixalpha = new Regex(@"^mixalpha.{0,23}$");


                Regex ualpha_sv   = new Regex(@"^sv-ualpha.{0,23}");
                Regex lalpha_sv   = new Regex(@"^sv-lalpha.{0,23}$");
                Regex mixalpha_sv = new Regex(@"^sv-mixalpha.{0,23}$");

                Regex lcyrillic   = new Regex(@"^lcyrillic.{0,23}");
                Regex ucyrillic   = new Regex(@"^ucyrillic.{0,23}");
                Regex mixcyrillic = new Regex(@"^mixcyrillic.{0,23}");

                for (int i = 0; i < args.Length; i++)
                {
                    if (hex.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Special charset = new Special();
                        charsetSelecting = charset.ListHexa(args[i].ToString().ToLower());
                        break;
                    }
                    else if (numeric.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Special charset = new Special();
                        charsetSelecting = charset.ListNumeric(args[i].ToString().ToLower());
                        break;
                    }
                    else if (symbols.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Special charset = new Special();
                        charsetSelecting = charset.ListSymbols(args[i].ToString().ToLower());
                        break;
                    }
                    else if (usyllable.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Syllable charset = new Syllable();
                        charsetSelecting = charset.ListSyllableUpperCase_fr(args[i].ToString().ToLower());
                        break;
                    }
                    else if (lsyllable.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Syllable charset = new Syllable();
                        charsetSelecting = charset.ListSyllableLowerCase_fr(args[i].ToString().ToLower());
                        break;
                    }
                    else if (mixsyllable.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Syllable charset = new Syllable();
                        charsetSelecting = charset.ListMixsyllable_fr(args[i].ToString().ToLower());
                        break;
                    }
                    else if (ualpha.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Alpha charset = new Alpha();
                        charsetSelecting = charset.Ualpha_List(args[i].ToString().ToLower());
                        break;
                    }
                    else if (lalpha.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Alpha charset = new Alpha();
                        charsetSelecting = charset.Lalpha_List(args[i].ToString().ToLower());
                        break;
                    }
                    else if (mixalpha.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Alpha charset = new Alpha();
                        charsetSelecting = charset.MixAlphaList(args[i].ToString().ToLower());
                        break;
                    }
                    else if (ualpha_sv.IsMatch(args[i].ToString()))
                    {
                        no_pattern = false;
                        Alpha_sv charset = new Alpha_sv();
                        charsetSelecting = charset.Ualpha_svList(args[i].ToString().ToLower());
                        break;
                    }
                    else if (lalpha_sv.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Alpha_sv charset = new Alpha_sv();
                        charsetSelecting = charset.Lalpha_svList(args[i].ToString().ToLower());
                        break;
                    }
                    else if (mixalpha_sv.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Alpha_sv charset = new Alpha_sv();
                        charsetSelecting = charset.MixAlpha_svList(args[i].ToString().ToLower());
                        break;
                    }
                    else if (wifi.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Special charset = new Special();
                        charsetSelecting = charset.ListWifiCharset(args[i].ToString().ToLower());
                        break;
                    }
                    else if (lcyrillic.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Cyrillic charset = new Cyrillic();
                        charsetSelecting = charset.ListcyrillicLowerCase(args[i].ToString().ToLower());
                        break;
                    }
                    else if (ucyrillic.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Cyrillic charset = new Cyrillic();
                        charsetSelecting = charset.ListCyrillicUpperCase(args[i].ToString().ToLower());
                        break;
                    }
                    else if (mixcyrillic.IsMatch(args[i].ToString().ToLower()))
                    {
                        no_pattern = false;
                        Cyrillic charset = new Cyrillic();
                        charsetSelecting = charset.ListMixCyrillic(args[i].ToString().ToLower());
                        break;
                    }
                    else if (Wordlist.CUSTOM)
                    {
                        string s = null;
                        if (args.Length == 1)
                        {
                            s = args[0].ToString();
                        }

                        for (int x = 0; x < s.Length; x++)
                        {
                            charsetSelecting.Add(s[x].ToString());
                        }
                        break;
                    }
                }

                if (no_pattern)
                {
                    for (int i = 0; i < args.Length - 1; i++)
                    {
                        if ((i > 1 & i < args.Length & args[i] == "-f"))
                        {
                            string s = args[i + 1].ToString();

                            if (s.Length > 1 & s != null)
                            {
                                for (int x = 0; x < s.Length; x++)
                                {
                                    charsetSelecting.Add(s[x].ToString());
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n {0} \n", e.Message);
                Console.ResetColor();
            }

            return(charsetSelecting);
        }
 public abstract string Romanise(Syllable Syllable1, Syllable? PrecedingSyllable = null, Syllable? SucceedingSyllable = null);
Example #24
0
        static void Main(string[] args)
        {
            Syllable syllable = new Syllable();
            List <KeyValuePair <string, string> > palavras = new List <KeyValuePair <string, string> >();

            // DITONGOS E TRITONGOS:
            palavras.Add(new KeyValuePair <string, string> ("aumento", "au-men-to"));
            palavras.Add(new KeyValuePair <string, string> ("pinheiro", "pi-nhei-ro"));
            palavras.Add(new KeyValuePair <string, string> ("água", "á-gua"));
            palavras.Add(new KeyValuePair <string, string> ("outros", "ou-tros"));
            palavras.Add(new KeyValuePair <string, string> ("coisas", "coi-sas"));
            palavras.Add(new KeyValuePair <string, string> ("iguais", "i-guais"));
            palavras.Add(new KeyValuePair <string, string> ("Paraguai", "Pa-ra-guai"));
            palavras.Add(new KeyValuePair <string, string> ("quaisquer", "quais-quer"));
            palavras.Add(new KeyValuePair <string, string> ("saguões", "sa-guões"));

            //DÍGRAFOS LH, CH, NH, GU, QU:
            palavras.Add(new KeyValuePair <string, string> ("maravilha", "ma-ra-vi-lha"));
            palavras.Add(new KeyValuePair <string, string> ("chuva", "chu-va"));
            palavras.Add(new KeyValuePair <string, string> ("carinho", "ca-ri-nho"));
            palavras.Add(new KeyValuePair <string, string> ("guindaste", "guin-das-te"));
            palavras.Add(new KeyValuePair <string, string> ("quente", "quen-te"));

            // ENCONTROS CONSONANTAIS PUROS (BL, CL, GL, PL, FL, BR, CR, DR, GR, PR, TR, FR, VR)
            palavras.Add(new KeyValuePair <string, string> ("bloco", "blo-co"));
            palavras.Add(new KeyValuePair <string, string> ("claridade", "cla-ri-da-de"));
            palavras.Add(new KeyValuePair <string, string> ("glóbulo", "gló-bu-lo"));
            palavras.Add(new KeyValuePair <string, string> ("planeta", "pla-ne-ta"));
            palavras.Add(new KeyValuePair <string, string> ("flamingo", "fla-min-go"));
            palavras.Add(new KeyValuePair <string, string> ("Brasil", "Bra-sil"));
            palavras.Add(new KeyValuePair <string, string> ("cravo", "cra-vo"));
            palavras.Add(new KeyValuePair <string, string> ("dragão", "dra-gão"));
            palavras.Add(new KeyValuePair <string, string> ("gravidade", "gra-vi-da-de"));
            palavras.Add(new KeyValuePair <string, string> ("praticamente", "pra-ti-ca-men-te"));
            palavras.Add(new KeyValuePair <string, string> ("trevas", "tre-vas"));
            palavras.Add(new KeyValuePair <string, string> ("francês", "fran-cês"));
            palavras.Add(new KeyValuePair <string, string> ("livre", "li-vre"));

            // GRUPOS CONSONANTAIS INICIAIS (PS, MN, PN, GN,...):
            palavras.Add(new KeyValuePair <string, string>("psicólogo", "psi-có-lo-go"));
            palavras.Add(new KeyValuePair <string, string>("mnésico", "mné-si-co"));
            palavras.Add(new KeyValuePair <string, string>("pneumático", "pneu-má-ti-co"));
            palavras.Add(new KeyValuePair <string, string>("gnóstico", "gnós-ti-co"));

            //HIATOS:
            palavras.Add(new KeyValuePair <string, string>("moeda", "mo-e-da"));
            palavras.Add(new KeyValuePair <string, string>("saída", "sa-í-da"));
            palavras.Add(new KeyValuePair <string, string>("saúde", "sa-ú-de"));
            palavras.Add(new KeyValuePair <string, string>("poesia", "po-e-sia"));
            palavras.Add(new KeyValuePair <string, string>("navio", "na-vi-o"));
            palavras.Add(new KeyValuePair <string, string>("dia", "di-a"));

            //DÍGRAFOS RR, SS, SC, SÇ, XC, XS:
            palavras.Add(new KeyValuePair <string, string>("carro", "car-ro"));
            palavras.Add(new KeyValuePair <string, string>("pássaro", "pas-sá-ro"));
            palavras.Add(new KeyValuePair <string, string>("nascer", "nas-cer"));
            palavras.Add(new KeyValuePair <string, string>("nasço", "nas-ço"));
            palavras.Add(new KeyValuePair <string, string>("exceção", "ex-ce-ção"));
            palavras.Add(new KeyValuePair <string, string>("exsudativo", "ex-su-da-ti-vo"));

            //ENCONTROS CONSONANTAIS DISJUNTOS:
            palavras.Add(new KeyValuePair <string, string>("advogado", "ad-vo-ga-do"));
            palavras.Add(new KeyValuePair <string, string>("afta", "af-ta"));
            palavras.Add(new KeyValuePair <string, string>("alface", "al-fa-ce"));
            palavras.Add(new KeyValuePair <string, string>("força", "for-ça"));
            palavras.Add(new KeyValuePair <string, string>("magnético", "mag-né-ti-co"));
            palavras.Add(new KeyValuePair <string, string>("objeto", "ob-je-to"));
            palavras.Add(new KeyValuePair <string, string>("desmentir", "des-men-tir"));

            int countRightWords = 0;

            foreach (var palSep in palavras)
            {
                var palavra    = palSep.Key;
                var split      = syllable.word2syllables(palavra);
                var spliString = string.Join("-", split.ToArray());

                Console.WriteLine("--------------------------------------------------");
                Console.WriteLine("Palavra: " + palavra);
                Console.WriteLine("Separa automaticamente: " + spliString);
                Console.WriteLine("Separação correta: " + palSep.Value);
                Console.WriteLine("--------------------------------------------------\n");

                if (spliString.Equals(palSep.Value))
                {
                    countRightWords++;
                }
            }

            Console.WriteLine("Total de palavras: " + palavras.Count);
            Console.WriteLine("Total separações certas: " + countRightWords);
        }
Example #25
0
    public static void Main(string[] args)
    {
        // build up a very simple vowel inventory
        // make sure features are within simple set in Inventory's place/manner/voicing
        Inventory inventory = new Inventory();

        inventory.AddConsonant("b", "voiced", "bilabial", "plosive");
        inventory.AddConsonant("p", "voiceless", "bilabial", "plosive");
        inventory.AddConsonant("g", "voiced", "velar", "plosive");
        inventory.AddConsonant("k", "voiceless", "velar", "plosive");
        inventory.AddConsonant("d", "voiced", "dental", "plosive");
        inventory.AddConsonant("t", "voiceless", "dental", "plosive");
        inventory.AddConsonant("h", "voiceless", "glottal", "fricative");
        inventory.AddConsonant("l", "voiced", "alveolar", "lateral");
        inventory.AddConsonant("r", "voiced", "alveolar", "approximant");
        inventory.AddConsonant("w", "voiced", "velar", "approximant");
        // build up very simple consonant inventory
        // make sure features are within simple set in Inventory's height/backness/rounding
        inventory.AddVowel("i", "close", "front", "unrounded");
        inventory.AddVowel("a", "open", "central", "unrounded");
        inventory.AddVowel("u", "close", "back", "rounded");

        // recall features using any letter
        Debug.Log(inventory.GetFeatures("b"));

        // This finds "b":
        List <string> testFeaturesList = new List <string> {
            "voiced", "bilabial", "plosive"
        };

        inventory.GetLetter(testFeaturesList);
        // This will not find "b":
        testFeaturesList [0] = "bilabial";
        testFeaturesList [1] = "voiced";
        inventory.GetLetter(testFeaturesList);

        Syllable syllableStructure = new Syllable();

        syllableStructure.AddStructure(new List <string> {
            "C", "V"
        });
        syllableStructure.AddStructure(new List <string> {
            "C", "V", "V"
        });
        syllableStructure.AddStructure(new List <string> {
            "C", "V", "C"
        });
        syllableStructure.AddStructure(new List <string> {
            "C", "V", "V", "C"
        });

        Rules rules = new Rules();

        rules.AddRule("voiced", "voiceless", "_ voiceless");

        Affixes affixes = new Affixes();

        // add prefixes and suffixes
        // trusts you to use only characters found in inventory (matters for rule application)
        affixes.AddAffix("human", "-", "g", "u", "d");
        affixes.AddAffix("nonhuman", "-", "i", "d");
        affixes.AddAffix("strong", "t", "-");
        affixes.AddAffix("small", "l", "-");
        affixes.AddAffix("strange", "g", "-");

        // TODO structure language
        Language language = new Language(inventory, syllableStructure, rules, affixes);

        // build a long proper noun
        List <string> properNoun = language.BuildWord(3, true, "strong", "nonhuman");

        Debug.Log(string.Join("", properNoun.ToArray()));

        // build a short regular noun
        List <string> justSomeNoun = language.BuildWord(2);

        // add both to the dictionary
        language.AddEntry(properNoun, "Wolf");
        language.AddEntry(justSomeNoun, "food");
        Debug.Log(language.PrintDictionary());
    }
        private string RomaniseFinal(Syllable Syllable1)
        {
            if (Syllable1.HasFinal)
            {
                return FinalRomanisationRules.First(f => f.Final == Syllable1.Final).Romanisation;
            }

            return "";
        }
        private string RomaniseInitial(Syllable Syllable1, Syllable? PrecedingSyllable, Syllable? SucceedingSyllable)
        {
            if (PrecedingSyllable != null)
            {
                if (InitialPronunciationChangesRomanisationRules.Any(c => c.PrecedingFinal == PrecedingSyllable.Value.Final && c.Initial == Syllable1.Initial))
                {
                    return InitialPronunciationChangesRomanisationRules.First(c => c.PrecedingFinal == PrecedingSyllable.Value.Final && c.Initial == Syllable1.Initial).Romanisation;
                }
            }

            if (PrecedingSyllable == null)
            {
                var IsIMedial = (Syllable1.Medial == Jamo.I || Syllable1.Medial == Jamo.Ya || Syllable1.Medial == Jamo.Yae || Syllable1.Medial == Jamo.Yeo || Syllable1.Medial == Jamo.Ye || Syllable1.Medial == Jamo.Yo || Syllable1.Medial == Jamo.Yu);

                if (UseSh && Syllable1.Initial == Jamo.Shiot && IsIMedial)
                {
                    return "sh";
                }
                if (UseSh && Syllable1.Initial == Jamo.SsangShiot && IsIMedial)
                {
                    return "ssh";
                }
            }

            return InitialRomanisationRules.First(r => r.Initial == Syllable1.Initial).Romanisation;
        }
Example #28
0
        private void syllabifier_method()
        {
            string        enterredText = enter_text.Text.ToString();
            List <string> words        = enterredText.Replace(",", "").Replace(".", "").Replace(":", "").Split(' ').ToList();
            int           i            = 0;

            this.Invoke((MethodInvoker) delegate()

            {
                Syllable.Text = "";

                foreach (string word in words)
                {
                    for (i = 0; i < word.Length; i++)
                    {
                        Syllable.Text = Syllable.Text + word[i].ToString();

                        if (i + 5 <= word.Length - 1)
                        {
                            if (isVowel(word, i))
                            {
                                if (word[i + 1].Equals('\u0302') || word[i + 1].Equals('\u030c'))
                                {
                                    if (word[i + 2].Equals('w') || word[i + 2].Equals('W'))
                                    {
                                        Syllable.Text += word[i + 1].ToString();
                                        Syllable.Text += word[i + 2].ToString();
                                        if (!isVowel(word, i + 3))
                                        {
                                            Syllable.Text += word[i + 3].ToString();
                                        }
                                        Syllable.Text += ",";
                                        i             += 3;
                                    }
                                    else
                                    {
                                        Syllable.Text += word[i + 1].ToString();
                                        Syllable.Text += word[i + 2].ToString();
                                        Syllable.Text += ",";
                                        i             += 2;
                                    }
                                }
                            }
                            else if ((!isVowel(word, i) && isVowel(word, i + 1) && (word[i + 2].Equals('\u0302') || word[i + 2].Equals('\u030c'))))
                            {
                                if (word[i + 3].Equals('w') || word[i + 3].Equals('W'))
                                {
                                    if (word[i + 4].Equals('n') || word[i + 4].Equals('N'))
                                    {
                                        if (word[i + 5].Equals('G') || word[i + 5].Equals('g'))
                                        {
                                            Syllable.Text += word[i + 1].ToString();
                                            Syllable.Text += word[i + 2].ToString();
                                            Syllable.Text += word[i + 3].ToString();
                                            Syllable.Text += word[i + 4].ToString();
                                            Syllable.Text += word[i + 5].ToString();
                                            Syllable.Text += ",";
                                            i             += 5;
                                        }
                                    }
                                    else
                                    {
                                        Syllable.Text += word[i + 1].ToString();
                                        Syllable.Text += word[i + 2].ToString();
                                        Syllable.Text += word[i + 3].ToString();
                                        if (!isVowel(word, i + 4))
                                        {
                                            Syllable.Text += word[i + 4].ToString();
                                        }
                                        Syllable.Text += ",";
                                        i             += 4;
                                    }
                                }
                                else if (!isVowel(word, i + 3))
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                    Syllable.Text += word[i + 2].ToString();
                                    Syllable.Text += word[i + 3].ToString();
                                    Syllable.Text += ",";
                                    i             += 3;
                                }
                            }
                            else if ((!isVowel(word, i) && isVowel(word, i + 1) && !isVowel(word, i + 1 + 1)))
                            {
                                if (word[i + 1 + 1].Equals('W') || word[i + 1 + 1].Equals('w'))
                                {
                                    if (!isVowel(word, i + 1 + 1 + 1))
                                    {
                                        Syllable.Text += word[i + 1].ToString();
                                        Syllable.Text += word[i + 2].ToString();
                                        Syllable.Text += word[i + 3].ToString();
                                        Syllable.Text += ",";
                                        i             += 3;
                                    }
                                }
                                else if (word[i + 1 + 1 + 1].Equals('G') || word[i + 1 + 1 + 1].Equals('g'))
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                    Syllable.Text += word[i + 2].ToString();
                                    Syllable.Text += word[i + 3].ToString();
                                    Syllable.Text += ",";
                                    i             += 3;
                                }
                                else
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                    Syllable.Text += word[i + 2].ToString();
                                    Syllable.Text += ",";
                                    i             += 2;
                                }
                            }
                            else if ((word[i].Equals('A') || word[i].Equals('a')) && (word[i + 1].Equals('W') || word[i + 1].Equals('w')) && !isVowel(word, i + 1 + 1))
                            {
                                Syllable.Text += word[i + 1].ToString();
                                Syllable.Text += word[i + 2].ToString();
                                Syllable.Text += ",";
                                i             += 2;
                            }

                            else if ((word[i].Equals('N') || word[i].Equals('n')) && (word[i + 1].Equals('g') || word[i + 1].Equals('G')))
                            {
                                if (!isVowel(word, i + 1 + 1))
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                    Syllable.Text += ",";
                                }
                                else
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                }
                                i++;
                            }
                            else if ((word[i].Equals('C') || word[i].Equals('c')) && (word[i + 1].Equals('h') || word[i + 1].Equals('H')))
                            {
                                if (!isVowel(word, i + 1 + 1))
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                    Syllable.Text += ",";
                                }
                                else
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                }
                                i++;
                            }
                            else if (!isVowel(word, i) && !isVowel(word, i + 1))
                            {
                                Syllable.Text += ",";
                            }
                            else if ((isVowel(word, i) && isVowel(word, i + 1)) && (word[i] != word[i + 1]))
                            {
                                Syllable.Text += ",";
                            }

                            else if ((!isVowel(word, i) && isVowel(word, i + 1)) || (isVowel(word, i) && !isVowel(word, i + 1)))
                            {
                                if (word[i + 1 + 1] == 'g' || word[i + 1 + 1] == 'G')
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                    Syllable.Text += word[i + 2].ToString();
                                    Syllable.Text += ",";
                                    i             += 2;
                                }
                                else
                                {
                                    Syllable.Text += word[i + 1].ToString();
                                    Syllable.Text += ",";
                                    i++;
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    Syllable.AppendText(Environment.NewLine);
                }
            });
        }
 private string RomaniseMedial(Syllable Syllable1, Syllable? PrecedingSyllable, Syllable? SucceedingSyllable)
 {
     return MedialRomanisationRules.First(m => m.Jamo == Syllable1.Medial).Romanisation;
 }
Example #30
0
    public static ReturnModel Handle(string text, MSCGJson son)
    {
        string[][] sentences = son.result;

        string[] originalSentences = text.Split(' ');
        int      originIndex       = 0;
        int      wordIndex         = 0;

        Word[][]    postags = new Word[sentences.Length][];
        List <Word> list;

        for (int i = 0; i < sentences.Length; ++i)
        {
            list = new List <Word>();

            foreach (string j in sentences[i])
            {
                if (!isMSCGSymbol(j))
                {
                    list.Add(new Word(originalSentences[originIndex], POSType(j), syllableIndices(originalSentences[originIndex]), Syllable.Syllabify(originalSentences[originIndex++]), wordIndex++));
                }
            }


            postags[i] = list.ToArray();
        }

        return(new ReturnModel(postags, GenerateHTML(postags, true)));
    }
Example #31
0
 public Element(Syllable syllable)
 {
     Syllable = syllable;
 }
 private string RomaniseInitial(Syllable Syllable1)
 {
     return InitialRomanisationRules.First(r => r.Initial == Syllable1.Initial).Romanisation;
 }