Example #1
0
        private void CreateLexentryWithOnlyCitationForm(string citationForm, string writingSystemId)
        {
            LexEntry entry = _lexEntryRepository.CreateItem();

            entry.CitationForm[writingSystemId] = citationForm;
            _lexEntryRepository.SaveItem(entry);
        }
Example #2
0
        private void SaveAndCleanUpPreviousEntry()
        {
            LexEntry previousEntry = Control_EntryDetailPanel.DataSource;

            if (previousEntry != null)
            {
                previousEntry.PropertyChanged -= OnEntryChanged;
                if (!previousEntry.IsBeingDeleted)
                {
                    _lexEntryRepository.SaveItem(previousEntry);
                }
            }
        }
 public void ModifiedEntry_ByEntry_TriggersModifiedEntryAdded()
 {
     using (TemporaryFolder f = new TemporaryFolder("eventTests"))
     {
         using (LexEntryRepository r = new LexEntryRepository(f.GetPathForNewTempFile(true)))
         {
             LexEntry entry = r.CreateItem();
             r.SaveItem(entry);
             r.AfterEntryModified += OnEvent;
             entry.Senses.Add(new LexSense());
             r.SaveItem(entry);
             Assert.IsTrue(_gotEventCall);
         }
     }
 }
Example #4
0
        private Guid AddEntry(string lexemeForm,
                              string meaningWritingSystemId,
                              string meaning,
                              bool includeExample)
        {
            LexEntry entry = _lexEntryRepository.CreateItem();

            entry.LexicalForm.SetAlternative("th", lexemeForm);

            LexSense sense = new LexSense();

            entry.Senses.Add(sense);
#if GlossMeaning
            sense.Gloss[
                WeSayWordsProject.Project.DefaultViewTemplate.GetField("SenseGloss").WritingSystemIds[0]] =
                meaning;
#else
            sense.Definition.SetAlternative(meaningWritingSystemId, meaning);
#endif
            if (includeExample)
            {
                LexExampleSentence ex = new LexExampleSentence();
                sense.ExampleSentences.Add(ex);
                ex.Sentence.SetAlternative("th", "hello");
            }
            _lexEntryRepository.SaveItem(entry);
            return(entry.Guid);
        }
Example #5
0
 private void SaveRecord()
 {
     if (_missingInfoControl != null && _missingInfoControl.CurrentEntry != null)
     {
         LexEntryRepository.SaveItem(_missingInfoControl.CurrentEntry);
     }
 }
Example #6
0
        //private void OnCreateNewLexEntry(object sender,
        //                                      CreateNewArgs e)
        //{
        //    LexEntry newGuy = CreateNewLexEntry(e);
        //    e.NewlyCreatedItem = newGuy;

        //}

        private void OnCreateNewPairStringLexEntryId(object sender, CreateNewArgs e)
        {
            LexEntry newGuy = CreateNewLexEntry(e);
            IWritingSystemDefinition writingSystem = GetWritingSystemFromField();

            _lexEntryRepository.SaveItem(newGuy);
            _resultSet         = _lexEntryRepository.GetAllEntriesSortedByLexicalFormOrAlternative(writingSystem);
            e.NewlyCreatedItem = GetRecordTokenFromLexEntry(newGuy);
        }
Example #7
0
        private LexEntry CreateEntryWithLexicalFormBeforeFirstQuery(string writingSystem, string lexicalForm)
        {
            LexEntry entryBeforeFirstQuery = _repository.CreateItem();

            entryBeforeFirstQuery.LexicalForm.SetAlternative(writingSystem, lexicalForm);
            _repository.SaveItem(entryBeforeFirstQuery);
            return(entryBeforeFirstQuery);
        }
Example #8
0
        /// <summary>
        /// Adds this word and gloss, potentially adding the current semantic domain to multiple entriew with that word and gloss.
        /// </summary>
        /// <param name="lexicalForm"></param>
        /// <param name="gloss"></param>
        /// <returns>the entries that were modified </returns>
        public IList <LexEntry> AddWord(string lexicalForm, string gloss)
        {
            VerifyTaskActivated();

            if (string.IsNullOrEmpty(lexicalForm))
            {
                throw new ArgumentNullException();
            }
            var modifiedEntries = new List <LexEntry>();

            if (lexicalForm != string.Empty)
            {
                ResultSet <LexEntry> recordTokens =
                    LexEntryRepository.GetEntriesWithMatchingLexicalForm(lexicalForm,
                                                                         FormWritingSystem);
                if (recordTokens.Count == 0)                //no entries with a matching form
                {
                    LexEntry entry = LexEntryRepository.CreateItem();
                    entry.LexicalForm.SetAlternative(WordWritingSystemId, lexicalForm);
                    AddCurrentSemanticDomainToEntry(entry, gloss);
                    LexEntryRepository.SaveItem(entry);
                    modifiedEntries.Add(entry);

                    _logger.WriteConciseHistoricalEvent("SD-Added '{0}' with Domain to '{1}'", entry.GetSimpleFormForLogging(), CurrentDomainName);
                }
                else                // one or more matching entries
                {
                    var entriesMatchingWord = new List <LexEntry>(from RecordToken <LexEntry> x in recordTokens select x.RealObject);
                    foreach (var entry in entriesMatchingWord)
                    {
                        if (HasMatchingSense(entry, gloss))
                        {
                            modifiedEntries.Add(entry);
                            AddCurrentSemanticDomainToEntry(entry, gloss);
                            _logger.WriteConciseHistoricalEvent("SD-Added Domain to '{0}'", entry.GetSimpleFormForLogging());
                            break;
                        }
                    }
                    if (modifiedEntries.Count == 0)                     //didn't find any matching glosses
                    {
                        //NB: what to do IS NOT CLEAR. This just adds to the first entry,
                        // but it's just rolling the dice!  What to do???
                        var first = entriesMatchingWord.First();
                        modifiedEntries.Add(first);
                        AddCurrentSemanticDomainToEntry(first, gloss);
                        _logger.WriteConciseHistoricalEvent("SD-Added Domain {0} to '{1}' REVIEW", CurrentDomainName, first.GetSimpleFormForLogging());
                    }
                }
            }
            _savedSensesDuringMoveToEditArea = null;
            UpdateCurrentWords();
            return(modifiedEntries);
        }
        public void WordCollected_LexEntryAlreadyExists_WordAppearsInCompletedBox()
        {
            LexEntry e = _lexEntryRepository.CreateItem();

            e.LexicalForm[VernWs.Id] = "uno";
            Assert.AreEqual(1, _lexEntryRepository.CountAllItems());
            MultiText word = new MultiText();

            word[VernWs.Id] = "uno";
            Assert.AreEqual(0, e.Senses.Count);
            _lexEntryRepository.SaveItem(e);

            Task.NavigateFirstToShow();
            Task.WordCollected(word);
            Task.NavigateNext();
            Task.WordCollected(word);

            ResultSet <LexEntry> matchingLexicalForms = Task.GetRecordsWithMatchingMeaning();

            Assert.AreEqual(1, matchingLexicalForms.Count);
            Task.Deactivate();
        }
Example #10
0
        private LexEntry CreateEntry(string lexemeForm, string meaning)
        {
            LexEntry entry = _lexEntryRepository.CreateItem();

            entry.LexicalForm.SetAlternative(WritingSystemsIdsForTests.OtherIdForTest, lexemeForm);

            LexSense sense = new LexSense();

            entry.Senses.Add(sense);
            sense.Gloss[
                WeSayWordsProject.Project.DefaultViewTemplate.GetField(
                    LexSense.WellKnownProperties.Definition).WritingSystemIds[0]] = meaning;
            _lexEntryRepository.SaveItem(entry);
            return(entry);
        }
Example #11
0
        private void CreateTestEntry(string lexicalForm, string Definition, string exampleSentence)
        {
            var entry = _lexEntryRepository.CreateItem();

            entry.LexicalForm[_writingSystem.Id] = lexicalForm;
            var sense = new LexSense();

            entry.Senses.Add(sense);
            sense.Definition[WritingSystemsIdsForTests.AnalysisIdForTest] = Definition;
            var example = new LexExampleSentence();

            sense.ExampleSentences.Add(example);
            example.Sentence[_writingSystem.Id] = exampleSentence;
            _lexEntryRepository.SaveItem(entry);
            return;
        }
        public void DeleteEntry_ByEntry_TriggersAfterEntryDeleted()
        {
            using (TemporaryFolder f = new TemporaryFolder("eventTests"))
            {
                using (LexEntryRepository r = new LexEntryRepository(f.GetPathForNewTempFile(true)))
                {
                    r.AfterEntryDeleted += OnEvent;

                    LexEntry entry = r.CreateItem();
                    r.SaveItem(entry);

                    r.DeleteItem(entry);
                    Assert.IsTrue(_gotEventCall);
                }
            }
        }
Example #13
0
        public void Setup()
        {
            _tempFolder         = new TemporaryFolder();
            _filePath           = _tempFolder.GetTemporaryFile();
            _lexEntryRepository = new LexEntryRepository(_filePath);

            WeSayProjectTestHelper.InitializeForTests();
            RtfRenderer.HeadWordWritingSystemId = _vernacularWritingSystemId;

            _missingFieldName = LexSense.WellKnownProperties.Definition;

            LexEntry entry = _lexEntryRepository.CreateItem();

            _lexicalForm = "vernacular";
            entry.LexicalForm.SetAlternative(_vernacularWritingSystemId, _lexicalForm);
            _lexEntryRepository.SaveItem(entry);
            _longLabel          = "Long label";
            _remainingCountText = "Remaining count:";
            _referenceCountText = "Reference count:";

            _fieldsToShow = "LexicalForm";
            _label        = "My label";
            _description  = "My description";

            _viewTemplate = new ViewTemplate();
            _viewTemplate.Add(new Field(LexEntry.WellKnownProperties.LexicalUnit,
                                        "LexEntry",
                                        new string[] { _vernacularWritingSystemId }));
            _viewTemplate.Add(new Field(LexSense.WellKnownProperties.Definition,
                                        "LexSense",
                                        new string[] { "en" }));
            _viewTemplate.Add(new Field(Field.FieldNames.ExampleSentence.ToString(),
                                        "LexExampleSentence",
                                        new string[] { "th" }));
            _task = CreateMissingInfoTask(_lexEntryRepository,
                                          _missingFieldName,
                                          _label,
                                          _longLabel,
                                          _description,
                                          _remainingCountText,
                                          _referenceCountText,
                                          _viewTemplate,
                                          _fieldsToShow, string.Empty);
        }
Example #14
0
        private LexEntry CreateTestEntry(string lexicalForm, string meaning, string exampleSentence)
        {
            LexEntry entry = _lexEntryRepository.CreateItem();

            entry.LexicalForm[GetSomeValidWsIdForField("EntryLexicalForm")] = lexicalForm;
            LexSense sense = new LexSense();

            entry.Senses.Add(sense);
#if GlossMeaning
            sense.Gloss[GetSomeValidWsIdForField("SenseGloss")] = meaning;
#else
            sense.Definition[WritingSystemsIdsForTests.AnalysisIdForTest] = meaning;
#endif
            LexExampleSentence example = new LexExampleSentence();
            sense.ExampleSentences.Add(example);
            example.Sentence[GetSomeValidWsIdForField("ExampleSentence")] = exampleSentence;
            _lexEntryRepository.SaveItem(entry);
            return(entry);
        }
Example #15
0
        private string GetXhtmlContents(IList <LexEntry> entries)
        {
            if (entries != null)
            {
                entries.ForEach(e => _repo.SaveItem(e));
            }


            var pliftbuilder = new StringBuilder();

            using (var pexp = new PLiftExporter(pliftbuilder, false, _repo, _project.DefaultPrintingTemplate))
            {
                ResultSet <LexEntry> recordTokens =
                    _repo.GetAllEntriesSortedByHeadword(_project.DefaultPrintingTemplate.HeadwordWritingSystems[0]);


                foreach (RecordToken <LexEntry> token in recordTokens)
                {
                    pexp.Add(token.RealObject);
                }
                pexp.End();
            }
            var builder = new StringBuilder();

            using (var w = new StringWriter(builder))
            {
                var x = new FLExCompatibleXhtmlWriter();

                //  try
                {
                    x.Write(new StringReader(pliftbuilder.ToString()), w);
                }
//                catch(Exception e)
//                {
//                    Console.WriteLine(pliftbuilder.ToString());
//                    throw e;
//                }
            }
            return(builder.ToString());
        }
Example #16
0
        private LexEntry CreateTestEntry(string lexicalForm, string meaning, string exampleSentence)
        {
            List <String> headwordWritingSystemIds = new List <string>(_viewTemplate.GetHeadwordWritingSystemIds());
            string        wsA   = headwordWritingSystemIds[0];
            string        wsB   = _viewTemplate.GetDefaultWritingSystemForField("definition").Id;
            LexEntry      entry = _lexEntryRepository.CreateItem();

            entry.LexicalForm[wsA] = lexicalForm;
            LexSense sense = new LexSense();

#if GlossMeaning
            sense.Gloss[GetSomeValidWsIdForField("SenseGloss")] = meaning;
#else
            sense.Definition[wsB] = meaning;
#endif
            LexExampleSentence example = new LexExampleSentence();
            example.Sentence[wsA] = exampleSentence;
            sense.ExampleSentences.Add(example);
            entry.Senses.Add(sense);
            _lexEntryRepository.SaveItem(entry);
            return(entry);
        }
Example #17
0
        /// <summary>
        /// Removes the sense (if otherwise empty) and deletes the entry if it has no reason left to live
        /// </summary>
        public void TryToRemoveAssociationWithListWordFromEntry(RecordToken <LexEntry> recordToken)
        {
            // have to iterate through these in reverse order
            // since they might get modified
            LexEntry entry = recordToken.RealObject;

            for (int i = entry.Senses.Count - 1; i >= 0; i--)
            {
                if (entry.Senses[i].Equals(CurrentTemplateSense))
                {
                    entry.Senses.RemoveAt(i);
                }
            }
            entry.CleanUpAfterEditting();
            if (entry.IsEmptyExceptForLexemeFormForPurposesOfDeletion)
            {
                LexEntryRepository.DeleteItem(entry);
            }
            else
            {
                LexEntryRepository.SaveItem(entry);
            }
        }
Example #18
0
        /// <summary>
        /// Try to add the sense to a matching entry. If none found, make a new entry with the sense
        /// </summary>
        private void AddSenseToLexicon(MultiTextBase lexemeForm, LexSense sense)
        {
            //remove from the gloss and def any forms we don't want in our project for those fields
            foreach (var form in sense.Gloss.Forms)
            {
                //why are we checking definition writing system here? Well, the whole gloss/def thing continues to be murky. When gathering, we're just
                //trying to populate both.  And if you have your 1st def be, say, french, and don't have that in your glosses, well
                // in the WordList task, you won't see the words you gathered, because that's based on glosses!
                if (!_glossWritingSystemIds.Contains(form.WritingSystemId) && !_definitionWritingSystemIds.Contains(form.WritingSystemId))
                {
                    sense.Gloss.SetAlternative(form.WritingSystemId, null);
                }
            }
            foreach (var form in sense.Definition.Forms)
            {
                if (!_definitionWritingSystemIds.Contains(form.WritingSystemId) && !_glossWritingSystemIds.Contains(form.WritingSystemId))
                {
                    sense.Definition.SetAlternative(form.WritingSystemId, null);
                }
            }

            //I don't recall why we did this, but what it is doing is populating def from gloss and vice-versa, where there are blanks

            /* var definition = sense.Definition;
             * if(definition.Empty)
             * {
             *      foreach (var form in sense.Gloss.Forms)
             *      {
             *              //this check makes sure we don't introduce a form form a lang we allow for gloss, but not def
             *              if (_definitionWritingSystemIds.Contains(form.WritingSystemId))
             *                      definition.SetAlternative(form.WritingSystemId, form.Form);
             *      }
             * }
             *
             * var gloss = sense.Gloss;
             * if (gloss.Empty)
             * {
             *      foreach (var form in sense.Definition.Forms)
             *      {
             *              //this check makes sure we don't introduce a form form a lang we allow for def, but not gloss
             *              if (_glossWritingSystemIds.Contains(form.WritingSystemId))
             *                      gloss.SetAlternative(form.WritingSystemId, form.Form);
             *      }
             * } */

            //review: the desired semantics of this find are unclear, if we have more than one ws
            ResultSet <LexEntry> entriesWithSameForm =
                LexEntryRepository.GetEntriesWithMatchingLexicalForm(
                    lexemeForm[_lexicalUnitWritingSystem.Id], _lexicalUnitWritingSystem);
            var          meaningField = _glossMeaningField ? sense.Gloss : sense.Definition;
            LanguageForm firstMeaning = new LanguageForm("en", "-none-", null);

            if (meaningField.Forms.Length > 0)
            {
                firstMeaning = meaningField.Forms[0];
            }

            if (entriesWithSameForm.Count == 0)
            {
                LexEntry entry = LexEntryRepository.CreateItem();
                entry.LexicalForm.MergeIn(lexemeForm);
                entry.Senses.Add(sense.Clone());
                LexEntryRepository.SaveItem(entry);
                Logger.WriteEvent("WordList-Adding new word '{0}'and giving the sense '{1}'", entry.GetSimpleFormForLogging(), firstMeaning);
            }
            else
            {
                LexEntry entry = entriesWithSameForm[0].RealObject;

                foreach (LexSense s in entry.Senses)
                {
                    if (meaningField.Forms.Length > 0)
                    {
                        LanguageForm meaningWeAreAdding         = firstMeaning;
                        string       meaningInThisWritingSystem = _glossMeaningField ?
                                                                  s.Gloss.GetExactAlternative(meaningWeAreAdding.WritingSystemId) :
                                                                  s.Definition.GetExactAlternative(meaningWeAreAdding.WritingSystemId);
                        if (meaningInThisWritingSystem == meaningWeAreAdding.Form)
                        {
                            Logger.WriteEvent("WordList '{0}' already exists in '{1}'", firstMeaning, entry.GetSimpleFormForLogging());
                            return;                             //don't add it again
                        }
                    }
                }
                if (sense.Gloss.Forms.Length == 0 && sense.Definition.Forms.Length == 0 && sense.ExampleSentences.Count == 0)
                {
                    return;                    //nothing worth adding (may happen in unit test)
                }
                entry.Senses.Add(sense);

                //REVIEW: June 2011, Hatton added this, because of WS-34024: if a new *meaning* was added to an existing entry,
                //and then the user quit, this change was unsaved.
                LexEntryRepository.SaveItem(entry);
                Logger.WriteEvent("WordList-Added '{0}' to preexisting '{1}'", firstMeaning, entry.GetSimpleFormForLogging());
            }
        }
Example #19
0
        private void AddCurrentSemanticDomainToEntry(LexEntry entry, string meaning)
        {
            LexSense sense = null;

            ////This can lead to wrongly assigned semantic domains in the case of multiple senses. Say I gather "shoot"  in the "weapons" domain (no idea if that even exists but bear with me)
            ////then I gather "shoot" in the "plants" domain. Both domains would be assigned to the same sense. That being said I assume this approach was taken because it will USUALLY be
            ////what the user intends as homographs/multiple senses are not as frequent as one sense belonging to multiple domains (i.e. "Rain" could be "Universe/Creation", "Agriculture",
            ////"Times of year" etc etc.) --TA Oct/3/2012
            //is the meaning empty? Then just grab the first sense
            if (ShowMeaningField && string.IsNullOrEmpty(meaning))
            {
                sense = entry.Senses.FirstOrDefault();
            }
            else
            {
                if ((_savedSensesDuringMoveToEditArea != null) && (_savedSensesDuringMoveToEditArea.Count > 0))                //we are editing a word we entered previously
                {
                    //in this case, we have this saved sense we want to put back,
                    //which could conceivably have example sentences and other stuff
                    //so update the meaning in case they edited that
                    if (ShowMeaningField)
                    {
                        _savedSensesDuringMoveToEditArea[0].Definition.SetAlternative(DefinitionWritingSystem.Id, meaning);
                    }

                    //are there senses with a matching glosses?
                    foreach (var lexSense in _savedSensesDuringMoveToEditArea)
                    {
                        sense = entry.Senses.FirstOrDefault(s => s.Definition.ContainsEqualForm(
                                                                lexSense.Definition[DefinitionWritingSystem.Id],
                                                                DefinitionWritingSystem.Id));
                        if (sense != null)
                        {
                            //now, can we merge this sense in?
                            if (!SenseMerger.TryMergeSenseWithSomeExistingSense(sense, lexSense, new string[] {}, new NullProgress()))
                            {
                                //ah well, they'll have to hand-merge at some point
                                //Enhance: add a chorus note
                                entry.Senses.Add(lexSense);
                            }
                        }
                        else                         //ok, no matching sense to try and merge with, so just add this
                        {
                            entry.Senses.Add(lexSense);
                            sense = lexSense;
                        }
                    }
                }
                else
                {
                    //is there a sense with a matching gloss?
                    sense = entry.Senses.FirstOrDefault(s => s.Definition.ContainsEqualForm(meaning, DefinitionWritingSystem.Id));
                }
            }
            if (sense == null)
            {
                sense = entry.GetOrCreateSenseWithMeaning(new MultiText());
                sense.Definition.SetAlternative(DefinitionWritingSystem.Id, meaning);
            }
            OptionRefCollection semanticDomains =
                sense.GetOrCreateProperty <OptionRefCollection>(_semanticDomainField.FieldName);

            if (!semanticDomains.Contains(CurrentDomainKey))
            {
                semanticDomains.Add(CurrentDomainKey);
            }
            LexEntryRepository.SaveItem(entry);
        }
Example #20
0
        public void PrepareToMoveWordToEditArea(WordDisplay wordDisplay)
        {
            VerifyTaskActivated();
            _savedSensesDuringMoveToEditArea = null;

            if (wordDisplay == null)
            {
                throw new ArgumentNullException();
            }
            // this task was coded to have a list of word-forms, not actual entries.
            //so we have to go searching for possible matches at this point.
            ResultSet <LexEntry> matchingEntries =
                LexEntryRepository.GetEntriesWithMatchingLexicalForm(wordDisplay.Vernacular.Form, FormWritingSystem);

            foreach (RecordToken <LexEntry> recordToken in matchingEntries)
            {
                if (_savedSensesDuringMoveToEditArea == null)
                {
                    _savedSensesDuringMoveToEditArea = new List <LexSense>();
                }
                // have to iterate through these in reverse order since they might get modified
                LexEntry entry = recordToken.RealObject;
                //If we aren't showing the meaning field then we are going let any edits effect all matching Senses
                if (!ShowMeaningField)
                {
                    for (int i = entry.Senses.Count - 1; i >= 0; i--)
                    {
                        LexSense sense           = entry.Senses[i];
                        var      semanticDomains = sense.GetProperty <OptionRefCollection>(_semanticDomainField.FieldName);
                        if (semanticDomains != null)
                        {
                            if (semanticDomains.Contains(CurrentDomainKey))
                            {
                                RememberMeaningOfDissociatedWord(sense);
                                entry.Senses.Remove(sense);
                                //if we don't do this and it has a meaning, we'll fail to delete the word when the user is trying to correct the spelling. (WS-34245)
                            }
                        }
                    }
                }
                //If we are showing the meaning field then we only let edits effect the sense that matches the shown meaning (definition)
                else
                {
                    var firstSenseMatchingSemDomAndMeaning =
                        entry.Senses.
                        Where(s => s.GetProperty <OptionRefCollection>(LexSense.WellKnownProperties.SemanticDomainDdp4) != null).
                        FirstOrDefault(s => s.GetProperty <OptionRefCollection>(LexSense.WellKnownProperties.SemanticDomainDdp4).Contains(CurrentDomainKey) &&
                                       s.Definition.GetBestAlternative(new[] { DefinitionWritingSystem.Id }) == wordDisplay.Meaning);
                    if (firstSenseMatchingSemDomAndMeaning != null)
                    {
                        RememberMeaningOfDissociatedWord(firstSenseMatchingSemDomAndMeaning);
                        entry.Senses.Remove(firstSenseMatchingSemDomAndMeaning);
                    }
                }
                entry.CleanUpAfterEditting();
                if (entry.IsEmptyExceptForLexemeFormForPurposesOfDeletion)
                {
                    LexEntryRepository.DeleteItem(entry);                     // if there are no senses left, get rid of it
                }
                else
                {
                    LexEntryRepository.SaveItem(entry);
                }
            }

            UpdateCurrentWords();
        }