示例#1
0
 public void UpdateEntry(DictionaryDataEntry entry)
 {
     var prev = GetLocalEntryFromID(entry.ID);
     if (prev != null) {
         Entries.Remove(prev);
     }
     Entries.Add(entry);
     if(IdToEntryMapping.ContainsKey(entry.ID)){
         IdToEntryMapping[entry.ID] = Entries.Count - 1;
     }else{
         IdToEntryMapping.Add(entry.ID, Entries.Count - 1);
     }
 }
    //managing response to keyboard entries about inputs
    void ListenToTyping(KeyCode key)
    {
        //deleting text
        if (key == KeyCode.Backspace || key == KeyCode.Delete) {
            //if no imetext, delete the entry in front of cursor
            if(imeText == "" && cursorPosition != 0){
                setCursorPosition(cursorPosition - 1);
                phraseSequence.RemoveAt(cursorPosition);
            }
            //if there is imetext, delete one letter from it
            else{
                onConjugate = false;
                toConjugate = null;
                imeText = imeText.Substring(0, Mathf.Max(0, imeText.Length - 1));
            }
        }
        //entering letters into imeText
        if(IsText(key)){//key.ToString().Length == 1 && IsAlphabet(key.ToString()[0])){
            //set onConjugate and toConjugate as such for every action that will change imeText
            onConjugate = false;
            toConjugate = null;
            imeText += GetText(key);
        }
        /** Potential key strokes that can be used for entering into text ***/
        //TODO maybe enable punctuations
        /********************************************************************/

        /** selection key strokes *****/
        int index;

        //conjugate words selection when modifying existing verbs
        if (IsNumeric (key.ToString (), out index)
            && onConjugate
            && selected < phraseSequence.PhraseElements.Count
            && phraseSequence.PhraseElements [selected].IsDictionaryWord) {
            if(index >= 0 && index < conjugateDisplay.Length && conjugateDisplay[index] != null){
                phraseSequence.UpdateAt(selected, conjugateDisplay[index]);
            }
        }

        else if(IsNumeric(key.ToString(), out index) && imeText != ""){
            //conjugate words selection for newly typed words
            if(onConjugate){
                if(index >= 0 && index < conjugateDisplay.Length && conjugateDisplay[index] != null){
                    phraseSequence.PhraseElements.Insert (cursorPosition, conjugateDisplay[index]);
                    imeText = "";
                    toConjugate = null;
                    onConjugate = false;
                    setCursorPosition(cursorPosition + 1);
                }
            }
            //Japanese word selection
            else{
                if(index >= 0 && index < OnDisplay.Length && OnDisplay[index] != null){
                    if(hasConjugate(OnDisplay[index])){
                        toConjugate = OnDisplay[index];
                        //Debug.Log (toConjugate);
                        onConjugate = true;
                    }
                    else{
                        phraseSequence.PhraseElements.Insert (cursorPosition, new PhraseSequenceElement(OnDisplay[index].ID, 0));
                        imeText = "";
                        setCursorPosition(cursorPosition + 1);
                    }
                }
            }
        }

        /**   HotKeys for selection when imeText isn't empty  ********************/
        //TODO maybe change hotkey to ctrl
        else if (key == KeyCode.Tab && imeText != "") {
            var element = new PhraseSequenceElement (PhraseSequenceElementType.Text, imeText);
            //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.Text, imeText));
            imeText = "";
            phraseSequence.PhraseElements.Insert (cursorPosition, element);
            setCursorPosition(cursorPosition + 1);
        }
        else if (key == KeyCode.LeftControl && imeText != "") {
            var element = new PhraseSequenceElement (PhraseSequenceElementType.ContextSlot, imeText);
            //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.Text, imeText));
            imeText = "";
            phraseSequence.PhraseElements.Insert (cursorPosition, element);
            setCursorPosition(cursorPosition + 1);
        }
        else if (key == KeyCode.Tab && imeText == "") {
            var element = new PhraseSequenceElement (PhraseSequenceElementType.Wildcard, "");
            //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.Text, imeText));
            imeText = "";
            phraseSequence.PhraseElements.Insert (cursorPosition, element);
            setCursorPosition(cursorPosition + 1);
        }
    }
示例#3
0
    public DictionaryDataEntry AddNewEntry()
    {
        var id = AdditionalEntryStartID;
        for (int i = AdditionalEntryStartID; i < AdditionalEntryStartID + 10000; i++) {
            if (GetEntryFromID(i) != null) {
                id = i;
            }
        }
        id += 10;

        var entry = new DictionaryDataEntry(id, "temp", "temp", new List<string>(), PartOfSpeech.Noun);
        Entries.Add(entry);
        IdToEntryMapping.Add(entry.ID, Entries.Count - 1);
        return entry;
    }
 void DrawTenWordForms(DictionaryDataEntry entry, bool update, int selected)
 {
     currentConjugations = ConjugationTool.GetForms (entry);
     if (conjugateOffset + displayLines >= currentConjugations.Length)
         conjugateOffset = Mathf.Max (0, currentConjugations.Length - displayLines);
     if (conjugateOffset < 0)
         conjugateOffset = 0;
     for (int i = 0; i < displayLines; i++) {
         if (conjugateOffset + i >= currentConjugations.Length || conjugateOffset + i < 0)
             conjugateDisplay[i] = null;
         else{
             var e = currentConjugations [conjugateOffset + i];
             var label = string.Format ("{0}:   {1}", i + 1, e.GetText());
             GUIStyle buttonStyle = new GUIStyle();
             buttonStyle.alignment = TextAnchor.LowerLeft;
             if (GUILayout.Button (label, buttonStyle)) {
                 if(update){
                     phraseSequence.UpdateAt(selected, e);
                     break;
                 }
                 else{
                     phraseSequence.PhraseElements.Insert (cursorPosition, e);
                     imeText = "";
                     toConjugate = null;
                     break;
                 }
             }
             conjugateDisplay [i] = e;
         }
     }
 }
 private bool hasConjugate(DictionaryDataEntry e)
 {
     //e itself is always returned, check if any other form exists
     return ConjugationTool.GetForms (e).Length > 1;
 }
示例#6
0
 public static PhraseSequenceElement[] GetVerbForms(DictionaryDataEntry entry)
 {
     var forms = GetVerbForms();
     var arr = new PhraseSequenceElement[forms.Length];
     for (int i = 0; i < forms.Length; i++) {
         arr[i] = new PhraseSequenceElement(entry.ID, forms[i]);
     }
     return arr;
 }
示例#7
0
        public static string GetVerbForm(DictionaryDataEntry entry, int form, JapaneseScriptType scriptType)
        {
            if (form == Want) {
                var s = GetVerbForm(entry, PolitePresentIndicative, scriptType);
                s = s.Substring(0, s.Length - 2);
                return s + verbEndings[Want];
            }

            var text = entry.Kana;
            switch (scriptType) {
                case JapaneseScriptType.Kanji:
                    text = entry.Kanji;
                    break;
            }

            switch (entry.GetPartOfSpeech()) {
                case PartOfSpeech.GodanVerb:
                    return ConjugateGroup1Verb(text, form);

                case PartOfSpeech.IchidanVerb:
                    return ConjugateGroup2Verb(text, form);

                case PartOfSpeech.Copula:
                case PartOfSpeech.SuruVerb:
                    return ConjugateIrregularVerb(text, form);
            }
            return null;
        }
示例#8
0
        public static PhraseSequenceElement[] GetForms(DictionaryDataEntry entry)
        {
            if (additionalForms.ContainsKey(entry.Kanji)) {
                var forms = new PhraseSequenceElement[additionalForms[entry.Kanji].Count];
                for (int i = 0; i < forms.Length; i++) {
                    forms[i] = new PhraseSequenceElement(entry.ID, i);
                }
                return forms;
            }

            switch (entry.GetPartOfSpeech()) {
                case PartOfSpeech.GodanVerb:
                case PartOfSpeech.IchidanVerb:
                case PartOfSpeech.Copula:
                case PartOfSpeech.SuruVerb:
                    return GetVerbForms(entry);

                case PartOfSpeech.Adjective:
                    return GetAdjectiveForms(entry);

                default:
                    return new PhraseSequenceElement[] { new PhraseSequenceElement(entry.ID, 0) };
            }
        }
示例#9
0
        public static string GetForm(DictionaryDataEntry entry, int form, JapaneseScriptType scriptType = JapaneseScriptType.Kanji)
        {
            if (entry == null) {
                return null;
            }

            if (additionalForms.ContainsKey(entry.Kanji)) {
                //if (scriptType == JapaneseScriptType.Kanji) {
                //    return entry.Kanji;
                //}
                var formString = additionalForms[entry.Kanji].GetSafely(form);
                if (scriptType == JapaneseScriptType.Romaji) {
                    return KanaConverter.Instance.ConvertToRomaji(formString);
                } else {
                    return formString;
                }
            }

            switch (entry.GetPartOfSpeech()) {
                case PartOfSpeech.GodanVerb:
                case PartOfSpeech.IchidanVerb:
                case PartOfSpeech.Copula:
                case PartOfSpeech.SuruVerb:
                    switch (scriptType) {
                        case JapaneseScriptType.Romaji:
                            return KanaConverter.Instance.ConvertToRomaji(GetVerbForm(entry, form, scriptType));
                        default:
                            return GetVerbForm(entry, form, scriptType);
                    }

                case PartOfSpeech.Adjective:

                if (scriptType == JapaneseScriptType.Romaji) {
                        return KanaConverter.Instance.ConvertToRomaji(GetAdjectiveForm(entry, form, scriptType));
                    } else {
                        return GetAdjectiveForm(entry, form, scriptType);
                    }

                default:
                    switch (scriptType) {
                        case JapaneseScriptType.Kana:
                            return entry.Kana;
                        case JapaneseScriptType.Romaji:
                            return KanaConverter.Instance.ConvertToRomaji(entry.Kana);

                        default:
                            return entry.Kanji;
                    }
            }
        }
示例#10
0
        public static string GetAdjectiveForm(DictionaryDataEntry entry, int form, JapaneseScriptType scriptType)
        {
            if (form == AdjectiveI) {
                return entry.Kana.Substring(0, entry.Kana.Length - 1) + adjectiveEndings[AdjectiveI];
            }

            if (form == AdjectiveNa) {
                return entry.Kana + adjectiveEndings[AdjectiveNa];
            }

            return entry.Kana;
        }