From efee3f8d72fdf6443411d68e93733f09553889b2 Mon Sep 17 00:00:00 2001 From: Jason Naylor Date: Tue, 25 Aug 2020 14:43:00 -0500 Subject: [PATCH] Do not export deleted senses (#643) * Do not export deleted senses * Exclude non-active senses during the export * Minor code clean-up --- Backend.Tests/LiftControllerTests.cs | 8 +++++++- Backend/Services/LiftApiServices.cs | 17 ++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Backend.Tests/LiftControllerTests.cs b/Backend.Tests/LiftControllerTests.cs index 8575608ed0..727f47687b 100644 --- a/Backend.Tests/LiftControllerTests.cs +++ b/Backend.Tests/LiftControllerTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using BackendFramework.Controllers; using BackendFramework.Helper; using BackendFramework.Interfaces; @@ -179,7 +180,9 @@ public void TestExportDeleted() _projServ.Create(proj); var word = RandomWord(proj.Id); + var secondWord = RandomWord(proj.Id); var createdWord = _wordrepo.Create(word).Result; + _wordrepo.Create(secondWord); word.Id = ""; word.Vernacular = "updated"; @@ -192,8 +195,10 @@ public void TestExportDeleted() var exportPath = Path.Combine(combinePath, proj.Id, "Export", "LiftExport", Path.Combine("Lift", "NewLiftFile.lift")); var text = File.ReadAllText(exportPath, Encoding.UTF8); + // Make sure we exported 2 live and one dead entry + Assert.That(Regex.Matches(text, " x.Senses.Any(s => s.Accessibility == State.Active)).ToList(); - // TODO: this is wrong, deleted is a subset of active, are not exclusive - var deletedWords = allWords.Where(x => activeWords.Contains(x)).ToList(); + // All words in the frontier with any senses are considered current. The Combine does not import senseless entries + // and the interface is supposed to prevent creating them. So the the words found in allWords, but not in activeWords + // are exported as 'deleted'. + var deletedWords = allWords.Where(x => !activeWords.Contains(x)).ToList(); foreach (var wordEntry in activeWords) { var entry = new LexEntry(); @@ -254,11 +256,12 @@ private void AddVern(LexEntry entry, Word wordEntry, string projectId) /// Adds each sense of a word to be written out to lift private void AddSenses(LexEntry entry, Word wordEntry) { - for (var i = 0; i < wordEntry.Senses.Count; i++) + var activeSenses = wordEntry.Senses.Where(s => s.Accessibility == State.Active).ToList(); + foreach (var currentSense in activeSenses) { // Merge in senses var dict = new Dictionary(); - foreach (var gloss in wordEntry.Senses[i].Glosses) + foreach (var gloss in currentSense.Glosses) { if (dict.ContainsKey(gloss.Language)) { @@ -277,12 +280,12 @@ private void AddSenses(LexEntry entry, Word wordEntry) entry.Senses.Add(lexSense); // Merge in semantic domains - foreach (var semdom in wordEntry.Senses[i].SemanticDomains) + foreach (var semDom in currentSense.SemanticDomains) { var orc = new OptionRefCollection(); - orc.Add(semdom.Id + " " + semdom.Name); + orc.Add(semDom.Id + " " + semDom.Name); - entry.Senses[i].Properties.Add( + lexSense.Properties.Add( new KeyValuePair("semantic-domain-ddp4", orc)); } }