-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextExtractor.cs
More file actions
41 lines (30 loc) · 848 Bytes
/
TextExtractor.cs
File metadata and controls
41 lines (30 loc) · 848 Bytes
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
using System.Text;
namespace TelegramAIBot
{
internal sealed class TextExtractor
{
private static readonly Dictionary<string, TextExtractorUnit> _units = new()
{
["application/pdf"] = ProcessPDF,
["text/plain"] = ProcessPlainText
};
public TextExtractor()
{
}
public string Extract(ReadOnlySpan<byte> data, string mimeType)
{
if (_units.TryGetValue(mimeType, out var unit))
return unit(data);
else throw new NotSupportedException($"Type {mimeType} is not supported to be converted to plain text");
}
private static string ProcessPDF(ReadOnlySpan<byte> data)
{
throw new NotImplementedException();
}
private static string ProcessPlainText(ReadOnlySpan<byte> data)
{
return Encoding.UTF8.GetString(data);
}
private delegate string TextExtractorUnit(ReadOnlySpan<byte> data);
}
}