public void WriteTextDictionary(TextDictionary textDictionary, IDataWriter dataWriter)
        {
            dataWriter.Write((ushort)textDictionary.Entries.Count);

            foreach (var entry in textDictionary.Entries)
            {
                dataWriter.Write(entry);
            }
        }
        public void ReadTextDictionary(TextDictionary textDictionary, IDataReader dataReader, string language)
        {
            textDictionary.Language = language;
            int numEntries = dataReader.ReadWord();

            for (int i = 0; i < numEntries; ++i)
            {
                textDictionary.Entries.Add(dataReader.ReadString());
            }
        }
Beispiel #3
0
        public LWF(Data lwfData, IRendererFactory r)
#endif
        {
            m_data = lwfData;

            interactive     = m_data.buttonConditions.Length > 0;
            m_frameRate     = m_data.header.frameRate;
            m_execLimit     = 3;
            m_frameSkip     = true;
            m_tick          = 1.0f / m_frameRate;
            m_roundOffTick  = m_tick * ROUND_OFF_TICK_RATE;
            m_attachVisible = true;
            m_interceptByNotAllowOrDenyButtons = true;
            m_intercepted             = false;
            scaleByStage              = 1.0f;
            m_needsUpdate             = false;
            m_needsUpdateForAttachLWF = false;
            m_pointX     = Single.MinValue;
            m_pointY     = Single.MinValue;
            m_pressing   = false;
            m_instanceId = ++m_instanceOffset;
            m_alive      = true;
#if LWF_USE_LUA
            m_luaState         = l;
            m_instanceIdString = instanceId.ToString();
            InitLua();
#endif

            if (!interactive && m_data.frames.Length == 1)
            {
                DisableExec();
            }

            m_property  = new Property(this);
            m_instances = new IObject[m_data.instanceNames.Length];
            InitEvent();
            m_movieCommands             = new MovieCommands();
            m_programObjectConstructors =
                new ProgramObjectConstructor[m_data.programObjects.Length];
            m_textDictionary = new TextDictionary();

            m_matrix                 = new Matrix();
            m_matrixIdentity         = new Matrix();
            m_execMatrix             = new Matrix();
            m_colorTransform         = new ColorTransform();
            m_colorTransformIdentity = new ColorTransform();
            m_execColorTransform     = new ColorTransform();
            m_blendModes             = new BlendModes();
            m_maskModes              = new MaskModes();

            Init();

            SetRendererFactory(r);
        }
Beispiel #4
0
        static TextDictionary GetTextInfo(ILocalizable entity, IEnumerable <string> properties)
        {
            var entityKey = EntityKey.FromEntity(entity);
            var texts     = new TextDictionary();

            foreach (var propName in properties)
            {
                var prop = TypeHelper.GetProperty(entityKey.EntityType, propName);
                if (prop != null)
                {
                    var value = prop.GetValue(entity, null) as string;
                    texts.Add(propName, value);
                }
            }

            return(texts);
        }
        public void LargeNGram_Ngram()
        {
            var dictUrl      = new URL("100.dict");
            var noisedictUrl = new URL("noisedict");

            var dictionary = new TextDictionary(dictUrl,
                                                noisedictUrl,
                                                null,
                                                null,
                                                new UnitManager());

            var lm    = new URL("100.arpa.dmp");
            var model = new LargeTrigramModel("",
                                              lm,
                                              null,
                                              100,
                                              100,
                                              false,
                                              3,
                                              dictionary,
                                              false,
                                              1.0f,
                                              1.0f,
                                              1.0f,
                                              false);

            dictionary.Allocate();
            model.Allocate();
            Assert.AreEqual(model.MaxDepth, 3);

            Word[] words =
            {
                new Word("huggins", null, false),
                new Word("daines",  null, false)
            };
            Assert.IsTrue(Helper.CloseTo(model.GetProbability(new WordSequence(words)), -830.862, .001));

            Word[] words1 =
            {
                new Word("huggins", null, false),
                new Word("daines",  null, false),
                new Word("david",   null, false)
            };
            Assert.IsTrue(Helper.CloseTo(model.GetProbability(new WordSequence(words1)), -67625.77, .01));
        }
Beispiel #6
0
        public void Dictionary_BadDictionary()
        {
            var dictUrl      = new URL(Helper.FilesDirectory + "/linguist/dictionary/cmudict-en-us.dict");
            var noiseDictUrl = new URL("noisedict");

            var dictionary = new TextDictionary(dictUrl, noiseDictUrl, null, null, new UnitManager());


            bool failed = false;

            try
            {
                dictionary.Allocate();
            }
            catch (Exception)
            {
                failed = true;
            }

            Assert.IsTrue(failed);
        }
        public void FSTGrammar_ForcedAlignGrammar()
        {
            var dictionaryUrl = new URL("FSTGrammarTest.dic");
            var noisedictUrl  = new URL("noisedict");

            var dictionary = new TextDictionary(dictionaryUrl,
                                                noisedictUrl,
                                                null,
                                                null,
                                                new UnitManager());

            URL url     = new URL("FSTGrammarTest.gram");
            var grammar = new FSTGrammar(url.Path,
                                         true,
                                         true,
                                         true,
                                         true,
                                         dictionary);

            grammar.Allocate();
            Assert.IsTrue(grammar.GrammarNodes.Count == 14);
        }
Beispiel #8
0
        public void FullDictionaryTest()
        {
            var dictUrl      = new URL("cmudict-en-us.dict");
            var noiseDictUrl = new URL("noisedict");

            var dictionary = new TextDictionary(dictUrl, noiseDictUrl, null, null, new UnitManager());

            dictionary.Allocate();
            var word = dictionary.GetWord("one");

            Assert.AreEqual(word.GetPronunciations().Length, 2);
            Assert.AreEqual(word.GetPronunciations()[0].ToString(), "one(W AH N )");
            Assert.AreEqual(word.GetPronunciations()[1].ToString(), "one(HH W AH N )");

            word = dictionary.GetWord("something_missing");
            Assert.AreEqual(word, null);

            Assert.AreEqual(dictionary.GetSentenceStartWord().Spelling, "<s>");
            Assert.AreEqual(dictionary.GetSentenceEndWord().Spelling, "</s>");
            Assert.AreEqual(dictionary.GetSilenceWord().Spelling, "<sil>");

            Assert.AreEqual(dictionary.GetFillerWords().Count(), 5);
        }
Beispiel #9
0
        public void Batch_ForcedAlignerGrammar()
        {
            var dictionaryUrl = new URL("cmudict-en-us.dict");
            var noisedictUrl  = new URL("noisedict");

            IDictionary dictionary = new TextDictionary(dictionaryUrl,
                                                        noisedictUrl,
                                                        null,
                                                        null,
                                                        new UnitManager());

            URL url = new URL("BatchForcedAlignerGrammarTest.utts");
            BatchForcedAlignerGrammar grammar;

            grammar = new BatchForcedAlignerGrammar(url.Path,
                                                    true,
                                                    true,
                                                    true,
                                                    true,
                                                    dictionary);
            grammar.Allocate();
            Assert.IsTrue(Helper.IsOneOf(grammar.GetRandomSentence(), "one", "two", "three"));
        }
Beispiel #10
0
	public LWF(Data lwfData, IRendererFactory r)
#endif
	{
		m_data = lwfData;

		interactive = m_data.buttonConditions.Length > 0;
		m_frameRate = m_data.header.frameRate;
		m_execLimit = 3;
		m_frameSkip = true;
		m_tick = 1.0f / m_frameRate;
		m_roundOffTick = m_tick * ROUND_OFF_TICK_RATE;
		m_attachVisible = true;
		m_interceptByNotAllowOrDenyButtons = true;
		m_intercepted = false;
		scaleByStage = 1.0f;
		m_needsUpdate = false;
		m_needsUpdateForAttachLWF = false;
		m_pointX = Single.MinValue;
		m_pointY = Single.MinValue;
		m_pressing = false;
		m_instanceId = ++m_instanceOffset;
		m_alive = true;
#if LWF_USE_LUA
		m_luaState = l;
		m_instanceIdString = instanceId.ToString();
		InitLua();
#endif

		if (!interactive && m_data.frames.Length == 1)
			DisableExec();

		m_property = new Property(this);
		m_instances = new IObject[m_data.instanceNames.Length];
		InitEvent();
		m_movieCommands = new MovieCommands();
		m_programObjectConstructors =
			new ProgramObjectConstructor[m_data.programObjects.Length];
		m_textDictionary = new TextDictionary();

		m_matrix = new Matrix();
		m_matrixIdentity = new Matrix();
		m_execMatrix = new Matrix();
		m_colorTransform = new ColorTransform();
		m_colorTransformIdentity = new ColorTransform();
		m_execColorTransform = new ColorTransform();
		m_blendModes = new BlendModes();
		m_maskModes = new MaskModes();

		Init();

		SetRendererFactory(r);
	}
Beispiel #11
0
    public void SetText(string newText)
    {
        text           = newText;
        textDictionary = GameObject.FindGameObjectWithTag("TextDictionary").GetComponent <TextDictionary>();

        foreach (Transform textChild in textContainer)
        {
            Destroy(textChild.gameObject);
        }

        List <Sprite> textSprites = textDictionary.GetSprites(newText);

        float initialOffset = 0;

        if (textAlignment == TextAlignment.Center)
        {
            initialOffset = -pixelUnit / 2;
            foreach (Sprite textSprite in textSprites)
            {
                initialOffset -= (textSprite.textureRect.width / 24) - pixelUnit;
                if (textSprite != textSprites[0])
                {
                    initialOffset -= pixelUnit;
                }
            }
        }
        else if (textAlignment == TextAlignment.Right)
        {
            initialOffset = -pixelUnit;
            foreach (Sprite textSprite in textSprites)
            {
                initialOffset -= ((textSprite.textureRect.width / 12) - pixelUnit);
                if (textSprite != textSprites[0])
                {
                    initialOffset -= (1 / 12);
                }
            }
        }

        for (int i = 0; i < 5; i++)
        {
            float widthCurrent = 0;
            foreach (Sprite textSprite in textSprites)
            {
                GameObject newLetter = (GameObject)Instantiate(prefab_Letter, transform.position, Quaternion.identity, textContainer);
                newLetter.transform.localPosition = new Vector3((textSprite.textureRect.width / 24) + widthCurrent + initialOffset, 0);
                SpriteRenderer newLetterRenderer = newLetter.GetComponent <SpriteRenderer>();
                newLetterRenderer.sprite = textSprite;
                widthCurrent            += (textSprite.textureRect.width / 12) - pixelUnit;
                newLetterRenderer.color  = (i == 0 ? textColor : new Color(0.188f, 0.172f, 0.180f));

                if (i > 0)                      // Border
                {
                    Vector2 borderOffset = Vector2.zero;
                    switch (i)
                    {
                    case (1):
                        borderOffset = Vector2.up * pixelUnit;
                        break;

                    case (2):
                        borderOffset = Vector2.up * -pixelUnit;
                        break;

                    case (3):
                        borderOffset = Vector2.right * pixelUnit;
                        break;

                    case (4):
                        borderOffset = Vector2.right * -pixelUnit;
                        break;
                    }

                    newLetterRenderer.transform.position += (Vector3)borderOffset;
                    newLetterRenderer.sortingOrder        = textSortingOrder - 1;
                }
                else
                {
                    newLetterRenderer.sortingOrder = textSortingOrder;
                }
            }
        }
    }
Beispiel #12
0
        /// <summary>
        /// Для добавлени, обновления записей в бд программу необходимо запускать
        /// с праметром шаблона /MyOperation:pathToFile
        /// Sample:/CreateDictonary:C:\Тест\TestFile.txt.
        /// Для удаления с параметром /ClearDictionary:pathToFile
        /// </summary>
        static void Main(string[] args)
        {
            if (args.Length > 1)
            {
                Console.WriteLine(@"Запустить приложение можно только с одним параметром");
                Console.ReadKey();
                Environment.Exit(0);
            }

            if (args.Length == 1)
            {
                var dictonaryWordRepository = new DictonaryWordRepository();
                var argCommand = args[0];
                if (argCommand.Contains(CommandParametrs.ClearDictionary.ToString()))
                {
                    dictonaryWordRepository.Clear();
                    Console.WriteLine(@"Таблица DictionaryWord была очищена");
                    Thread.Sleep(5000);
                }

                if (argCommand.Contains(CommandParametrs.CreateDictonary.ToString()) ||
                    argCommand.Contains(CommandParametrs.UpdateDictionary.ToString()))
                {
                    var serviceConfig = new ServiceConfiguration(args);

                    var stringCommandParametr = serviceConfig.GetFirstStringKey();
                    var pathFile = serviceConfig.GetStringParametr(stringCommandParametr);

                    var textDictionary = new TextDictionary();

                    var dictionaryFromFile = textDictionary.GetDictionaryFromFile(pathFile);
                    Task.WaitAll(dictionaryFromFile);
                    var words = textDictionary.GetDictionaryWord(dictionaryFromFile.Result);

                    var dictionaryWords = words as DictionaryWord[] ?? words.ToArray();

                    if (stringCommandParametr == CommandParametrs.CreateDictonary.ToString())
                    {
                        dictonaryWordRepository.AddRange(dictionaryWords);
                        Console.WriteLine(@"В таблицу DictionaryWord были добавлены записи");
                        Thread.Sleep(5000);
                    }

                    if (stringCommandParametr == CommandParametrs.UpdateDictionary.ToString())
                    {
                        dictonaryWordRepository.Update(dictionaryWords);
                        Console.WriteLine(@"В таблице DictionaryWord были обновлены записи");
                        Thread.Sleep(5000);
                    }
                }
            }
            if (args.Length == 0)
            {
                ConsoleKeyInfo cki;
                var            stringBuilder = new StringBuilder();
                do
                {
                    cki = Console.ReadKey();
                    if (cki.Key != ConsoleKey.Enter)
                    {
                        stringBuilder.Append(cki.KeyChar);
                    }
                    else
                    {
                        Console.WriteLine();
                        using (var unitOfWork = new UnitOfWork <DictionaryWord>())
                        {
                            var searchString = stringBuilder.ToString();
                            var result       = unitOfWork.DictionaryWordRepository.Get(word => word.Word.StartsWith(searchString)
                                                                                       , 5
                                                                                       , order => order.OrderByDescending(word => word.Count).ThenBy(word => word.Word));
                            foreach (var word in result)
                            {
                                Console.WriteLine(word.Word);
                            }
                            stringBuilder.Clear();
                        }
                    }
                } while (cki.Key != ConsoleKey.Escape && cki.Key != ConsoleKey.Spacebar);
            }
        }