Skip to content

Commit

Permalink
[Import] Use vernacular writing system in vernacular selection (#2883)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Jan 16, 2024
1 parent 761f557 commit a8e6f4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
15 changes: 8 additions & 7 deletions Backend/Controllers/LiftController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,22 @@ private async Task<IActionResult> AddImportToProject(string liftStoragePath, str
return new UnsupportedMediaTypeResult();
}

var proj = await _projRepo.GetProject(projectId);
if (proj is null)
{
return NotFound(projectId);
}

int liftParseResult;
// Sets the projectId of our parser to add words to that project
var liftMerger = _liftService.GetLiftImporterExporter(projectId, _wordRepo);
var liftMerger = _liftService.GetLiftImporterExporter(
projectId, proj.VernacularWritingSystem.Bcp47, _wordRepo);
var importedAnalysisWritingSystems = new List<WritingSystem>();
var doesImportHaveDefinitions = false;
var doesImportHaveGrammaticalInfo = false;
try
{
// Add character set to project from ldml file
var proj = await _projRepo.GetProject(projectId);
if (proj is null)
{
return NotFound(projectId);
}

await _liftService.LdmlImport(liftStoragePath, _projRepo, proj);

var parser = new LiftParser<LiftObject, LiftEntry, LiftSense, LiftExample>(liftMerger);
Expand Down
2 changes: 1 addition & 1 deletion Backend/Interfaces/ILiftService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BackendFramework.Interfaces
{
public interface ILiftService
{
ILiftMerger GetLiftImporterExporter(string projectId, IWordRepository wordRepo);
ILiftMerger GetLiftImporterExporter(string projectId, string vernLang, IWordRepository wordRepo);
Task<bool> LdmlImport(string dirPath, IProjectRepository projRepo, Project project);
Task<string> LiftExport(string projectId, IWordRepository wordRepo, IProjectRepository projRepo);
Task<List<string>> CreateLiftRanges(List<Word> projWords, List<SemanticDomain> projDoms, string rangesDest);
Expand Down
29 changes: 19 additions & 10 deletions Backend/Services/LiftService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@ public static string MakeSafeXmlAttribute(string sInput)
return SecurityElement.Escape(sInput);
}

public ILiftMerger GetLiftImporterExporter(string projectId, IWordRepository wordRepo)
public ILiftMerger GetLiftImporterExporter(string projectId, string vernLang, IWordRepository wordRepo)
{
return new LiftMerger(projectId, wordRepo);
return new LiftMerger(projectId, vernLang, wordRepo);
}

private static void WriteRangeElement(
Expand Down Expand Up @@ -664,12 +664,14 @@ protected ExportException(SerializationInfo info, StreamingContext context) : ba
private sealed class LiftMerger : ILiftMerger
{
private readonly string _projectId;
private readonly string _vernLang;
private readonly IWordRepository _wordRepo;
private readonly List<Word> _importEntries = new();

public LiftMerger(string projectId, IWordRepository wordRepo)
public LiftMerger(string projectId, string vernLang, IWordRepository wordRepo)
{
_projectId = projectId;
_vernLang = vernLang;
_wordRepo = wordRepo;
}

Expand Down Expand Up @@ -750,20 +752,27 @@ public void FinishEntry(LiftEntry entry)
newWord.Note = new Note(language, liftString.Text);
}

// Add vernacular
// TODO: currently we just add the first listed option, we may want to choose eventually
if (!entry.CitationForm.IsEmpty) // Prefer citation form for vernacular
// Add vernacular, prioritizing citation form over vernacular form.
var vern = entry.CitationForm.FirstOrDefault(x => x.Key == _vernLang).Value?.Text;
if (string.IsNullOrWhiteSpace(vern))
{
newWord.Vernacular = entry.CitationForm.FirstValue.Value.Text;
vern = entry.LexicalForm.FirstOrDefault(x => x.Key == _vernLang).Value?.Text;
}
else if (!entry.LexicalForm.IsEmpty) // lexeme form for backup
// If not available in the project's vernacular writing system, fall back to the first available one.
if (string.IsNullOrWhiteSpace(vern))
{
newWord.Vernacular = entry.LexicalForm.FirstValue.Value.Text;
vern = entry.CitationForm.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Value.Text)).Value?.Text;
}
else // this is not a word if there is no vernacular
if (string.IsNullOrWhiteSpace(vern))
{
vern = entry.LexicalForm.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Value.Text)).Value?.Text;
}
// This is not a word if there is no vernacular.
if (string.IsNullOrWhiteSpace(vern))
{
return;
}
newWord.Vernacular = vern;

// This is not a word if there are no senses
if (entry.Senses.Count == 0)
Expand Down

0 comments on commit a8e6f4f

Please sign in to comment.