コード例 #1
0
    public void importRuleButtonPressed(int buttonIndex)
    {
        if (buttonIndex >= otherPartOfSpeech.Length)
        {
            return;
        }

        GameObject template = otherPartOfSpeech[buttonIndex];

        Debug.Log(template.transform.childCount);
        for (int i = 0; i < template.transform.childCount; i++)
        {
            RuleBannerPageSix bannerScriptOld = template.transform.GetChild(i).GetComponent <RuleBannerPageSix>();
            GameObject        instanceBanner  = (GameObject)Instantiate(prefabedBanner, thisPanel.transform);
            RuleBannerPageSix bannerScriptNew = instanceBanner.GetComponent <RuleBannerPageSix>();
            bannerScriptNew.description.text = bannerScriptOld.description.text;

            WordFormat newWordFormat = new WordFormat();
            // Copy the fields that is primary type or need not deep copy
            newWordFormat.numOfSyllable          = bannerScriptOld.format.numOfSyllable;
            newWordFormat.arabicStyle            = bannerScriptOld.format.arabicStyle;
            newWordFormat.consonantWithSemivowel = bannerScriptOld.format.consonantWithSemivowel;
            newWordFormat.specialVowel           = bannerScriptOld.format.specialVowel;
            newWordFormat.specialConsonant       = bannerScriptOld.format.specialConsonant;
            newWordFormat.vowelHolders           = bannerScriptOld.format.vowelHolders;

            // Deep copy other field
            Phoneme newLeading = new Phoneme();
            newLeading.addPhone(bannerScriptOld.format.specialLeading);
            Phoneme newEnding = new Phoneme();
            newEnding.addPhone(bannerScriptOld.format.specialEnding);
            newWordFormat.specialLeading = newLeading;
            newWordFormat.specialEnding  = newEnding;

            // Deep copy accent rules
            if (bannerScriptOld.format.accentRules != null && bannerScriptOld.format.accentRules.Length > 0)
            {
                WordFormat.AccentRule[] newAccentRuleList = new WordFormat.AccentRule[bannerScriptOld.format.accentRules.Length];
                for (int j = 0; j < newAccentRuleList.Length; j++)
                {
                    WordFormat.AccentRule newAccentRule = new WordFormat.AccentRule();
                    WordFormat.AccentRule oldAccentRule = bannerScriptOld.format.accentRules[j];
                    newAccentRule.backword = oldAccentRule.backword;
                    newAccentRule.position = oldAccentRule.position;
                    newAccentRule.accents  = new AccentPhone[oldAccentRule.accents.Length];

                    for (int k = 0; k < newAccentRule.accents.Length; k++)
                    {
                        newAccentRule.accents[k] = oldAccentRule.accents[k];
                    }

                    newAccentRuleList[j] = newAccentRule;
                }
                newWordFormat.accentRules = newAccentRuleList;
            }

            bannerScriptNew.format = newWordFormat;
        }
    }
コード例 #2
0
    private Morphome getFormat(WordFormat format)
    {
        Morphome result = new Morphome();

        result.SyllableNumber = format.numOfSyllable;

        // Get info if the format is in arabic style
        if (format.arabicStyle)
        {
            result.AfroAsian            = true;
            result.Affixed              = false;
            result.SpecialPhone         = false;
            result.SemivoweledConsonant = format.consonantWithSemivowel;
            result.ClusteredConsonant   = format.consonantCluster;
            result.HolderVowels         = convertPhonemes(format.vowelHolders);
        }

        // Get info if the format is not arabic style
        else
        {
            result.AfroAsian            = false;
            result.SemivoweledConsonant = false;
            result.ClusteredConsonant   = false;
            result.Affixed      = false;
            result.SpecialPhone = false;

            // Set affix
            if (format.specialLeading != null && format.specialLeading.phones.Length > 0)
            {
                result.Affixed = true;
                result.Prefix  = convertPhoneme(format.specialLeading);
            }
            if (format.specialEnding != null && format.specialEnding.phones.Length > 0)
            {
                result.Affixed = true;
                result.Suffix  = convertPhoneme(format.specialEnding);
            }

            // Set special phone
            if (format.specialVowel != null && format.specialVowel.Length > 0)
            {
                result.SpecialPhone  = true;
                result.SpecialVowels = convertPhonemes(format.specialVowel);
            }
            if (format.specialConsonant != null && format.specialConsonant.Length > 0)
            {
                result.SpecialPhone      = true;
                result.SpecialConsonants = convertPhonemes(format.specialConsonant);
            }

            // Set accent rule
            if (format.accentRules != null && format.accentRules.Length > 0)
            {
                List <Morphome.ToneRequiement> ruleList = new List <Morphome.ToneRequiement>();
                for (int k = 0; k < format.accentRules.Length; k++)
                {
                    WordFormat.AccentRule   accentRule = format.accentRules[k];
                    Morphome.ToneRequiement tone       = new Morphome.ToneRequiement();

                    if (accentRule.backword)
                    {
                        int position = result.SyllableNumber - accentRule.position;
                        tone.Position = position;
                    }
                    else
                    {
                        tone.Position = accentRule.position;
                    }
                    if (tone.Position <= 0 || tone.Position > result.SyllableNumber)
                    {
                        continue;
                    }

                    Phone[] potentials = new Phone[accentRule.accents.Length];
                    for (int kk = 0; kk < potentials.Length; kk++)
                    {
                        Phone potential = new Phone();
                        potential.converProtoPhone(accentRule.accents[kk]);
                        potentials[kk] = potential;
                    }
                    tone.Accents = potentials;

                    ruleList.Add(tone);
                }
                result.Tones = ruleList.ToArray();
            }
        }

        return(result);
    }
コード例 #3
0
    // Save the newly created rule
    public void onSaveButtonPressed()
    {
        aFormat = new WordFormat();
        aFormat.numOfSyllable = syllableNum;

        if (arabicFormatToggle.isOn)
        {
            aFormat.arabicStyle            = true;
            aFormat.consonantWithSemivowel = useSemivoweledConsonant.isOn;
            aFormat.consonantCluster       = useClusteredConsonant.isOn;

            List <Phoneme> forVowelHolder = new List <Phoneme>();
            for (int i = 0; i < arabicFormatContent.transform.childCount; i++)
            {
                ToBePickedScript script = arabicFormatContent.transform.GetChild(i).GetComponent <ToBePickedScript>();
                if (script.aVowelPhoneme == null)
                {
                    aFormat.arabicStyle            = false;
                    aFormat.consonantWithSemivowel = false;
                    aFormat.consonantCluster       = false;
                    break;
                }
                forVowelHolder.Add(script.aVowelPhoneme);
            }
            aFormat.vowelHolders = forVowelHolder.ToArray();
        }
        else
        {
            aFormat.arabicStyle = false;

            // Get accent rules
            if (accentNum > 0)
            {
                List <WordFormat.AccentRule> aList = new List <WordFormat.AccentRule>();
                for (int i = 0; i < accentPanel.transform.childCount; i++)
                {
                    AddAccentPageSix      script = accentPanel.transform.GetChild(i).GetComponent <AddAccentPageSix>();
                    WordFormat.AccentRule wfar   = new WordFormat.AccentRule();

                    if (script.coundBack.options.ToArray()[script.coundBack.value].text.Equals("Backward"))
                    {
                        wfar.backword = true;
                    }
                    else
                    {
                        wfar.backword = false;
                    }

                    try
                    {
                        if (script.positionField.text.Equals(""))
                        {
                            wfar.position = int.Parse(script.holder.text);
                        }
                        else
                        {
                            wfar.position = int.Parse(script.positionField.text);
                        }
                        if (wfar.position > syllableNum)
                        {
                            continue;
                        }

                        Manager         manager         = UnityEngine.Object.FindObjectOfType <Manager>();
                        LanguageManager languageManager = manager.languageManager;
                        AccentPhone[]   accents         = languageManager.accents;

                        if (script.accentType.value.Equals("all"))
                        {
                            wfar.accents = accents;
                        }
                        else
                        {
                            List <AccentPhone> potentialAccent = new List <AccentPhone>();
                            foreach (AccentPhone actp in accents)
                            {
                                string value   = script.accentType.options.ToArray()[script.accentType.value].text;
                                string IPA     = actp.IPA;
                                string contour = actp.Contour;
                                string level   = actp.Level;
                                if (value.Equals(IPA) || value.Equals(contour) || value.Equals(level))
                                {
                                    potentialAccent.Add(actp);
                                }
                            }
                            wfar.accents = potentialAccent.ToArray();
                        }
                        aList.Add(wfar);
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }
                aFormat.accentRules = aList.ToArray();
            }

            // Get special affix
            if (specialAffixToggle.isOn)
            {
                if (specialPrefixToggle.isOn && prefixPhoneme != null && prefixPhoneme.phones.Length > 0)
                {
                    aFormat.specialLeading = prefixPhoneme;
                }
                if (specialSuffixToggle.isOn && suffixPhoneme != null && suffixPhoneme.phones.Length > 0)
                {
                    aFormat.specialEnding = suffixPhoneme;
                }
            }

            // Get special phone
            if (specialPhoneToggle.isOn)
            {
                if (specialVowelToggle.isOn && specialPickedVowel != null && specialPickedVowel.Length > 0)
                {
                    aFormat.specialVowel = specialPickedVowel;
                }

                if (specialConsonantToggle.isOn && specialPickedConsonant != null && specialPickedConsonant.Length > 0)
                {
                    aFormat.specialConsonant = specialPickedConsonant;
                }
            }

            // Create a rule banner
            // prefabedRuleBanner
            // RuleBannerPageSix
        }

        if (oldBanner != null)
        {
            oldBanner.format           = aFormat;
            oldBanner.description.text = aFormat.getDescription();
        }
        if (oldBanner == null && fromThisPanel != null)
        {
            GameObject        instanceBanner = (GameObject)Instantiate(prefabedRuleBanner, fromThisPanel.transform);
            RuleBannerPageSix instanceScript = instanceBanner.GetComponent <RuleBannerPageSix>();
            instanceScript.format           = aFormat;
            instanceScript.description.text = aFormat.getDescription();
        }


        Destroy(this.transform.gameObject);
    }