Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{
public class FileParatextProjectSettingsParser : ParatextProjectSettingsParserBase
{
public FileParatextProjectSettingsParser(string projectDir)
: base(new FileParatextProjectFileHandler(projectDir)) { }
public FileParatextProjectSettingsParser(string projectDir, ParatextProjectSettings parentSettings = null)
: base(new FileParatextProjectFileHandler(projectDir), parentSettings) { }

public static ParatextProjectSettings Parse(string projectDir)
public static ParatextProjectSettings Parse(string projectDir, ParatextProjectSettings parentSettings = null)
{
return new FileParatextProjectSettingsParser(projectDir).Parse();
return new FileParatextProjectSettingsParser(projectDir, parentSettings).Parse();
}
}
}
8 changes: 5 additions & 3 deletions src/SIL.Machine/Corpora/FileParatextProjectTextUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
{
public class FileParatextProjectTextUpdater : ParatextProjectTextUpdaterBase
{
public FileParatextProjectTextUpdater(string projectDir)
: base(new FileParatextProjectFileHandler(projectDir), FileParatextProjectSettingsParser.Parse(projectDir))
{ }
public FileParatextProjectTextUpdater(string projectDir, ParatextProjectSettings parentSettings = null)
: base(
new FileParatextProjectFileHandler(projectDir),
FileParatextProjectSettingsParser.Parse(projectDir, parentSettings)
) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ namespace SIL.Machine.Corpora
{
public class FileParatextProjectVersificationErrorDetector : ParatextProjectVersificationErrorDetectorBase
{
public FileParatextProjectVersificationErrorDetector(string projectDir)
: base(new FileParatextProjectFileHandler(projectDir), FileParatextProjectSettingsParser.Parse(projectDir))
{ }
public FileParatextProjectVersificationErrorDetector(
string projectDir,
ParatextProjectSettings parentSettings = null
)
: base(
new FileParatextProjectFileHandler(projectDir),
FileParatextProjectSettingsParser.Parse(projectDir, parentSettings)
) { }
}
}
16 changes: 13 additions & 3 deletions src/SIL.Machine/Corpora/ParatextBackupTermsCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ public ParatextBackupTermsCorpus(
string fileName,
IEnumerable<string> termCategories,
bool useTermGlosses = true,
IDictionary<string, HashSet<int>> chapters = null
IDictionary<string, HashSet<int>> chapters = null,
string parentFileName = null
)
{
ParatextProjectSettings parentSettings = null;
if (parentFileName != null)
{
using (var archive = ZipFile.OpenRead(parentFileName))
{
parentSettings = ZipParatextProjectSettingsParser.Parse(archive);
}
}

using (var archive = ZipFile.OpenRead(fileName))
{
IEnumerable<KeyTerm> keyTerms = new ZipParatextProjectTermsParser(archive)
IEnumerable<KeyTerm> keyTerms = new ZipParatextProjectTermsParser(archive, parentSettings)
.Parse(termCategories, useTermGlosses, chapters)
.OrderBy(g => g.Id);

ParatextProjectSettings settings = ZipParatextProjectSettingsParser.Parse(archive);
ParatextProjectSettings settings = ZipParatextProjectSettingsParser.Parse(archive, parentSettings);

string textId =
$"{settings.BiblicalTermsListType}:{settings.BiblicalTermsProjectName}:{settings.BiblicalTermsFileName}";
Expand Down
18 changes: 16 additions & 2 deletions src/SIL.Machine/Corpora/ParatextBackupTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ namespace SIL.Machine.Corpora
{
public class ParatextBackupTextCorpus : ScriptureTextCorpus
{
public ParatextBackupTextCorpus(string fileName, bool includeMarkers = false, bool includeAllText = false)
public ParatextBackupTextCorpus(
string fileName,
bool includeMarkers = false,
bool includeAllText = false,
string parentFileName = null
)
{
ParatextProjectSettings parentSettings = null;
if (parentFileName != null)
{
using (var archive = ZipFile.OpenRead(parentFileName))
{
parentSettings = ZipParatextProjectSettingsParser.Parse(archive);
}
}

using (ZipArchive archive = ZipFile.OpenRead(fileName))
{
var parser = new ZipParatextProjectSettingsParser(archive);
var parser = new ZipParatextProjectSettingsParser(archive, parentSettings);
ParatextProjectSettings settings = parser.Parse();

Versification = settings.Versification;
Expand Down
43 changes: 39 additions & 4 deletions src/SIL.Machine/Corpora/ParatextProjectSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using SIL.Scripture;
Expand All @@ -8,6 +9,7 @@ namespace SIL.Machine.Corpora
public class ParatextProjectSettings
{
public ParatextProjectSettings(
string guid,
string name,
string fullName,
Encoding encoding,
Expand All @@ -19,9 +21,14 @@ public ParatextProjectSettings(
string biblicalTermsListType,
string biblicalTermsProjectName,
string biblicalTermsFileName,
string languageCode
string languageCode,
string translationType,
string parentGuid = null,
string parentName = null,
ParatextProjectSettings parentSettings = null
)
{
Guid = guid;
Name = name;
FullName = fullName;
Encoding = encoding;
Expand All @@ -34,21 +41,40 @@ string languageCode
BiblicalTermsProjectName = biblicalTermsProjectName;
BiblicalTermsFileName = biblicalTermsFileName;
LanguageCode = languageCode;
TranslationType = translationType;
ParentGuid = parentGuid;
ParentName = parentName;
_parent = parentSettings;
}

public string Guid { get; }
public string Name { get; }
public string FullName { get; }
public Encoding Encoding { get; }
public ScrVers Versification { get; }
public ScrVers Versification { get; private set; }
public UsfmStylesheet Stylesheet { get; }
public string FileNamePrefix { get; }
public string FileNameForm { get; }
public string FileNameSuffix { get; }
public string BiblicalTermsListType { get; }
public string BiblicalTermsProjectName { get; }
public string BiblicalTermsFileName { get; }

public string LanguageCode { get; }
public string TranslationType { get; }
public string ParentGuid { get; }
public string ParentName { get; }
public ParatextProjectSettings Parent
{
get { return _parent; }
set
{
if (!IsDaughterProjectOf(value))
throw new ArgumentException($"Project {value.Name} is not the parent project of project {Name}.");
_parent = value;
Versification = value.Versification;
}
}
private ParatextProjectSettings _parent;

public bool IsBookFileName(string fileName, out string bookId)
{
Expand Down Expand Up @@ -114,6 +140,15 @@ public IEnumerable<string> GetAllScriptureBookIds()
}
}

public bool HasParent => !string.IsNullOrEmpty(ParentGuid);

public bool IsDaughterProjectOf(ParatextProjectSettings parentSettings)
{
if (!HasParent)
return false;
return ParentGuid.Equals(parentSettings.Guid);
}

private static string GetBookFileNameDigits(string bookId)
{
int bookNum = Canon.BookIdToNumber(bookId);
Expand Down
38 changes: 33 additions & 5 deletions src/SIL.Machine/Corpora/ParatextProjectSettingsParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ namespace SIL.Machine.Corpora
public abstract class ParatextProjectSettingsParserBase
{
private readonly IParatextProjectFileHandler _paratextProjectFileHandler;
private readonly ParatextProjectSettings _parentParatextProjectSettings;

public ParatextProjectSettingsParserBase(IParatextProjectFileHandler paratextProjectFileHandler)
public ParatextProjectSettingsParserBase(
IParatextProjectFileHandler paratextProjectFileHandler,
ParatextProjectSettings parentParatextProjectSettings = null
)
{
_paratextProjectFileHandler = paratextProjectFileHandler;
_parentParatextProjectSettings = parentParatextProjectSettings;
}

public ParatextProjectSettings Parse()
Expand All @@ -29,6 +34,7 @@ public ParatextProjectSettings Parse()
settingsDoc = XDocument.Load(stream);
}

string guid = settingsDoc.Root.Element("Guid").Value;
string name = settingsDoc.Root.Element("Name").Value;
string fullName = settingsDoc.Root.Element("FullName").Value;

Expand All @@ -45,7 +51,6 @@ public ParatextProjectSettings Parse()
var versification = new ScrVers((ScrVersType)scrVersType);
if (_paratextProjectFileHandler.Exists("custom.vrs"))
{
var guid = (string)settingsDoc.Root.Element("Guid");
string versName = ((ScrVersType)scrVersType).ToString() + "-" + guid;
if (Versification.Table.Implementation.Exists(versName))
{
Expand Down Expand Up @@ -107,14 +112,27 @@ public ParatextProjectSettings Parse()
string languageIsoCodeSetting = settingsDoc.Root.Element("LanguageIsoCode")?.Value;
if (languageIsoCodeSetting != null)
{
string[] languageIsoCodeSettingParts = settingsDoc.Root.Element("LanguageIsoCode").Value.Split(':');
string[] languageIsoCodeSettingParts = languageIsoCodeSetting.Split(':');
if (languageIsoCodeSettingParts.Length > 0)
{
languageCode = languageIsoCodeSettingParts[0];
}
}

return new ParatextProjectSettings(
string translationInfoSetting = settingsDoc.Root.Element("TranslationInfo")?.Value;
string translationType = "Standard";
string parentName = null;
string parentGuid = null;
if (translationInfoSetting != null)
{
string[] translationInfoSettingParts = translationInfoSetting.Split(':');
translationType = translationInfoSettingParts[0];
parentName = translationInfoSettingParts[1] != "" ? translationInfoSettingParts[1] : null;
parentGuid = translationInfoSettingParts[2] != "" ? translationInfoSettingParts[2] : null;
}

var settings = new ParatextProjectSettings(
guid,
name,
fullName,
encoding,
Expand All @@ -126,8 +144,18 @@ public ParatextProjectSettings Parse()
parts[0],
parts[1],
parts[2],
languageCode
languageCode,
translationType,
parentGuid,
parentName
);

if (_parentParatextProjectSettings != null && settings.HasParent)
{
settings.Parent = _parentParatextProjectSettings;
}

return settings;
}
}
}
16 changes: 14 additions & 2 deletions src/SIL.Machine/Corpora/ParatextTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ namespace SIL.Machine.Corpora
{
public class ParatextTextCorpus : ScriptureTextCorpus
{
public ParatextTextCorpus(string projectDir, bool includeMarkers = false, bool includeAllText = false)
public ParatextTextCorpus(
string projectDir,
bool includeMarkers = false,
bool includeAllText = false,
string parentProjectDir = null
)
{
var parser = new FileParatextProjectSettingsParser(projectDir);
ParatextProjectSettings parentSettings = null;
if (parentProjectDir != null)
{
var parentParser = new FileParatextProjectSettingsParser(parentProjectDir);
parentSettings = parentParser.Parse();
}

var parser = new FileParatextProjectSettingsParser(projectDir, parentSettings);
ParatextProjectSettings settings = parser.Parse();

Versification = settings.Versification;
Expand Down
8 changes: 4 additions & 4 deletions src/SIL.Machine/Corpora/ZipParatextProjectSettingsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace SIL.Machine.Corpora
{
public class ZipParatextProjectSettingsParser : ParatextProjectSettingsParserBase
{
public ZipParatextProjectSettingsParser(ZipArchive archive)
: base(new ZipParatextProjectFileHandler(archive)) { }
public ZipParatextProjectSettingsParser(ZipArchive archive, ParatextProjectSettings parentSettings = null)
: base(new ZipParatextProjectFileHandler(archive), parentSettings) { }

public static ParatextProjectSettings Parse(ZipArchive archive)
public static ParatextProjectSettings Parse(ZipArchive archive, ParatextProjectSettings parentSettings = null)
{
return new ZipParatextProjectSettingsParser(archive).Parse();
return new ZipParatextProjectSettingsParser(archive, parentSettings).Parse();
}
}
}
7 changes: 5 additions & 2 deletions src/SIL.Machine/Corpora/ZipParatextProjectTermsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace SIL.Machine.Corpora
{
public class ZipParatextProjectTermsParser : ParatextProjectTermsParserBase
{
public ZipParatextProjectTermsParser(ZipArchive archive)
: base(new ZipParatextProjectFileHandler(archive), ZipParatextProjectSettingsParser.Parse(archive)) { }
public ZipParatextProjectTermsParser(ZipArchive archive, ParatextProjectSettings parentSettings = null)
: base(
new ZipParatextProjectFileHandler(archive),
ZipParatextProjectSettingsParser.Parse(archive, parentSettings)
) { }
}
}
7 changes: 5 additions & 2 deletions src/SIL.Machine/Corpora/ZipParatextProjectTextUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace SIL.Machine.Corpora
{
public class ZipParatextProjectTextUpdater : ParatextProjectTextUpdaterBase
{
public ZipParatextProjectTextUpdater(ZipArchive archive)
: base(new ZipParatextProjectFileHandler(archive), ZipParatextProjectSettingsParser.Parse(archive)) { }
public ZipParatextProjectTextUpdater(ZipArchive archive, ParatextProjectSettings parentSettings = null)
: base(
new ZipParatextProjectFileHandler(archive),
ZipParatextProjectSettingsParser.Parse(archive, parentSettings)
) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ namespace SIL.Machine.Corpora
{
public class ZipParatextProjectVersificationErrorDetector : ParatextProjectVersificationErrorDetectorBase
{
public ZipParatextProjectVersificationErrorDetector(ZipArchive archive)
: base(new ZipParatextProjectFileHandler(archive), ZipParatextProjectSettingsParser.Parse(archive)) { }
public ZipParatextProjectVersificationErrorDetector(
ZipArchive archive,
ParatextProjectSettings parentSettings = null
)
: base(
new ZipParatextProjectFileHandler(archive),
ZipParatextProjectSettingsParser.Parse(archive, parentSettings)
) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ namespace SIL.Machine.PunctuationAnalysis
{
public class ZipParatextProjectQuoteConventionDetector : ParatextProjectQuoteConventionDetector
{
public ZipParatextProjectQuoteConventionDetector(ZipArchive archive)
: base(new ZipParatextProjectFileHandler(archive), ZipParatextProjectSettingsParser.Parse(archive)) { }
public ZipParatextProjectQuoteConventionDetector(
ZipArchive archive,
ParatextProjectSettings parentSettings = null
)
: base(
new ZipParatextProjectFileHandler(archive),
ZipParatextProjectSettingsParser.Parse(archive, parentSettings)
) { }
}
}
Loading
Loading