Skip to content

Commit be83dea

Browse files
committed
1 parent 41bd65e commit be83dea

16 files changed

Lines changed: 209 additions & 44 deletions

src/SIL.Machine/Corpora/FileParatextProjectSettingsParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
{
33
public class FileParatextProjectSettingsParser : ParatextProjectSettingsParserBase
44
{
5-
public FileParatextProjectSettingsParser(string projectDir)
6-
: base(new FileParatextProjectFileHandler(projectDir)) { }
5+
public FileParatextProjectSettingsParser(string projectDir, ParatextProjectSettings parentSettings = null)
6+
: base(new FileParatextProjectFileHandler(projectDir), parentSettings) { }
77

8-
public static ParatextProjectSettings Parse(string projectDir)
8+
public static ParatextProjectSettings Parse(string projectDir, ParatextProjectSettings parentSettings = null)
99
{
10-
return new FileParatextProjectSettingsParser(projectDir).Parse();
10+
return new FileParatextProjectSettingsParser(projectDir, parentSettings).Parse();
1111
}
1212
}
1313
}

src/SIL.Machine/Corpora/FileParatextProjectTextUpdater.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
{
33
public class FileParatextProjectTextUpdater : ParatextProjectTextUpdaterBase
44
{
5-
public FileParatextProjectTextUpdater(string projectDir)
6-
: base(new FileParatextProjectFileHandler(projectDir), FileParatextProjectSettingsParser.Parse(projectDir))
7-
{ }
5+
public FileParatextProjectTextUpdater(string projectDir, ParatextProjectSettings parentSettings = null)
6+
: base(
7+
new FileParatextProjectFileHandler(projectDir),
8+
FileParatextProjectSettingsParser.Parse(projectDir, parentSettings)
9+
) { }
810
}
911
}

src/SIL.Machine/Corpora/FileParatextProjectVersificationErrorDetector.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ namespace SIL.Machine.Corpora
22
{
33
public class FileParatextProjectVersificationErrorDetector : ParatextProjectVersificationErrorDetectorBase
44
{
5-
public FileParatextProjectVersificationErrorDetector(string projectDir)
6-
: base(new FileParatextProjectFileHandler(projectDir), FileParatextProjectSettingsParser.Parse(projectDir))
7-
{ }
5+
public FileParatextProjectVersificationErrorDetector(
6+
string projectDir,
7+
ParatextProjectSettings parentSettings = null
8+
)
9+
: base(
10+
new FileParatextProjectFileHandler(projectDir),
11+
FileParatextProjectSettingsParser.Parse(projectDir, parentSettings)
12+
) { }
813
}
914
}

src/SIL.Machine/Corpora/ParatextBackupTermsCorpus.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,26 @@ public ParatextBackupTermsCorpus(
1010
string fileName,
1111
IEnumerable<string> termCategories,
1212
bool useTermGlosses = true,
13-
IDictionary<string, HashSet<int>> chapters = null
13+
IDictionary<string, HashSet<int>> chapters = null,
14+
string parentFileName = null
1415
)
1516
{
17+
ParatextProjectSettings parentSettings = null;
18+
if (parentFileName != null)
19+
{
20+
using (var archive = ZipFile.OpenRead(parentFileName))
21+
{
22+
parentSettings = ZipParatextProjectSettingsParser.Parse(archive);
23+
}
24+
}
25+
1626
using (var archive = ZipFile.OpenRead(fileName))
1727
{
18-
IEnumerable<KeyTerm> keyTerms = new ZipParatextProjectTermsParser(archive)
28+
IEnumerable<KeyTerm> keyTerms = new ZipParatextProjectTermsParser(archive, parentSettings)
1929
.Parse(termCategories, useTermGlosses, chapters)
2030
.OrderBy(g => g.Id);
2131

22-
ParatextProjectSettings settings = ZipParatextProjectSettingsParser.Parse(archive);
32+
ParatextProjectSettings settings = ZipParatextProjectSettingsParser.Parse(archive, parentSettings);
2333

2434
string textId =
2535
$"{settings.BiblicalTermsListType}:{settings.BiblicalTermsProjectName}:{settings.BiblicalTermsFileName}";

src/SIL.Machine/Corpora/ParatextBackupTextCorpus.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@ namespace SIL.Machine.Corpora
44
{
55
public class ParatextBackupTextCorpus : ScriptureTextCorpus
66
{
7-
public ParatextBackupTextCorpus(string fileName, bool includeMarkers = false, bool includeAllText = false)
7+
public ParatextBackupTextCorpus(
8+
string fileName,
9+
bool includeMarkers = false,
10+
bool includeAllText = false,
11+
string parentFileName = null
12+
)
813
{
14+
ParatextProjectSettings parentSettings = null;
15+
if (parentFileName != null)
16+
{
17+
using (var archive = ZipFile.OpenRead(parentFileName))
18+
{
19+
parentSettings = ZipParatextProjectSettingsParser.Parse(archive);
20+
}
21+
}
22+
923
using (ZipArchive archive = ZipFile.OpenRead(fileName))
1024
{
11-
var parser = new ZipParatextProjectSettingsParser(archive);
25+
var parser = new ZipParatextProjectSettingsParser(archive, parentSettings);
1226
ParatextProjectSettings settings = parser.Parse();
1327

1428
Versification = settings.Versification;

src/SIL.Machine/Corpora/ParatextProjectSettings.cs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Globalization;
34
using System.Text;
45
using SIL.Scripture;
@@ -8,6 +9,7 @@ namespace SIL.Machine.Corpora
89
public class ParatextProjectSettings
910
{
1011
public ParatextProjectSettings(
12+
string guid,
1113
string name,
1214
string fullName,
1315
Encoding encoding,
@@ -19,9 +21,14 @@ public ParatextProjectSettings(
1921
string biblicalTermsListType,
2022
string biblicalTermsProjectName,
2123
string biblicalTermsFileName,
22-
string languageCode
24+
string languageCode,
25+
string translationType,
26+
string parentGuid = null,
27+
string parentName = null,
28+
ParatextProjectSettings parentSettings = null
2329
)
2430
{
31+
Guid = guid;
2532
Name = name;
2633
FullName = fullName;
2734
Encoding = encoding;
@@ -34,21 +41,40 @@ string languageCode
3441
BiblicalTermsProjectName = biblicalTermsProjectName;
3542
BiblicalTermsFileName = biblicalTermsFileName;
3643
LanguageCode = languageCode;
44+
TranslationType = translationType;
45+
ParentGuid = parentGuid;
46+
ParentName = parentName;
47+
Parent = parentSettings;
3748
}
3849

50+
public string Guid { get; }
3951
public string Name { get; }
4052
public string FullName { get; }
4153
public Encoding Encoding { get; }
42-
public ScrVers Versification { get; }
54+
public ScrVers Versification { get; private set; }
4355
public UsfmStylesheet Stylesheet { get; }
4456
public string FileNamePrefix { get; }
4557
public string FileNameForm { get; }
4658
public string FileNameSuffix { get; }
4759
public string BiblicalTermsListType { get; }
4860
public string BiblicalTermsProjectName { get; }
4961
public string BiblicalTermsFileName { get; }
50-
5162
public string LanguageCode { get; }
63+
public string TranslationType { get; }
64+
public string ParentGuid { get; }
65+
public string ParentName { get; }
66+
public ParatextProjectSettings Parent
67+
{
68+
get { return _parent; }
69+
set
70+
{
71+
if (!IsDaughterProjectOf(value))
72+
throw new ArgumentException($"Project {value.Name} is not the parent project of project {Name}.");
73+
_parent = value;
74+
Versification = value.Versification;
75+
}
76+
}
77+
private ParatextProjectSettings _parent;
5278

5379
public bool IsBookFileName(string fileName, out string bookId)
5480
{
@@ -114,6 +140,15 @@ public IEnumerable<string> GetAllScriptureBookIds()
114140
}
115141
}
116142

143+
public bool HasParent => !string.IsNullOrEmpty(ParentGuid);
144+
145+
public bool IsDaughterProjectOf(ParatextProjectSettings parentSettings)
146+
{
147+
if (!HasParent)
148+
return false;
149+
return ParentGuid.Equals(parentSettings.Guid);
150+
}
151+
117152
private static string GetBookFileNameDigits(string bookId)
118153
{
119154
int bookNum = Canon.BookIdToNumber(bookId);

src/SIL.Machine/Corpora/ParatextProjectSettingsParserBase.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ namespace SIL.Machine.Corpora
99
public abstract class ParatextProjectSettingsParserBase
1010
{
1111
private readonly IParatextProjectFileHandler _paratextProjectFileHandler;
12+
private readonly ParatextProjectSettings _parentParatextProjectSettings;
1213

13-
public ParatextProjectSettingsParserBase(IParatextProjectFileHandler paratextProjectFileHandler)
14+
public ParatextProjectSettingsParserBase(
15+
IParatextProjectFileHandler paratextProjectFileHandler,
16+
ParatextProjectSettings parentParatextProjectSettings = null
17+
)
1418
{
1519
_paratextProjectFileHandler = paratextProjectFileHandler;
20+
_parentParatextProjectSettings = parentParatextProjectSettings;
1621
}
1722

1823
public ParatextProjectSettings Parse()
@@ -29,6 +34,7 @@ public ParatextProjectSettings Parse()
2934
settingsDoc = XDocument.Load(stream);
3035
}
3136

37+
string guid = settingsDoc.Root.Element("Guid").Value;
3238
string name = settingsDoc.Root.Element("Name").Value;
3339
string fullName = settingsDoc.Root.Element("FullName").Value;
3440

@@ -45,7 +51,6 @@ public ParatextProjectSettings Parse()
4551
var versification = new ScrVers((ScrVersType)scrVersType);
4652
if (_paratextProjectFileHandler.Exists("custom.vrs"))
4753
{
48-
var guid = (string)settingsDoc.Root.Element("Guid");
4954
string versName = ((ScrVersType)scrVersType).ToString() + "-" + guid;
5055
if (Versification.Table.Implementation.Exists(versName))
5156
{
@@ -107,14 +112,27 @@ public ParatextProjectSettings Parse()
107112
string languageIsoCodeSetting = settingsDoc.Root.Element("LanguageIsoCode")?.Value;
108113
if (languageIsoCodeSetting != null)
109114
{
110-
string[] languageIsoCodeSettingParts = settingsDoc.Root.Element("LanguageIsoCode").Value.Split(':');
115+
string[] languageIsoCodeSettingParts = languageIsoCodeSetting.Split(':');
111116
if (languageIsoCodeSettingParts.Length > 0)
112117
{
113118
languageCode = languageIsoCodeSettingParts[0];
114119
}
115120
}
116121

117-
return new ParatextProjectSettings(
122+
string translationInfoSetting = settingsDoc.Root.Element("TranslationInfo")?.Value;
123+
string translationType = "Standard";
124+
string parentName = null;
125+
string parentGuid = null;
126+
if (translationInfoSetting != null)
127+
{
128+
string[] translationInfoSettingParts = translationInfoSetting.Split(':');
129+
translationType = translationInfoSettingParts[0];
130+
parentName = translationInfoSettingParts[1] != "" ? translationInfoSettingParts[1] : null;
131+
parentGuid = translationInfoSettingParts[2] != "" ? translationInfoSettingParts[2] : null;
132+
}
133+
134+
var settings = new ParatextProjectSettings(
135+
guid,
118136
name,
119137
fullName,
120138
encoding,
@@ -126,8 +144,18 @@ public ParatextProjectSettings Parse()
126144
parts[0],
127145
parts[1],
128146
parts[2],
129-
languageCode
147+
languageCode,
148+
translationType,
149+
parentGuid,
150+
parentName
130151
);
152+
153+
if (_parentParatextProjectSettings != null && settings.HasParent)
154+
{
155+
settings.Parent = _parentParatextProjectSettings;
156+
}
157+
158+
return settings;
131159
}
132160
}
133161
}

src/SIL.Machine/Corpora/ParatextTextCorpus.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ namespace SIL.Machine.Corpora
44
{
55
public class ParatextTextCorpus : ScriptureTextCorpus
66
{
7-
public ParatextTextCorpus(string projectDir, bool includeMarkers = false, bool includeAllText = false)
7+
public ParatextTextCorpus(
8+
string projectDir,
9+
bool includeMarkers = false,
10+
bool includeAllText = false,
11+
string parentProjectDir = null
12+
)
813
{
9-
var parser = new FileParatextProjectSettingsParser(projectDir);
14+
ParatextProjectSettings parentSettings = null;
15+
if (parentProjectDir != null)
16+
{
17+
var parentParser = new FileParatextProjectSettingsParser(parentProjectDir);
18+
parentSettings = parentParser.Parse();
19+
}
20+
21+
var parser = new FileParatextProjectSettingsParser(projectDir, parentSettings);
1022
ParatextProjectSettings settings = parser.Parse();
1123

1224
Versification = settings.Versification;

src/SIL.Machine/Corpora/ZipParatextProjectSettingsParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace SIL.Machine.Corpora
44
{
55
public class ZipParatextProjectSettingsParser : ParatextProjectSettingsParserBase
66
{
7-
public ZipParatextProjectSettingsParser(ZipArchive archive)
8-
: base(new ZipParatextProjectFileHandler(archive)) { }
7+
public ZipParatextProjectSettingsParser(ZipArchive archive, ParatextProjectSettings parentSettings = null)
8+
: base(new ZipParatextProjectFileHandler(archive), parentSettings) { }
99

10-
public static ParatextProjectSettings Parse(ZipArchive archive)
10+
public static ParatextProjectSettings Parse(ZipArchive archive, ParatextProjectSettings parentSettings = null)
1111
{
12-
return new ZipParatextProjectSettingsParser(archive).Parse();
12+
return new ZipParatextProjectSettingsParser(archive, parentSettings).Parse();
1313
}
1414
}
1515
}

src/SIL.Machine/Corpora/ZipParatextProjectTextUpdater.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ namespace SIL.Machine.Corpora
44
{
55
public class ZipParatextProjectTextUpdater : ParatextProjectTextUpdaterBase
66
{
7-
public ZipParatextProjectTextUpdater(ZipArchive archive)
8-
: base(new ZipParatextProjectFileHandler(archive), ZipParatextProjectSettingsParser.Parse(archive)) { }
7+
public ZipParatextProjectTextUpdater(ZipArchive archive, ParatextProjectSettings parentSettings = null)
8+
: base(
9+
new ZipParatextProjectFileHandler(archive),
10+
ZipParatextProjectSettingsParser.Parse(archive, parentSettings)
11+
) { }
912
}
1013
}

0 commit comments

Comments
 (0)