Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HumanReadableTextsTokenizer.cs
1using System;
3using System.Reflection;
4using System.Threading.Tasks;
12
14{
19 {
24 {
25 }
26
32 public Grade Supports(Type Type)
33 {
34 if (typeInfo.IsAssignableFrom(Type))
35 return Grade.Ok;
36 else
37 return Grade.NotAtAll;
38 }
39
40 private static readonly TypeInfo typeInfo = typeof(IEnumerable<HumanReadableText>).GetTypeInfo();
41
47 public async Task Tokenize(object Value, TokenizationProcess Process)
48 {
49 if (Value is IEnumerable<HumanReadableText> HumanReadableTexts)
50 await Tokenize(HumanReadableTexts, null, Process);
51 }
52
59 public static async Task Tokenize(IEnumerable<HumanReadableText> HumanReadableTexts,
61 {
62 if (!(HumanReadableTexts is null))
63 {
64 foreach (HumanReadableText HumanReadableText in HumanReadableTexts)
65 {
67 Process.DocumentIndexOffset++; // Make sure sequences of keywords don't cross element boundaries.
68 }
69 }
70 }
71
76 public Task Prepare(string Definition)
77 {
78 return Task.CompletedTask;
79 }
80
86 public async Task<object> Evaluate(object Instance)
87 {
88 if (Instance is Contract Contract)
89 return Contract.ForHumans;
90 else if (Instance is GenericObject Obj)
91 {
92 if (Obj.TryGetFieldValue("ForHumans", out object Obj2) &&
93 Obj2 is Array A)
94 {
95 if (A.Length == 0)
96 return Array.Empty<HumanReadableText>();
97
98 ChunkedList<HumanReadableText> HumanReadableTexts = new ChunkedList<HumanReadableText>(A.Length);
99
100 foreach (object Item in A)
101 {
102 if (Item is GenericObject GenHumanReadableText &&
103 await Database.Specialize(GenHumanReadableText) is HumanReadableText HumanReadableText)
104 {
105 HumanReadableTexts.Add(HumanReadableText);
106 }
107 else if (Item is HumanReadableText HumanReadableText2)
108 HumanReadableTexts.Add(HumanReadableText2);
109 }
110
111 return HumanReadableTexts;
112 }
113
114 return null;
115 }
116 else if (Instance is IEnumerable<HumanReadableText> HumanReadableTexts)
117 return HumanReadableTexts;
118 else
119 return null;
120 }
121 }
122}
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static Task< object > Specialize(GenericObject Object)
Creates a specialized representation of a generic object.
Definition: Database.cs:2483
Contains information about a tokenization process.
uint DocumentIndexOffset
Document Index Offset. Used to identify sequences of tokens in a document.
Generic object. Contains a sequence of properties.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Interface for full-text-search tokenizers
Definition: ITokenizer.cs:12
Grade
Grade enumeration
Definition: Grade.cs:7