-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ParatextProjectTextUpdaterBase class
- Loading branch information
Showing
5 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.IO; | ||
|
||
namespace SIL.Machine.Corpora | ||
{ | ||
public class FileParatextProjectTextUpdater : ParatextProjectTextUpdaterBase | ||
{ | ||
private readonly string _projectDir; | ||
|
||
public FileParatextProjectTextUpdater(string projectDir) | ||
: base(new FileParatextProjectSettingsParser(projectDir)) | ||
{ | ||
_projectDir = projectDir; | ||
} | ||
|
||
protected override bool Exists(string fileName) | ||
{ | ||
return File.Exists(Path.Combine(_projectDir, fileName)); | ||
} | ||
|
||
protected override Stream Open(string fileName) | ||
{ | ||
return File.OpenRead(Path.Combine(_projectDir, fileName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace SIL.Machine.Corpora | ||
{ | ||
public abstract class ParatextProjectTextUpdaterBase | ||
{ | ||
private readonly ParatextProjectSettingsParserBase _settingsParser; | ||
|
||
protected ParatextProjectTextUpdaterBase(ParatextProjectSettingsParserBase settingsParser) | ||
{ | ||
_settingsParser = settingsParser; | ||
} | ||
|
||
public string UpdateUsfm( | ||
string bookId, | ||
IReadOnlyList<(IReadOnlyList<ScriptureRef>, string)> rows, | ||
string fullName = null, | ||
bool stripAllText = false, | ||
bool preferExistingText = true | ||
) | ||
{ | ||
ParatextProjectSettings settings = _settingsParser.Parse(); | ||
|
||
string fileName = settings.GetBookFileName(bookId); | ||
if (!Exists(fileName)) | ||
return null; | ||
|
||
string usfm; | ||
using (var reader = new StreamReader(Open(fileName))) | ||
{ | ||
usfm = reader.ReadToEnd(); | ||
} | ||
|
||
var handler = new UpdateUsfmParserHandler( | ||
rows, | ||
fullName is null ? null : $"- {fullName}", | ||
stripAllText, | ||
preferExistingText: preferExistingText | ||
); | ||
UsfmParser.Parse(usfm, handler, settings.Stylesheet, settings.Versification); | ||
return handler.GetUsfm(settings.Stylesheet); | ||
} | ||
|
||
protected abstract bool Exists(string fileName); | ||
protected abstract Stream Open(string fileName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters