Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix terms bugs #208

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading