-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for detokenizing USFM (#154)
- closes #153
- Loading branch information
Showing
9 changed files
with
305 additions
and
85 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.SFM eol=crlf |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using SIL.Scripture; | ||
|
||
|
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,47 @@ | ||
using NUnit.Framework; | ||
|
||
namespace SIL.Machine.Corpora | ||
{ | ||
[TestFixture] | ||
public class UsfmTokenizerTests | ||
{ | ||
[Test] | ||
public void Tokenize() | ||
{ | ||
string usfm = ReadUsfm(); | ||
var tokenizer = new UsfmTokenizer(); | ||
IReadOnlyList<UsfmToken> tokens = tokenizer.Tokenize(usfm); | ||
Assert.That(tokens, Has.Count.EqualTo(136)); | ||
|
||
Assert.That(tokens[0].Type, Is.EqualTo(UsfmTokenType.Book)); | ||
Assert.That(tokens[0].Marker, Is.EqualTo("id")); | ||
Assert.That(tokens[0].Data, Is.EqualTo("MAT")); | ||
|
||
Assert.That(tokens[10].Type, Is.EqualTo(UsfmTokenType.Text)); | ||
Assert.That(tokens[10].Text, Is.EqualTo("Chapter One ")); | ||
|
||
Assert.That(tokens[11].Type, Is.EqualTo(UsfmTokenType.Verse)); | ||
Assert.That(tokens[11].Marker, Is.EqualTo("v")); | ||
Assert.That(tokens[11].Data, Is.EqualTo("1")); | ||
|
||
Assert.That(tokens[20].Type, Is.EqualTo(UsfmTokenType.Note)); | ||
Assert.That(tokens[20].Marker, Is.EqualTo("f")); | ||
Assert.That(tokens[20].Data, Is.EqualTo("+")); | ||
} | ||
|
||
[Test] | ||
public void Detokenize() | ||
{ | ||
string usfm = ReadUsfm(); | ||
var tokenizer = new UsfmTokenizer(); | ||
IReadOnlyList<UsfmToken> tokens = tokenizer.Tokenize(usfm); | ||
string result = tokenizer.Detokenize(tokens); | ||
Assert.That(result, Is.EqualTo(usfm)); | ||
} | ||
|
||
private static string ReadUsfm() | ||
{ | ||
return File.ReadAllText(Path.Combine(CorporaTestHelpers.UsfmTestProjectPath, "41MATTes.SFM")); | ||
} | ||
} | ||
} |