public void DeleteEntry_ByEntry_TriggersAfterEntryDeleted() { using (TemporaryFolder f = new TemporaryFolder("eventTests")) { using (LiftLexEntryRepository r = new LiftLexEntryRepository(f.GetPathForNewTempFile(true))) { r.AfterEntryDeleted += OnEvent; LexEntry entry = r.CreateItem(); r.SaveItem(entry); r.DeleteItem(entry); Assert.IsTrue(_gotEventCall); } } }
public void GetAllEntriesSortedByHeadWord_DeleteAfterFirstCall_EntryIsDeletedInResultSet() { LexEntry entrytoBeDeleted = CreateEntryWithLexicalFormBeforeFirstQuery("de", "word 0"); _repository.GetAllEntriesSortedByHeadword(WritingSystemDefinitionForTest("de", SystemFonts.DefaultFont)); _repository.DeleteItem(entrytoBeDeleted); ResultSet <LexEntry> results = _repository.GetAllEntriesSortedByHeadword(WritingSystemDefinitionForTest("de", SystemFonts.DefaultFont)); Assert.AreEqual(0, results.Count); }
/// <summary> /// Merge homographs. /// </summary> public static void Merge(LiftLexEntryRepository repo, string writingSystemIdForMatching, string[] traitsWithMultiplicity, IProgress progress) { var alreadyProcessed = new List<RepositoryId>(); var ids = new List<RepositoryId>(repo.GetAllItems()); foreach (RepositoryId id in ids) { if (progress.CancelRequested) { throw new OperationCanceledException("User cancelled"); } if (alreadyProcessed.Contains(id)) continue; alreadyProcessed.Add(id); var entry = repo.GetItem(id); var writingSystemForMatching = new WritingSystemDefinition(writingSystemIdForMatching) {DefaultCollation = new IcuRulesCollationDefinition("standard")}; var matches = repo.GetEntriesWithMatchingLexicalForm( entry.LexicalForm.GetExactAlternative(writingSystemIdForMatching), writingSystemForMatching ); //at this point we have entries which match along a single ws axis. We may or may not be able to merge them... var lexicalForm = entry.LexicalForm.GetExactAlternative(writingSystemForMatching.LanguageTag); if (matches.Count > 1) //>1 becuase each will match itself { progress.WriteMessageWithColor("gray", "Found {0} homograph(s) for {1}", matches.Count, lexicalForm); } var mergeCount = 0; var matchAlreadyProcessed = new List<RepositoryId>(); foreach (RecordToken<LexEntry> incomingMatch in matches) { if (incomingMatch.Id == id) continue; // The entry will match itself at least this time. if (matchAlreadyProcessed.Contains(incomingMatch.Id)) continue; //we'll be here at least as each element matches itself matchAlreadyProcessed.Add(incomingMatch.Id); if (EntryMerger.TryMergeEntries(entry, incomingMatch.RealObject, traitsWithMultiplicity, progress)) { mergeCount++; alreadyProcessed.Add(incomingMatch.Id); repo.DeleteItem(incomingMatch.RealObject); repo.SaveItem(entry); } } if (matches.Count > 1) { if (mergeCount == 0) { //progress.WriteMessageWithColor("gray", "Not merged."); } else { progress.WriteMessageWithColor("black", "Merged {0} homographs of {1}.", 1 + mergeCount, lexicalForm); } progress.WriteMessage(""); //blank line } } MergeSensesWithinEntries(repo, traitsWithMultiplicity, progress); }
public static void Merge(LiftLexEntryRepository repo, string writingSystemIdForMatching, string[] traitsWithMultiplicity, IProgress progress) { var alreadyProcessed = new List <RepositoryId>(); var ids = new List <RepositoryId>(repo.GetAllItems()); for (int i = 0; i < ids.Count; i++) { if (progress.CancelRequested) { throw new OperationCanceledException("User cancelled"); } if (alreadyProcessed.Contains(ids[i])) { continue; } alreadyProcessed.Add(ids[i]); var entry = repo.GetItem(ids[i]); var writingSystemForMatching = WritingSystemDefinition.Parse(writingSystemIdForMatching); var matches = repo.GetEntriesWithMatchingLexicalForm( entry.LexicalForm.GetExactAlternative(writingSystemIdForMatching), writingSystemForMatching ); //at this point we have entries which match along a single ws axis. We may or may not be able to merge them... var lexicalForm = entry.LexicalForm.GetExactAlternative(writingSystemForMatching.Id); if (matches.Count > 1) //>1 becuase each will match itself { progress.WriteMessageWithColor("gray", "Found {0} homograph(s) for {1}", matches.Count, lexicalForm); } var mergeCount = 0; var matchAlreadyProcessed = new List <RepositoryId>(); foreach (RecordToken <LexEntry> incomingMatch in matches) { if (incomingMatch.Id == ids[i]) { continue; // The entry will match itself at least this time. } if (matchAlreadyProcessed.Contains(incomingMatch.Id)) { continue; //we'll be here at least as each element matches itself } matchAlreadyProcessed.Add(incomingMatch.Id); if (EntryMerger.TryMergeEntries(entry, incomingMatch.RealObject, traitsWithMultiplicity, progress)) { mergeCount++; alreadyProcessed.Add(incomingMatch.Id); repo.DeleteItem(incomingMatch.RealObject); repo.SaveItem(entry); } } if (matches.Count > 1) { if (mergeCount == 0) { //progress.WriteMessageWithColor("gray", "Not merged."); } else { progress.WriteMessageWithColor("black", "Merged {0} homographs of {1}.", 1 + mergeCount, lexicalForm); } progress.WriteMessage(""); //blank line } } MergeSensesWithinEntries(repo, traitsWithMultiplicity, progress); }