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
3 changes: 3 additions & 0 deletions src/SIL.Machine/Corpora/CorporaUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Nito.AsyncEx;
using SIL.PlatformUtilities;
using SIL.Scripture;

namespace SIL.Machine.Corpora
{
public static class CorporaUtils
{
public static readonly AsyncLock VersificationLock = new AsyncLock();

public static ISet<int> GetSplitIndices(
int corpusSize,
double? percent = null,
Expand Down
6 changes: 5 additions & 1 deletion src/SIL.Machine/Corpora/DblBundleTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public DblBundleTextCorpus(string fileName)
versificationEntry.ExtractToFile(tempFile.Path);
var abbr = (string)
doc.Root.Elements("identification").Elements("abbreviation").FirstOrDefault();
Versification = Scripture.Versification.Table.Implementation.Load(tempFile.Path, abbr);
using (CorporaUtils.VersificationLock.Lock())
{
Versification = Scripture.Versification.Table.Implementation.Load(tempFile.Path, abbr);
Scripture.Versification.Table.Implementation.RemoveAllUnknownVersifications();
}
}
}

Expand Down
30 changes: 17 additions & 13 deletions src/SIL.Machine/Corpora/ParatextProjectSettingsParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ public ParatextProjectSettings Parse()
if (_paratextProjectFileHandler.Exists("custom.vrs"))
{
string versName = ((ScrVersType)scrVersType).ToString() + "-" + guid;
if (Versification.Table.Implementation.Exists(versName))
using (CorporaUtils.VersificationLock.Lock())
{
versification = new ScrVers(versName);
}
else
{
using (var reader = new StreamReader(_paratextProjectFileHandler.Open("custom.vrs")))
if (Versification.Table.Implementation.Exists(versName))
{
versification = new ScrVers(versName);
}
else
{
versification = Versification.Table.Implementation.Load(
reader,
"custom.vrs",
versification,
versName
);
using (var reader = new StreamReader(_paratextProjectFileHandler.Open("custom.vrs")))
{
versification = Versification.Table.Implementation.Load(
reader,
"custom.vrs",
versification,
versName
);
}

Versification.Table.Implementation.RemoveAllUnknownVersifications();
}
Versification.Table.Implementation.RemoveAllUnknownVersifications();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/SIL.Machine/Corpora/UsxFileTextCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private static ScrVers GetVersification(string projectPath, ScrVers versificatio
{
string vrsName = Path.GetFileName(projectPath);
versification = Scripture.Versification.Table.Implementation.Load(versificationFileName, vrsName);
Scripture.Versification.Table.Implementation.RemoveAllUnknownVersifications();
}
return versification ?? ScrVers.English;
}
Expand Down
6 changes: 5 additions & 1 deletion src/SIL.Machine/Corpora/UsxTextAlignmentCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ private static ScrVers GetVersification(string projectPath, ScrVers versificatio
if (versification == null && File.Exists(versificationFileName))
{
string vrsName = Path.GetFileName(projectPath);
versification = Versification.Table.Implementation.Load(versificationFileName, vrsName);
using (CorporaUtils.VersificationLock.Lock())
{
versification = Versification.Table.Implementation.Load(versificationFileName, vrsName);
Versification.Table.Implementation.RemoveAllUnknownVersifications();
}
}
return versification ?? ScrVers.English;
}
Expand Down
7 changes: 4 additions & 3 deletions tests/SIL.Machine.Tests/Corpora/ParallelTextCorpusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,13 @@ public void GetRows_SameRefLastManyToOne()
[Test]
public void GetRows_SameVerseRefOneToMany()
{
Versification.Table.Implementation.RemoveAllUnknownVersifications();
string src = "&MAT 1:2-3 = MAT 1:2\nMAT 1:4 = MAT 1:3\n";
ScrVers versification;
using (var reader = new StringReader(src))
using (CorporaUtils.VersificationLock.Lock())
{
string src = "&MAT 1:2-3 = MAT 1:2\nMAT 1:4 = MAT 1:3\n";
using var reader = new StringReader(src);
versification = Versification.Table.Implementation.Load(reader, "vers.txt", ScrVers.English, "custom");
Versification.Table.Implementation.RemoveAllUnknownVersifications();
}

var sourceCorpus = new DictionaryTextCorpus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,18 @@ private static ScrVers GetCustomVersification(string customVrsContents, ScrVers?
{
baseVersification ??= ScrVers.English;
ScrVers customVersification = baseVersification;
using (var reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(customVrsContents))))
using var reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(customVrsContents)));
using (CorporaUtils.VersificationLock.Lock())
{
customVersification = Versification.Table.Implementation.Load(
reader,
"custom.vrs",
baseVersification,
baseVersification.ToString() + "-" + customVrsContents.GetHashCode()
);
Versification.Table.Implementation.RemoveAllUnknownVersifications();
}
Versification.Table.Implementation.RemoveAllUnknownVersifications();

return customVersification;
}
}
Loading