Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix error on terms id duplication
  • Loading branch information
Enkidu93 authored and johnml1135 committed Jun 7, 2024
1 parent afc6328 commit 2fb3422
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/SIL.Machine/Corpora/ParatextBackupTermsCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using SIL.Extensions;

namespace SIL.Machine.Corpora
{
Expand All @@ -21,7 +22,6 @@ public class ParatextBackupTermsCorpus : DictionaryTextCorpus

public ParatextBackupTermsCorpus(string fileName, IEnumerable<string> termCategories)
{
List<TextRow> rows = new List<TextRow>();
using (var archive = ZipFile.OpenRead(fileName))
{
ZipArchiveEntry termsFileEntry = archive.GetEntry("TermRenderings.xml");
Expand All @@ -41,7 +41,30 @@ public ParatextBackupTermsCorpus(string fileName, IEnumerable<string> termCatego

XDocument biblicalTermsDoc;
IDictionary<string, string> termIdToCategoryDictionary;
if (PredefinedTermsListTypes.Contains(settings.BiblicalTermsListType))
if (settings.BiblicalTermsListType == "Project")
{
if (biblicalTermsFileEntry != null)
{
using (Stream keyTermsFile = biblicalTermsFileEntry.Open())
{
biblicalTermsDoc = XDocument.Load(keyTermsFile);
termIdToCategoryDictionary = GetCategoryPerId(biblicalTermsDoc);
}
}
else
{
using (
Stream keyTermsFile = Assembly
.GetExecutingAssembly()
.GetManifestResourceStream("SIL.Machine.Corpora.BiblicalTerms.xml")
)
{
biblicalTermsDoc = XDocument.Load(keyTermsFile);
termIdToCategoryDictionary = GetCategoryPerId(biblicalTermsDoc);
}
}
}
else if (PredefinedTermsListTypes.Contains(settings.BiblicalTermsListType))
{
using (
Stream keyTermsFile = Assembly
Expand All @@ -53,17 +76,6 @@ public ParatextBackupTermsCorpus(string fileName, IEnumerable<string> termCatego
termIdToCategoryDictionary = GetCategoryPerId(biblicalTermsDoc);
}
}
else if (
settings.BiblicalTermsListType == "Project"
&& settings.BiblicalTermsProjectName == settings.Name
)
{
using (Stream keyTermsFile = biblicalTermsFileEntry.Open())
{
biblicalTermsDoc = XDocument.Load(keyTermsFile);
termIdToCategoryDictionary = GetCategoryPerId(biblicalTermsDoc);
}
}
else
{
termIdToCategoryDictionary = new Dictionary<string, string>();
Expand All @@ -75,6 +87,7 @@ public ParatextBackupTermsCorpus(string fileName, IEnumerable<string> termCatego

string textId =
$"{settings.BiblicalTermsListType}:{settings.BiblicalTermsProjectName}:{settings.BiblicalTermsFileName}";
List<TextRow> rows = new List<TextRow>();
foreach (XElement element in termsElements)
{
string id = element.Attribute("Id").Value;
Expand Down Expand Up @@ -160,6 +173,7 @@ private static IDictionary<string, string> GetCategoryPerId(XDocument biblicalTe
return biblicalTermsDocument
.Descendants()
.Where(n => n.Name.LocalName == "Term")
.DistinctBy(e => e.Attribute("Id").Value)
.ToDictionary(e => e.Attribute("Id").Value, e => e.Element("Category")?.Value ?? "");
}
}
Expand Down

0 comments on commit 2fb3422

Please sign in to comment.