Ejemplo n.º 1
0
 public override void OnInspectorGUI()
 {
     if (WordList.Words.Count == 0)
     {
         WordList.Load();
     }
     _tgt = (WordPuzzle)target;
     if (GUILayout.Button("Refresh wordlist"))
     {
         WordList.Load();
     }
     if (_selectedWord != null)
     {
         _selectedWord = _tgt.Word;
     }
     GUILayout.BeginHorizontal();
     _selectedWordIndex = EditorGUILayout.Popup(_selectedWordIndex, WordList.GetArray());
     if (GUILayout.Button("Set"))
     {
         _selectedWord             = WordList.Words[_selectedWordIndex];
         ((WordPuzzle)target).Word = _selectedWord;
     }
     ((WordPuzzle)target).RandomWord = GUILayout.Toggle(_tgt.RandomWord, "Random");
     GUILayout.EndHorizontal();
     if (_tgt.Word != null)
     {
         GUILayout.Label("Selected word: " + _tgt.Word.ToString());
     }
     base.OnInspectorGUI();
 }
        private void ValidateAndHandleEnteredWord()
        {
            WordPair currentWordPair = _unknownWords.First(unknownWord => unknownWord.Id == _currentUnknownWordPairId);

            if (!SecondLanguageWordTextBox.ReadOnly)
            {
                bool isEqual = _wordsService.CheckIfWordsMatches(SecondLanguageWordTextBox.Text, currentWordPair.SecondLanguageWord);
                if (isEqual)
                {
                    HandleCorrectlyEnteredWord();
                }
                else
                {
                    HandleIncorrectlyEnteredWord(SecondLanguageWordTextBox, currentWordPair.SecondLanguageWord);
                }
            }
            else if (!FirstLanguageWordTextBox.ReadOnly)
            {
                bool isEqual = _wordsService.CheckIfWordsMatches(FirstLanguageWordTextBox.Text, currentWordPair.FirstLanguageWord);
                if (isEqual)
                {
                    HandleCorrectlyEnteredWord();
                }
                else
                {
                    HandleIncorrectlyEnteredWord(FirstLanguageWordTextBox, currentWordPair.FirstLanguageWord);
                }
            }
        }
Ejemplo n.º 3
0
        private Dictionary <string, WordPair> GetWords()
        {
            var wordPairs    = new Dictionary <string, WordPair>();
            var assembly     = Assembly.GetExecutingAssembly();
            var nameSpace    = "Problems";
            var resourceName = $"{nameSpace}.DataFiles.p98.txt";
            var wordList     = new List <string>();

            var data = string.Empty;

            using (var stream = assembly.GetManifestResourceStream(resourceName))
                using (var reader = new StreamReader(stream))
                {
                    while (true)
                    {
                        var word = reader.ReadLine();
                        if (string.IsNullOrEmpty(word))
                        {
                            break;
                        }
                        wordList.Add(word);

                        var key = Utility.SortCharacters(word);
                        if (!wordPairs.TryGetValue(key, out var wp))
                        {
                            wp = new WordPair();
                            wordPairs.Add(key, wp);
                        }
                        wp.AddWord(word);
                    }
                }
            return(wordPairs);
        }
Ejemplo n.º 4
0
        public WordPairViewModel(IProjectService projectService, IAnalysisService analysisService, WordPair wordPair, bool areVarietiesInOrder)
        {
            _projectService      = projectService;
            _analysisService     = analysisService;
            _wordPair            = wordPair;
            _areVarietiesInOrder = areVarietiesInOrder;
            _meaning             = new MeaningViewModel(_wordPair.Word1.Meaning);
            _variety1            = new VarietyViewModel(_wordPair.VarietyPair.Variety1);
            _variety2            = new VarietyViewModel(_wordPair.VarietyPair.Variety2);

            IWordAlignerResult results = _projectService.Project.WordAligners[ComponentIdentifiers.PrimaryWordAligner].Compute(_wordPair);

            _alignment  = results.GetAlignments().First();
            _prefixNode = new AlignedNodeViewModel(_alignment.Prefixes[0], _alignment.Prefixes[1]);
            var nodes = new List <AlignedNodeViewModel>();
            int i     = 0;

            for (int column = 0; column < _alignment.ColumnCount; column++)
            {
                string note = null;
                if (i < _wordPair.AlignmentNotes.Count)
                {
                    note = _wordPair.AlignmentNotes[i];
                }
                nodes.Add(new AlignedNodeViewModel(column, _alignment[0, column], _alignment[1, column], note));
                i++;
            }
            _suffixNode = new AlignedNodeViewModel(_alignment.Suffixes[0], _alignment.Suffixes[1]);

            _alignedNodes = new ReadOnlyCollection <AlignedNodeViewModel>(nodes);

            _showInMultipleWordAlignmentCommand = new RelayCommand(ShowInMultipleWordAlignment);
            _pinUnpinCommand = new RelayCommand(PinUnpin);
        }
Ejemplo n.º 5
0
        private async Task <SyncBase> AddUserWordPairAsync(int userId, WordTranslation wordTranslation)
        {
            // add word pair in repository
            WordPair wordPair = await AddPairAsync(wordTranslation).ConfigureAwait(false);

            // Load a word from a cell of a foreign word
            Word wordForeign = await wordRepository.FindById(wordPair.WordForeignId).ConfigureAwait(false);

            // If the loaded foreign word does not match the word
            // in the repository then the pair is considered inverted
            var createdPair = new UserWordPair
            {
                WordPairId   = wordPair.WordPairId,
                IsInvertPair = !wordForeign.Content.Equals(wordTranslation.WordForeign.ToLower()),
                UserId       = userId
            };

            // add pair to user dictionary
            createdPair = await userWordPairRepository.Stack(createdPair).ConfigureAwait(false);

            // create answer
            var resultPair = new SyncBase
            {
                Id       = wordTranslation.Id,
                ServerId = createdPair.UserWordPairId
            };

            return(resultPair);
        }
Ejemplo n.º 6
0
        public WordPairViewModel(IWordAligner aligner, WordPair wordPair, bool areVarietiesInOrder)
        {
            _wordPair            = wordPair;
            _areVarietiesInOrder = areVarietiesInOrder;
            _meaning             = new MeaningViewModel(_wordPair.Word1.Meaning);
            _variety1            = new VarietyViewModel(_wordPair.VarietyPair.Variety1);
            _variety2            = new VarietyViewModel(_wordPair.VarietyPair.Variety2);

            IWordAlignerResult results = aligner.Compute(_wordPair);

            _alignment  = results.GetAlignments().First();
            _prefixNode = new AlignedNodeViewModel(_alignment.Prefixes[0], _alignment.Prefixes[1]);
            var nodes = new List <AlignedNodeViewModel>();
            int i     = 0;

            for (int column = 0; column < _alignment.ColumnCount; column++)
            {
                string note = null;
                if (i < _wordPair.AlignmentNotes.Count)
                {
                    note = _wordPair.AlignmentNotes[i];
                }
                nodes.Add(new AlignedNodeViewModel(column, _alignment[0, column], _alignment[1, column], note));
                i++;
            }
            _suffixNode = new AlignedNodeViewModel(_alignment.Suffixes[0], _alignment.Suffixes[1]);

            _alignedNodes = new ReadOnlyCollection <AlignedNodeViewModel>(nodes);
        }
Ejemplo n.º 7
0
        private bool IsRegular(WordPair wordPair, IWordAlignerResult alignerResult, Alignment <Word, ShapeNode> alignment, int column,
                               Ngram <Segment> v)
        {
            VarietyPair  vp      = wordPair.VarietyPair;
            SoundContext context = alignment.ToSoundContext(_segmentPool, 0, column, alignerResult.WordAligner.ContextualSoundClasses);
            FrequencyDistribution <Ngram <Segment> > freqDist = vp.CognateSoundCorrespondenceFrequencyDistribution[context];
            int threshold;

            if (AutomaticRegularCorrespondenceThreshold)
            {
                int seg2Count = vp.CognateSoundCorrespondenceFrequencyDistribution.Conditions
                                .Where(sc => sc.LeftEnvironment == context.LeftEnvironment && sc.RightEnvironment == context.RightEnvironment)
                                .Sum(sc => vp.CognateSoundCorrespondenceFrequencyDistribution[sc][v]);
                if (!_regularCorrespondenceThresholdTable.TryGetThreshold(vp.CognateCount, freqDist.SampleOutcomeCount, seg2Count,
                                                                          out threshold))
                {
                    threshold = DefaultRegularCorrespondenceThreshold;
                }
            }
            else
            {
                threshold = DefaultRegularCorrespondenceThreshold;
            }
            return(freqDist[v] >= threshold);
        }
        public async void updateFireBaseElement(InputData.InputData input, string englishKey)
        {
            WordPair updatedWordPair = input.WordPairs.Single(p => p.EnglishWord == englishKey);

            updatedWordPair.CheckDate = DateTime.ParseExact(DateTime.Now.AddHours(2).ToString("yy/MM/dd HH:mm:ss"), "yy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
            FirebaseResponse response = await client.UpdateTaskAsync("WordPairs/" + updatedWordPair.EnglishWord + " - " + updatedWordPair.HungarianWord, updatedWordPair);
        }
Ejemplo n.º 9
0
 private void Start()
 {
     if (RandomWord)
     {
         Word = WordList.RandomWord();
     }
 }
Ejemplo n.º 10
0
    void TestInput()
    {
        Results results = new Results();
        int     index   = SpellingListManager.Instance.currIndex;

        results.listName = SpellingListManager.Instance.masterList[index].name;
        WordPair answerPairs = new WordPair();

        answerPairs.correctSpelling = "cgews";
        answerPairs.enteredSpelling = "sdag";
        List <WordPair> blah = new List <WordPair>();

        blah.Add(answerPairs);
        results.answerPairs        = blah;
        results.answerPairsCorrect = blah;
        results.totalWords         = SpellingListManager.Instance.masterList[index].list.Count;
        results.date = System.DateTime.Now + "";
        resultsList.Add(results);


        int index2 = SpellingListManager.Instance.currIndex;

        results.listName            = "second";
        answerPairs                 = new WordPair();
        answerPairs.correctSpelling = "Second";
        answerPairs.enteredSpelling = "entered";
        blah = new List <WordPair>();
        blah.Add(answerPairs);
        results.answerPairs        = blah;
        results.answerPairsCorrect = blah;
        results.totalWords         = SpellingListManager.Instance.masterList[index].list.Count;
        results.date = System.DateTime.Now + "";
        resultsList.Add(results);
    }
Ejemplo n.º 11
0
        private void HandleCorrectlyEnteredWord()
        {
            WordPair currentLearnedWord = _allWords.First(uw => uw.Id == _currentWordPairId);
            bool     learnedUnknownWord = _wordsService.RemoveLearnedUnknownWordIfExist(currentLearnedWord);

            if (learnedUnknownWord)
            {
                _learnedWords.Add(currentLearnedWord);
                NewLearnedWordsCountLinkLabel.Text = _learnedWords.Count.ToString();
            }
            else
            {
                _knownWords.Add(currentLearnedWord);
                KnownWordsCountLinkLabel.Text = _knownWords.Count.ToString();
            }

            _allWords = _allWords.Where(aw => aw.Id != _currentWordPairId).ToArray();

            NewLearnedWordsCountLinkLabel.Enabled = _learnedWords.Count > 0;
            KnownWordsCountLinkLabel.Enabled      = _knownWords.Count > 0;

            if (_allWords.Length > 0)
            {
                CommonFormService.SetProgressLabelText(ProgressLabel, _allWords);
                _currentWordPairId = _allWords.First().Id;

                GrammarFormService.HandleNextWordButtonEvent(ValidateWordButton, NextWordButton,
                                                             CorrectWordTextBox, _selectedLanguage, FirstLanguageWordTextBox, SecondLanguageWordTextBox,
                                                             _allWords);
            }
            else
            {
                HandleFinishedTest();
            }
        }
Ejemplo n.º 12
0
        private void HandleIncorrectlyEnteredWord(TextBox textBox, string correctValueForTextBox)
        {
            GrammarFormService.HandleVisibilityOnIncorrectlyEnteredWordEvent(ValidateWordButton, NextWordButton,
                                                                             CorrectWordTextBox, textBox, correctValueForTextBox);

            WordPair currentUnknownWord = _allWords.First(aw => aw.Id == _currentWordPairId);
            bool     unknownWordAdded   = _wordsService.InsertNewUnknownWordIfDoesntExist(currentUnknownWord);

            if (unknownWordAdded)
            {
                _newUnknownWords.Add(currentUnknownWord);
                NewUnknownWordsCountLinkLabel.Text = _newUnknownWords.Count.ToString();
            }
            else
            {
                _unknownWords.Add(currentUnknownWord);
                UnknownWordsCountLinkLabel.Text = _unknownWords.Count.ToString();
            }

            NewUnknownWordsCountLinkLabel.Enabled = _newUnknownWords.Count > 0;
            UnknownWordsCountLinkLabel.Enabled    = _unknownWords.Count > 0;

            _allWords = _allWords.Where(aw => aw.Id != _currentWordPairId).ToArray();

            if (_allWords.Length > 0)
            {
                _currentWordPairId = _allWords.First().Id;
            }
        }
Ejemplo n.º 13
0
        private void HandleNextWordButtonClickedEvent()
        {
            if (IDontKnowTheWordButton.Visible)
            {
                _learnedWords.Add(_unknownWords.First(uw => uw.Id == _currentUnknownWordPairId));
                LearnedWordsCountLinkLabel.Text    = _learnedWords.Count.ToString();
                LearnedWordsCountLinkLabel.Enabled = _learnedWords.Count > 0;

                _unknownWords = _unknownWords.Where(unknownWord => unknownWord.Id != _currentUnknownWordPairId).ToArray();
            }
            else
            {
                VerbalFormService.SetWordTextBoxVisibilityForSelectedLanguage(_selectedLanguage, FirstLanguageWordTextBox, SecondLanguageWordTextBox);
            }

            VerbalFormService.HandleNextWordButtonClickedEvent(IDontKnowTheWordButton, FirstLanguageWordTextBox, SecondLanguageWordTextBox, _selectedLanguage);

            if (_unknownWords.Length > 0)
            {
                CommonFormService.SetProgressLabelText(ProgressLabel, _unknownWords);

                WordPair nextWord = _unknownWords.First();

                FirstLanguageWordTextBox.Text  = nextWord.FirstLanguageWord;
                SecondLanguageWordTextBox.Text = nextWord.SecondLanguageWord;

                _currentUnknownWordPairId = nextWord.Id;
            }
            else
            {
                HandleFinishedTest();
            }
        }
Ejemplo n.º 14
0
        public void UpdateCognicity(WordPair wordPair, IWordAlignerResult alignerResult)
        {
            wordPair.AlignmentNotes.Clear();
            Alignment <Word, ShapeNode> alignment = alignerResult.GetAlignments().First();
            int  initialEquivalentClasses         = 0;
            bool mismatchFound = false;

            for (int column = 0; column < alignment.ColumnCount; column++)
            {
                AlignmentCell <ShapeNode> cell1 = alignment[0, column];
                AlignmentCell <ShapeNode> cell2 = alignment[1, column];

                if ((cell1.Count > 0 && cell1[0].Type() == CogFeatureSystem.VowelType) || (cell2.Count > 0 && cell2[0].Type() == CogFeatureSystem.VowelType))
                {
                    wordPair.AlignmentNotes.Add("X");
                }
                else
                {
                    if (cell1.StrRep() == cell2.StrRep())
                    {
                        wordPair.AlignmentNotes.Add("1");
                        if (!mismatchFound)
                        {
                            initialEquivalentClasses++;
                        }
                    }
                    else
                    {
                        SoundClass sc1;
                        if (!_soundClasses.TryGetMatchingSoundClass(_segmentPool, alignment, 0, column, out sc1))
                        {
                            sc1 = null;
                        }
                        SoundClass sc2;
                        if (!_soundClasses.TryGetMatchingSoundClass(_segmentPool, alignment, 1, column, out sc2))
                        {
                            sc2 = null;
                        }
                        if (sc1 != null && sc2 != null && sc1 == sc2)
                        {
                            wordPair.AlignmentNotes.Add("1");
                            if (!mismatchFound)
                            {
                                initialEquivalentClasses++;
                            }
                        }
                        else
                        {
                            wordPair.AlignmentNotes.Add("0");
                            mismatchFound = true;
                        }
                    }
                }
            }

            wordPair.AreCognatePredicted = !mismatchFound || initialEquivalentClasses >= _initialEquivalenceThreshold;
            wordPair.CognicityScore      = (double)initialEquivalentClasses / alignment.ColumnCount;
        }
        public UpdateDeletePage(WordPair data)
        {
            InitializeComponent();

            item = data;

            entry_tr.Text = item.TR;
            entry_en.Text = item.EN;
        }
Ejemplo n.º 16
0
        private WordPair PrepareAddedWords(WordPair wordPair, DateTime modificationTime)
        {
            wordPair.LanguagePair = LanguagePair.LithuanianEnglish;

            wordPair.CreatedAt  = modificationTime;
            wordPair.ModifiedAt = modificationTime;

            return(wordPair);
        }
Ejemplo n.º 17
0
 public WordPairSurrogate(WordPair wp)
 {
     Meaning                 = wp.Meaning.Gloss;
     Word1                   = wp.Word1.StrRep;
     Word2                   = wp.Word2.StrRep;
     _alignmentNotes         = wp.AlignmentNotes.ToList();
     AreCognatePredicted     = wp.AreCognatePredicted;
     PhoneticSimilarityScore = wp.PhoneticSimilarityScore;
     CognicityScore          = wp.CognicityScore;
 }
Ejemplo n.º 18
0
        public void Process()
        {
            var        segmentPool = new SegmentPool();
            CogProject project     = TestHelpers.GetTestProject(_spanFactory, segmentPool);

            project.Meanings.AddRange(new[] { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") });
            project.Varieties.AddRange(new[] { new Variety("variety1"), new Variety("variety2") });
            project.Varieties[0].Words.AddRange(new[] { new Word("hɛ.loʊ", project.Meanings[0]), new Word("gan", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæ", project.Meanings[2]), new Word("ban", project.Meanings[2]) });
            project.Varieties[1].Words.AddRange(new[] { new Word("hɛ.ɬa", project.Meanings[0]), new Word("gud", project.Meanings[1]), new Word("tan", project.Meanings[1]), new Word("pæ", project.Meanings[2]) });
            project.WordAligners["primary"] = new TestWordAligner(segmentPool);
            var cognateIdentifier = Substitute.For <ICognateIdentifier>();

            cognateIdentifier.When(ci => ci.UpdateCognicity(Arg.Any <WordPair>(), Arg.Any <IWordAlignerResult>())).Do(ci =>
            {
                var wordPair = ci.Arg <WordPair>();
                if ((wordPair.Word1.StrRep == "hɛ.loʊ" && wordPair.Word2.StrRep == "hɛ.ɬa") ||
                    (wordPair.Word1.StrRep == "gʊd" && wordPair.Word2.StrRep == "tan") ||
                    (wordPair.Word1.StrRep == "bæ" && wordPair.Word2.StrRep == "pæ") ||
                    (wordPair.Word1.StrRep == "ban" && wordPair.Word2.StrRep == "pæ"))
                {
                    wordPair.AreCognatePredicted = true;
                    wordPair.CognicityScore      = 1.0;
                }
            });
            project.CognateIdentifiers["primary"] = cognateIdentifier;

            var varSegementer = new VarietySegmenter(project.Segmenter);

            foreach (Variety variety in project.Varieties)
            {
                varSegementer.Process(variety);
            }

            var vp = new VarietyPair(project.Varieties[0], project.Varieties[1]);

            project.VarietyPairs.Add(vp);

            var wordPairGenerator = new CognicityWordPairGenerator(segmentPool, project, 0.3, "primary", "primary");

            wordPairGenerator.Process(vp);

            WordPair wp = vp.WordPairs[0];

            Assert.That(wp.Word1.StrRep, Is.EqualTo("hɛ.loʊ"));
            Assert.That(wp.Word2.StrRep, Is.EqualTo("hɛ.ɬa"));

            wp = vp.WordPairs[1];
            Assert.That(wp.Word1.StrRep, Is.EqualTo("gʊd"));
            Assert.That(wp.Word2.StrRep, Is.EqualTo("tan"));

            wp = vp.WordPairs[2];
            Assert.That(wp.Word1.StrRep, Is.EqualTo("bæ"));
            Assert.That(wp.Word2.StrRep, Is.EqualTo("pæ"));
        }
Ejemplo n.º 19
0
        private CogProject CreateProject()
        {
            var project  = new CogProject();
            var variety1 = new Variety("variety1");

            project.Varieties.Add(variety1);
            var variety2 = new Variety("variety2");

            project.Varieties.Add(variety2);
            var variety3 = new Variety("variety3");

            project.Varieties.Add(variety3);
            var meaning1 = new Meaning("meaning1", null);

            project.Meanings.Add(meaning1);
            var meaning2 = new Meaning("meaning2", null);

            project.Meanings.Add(meaning2);
            var meaning3 = new Meaning("meaning3", null);

            project.Meanings.Add(meaning3);

            variety1.Words.Add(new Word("word1", meaning1));
            variety1.Words.Add(new Word("word2", meaning2));
            variety1.Words.Add(new Word("word3", meaning3));

            variety2.Words.Add(new Word("word4", meaning1));
            variety2.Words.Add(new Word("word5", meaning2));
            variety2.Words.Add(new Word("word6", meaning3));

            variety3.Words.Add(new Word("word7", meaning1));
            variety3.Words.Add(new Word("word8", meaning2));
            variety3.Words.Add(new Word("word9", meaning3));

            var vpGenerator = new VarietyPairGenerator();

            vpGenerator.Process(project);

            double score = 1.0;

            foreach (VarietyPair vp in project.VarietyPairs)
            {
                foreach (Meaning meaning in project.Meanings)
                {
                    Word     w1 = vp.Variety1.Words[meaning].First();
                    Word     w2 = vp.Variety2.Words[meaning].First();
                    WordPair wp = vp.WordPairs.Add(w1, w2);
                    wp.PredictedCognacyScore = score;
                    wp.PredictedCognacy      = true;
                    score -= 0.1;
                }
            }
            return(project);
        }
Ejemplo n.º 20
0
        public bool InsertNewUnknownWordIfDoesntExist(WordPair newUnknownWordCandidate)
        {
            bool unknownWordAdded = false;

            bool unknownWordAlreadyExist = _wordsRepository.CheckIfUnknownWordAlreadyExist(newUnknownWordCandidate.Id);

            if (!unknownWordAlreadyExist)
            {
                unknownWordAdded = _wordsRepository.AddNewUnknownWord(newUnknownWordCandidate.Id);
            }

            return(unknownWordAdded);
        }
Ejemplo n.º 21
0
        public bool RemoveLearnedUnknownWordIfExist(WordPair learnedWord)
        {
            bool unknownWordRemoved = false;

            bool unknownWordExists = _wordsRepository.CheckIfUnknownWordAlreadyExist(learnedWord.Id);

            if (unknownWordExists)
            {
                unknownWordRemoved = _wordsRepository.RemoveLearnedUnknownWord(learnedWord.Id);
            }

            return(unknownWordRemoved);
        }
Ejemplo n.º 22
0
        public void UpdateCognicity(WordPair wordPair, IWordAlignerResult alignerResult)
        {
            int    alignmentCount      = 0;
            double totalAlignmentScore = 0.0;

            foreach (Alignment <Word, ShapeNode> alignment in alignerResult.GetAlignments())
            {
                totalAlignmentScore += alignment.NormalizedScore;
                alignmentCount++;
            }
            wordPair.CognicityScore      = totalAlignmentScore / alignmentCount;
            wordPair.AreCognatePredicted = wordPair.CognicityScore >= _threshold;
        }
Ejemplo n.º 23
0
    public void GenerateWord()
    {
        wordIndex = Random.Range(0, words.Count);
        gameWord  = words[wordIndex];

        image = new GameObject();
        image.transform.SetParent(transform, true);
        image.transform.position = imagePosition.position;
        SpriteRenderer sr = image.AddComponent <SpriteRenderer>();

        sr.sprite           = gameWord.sprite;
        sr.sortingLayerName = "Foreground";
    }
Ejemplo n.º 24
0
        private void SelectNextPair()
        {
            this.lang1TextBox.Text = string.Empty;
            this.lang2TextBox.Text = string.Empty;
            if (this.wordPairList.Count > 0)
            {
                do
                {
                    this.currentPair = wordPairList[rnd.Next(wordPairList.Count)];
                } while (rnd.Next(this.currentPair.CorrectTranslations + this.currentPair.WrongTranslations) > this.currentPair.CorrectTranslations);

                this.lang1TextBox.Text = this.currentPair.Language1Word;
            }
        }
Ejemplo n.º 25
0
        public void WordPairGroups_InputTwoDifferentWords_ReturnsOneCollectionItemWithOneCount()
        {
            IEnumerable <WordPair> expected = new WordPair[] { new WordPair()
                                                               {
                                                                   Text = "quick brown", Count = 1
                                                               } };

            IEnumerable <string> words = new List <string> {
                "quick", "brown"
            };
            IEnumerable <WordPair> actual = histogram.GetWordPairGroups(words);

            Assert.That(expected.Select(wpSelector), Is.EquivalentTo(actual.Select(wpSelector)));
        }
Ejemplo n.º 26
0
        public void WordPairGroups_InputThreeIdenticalWords_ReturnsOneCollectionItemWithTwoCounts()
        {
            IEnumerable <WordPair> expected = new WordPair[] { new WordPair()
                                                               {
                                                                   Text = "quick quick", Count = 2
                                                               } };

            IEnumerable <string> words = new List <string> {
                "quick", "quick", "quick"
            };
            IEnumerable <WordPair> actual = histogram.GetWordPairGroups(words);

            Assert.That(expected.Select(wpSelector), Is.EquivalentTo(actual.Select(wpSelector)));
        }
Ejemplo n.º 27
0
        private void HandleIDontKnowWordButtonClickedEvent()
        {
            VerbalFormService.HandleVisibilityOnIDontKnowButtonClickedEvent(IDontKnowTheWordButton, NextWordButton,
                                                                            FirstLanguageWordTextBox, SecondLanguageWordTextBox);

            WordPair unknownWordToMove = _unknownWords[0];

            List <WordPair> wordsWithoutUnknownWord = _unknownWords.Where(unknownWord => unknownWord.Id != _currentUnknownWordPairId).ToList();

            wordsWithoutUnknownWord.Add(unknownWordToMove);

            _unknownWords             = wordsWithoutUnknownWord.ToArray();
            _currentUnknownWordPairId = _unknownWords.First().Id;
        }
        private void HandleIncorrectlyEnteredWord(TextBox textBox, string correctValueForTextBox)
        {
            GrammarFormService.HandleVisibilityOnIncorrectlyEnteredWordEvent(ValidateWordButton, NextWordButton,
                                                                             CorrectWordTextBox, textBox, correctValueForTextBox);

            WordPair unknownWordToMove = _unknownWords[0];

            List <WordPair> wordsWithoutUnknownWord = _unknownWords.Where(unknownWord => unknownWord.Id != _currentUnknownWordPairId).ToList();

            wordsWithoutUnknownWord.Add(unknownWordToMove);

            _unknownWords             = wordsWithoutUnknownWord.ToArray();
            _currentUnknownWordPairId = _unknownWords.First().Id;
        }
Ejemplo n.º 29
0
        public void UpdatePredictedCognacy(WordPair wordPair, IWordAlignerResult alignerResult)
        {
            wordPair.AlignmentNotes.Clear();
            Alignment<Word, ShapeNode> alignment = alignerResult.GetAlignments().First();
            int initialEquivalentClasses = 0;
            bool mismatchFound = false;
            for (int column = 0; column < alignment.ColumnCount; column++)
            {
                AlignmentCell<ShapeNode> cell1 = alignment[0, column];
                AlignmentCell<ShapeNode> cell2 = alignment[1, column];

                if ((cell1.Count > 0 && cell1[0].Type() == CogFeatureSystem.VowelType) || (cell2.Count > 0 && cell2[0].Type() == CogFeatureSystem.VowelType))
                {
                    wordPair.AlignmentNotes.Add("X");
                }
                else
                {
                    if (cell1.StrRep() == cell2.StrRep())
                    {
                        wordPair.AlignmentNotes.Add("1");
                        if (!mismatchFound)
                            initialEquivalentClasses++;
                    }
                    else
                    {
                        SoundClass sc1;
                        if (!_soundClasses.TryGetMatchingSoundClass(_segmentPool, alignment, 0, column, out sc1))
                            sc1 = null;
                        SoundClass sc2;
                        if (!_soundClasses.TryGetMatchingSoundClass(_segmentPool, alignment, 1, column, out sc2))
                            sc2 = null;
                        if (sc1 != null && sc2 != null && sc1 == sc2)
                        {
                            wordPair.AlignmentNotes.Add("1");
                            if (!mismatchFound)
                                initialEquivalentClasses++;
                        }
                        else
                        {
                            wordPair.AlignmentNotes.Add("0");
                            mismatchFound = true;
                        }
                    }
                }
            }

            wordPair.PredictedCognacy = !mismatchFound || initialEquivalentClasses >= _initialEquivalenceThreshold;
            wordPair.PredictedCognacyScore = (double) initialEquivalentClasses / alignment.ColumnCount;
        }
Ejemplo n.º 30
0
        public static void HanldeVerbalFormLoadedEvent(
            WordPair[] wordsArray, out int currentWordPairId, Label progressLabel,
            TextBox firstLanguageWordTextBox, TextBox secondLanguageWordTextBox)
        {
            new Random().Shuffle(wordsArray);

            currentWordPairId = wordsArray[0].Id;

            CommonFormService.SetProgressLabelText(progressLabel, wordsArray);

            WordPair firstWord = wordsArray.First();

            firstLanguageWordTextBox.Text  = firstLanguageWordTextBox.ReadOnly ? firstWord.FirstLanguageWord : String.Empty;
            secondLanguageWordTextBox.Text = secondLanguageWordTextBox.ReadOnly ? firstWord.SecondLanguageWord : String.Empty;
        }
Ejemplo n.º 31
0
        public WordPair ToWordPair(CogProject project, VarietyPair vp)
        {
            Meaning meaning = project.Meanings[Meaning];
            Word    word1   = vp.Variety1.Words[meaning].First(w => w.StrRep == Word1);
            Word    word2   = vp.Variety2.Words[meaning].First(w => w.StrRep == Word2);
            var     wp      = new WordPair(word1, word2)
            {
                AreCognatePredicted     = AreCognatePredicted,
                PhoneticSimilarityScore = PhoneticSimilarityScore,
                CognicityScore          = CognicityScore
            };

            wp.AlignmentNotes.AddRange(_alignmentNotes);
            return(wp);
        }
Ejemplo n.º 32
0
        public async Task AddWordsToLevelAsync(List <WordTranslation> wordTranslations, int gameLevelId)
        {
            foreach (WordTranslation pair in wordTranslations)
            {
                WordPair wordPair = await wordsService.AddPairAsync(pair).ConfigureAwait(false);

                var gameLevelWord = new GameLevelWord
                {
                    GameLevelId = gameLevelId,
                    WordPairId  = wordPair.WordPairId
                };

                await gameLevelWordRepository.CreateAsync(gameLevelWord).ConfigureAwait(false);
            }
        }
Ejemplo n.º 33
0
 public IWordAlignerResult Compute(WordPair wordPair)
 {
     return new PairwiseWordAlignerResult(this, Scorer, _settings, wordPair.Word1, wordPair.Word2);
 }
Ejemplo n.º 34
0
 public void UpdateCognacy(WordPair wordPair, IWordAlignerResult alignerResult)
 {
     wordPair.CognacyScore = alignerResult.GetAlignments().First().NormalizedScore;
     wordPair.AreCognatePredicted = wordPair.CognacyScore >= _threshold;
 }
Ejemplo n.º 35
0
        public void UpdatePredictedCognacy(WordPair wordPair, IWordAlignerResult alignerResult)
        {
            wordPair.AlignmentNotes.Clear();
            int cat1Count = 0;
            int cat1And2Count = 0;
            int totalCount = 0;
            Alignment<Word, ShapeNode> alignment = alignerResult.GetAlignments().First();
            for (int column = 0; column < alignment.ColumnCount; column++)
            {
                ShapeNode uLeftNode = alignment.GetLeftNode(0, column);
                Ngram<Segment> u = alignment[0, column].ToNgram(_segmentPool);
                ShapeNode uRightNode = alignment.GetRightNode(0, column);
                ShapeNode vLeftNode = alignment.GetLeftNode(1, column);
                Ngram<Segment> v = alignment[1, column].ToNgram(_segmentPool);
                ShapeNode vRightNode = alignment.GetRightNode(1, column);

                int cat = 3;
                if (u.Equals(v))
                {
                    cat = 1;
                }
                else if (_ignoredMappings.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode))
                {
                    cat = 0;
                }
                else if (u.Length == 0 || v.Length == 0)
                {
                    if (_similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode))
                        cat = 1;
                    else if (_ignoreRegularInsertionDeletion && IsRegular(wordPair, alignerResult, alignment, column, v))
                        cat = 0;
                }
                else if (u[0].Type == CogFeatureSystem.VowelType && v[0].Type == CogFeatureSystem.VowelType)
                {
                    cat = _similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode) ? 1 : 2;
                }
                else if (u[0].Type == CogFeatureSystem.ConsonantType && v[0].Type == CogFeatureSystem.ConsonantType)
                {
                    if (_regularConsEqual)
                    {
                        if (IsRegular(wordPair, alignerResult, alignment, column, v))
                            cat = 1;
                        else if (_similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode))
                            cat = 2;
                    }
                    else
                    {
                        if (_similarSegments.IsMapped(uLeftNode, u, uRightNode, vLeftNode, v, vRightNode))
                            cat = IsRegular(wordPair, alignerResult, alignment, column, v) ? 1 : 2;
                    }
                }

                if (cat > 0 && cat < 3)
                {
                    cat1And2Count++;
                    if (cat == 1)
                        cat1Count++;
                }
                wordPair.AlignmentNotes.Add(cat == 0 ? "-" : cat.ToString(CultureInfo.InvariantCulture));
                if (cat > 0)
                    totalCount++;
            }

            double type1Score = (double) cat1Count / totalCount;
            double type1And2Score = (double) cat1And2Count / totalCount;
            wordPair.PredictedCognacy = type1Score >= 0.5 && type1And2Score >= 0.75;
            wordPair.PredictedCognacyScore = (type1Score * 0.75) + (type1And2Score * 0.25);
        }
Ejemplo n.º 36
0
 private bool IsRegular(WordPair wordPair, IWordAlignerResult alignerResult, Alignment<Word, ShapeNode> alignment, int column, Ngram<Segment> v)
 {
     VarietyPair vp = wordPair.VarietyPair;
     SoundContext context = alignment.ToSoundContext(_segmentPool, 0, column, alignerResult.WordAligner.ContextualSoundClasses);
     FrequencyDistribution<Ngram<Segment>> freqDist = vp.CognateSoundCorrespondenceFrequencyDistribution[context];
     int threshold;
     if (_automaticRegularCorrespondenceThreshold)
     {
         int seg2Count = vp.CognateSoundCorrespondenceFrequencyDistribution.Conditions.Where(sc => sc.LeftEnvironment == context.LeftEnvironment && sc.RightEnvironment == context.RightEnvironment)
             .Sum(sc => vp.CognateSoundCorrespondenceFrequencyDistribution[sc][v]);
         if (!_regularCorrespondenceThresholdTable.TryGetThreshold(vp.CognateCount, freqDist.SampleOutcomeCount, seg2Count, out threshold))
             threshold = _defaultRegularCorrepondenceThreshold;
     }
     else
     {
         threshold = _defaultRegularCorrepondenceThreshold;
     }
     return freqDist[v] >= threshold;
 }