-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTextInput.cs
More file actions
51 lines (38 loc) · 1.23 KB
/
TextInput.cs
File metadata and controls
51 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace TensorStack.Common
{
public class TextInput
{
private readonly string _sourceFile;
public TextInput(string textInput)
{
Text = textInput;
}
public TextInput(string filename, Encoding encoding)
: this(File.ReadAllText(filename, encoding))
{
_sourceFile = filename;
}
public string Text { get; set; }
public string SourceFile => _sourceFile;
public int Length => Text?.Length ?? 0;
public int Beam { get; set; }
public float Score { get; set; }
public float PenaltyScore { get; set; }
public void Save(string filename)
{
File.WriteAllText(filename, Text);
}
public async Task SaveAsync(string filename)
{
await File.WriteAllTextAsync(filename, Text);
}
public static async Task<TextInput> CreateAsync(string filename, Encoding encoding, CancellationToken cancellationToken = default)
{
return new TextInput(await File.ReadAllTextAsync(filename, encoding, cancellationToken));
}
}
}