1 | #Region "Microsoft.VisualBasic::4f9330b2b4aa82380531cd5a399c7e07, Microsoft.VisualBasic.Core\Text\StringSimilarity\Levenshtein\Extensions.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 | ' Module LevExtensions |
35 | ' |
36 | ' Function: StripSymbol |
37 | ' |
38 | ' Sub: GetMatches |
39 | ' |
40 | ' |
41 | ' /********************************************************************************/ |
42 | |
43 | #End Region |
44 | |
45 | Imports System.Runtime.CompilerServices |
46 | Imports System.Text |
47 | Imports Microsoft.VisualBasic.Language |
48 | |
49 | Namespace Text.Levenshtein |
50 | |
51 | Public Module LevExtensions |
52 | |
53 | <Extension> Public Sub GetMatches(Of T)(edits As DistResult, ref As T(), hyp As T(), ByRef refOUT As T(), ByRef hypOUT As T()) |
54 | Dim len As Integer = edits.DistEdits.Count("m"c) |
55 | Dim idx As int = Scan0 |
56 | Dim iiiii As Integer = 0 |
57 | |
58 | refOUT = New T(len - 1) {} |
59 | hypOUT = New T(len - 1) {} |
60 | |
61 | For j As Integer = 0 To hyp.Length ' 参照subject画列 |
62 | For i As Integer = 0 To ref.Length ' 参照query画行 |
63 | If edits.IsPath(i, j) Then |
64 | Dim ch As String = edits.DistEdits.Get(++idx) |
65 | |
66 | If ch = "m"c Then |
67 | refOUT(iiiii) = ref(i) |
68 | hypOUT(iiiii) = hyp(j - 1) |
69 | |
70 | iiiii += 1 |
71 | End If |
72 | End If |
73 | Next |
74 | Next |
75 | End Sub |
76 | |
77 | ''' <summary> |
78 | ''' 将字符串之中的标点符号删除,只留下字母 |
79 | ''' </summary> |
80 | ''' <param name="input$"></param> |
81 | ''' <param name="replaceAs$">将这些标点符号替换为目标字符串,默认为空格</param> |
82 | ''' <param name="stripMinusSign">是否将减号也替换掉,默认是不进行替换</param> |
83 | ''' <returns></returns> |
84 | <Extension> |
85 | Public Function StripSymbol(input$, Optional replaceAs$ = " ", Optional stripMinusSign As Boolean = False) As String |
86 | Dim sym As Char() = ASCII.Symbols |
87 | Dim sb As New StringBuilder(input$) |
88 | |
89 | If Not stripMinusSign Then |
90 | sym = sym.Where(Function(c) c <> "-"c).ToArray |
91 | End If |
92 | |
93 | For Each c As Char In sym |
94 | Call sb.Replace(c.ToString, replaceAs$) |
95 | Next |
96 | |
97 | Return sb.ToString |
98 | End Function |
99 | End Module |
100 | End Namespace |