Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
WildcardKeyword.cs
1using System.Collections.Generic;
2using System.Text.RegularExpressions;
3using System.Threading.Tasks;
4
6{
11 {
16 public WildcardKeyword(string Keyword)
17 : this(Keyword + "*", "*")
18 {
19 }
20
26 public WildcardKeyword(string Keyword, string Wildcard)
27 : base(Database.WildcardToRegex(Keyword, Wildcard))
28 {
29 this.Keyword = Keyword;
30 this.Wildcard = Wildcard;
31 }
32
36 public string Keyword { get; }
37
41 public string Wildcard { get; }
42
46 public override int OrderComplexity => this.Keyword.Length;
47
49 public override bool Equals(object obj)
50 {
51 return obj is WildcardKeyword k && this.Keyword == k.Keyword && this.Wildcard == k.Wildcard;
52 }
53
55 public override string ToString()
56 {
57 return this.Keyword;
58 }
59
65 public override async Task<IEnumerable<KeyValuePair<string, TokenReferences>>> GetTokenReferences(SearchProcess Process)
66 {
67 int i = this.Keyword.IndexOf(this.Wildcard);
68 if (i <= 0)
69 return await base.GetTokenReferences(Process);
70
71 string Preamble = this.Keyword.Substring(0, i);
72 char[] Characters = Preamble.ToCharArray();
73 Characters[i - 1]++;
74 string ToExclusive = new string(Characters);
75
76 LinkedList<KeyValuePair<string, TokenReferences>> Result = new LinkedList<KeyValuePair<string, TokenReferences>>();
77 KeyValuePair<string, object>[] Records = await Process.Index.GetEntriesAsync(Preamble, ToExclusive);
78
79 foreach (KeyValuePair<string, object> Rec in Records)
80 {
81 Match M = this.Parsed.Match(Rec.Key);
82 if (M.Success && M.Index == 0 && M.Length == Rec.Key.Length && Rec.Value is TokenReferences References)
83 Result.AddLast(new KeyValuePair<string, TokenReferences>(Rec.Key, References));
84 }
85
86 return Result;
87 }
88 }
89}
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
Abstract base class for keywords.
Definition: Keyword.cs:11
virtual async Task< bool > Process(SearchProcess Process)
Processes the keyword in a search process.
Definition: Keyword.cs:67
abstract Task< IEnumerable< KeyValuePair< string, TokenReferences > > > GetTokenReferences(SearchProcess Process)
Gets available token references.
Contains information about a search process.
WildcardKeyword(string Keyword)
Represents a plain keyword, where keyword acts as a prefix.
WildcardKeyword(string Keyword, string Wildcard)
Represents a wildcard keyword.
override async Task< IEnumerable< KeyValuePair< string, TokenReferences > > > GetTokenReferences(SearchProcess Process)
Gets available token references.
override int OrderComplexity
Order complexity (within category) of keyword
Contains a sequence of object references that include the token in its indexed text properties.