Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MarkdownTokenizer.cs
1using System;
2using System.Diagnostics;
3using System.Text;
4using System.Threading.Tasks;
13
15{
20 {
21 private string definition = string.Empty;
22
27 {
28 }
29
35 public Grade Supports(Type Type)
36 {
37 if (Type == typeof(MarkdownDocument))
38 return Grade.Ok;
39 else
40 return Grade.NotAtAll;
41 }
42
48 public Grade Supports(string Extension)
49 {
50 if (Extension == "md")
51 return Grade.Ok;
52 else
53 return Grade.NotAtAll;
54 }
55
61 public async Task Tokenize(object Value, TokenizationProcess Process)
62 {
63 if (Value is MarkdownDocument Doc)
64 await Tokenize(Doc, Process);
65 }
66
72 public static async Task Tokenize(MarkdownDocument Doc, TokenizationProcess Process)
73 {
74 StringBuilder sb = new StringBuilder();
75
76 Append(sb, Doc.Description);
77 Append(sb, Doc.Author);
78 Append(sb, Doc.Keywords);
79 Append(sb, Doc.Subtitle);
80 Append(sb, Doc.Title);
81
82 using (TextRenderer Renderer = new TextRenderer(sb))
83 {
84 await Renderer.RenderDocument(Doc, true);
85 }
86
87 StringTokenizer.Tokenize(sb.ToString(), Process);
88 }
89
90 private static void Append(StringBuilder sb, string[] Strings)
91 {
92 if (!(Strings is null))
93 {
94 foreach (string s in Strings)
95 sb.AppendLine(s);
96 }
97 }
98
104 public async Task Tokenize(FileReference Reference, TokenizationProcess Process)
105 {
106 string Text = await Files.ReadAllTextAsync(Reference.FileName);
108
109 await Tokenize(Doc, Process);
110 }
111
112 #region IPropertyEvaluator
113
118 public Task Prepare(string Definition)
119 {
120 this.definition = Definition;
121 return Task.CompletedTask;
122 }
123
129 public async Task<object> Evaluate(object Instance)
130 {
131 if (Instance is GenericObject Obj)
132 {
133 if (Obj.TryGetFieldValue(this.definition, out object Obj2) &&
134 Obj2 is string Markdown)
135 {
136 MarkdownDocument Doc = await MarkdownDocument.CreateAsync(Markdown);
137
138 if (MarkdownDocument.HeaderEndPosition(Markdown).HasValue)
139 return Doc;
140 else
141 return await Doc.GeneratePlainText();
142 }
143 }
144
145 return null;
146 }
147
148 #endregion
149 }
150}
Contains a markdown document. This markdown document class supports original markdown,...
string[] Author
Author(s) of document.
string[] Subtitle
Subtitle of document.
static ? int HeaderEndPosition(string Markdown)
Gets the end position of the header, if one is found, null otherwise.
string[] Description
Description of document.
async Task< string > GeneratePlainText()
Generates Plain Text from the markdown text.
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Abstract base class for Markdown renderers.
Definition: Renderer.cs:15
virtual async Task RenderDocument(MarkdownDocument Document, bool Inclusion)
Renders a document.
Definition: Renderer.cs:76
Renders plain text from a Markdown document.
Definition: TextRenderer.cs:18
Tokenizes contents defined in a Markdown document.
async Task< object > Evaluate(object Instance)
Evaluates the property evaluator, on an object instance.
Grade Supports(string Extension)
How well the file tokenizer supports files of a given extension.
Grade Supports(Type Type)
If the interface understands objects such as Type .
Task Prepare(string Definition)
Prepares the evaluator with its definition.
static async Task Tokenize(MarkdownDocument Doc, TokenizationProcess Process)
Tokenizes a Markdown document.
MarkdownTokenizer()
Tokenizes contents defined in a Markdown document.
async Task Tokenize(FileReference Reference, TokenizationProcess Process)
Tokenizes an object.
async Task Tokenize(object Value, TokenizationProcess Process)
Tokenizes an object.
Contains a reference to an indexed file.
CaseInsensitiveString FileName
Name of collection hosting object.
Task Tokenize(object Value, TokenizationProcess Process)
Tokenizes an object.
Contains information about a tokenization process.
Generic object. Contains a sequence of properties.
Contains static methods
Definition: Files.cs:14
static async Task< string > ReadAllTextAsync(string FileName)
Reads a text file asynchronously.
Definition: Files.cs:84
Static class managing binary representations of strings.
Definition: Strings.cs:10
Interface for file tokenizers. Best tokenizer is selected
Interface for full-text-search tokenizers
Definition: ITokenizer.cs:12
Grade
Grade enumeration
Definition: Grade.cs:7