1 | #Region "Microsoft.VisualBasic::184b5e9cb0f452f19a6068c4d27d0691, Microsoft.VisualBasic.Core\Text\SearchEngine\TextIndexing\TextSegment.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Class TextSegment |
35 | ' |
36 | ' Properties: Array, Index, Segment |
37 | ' |
38 | ' Constructor: (+1 Overloads) Sub New |
39 | ' Function: ToString |
40 | ' Operators: (+2 Overloads) Like |
41 | ' |
42 | ' |
43 | ' /********************************************************************************/ |
44 | |
45 | #End Region |
46 | |
47 | Imports System.Runtime.CompilerServices |
48 | Imports Microsoft.VisualBasic.Language |
49 | Imports Microsoft.VisualBasic.Linq.Extensions |
50 | Imports Microsoft.VisualBasic.Text.Levenshtein |
51 | |
52 | Namespace Text.Search |
53 | |
54 | ''' <summary> |
55 | ''' 文本之中的一个片段 |
56 | ''' </summary> |
57 | Public Class TextSegment |
58 | |
59 | Dim _text As String |
60 | |
61 | ''' <summary> |
62 | ''' 当前的这个文本片段的字符串值 |
63 | ''' </summary> |
64 | ''' <returns></returns> |
65 | Public Property Segment As String |
66 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
67 | Get |
68 | Return _text |
69 | End Get |
70 | Set(value As String) |
71 | Dim ascii%() = value _ |
72 | .Select(AddressOf AscW) _ |
73 | .ToArray |
74 | |
75 | _Array = ascii |
76 | _text = value |
77 | End Set |
78 | End Property |
79 | |
80 | ''' <summary> |
81 | ''' ASCII值 |
82 | ''' </summary> |
83 | ''' <returns></returns> |
84 | Public ReadOnly Property Array As Integer() |
85 | ''' <summary> |
86 | ''' 在原始文本之中的左端起始位置 |
87 | ''' </summary> |
88 | ''' <returns></returns> |
89 | Public Property Index As Integer |
90 | |
91 | Sub New(Optional value As String = "") |
92 | Segment = value |
93 | End Sub |
94 | |
95 | Public Overrides Function ToString() As String |
96 | Return Segment |
97 | End Function |
98 | |
99 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
100 | Public Overloads Shared Narrowing Operator CType(segment As TextSegment) As String |
101 | Return segment.Segment |
102 | End Operator |
103 | |
104 | Public Shared Operator Like(segment As TextSegment, text$) As DistResult |
105 | With LevenshteinDistance.ComputeDistance(segment.Array, text) |
106 | .Reference = segment._text |
107 | Return .ByRef |
108 | End With |
109 | End Operator |
110 | End Class |
111 | End Namespace |