Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RolesTokenizer.cs
1using System;
3using System.Reflection;
4using System.Threading.Tasks;
11
13{
18 {
23 {
24 }
25
31 public Grade Supports(Type Type)
32 {
33 if (typeInfo.IsAssignableFrom(Type))
34 return Grade.Ok;
35 else
36 return Grade.NotAtAll;
37 }
38
39 private static readonly TypeInfo typeInfo = typeof(IEnumerable<Role>).GetTypeInfo();
40
46 public async Task Tokenize(object Value, TokenizationProcess Process)
47 {
48 if (Value is IEnumerable<Role> Roles)
49 await Tokenize(Roles, null, Process);
50 }
51
58 public static async Task Tokenize(IEnumerable<Role> Roles,
60 {
61 if (!(Roles is null))
62 {
63 foreach (Role Role in Roles)
64 {
65 await RoleTokenizer.Tokenize(Role, Contract, Process);
66 Process.DocumentIndexOffset++; // Make sure sequences of keywords don't cross element boundaries.
67 }
68 }
69 }
70
75 public Task Prepare(string Definition)
76 {
77 return Task.CompletedTask;
78 }
79
85 public async Task<object> Evaluate(object Instance)
86 {
87 if (Instance is Contract Contract)
88 return Contract.Roles;
89 else if (Instance is GenericObject Obj)
90 {
91 if (Obj.TryGetFieldValue("Roles", out object Obj2) &&
92 Obj2 is Array A)
93 {
94 if (A.Length == 0)
95 return Array.Empty<Role>();
96
97 ChunkedList<Role> Roles = new ChunkedList<Role>(A.Length);
98
99 foreach (object Item in A)
100 {
101 if (Item is GenericObject GenRole &&
102 await Database.Specialize(GenRole) is Role Role)
103 {
104 Roles.Add(Role);
105 }
106 else if (Item is Role Role2)
107 Roles.Add(Role2);
108 }
109
110 return Roles;
111 }
112
113 return null;
114 }
115 else if (Instance is IEnumerable<Role> Roles)
116 return Roles;
117 else
118 return null;
119 }
120 }
121}
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