public TestSelectWordsPresenter(ITestSelectWordsView view, ISQLiteTesting db, ITestSelectWordsReader wordsReader, TranslateDirection direction, int maxCountOfWords)
 {
     this.view = view;
     this.db = db;
     this.wordsReader = wordsReader;
     this.maxCountOfWords = maxCountOfWords;
     this.direction = direction;
 }
 public void InitDirection()
 {
     this.selectedChat = chatManager.GetItemForId(selectedChatID);
     Language userLang = languageManager.GetItemForId(this.selectedChat.LanguageFrom);
     Language robotLang = languageManager.GetItemForId(this.selectedChat.LanguageTo);
     direction = new TranslateDirection(this.db, new DirectionManager(this.db), languageManager);
     direction.SetDirection(userLang, robotLang);
     view.UpdateBackground("back" + robotLang.NameEng);
 }
Example #3
0
        private Transition TranslateTransitionFromPrototype(Transition prototype, TranslateDirection direction)
        {
            if (prototype != null)
            {
                TranslateTransition translatePrototype = prototype as TranslateTransition;
                if (translatePrototype != null)
                {
                    translatePrototype.SetDirection(direction);
                    return(translatePrototype);
                }
            }

            return(prototype);
        }
Example #4
0
        private void TranslateTransition(Image image)
        {
            TranslateDirection TD = TranslateDirection.Left;

            switch (this.TransitionAnimationStyle)
            {
            case TransitionType.TranslateLeft:
                TD = TranslateDirection.Left;
                break;

            case TransitionType.TranslateRight:
                TD = TranslateDirection.Right;
                break;
            }

            AnimationHelper.PerformFadeIn(image, 500d, 300d);
            AnimationHelper.PerformTranslateIn(image, TD, this.TransitionTranslateDistance, 300d, 300d);
        }
Example #5
0
        public static void PerformTranslateIn(DependencyObject dependencyObject, TranslateDirection translateDirection, double distance, double duration, double staggerDelay = 0)
        {
            Storyboard storyboard = null;

            double xStartingPosition = distance;

            if (translateDirection == TranslateDirection.Left)
            {
                xStartingPosition = distance;
            }
            else
            {
                xStartingPosition = distance * -1;
            }

            if (null != dependencyObject)
            {
                storyboard = CreateTranslateAnimation(dependencyObject, "X", 0.0, xStartingPosition, 0.0, duration, staggerDelay, false, false, new RepeatBehavior(1d));

                storyboard.Begin();
            }
        }
Example #6
0
        protected override void OnUpdate()
        {
            var commandBuffer = m_CommandBufferSystem.CreateCommandBuffer().AsParallelWriter();
            var deltaTime     = Time.DeltaTime;

            Entities
            .ForEach((int entityInQueryIndex, ref FireCooldown fireCooldown, in FireInput fireInput, in FireInterval fireInterval, in FireSpeed fireSpeed, in ProjectilePrefab projectilePrefab, in ProjectileSpawn projectileSpawn, in LocalToWorld localToWorld) =>
            {
                fireCooldown.value -= deltaTime;

                if (
                    fireInput.fire &&
                    fireCooldown.value <= 0.0f
                    )
                {
                    var firedProjectile = commandBuffer.Instantiate(entityInQueryIndex, projectilePrefab.value);

                    var firedTranslateDirectionComponent = new TranslateDirection {
                        value = localToWorld.Forward
                    };
                    var firedTranslateSpeedComponent = new TranslateSpeed {
                        value = fireSpeed.value
                    };
                    var firedTranslationComponent = new Translation {
                        Value = math.transform(localToWorld.Value, projectileSpawn.offset)
                    };
                    var firedRotationComponent = new Rotation {
                        Value = quaternion.LookRotation(localToWorld.Forward, math.up())
                    };

                    commandBuffer.SetComponent(entityInQueryIndex, firedProjectile, firedTranslateDirectionComponent);
                    commandBuffer.SetComponent(entityInQueryIndex, firedProjectile, firedTranslateSpeedComponent);
                    commandBuffer.SetComponent(entityInQueryIndex, firedProjectile, firedTranslationComponent);
                    commandBuffer.SetComponent(entityInQueryIndex, firedProjectile, firedRotationComponent);

                    fireCooldown.value = fireInterval.value;
                }
            })
 private TranslateRequestRunner getRequestRunner(TranslateDirection translateDirection)
 {
     TranslateRequestRunner reqRunner = new TranslateRequestRunner(
         db,
         new CachedResultReader(translateDirection, db),
         new TranslateRequest(TypeTranslateServices.YandexDictionary, translateDirection),
         new TranslateRequest(TypeTranslateServices.YandexTranslate, translateDirection));
     return reqRunner;
 }
Example #8
0
 private bool Predicate(string input, TranslateDirection dir)
 {
     return haveTranslation(input, dir);
 }
Example #9
0
        internal string BinarySearch(string haystack, TranslateDirection dir)
        {
            string[] words = haystack.Split(whitespace, StringSplitOptions.RemoveEmptyEntries);

            int it = words.Length;
            int res = 0;
            while(it > res)
            {
                    if(Predicate(Subarray(words, 0, it), dir))
                    {
                            res = it;
                            it += (words.Length - it)/2;
                    }
                    else
                    {
                            it -= (it - res)/2;
                            if(it - 1 == res && !Predicate(Subarray(words, 0, it), dir))
                            {
                                break;
                            }
                    }
            }
            string s = Subarray(words, 0, res);
            //putLogLine("Debug: BinarySearch returning " + s);
            return s;
        }
Example #10
0
        /*! \brief Translate a single word from an input language to an output language.
         *  \param _origKey The input word. Symbols are stripped from the beginning and end of the word before it is translated.
         *  \param val An "out" parameter for the output word. It will not be set if the function returns false.
         *  \param dir The translation direction. LeftToRight means the input sentence is in the left-hand language,
         *             and the output sentence is in the right-hand language. Vice-versa for RightToLeft.
         *  \return true if the word was translated; false if no translation was found in the dictionary.
         *
         *  No attempt is made to tokenize the string, so the entire input string will be looked up in the dictionary.
         *  Therefore you should call translate() instead if you want to translate a string containing multiple tokens.
         *  This function is reentrant, and can be used from multiple threads as long as WRITE functions are synchronized.
         * */
        public bool translateWord(string _origKey, out string val, TranslateDirection dir)
        {
            if(_origKey == null || (dir != TranslateDirection.LeftToRight && dir != TranslateDirection.RightToLeft))
            {
                putLogLine("Warning: null key or invalid direction in translateWord()");
                val = null;
                return false;
            }

            if(_origKey.Length > 2 && _origKey[0] == '[' && _origKey[_origKey.Length - 1] == ']')
            {
                 val = _origKey.Substring(1, _origKey.Length - 2);
                return true;
            }

            if(_origKey.ToLower() == "amarok")
            {
                string wocka = "";
                Random r = new Random();
                for(int i = 0; i < r.Next(100); i++)
                {
                    wocka += "wocka ";
                }
                val = StringCase.transformCase(wocka, StringCase.getCaseType(_origKey));
                return true;
            }

            string intermed_key = _origKey.ToLower();
            string trimmedStart, trimmedEnd;
            string key = trimSymbols(intermed_key, out trimmedStart, out trimmedEnd);
            Dictionary<string, List<string>> dict;

            if(dir == TranslateDirection.LeftToRight)
            {
                dict = ltr;
            }
            else
            {
                dict = rtl;
            }

            List<string> result;
            string final_suffix = "";
            if(!dict.TryGetValue(key, out result))
            {
                bool success = false;
                Dictionary<string, List<string>> suffixDict;
                if(dir == TranslateDirection.LeftToRight)
                {
                    suffixDict = ltrSuffixMap;
                }
                else
                {
                    suffixDict = rtlSuffixMap;
                }

                foreach(string suffixKey in suffixDict.Keys)
                {
                    Regex suffixRx = new Regex(@"(.+)" + suffixKey);
                    MatchCollection smc = suffixRx.Matches(key);
                    if(smc.Count == 1 && dict.TryGetValue(key.Substring(0, key.Length - suffixKey.Length).ToLower(), out result))
                    {
                        List<string> suffList;
                        if(suffixDict.TryGetValue(suffixKey, out suffList))
                        {
                            success = true; // We got a translation for the word with the suffix removed!
                            final_suffix = suffList[0];
                            break;
                        }
                    }
                }

                if(!success)
                {
                    putLogLine("Note: no translation for key `" + key + "'");
                    val = null;
                    return false;
                }
            }

            if(result == null || result.Count < 1 || result[0] == null)
            {
                val = null;
            }
            else
            { //Transform the output case into the input case.

                CaseType dict_case = StringCase.getCaseType(result[0]);
                CaseType key_case = StringCase.getCaseType(_origKey);
                string _outval = null;

                if(key.Length == 1)
                {
                    //Input one-letter uppercase word -> output proper-case
                    if(key_case == CaseType.Caps || key_case == CaseType.Proper)
                    {
                        _outval = StringCase.transformCase(result[0] + final_suffix, CaseType.Proper);
                    }
                    else
                    {
                        _outval = StringCase.transformCase(result[0]+ final_suffix, key_case);
                    }
                }
                else
                {
                    if(dict_case == CaseType.Mixed)
                    {
                        _outval = result[0] + final_suffix;
                    }
                    else
                    {
                        _outval = StringCase.transformCase(result[0] + final_suffix, key_case);
                    }
                }

                val = (trimmedStart != null ? trimmedStart : "")
                          + _outval
                          + (trimmedEnd != null ? trimmedEnd : "");

                if(result.Count > 1)
                {
                    putLogLine("Note: using first translation for ambiguous key `" + key + "' : `" + result[0] + "'");
                }
            }
            return true;
        }
Example #11
0
        /*! \brief Translate an input sentence into an output sentence.
         *  \param input The input sentence.
         *  \param dir The translation direction. LeftToRight means the input sentence is in the left-hand language,
         *             and the output sentence is in the right-hand language. Vice-versa for RightToLeft.
         *  \return The translated sentence in the output language.
         *
         *  A "sentence" is a string of one or more words, possibly containing symbols.\n
         *  A word is a substring separated from the rest of the string by whitespace.\n
         *  Sentences MAY contain the delimiter character used in the dictionary, but it will not be translated.\n
         *  Sentences MAY contain newlines, but it is preferred that each sentence does not contain any newlines.\n
         *  Any newlines present in the input sentence will be converted to spaces.\n
         *  Words that are not translated are omitted from the output sentence.\n
         * \n
         *  This function is reentrant, and can be used from multiple threads as long as WRITE functions are synchronized.
         * */
        public string translate(string input, TranslateDirection dir)
        {
            if(input == null)
            {
                return null;
            }

            int i = 0;
            string result = "";
            //string[] words = input.Split(whitespace, StringSplitOptions.RemoveEmptyEntries);
            List<string> words = new List<string>();
            int cursor = 0;
            while(cursor < input.Length)
            {
                string preSymbols = "", postSymbols = "";
                string scursor = input.Substring(cursor);
                string searchedWord = "";
                if(scursor.Trim()[0] == '[')
                {
                    int idx = scursor.IndexOf("]");
                    if(idx >= 0)
                    {
                        searchedWord = scursor.Substring(0, idx + 1);
                    }
                }
                else
                {
                    searchedWord = trimSymbols(BinarySearch(scursor, dir), out preSymbols, out postSymbols);
                    if(searchedWord == null || searchedWord.Length == 0)
                    {
                        int idx = scursor.IndexOf(' ');
                        if(idx >= 0)
                        {
                            searchedWord = scursor.Substring(0, idx + 1);
                        }
                    }
                }
                if(searchedWord.Trim().Length > 0)
                {
                    putLogLine("searchedWord: " + searchedWord + "preSymbols: " + preSymbols + " postSymbols: " + postSymbols);
                    words.Add(preSymbols + searchedWord.Trim() + postSymbols);
                    cursor += searchedWord.Length + preSymbols.Length + postSymbols.Length + 1;
                }
                else
                {
                    break;
                }
            }

            int skipLoad = 0; //The number of words we should skip before trying to parse the next word
            foreach(string word in words)
            {
                //putLogLine("Debug: Translating " + word);
                if(skipLoad > 0)
                {
                    skipLoad--;
                    continue;
                }
                string _out;
                string tmpword = null;

                //Check for a literal word: tmpword is set iff we found a literal word
                if(word[0] == '[' && word[word.Length - 1] == ']')
                {
                    //The easy case: one word surrounded by [these]
                    tmpword = word.Substring(1, word.Length - 2);
                }
                else if(word[0] == '[' && word[word.Length - 1] != ']')
                {
                    tmpword = word;
                    bool found_closing_bracket = false;
                    //We have to search the remainder of the sentence to see if there's a closing bracket
                    for(int j = i+1; j < words.Count; j++)
                    {
                        tmpword += " " + words[j];
                        if(tmpword[tmpword.Length - 1] == ']')
                        {
                            found_closing_bracket = true;
                            skipLoad = j - i;
                            break;
                        }
                    }

                    if(found_closing_bracket)
                    {
                        tmpword = tmpword.Substring(1, tmpword.Length - 2);
                    }
                    else
                    {
                        tmpword = null; //We'll set it back to word in just a sec
                    }
                }

                if(tmpword == null)
                {
                    translateWord(word, out _out, dir);
                }
                else
                {
                    _out = tmpword;
                }

                if(_out != null && _out.Trim().Length > 0)
                {
                    result += _out;
                    if(i < words.Count - 1)
                    {
                        result += " ";
                    }
                }
                i++;
            }

            return result;
        }
Example #12
0
        /*! \brief Attempt to translate a single word from an input language to an output language, returning true if a match was found.
         *  Determining whether a translation exists is slightly faster (by a decent-sized constant factor) than actually finding the translation.
         *  \param _origKey The input word. Symbols are stripped from the beginning and end of the word before it is translated.
         *  \param dir The translation direction. LeftToRight means the input sentence is in the left-hand language,
         *             and the output sentence is in the right-hand language. Vice-versa for RightToLeft.
         *  \return true if the word was translated; false if no translation was found in the dictionary.
         *
         *  No attempt is made to tokenize the string, so the entire input string will be looked up in the dictionary.
         *  Therefore you should call translate() instead if you want to translate a string containing multiple tokens.
         *  This function is reentrant, and can be used from multiple threads as long as WRITE functions are synchronized.
         * */
        public bool haveTranslation(string _origKey, TranslateDirection dir)
        {
            if(_origKey == null || (dir != TranslateDirection.LeftToRight && dir != TranslateDirection.RightToLeft))
            {
                putLogLine("Warning: null key or invalid direction in haveTranslation()");
                return false;
            }

            if((_origKey.Length > 2 && _origKey[0] == '[' && _origKey[_origKey.Length - 1] == ']') || _origKey.ToLower() == "amarok")
            {
                return true;
            }

            bool success = false;
            string intermed_key = _origKey.ToLower();
            string trimmedStart, trimmedEnd;
            string key = trimSymbols(intermed_key, out trimmedStart, out trimmedEnd);
            Dictionary<string, List<string>> dict;

            if(dir == TranslateDirection.LeftToRight)
            {
                dict = ltr;
            }
            else
            {
                dict = rtl;
            }

            if(dict.ContainsKey(key))
            {
                return true;
            }
            else
            {
                Dictionary<string, List<string>> suffixDict;
                if(dir == TranslateDirection.LeftToRight)
                {
                    suffixDict = ltrSuffixMap;
                }
                else
                {
                    suffixDict = rtlSuffixMap;
                }

                foreach(string suffixKey in suffixDict.Keys)
                {
                    Regex suffixRx = new Regex(@"(.+)" + suffixKey);
                    MatchCollection smc = suffixRx.Matches(key);
                    if(smc.Count == 1 && dict.ContainsKey(key.Substring(0, key.Length - suffixKey.Length).ToLower()))
                    {
                        if(suffixDict.ContainsKey(suffixKey))
                        {
                            success = true; // We got a translation for the word with the suffix removed!
                            break;
                        }
                    }
                }
            }

            return success;
        }