Skip to content

Commit 1bafc1e

Browse files
committed
ExpectedVerse should always be empty even if verse ref fails to parse if type is ExtraVerse; filter books; add project name
1 parent 14ee6cc commit 1bafc1e

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/SIL.Machine/Corpora/ParatextProjectSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ public string GetBookFileName(string bookId)
104104
return FileNamePrefix + bookPart + FileNameSuffix;
105105
}
106106

107-
public IEnumerable<string> GetAllScriptureBookFileNames()
107+
public IEnumerable<string> GetAllScriptureBookIds()
108108
{
109109
BookSet scriptureBooks = Canon.ScriptureBooks;
110110
scriptureBooks.SelectAll();
111111
foreach (string bookId in scriptureBooks.SelectedBookIds)
112112
{
113-
yield return GetBookFileName(bookId);
113+
yield return bookId;
114114
}
115115
}
116116

src/SIL.Machine/Corpora/ParatextProjectVersificationErrorDetectorBase.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Text;
5+
using SIL.Scripture;
56

67
namespace SIL.Machine.Corpora
78
{
@@ -20,15 +21,21 @@ ParatextProjectSettings settings
2021
}
2122

2223
public IReadOnlyList<UsfmVersificationError> GetUsfmVersificationErrors(
23-
UsfmVersificationErrorDetector handler = null
24+
UsfmVersificationErrorDetector handler = null,
25+
HashSet<int> books = null
2426
)
2527
{
26-
handler = handler ?? new UsfmVersificationErrorDetector(_settings.Versification);
27-
foreach (string fileName in _settings.GetAllScriptureBookFileNames())
28+
handler = handler ?? new UsfmVersificationErrorDetector(_settings);
29+
foreach (string bookId in _settings.GetAllScriptureBookIds())
2830
{
31+
string fileName = _settings.GetBookFileName(bookId);
32+
2933
if (!_paratextProjectFileHandler.Exists(fileName))
3034
continue;
3135

36+
if (books != null && !books.Contains(Canon.BookIdToNumber(bookId)))
37+
continue;
38+
3239
string usfm;
3340
using (var reader = new StreamReader(_paratextProjectFileHandler.Open(fileName)))
3441
{

src/SIL.Machine/Corpora/UsfmVersificationErrorDetector.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ public string ExpectedVerseRef
100100
{
101101
get
102102
{
103+
if (Type == UsfmVersificationErrorType.ExtraVerse)
104+
return "";
105+
103106
// We do not want to throw an exception here, and the VerseRef constructor can throw
104107
// an exception with certain invalid verse data; use TryParse instead.
105108
if (!VerseRef.TryParse($"{_bookNum} {_expectedChapter}:{_expectedVerse}", out VerseRef defaultVerseRef))
106109
{
107110
return DefaultVerse(_expectedChapter, _expectedVerse);
108111
}
109-
if (Type == UsfmVersificationErrorType.ExtraVerse)
110-
return "";
111112
if (
112113
Type == UsfmVersificationErrorType.MissingVerseSegment
113114
&& VerseRef.TryParse(
@@ -178,16 +179,18 @@ public class UsfmVersificationErrorDetector : UsfmParserHandlerBase
178179
private VerseRef _currentVerse;
179180
private readonly List<UsfmVersificationError> _errors;
180181

181-
public UsfmVersificationErrorDetector(ScrVers versification)
182+
public UsfmVersificationErrorDetector(ParatextProjectSettings settings)
182183
{
183-
_versification = versification;
184+
ProjectName = settings.Name;
185+
_versification = settings.Versification;
184186
_currentBook = 0;
185187
_currentChapter = 0;
186188
_currentVerse = new VerseRef();
187189
_errors = new List<UsfmVersificationError>();
188190
}
189191

190192
public IReadOnlyList<UsfmVersificationError> Errors => _errors;
193+
public string ProjectName { get; private set; }
191194

192195
public override void EndUsfm(UsfmParserState state)
193196
{

0 commit comments

Comments
 (0)