차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
tech:fuzzy [2012/06/11 19:46] – 새로 만듦 211.56.252.201 | tech:fuzzy [2016/07/12 09:26] (현재) – 바깥 편집 127.0.0.1 | ||
---|---|---|---|
줄 1: | 줄 1: | ||
+ | {{tag> | ||
+ | ======Fuzzy====== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | 퍼지.. 1과 1은 어느 정도 같은가???? | ||
+ | |||
+ | 의 해답... | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | <code vb> | ||
+ | Public Class CompareWords | ||
+ | |||
+ | #Region " | ||
+ | Private totalPointsValue As Int32 | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Public ReadOnly Property TotalPoints() As Int32 | ||
+ | Get | ||
+ | Return Me.totalPointsValue | ||
+ | End Get | ||
+ | End Property | ||
+ | |||
+ | Private matchTypeValue As MatchTypes | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Public Property MatchType() As MatchTypes | ||
+ | Get | ||
+ | Return Me.matchTypeValue | ||
+ | End Get | ||
+ | Set(ByVal value As MatchTypes) | ||
+ | Me.matchTypeValue = value | ||
+ | End Set | ||
+ | End Property | ||
+ | |||
+ | Private minimumSubstringLengthValue As Int32 | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Public Property MinimumSubstringLength() As Int32 | ||
+ | Get | ||
+ | Return Me.minimumSubstringLengthValue | ||
+ | End Get | ||
+ | Set(ByVal value As Int32) | ||
+ | If value > 0 Then | ||
+ | Me.minimumSubstringLengthValue = value | ||
+ | Else | ||
+ | Throw New System.ArgumentOutOfRangeException(" | ||
+ | End If | ||
+ | End Set | ||
+ | End Property | ||
+ | |||
+ | Private ignoreCaseValue As Boolean | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Public Property IgnoreCase() As Boolean | ||
+ | Get | ||
+ | Return Me.ignoreCaseValue | ||
+ | End Get | ||
+ | Set(ByVal value As Boolean) | ||
+ | Me.ignoreCaseValue = value | ||
+ | End Set | ||
+ | End Property | ||
+ | #End Region | ||
+ | |||
+ | #Region " | ||
+ | |||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Public Sub New(ByVal matchType As MatchTypes) | ||
+ | Me.MatchType = matchType | ||
+ | Me.MinimumSubstringLength = 4 | ||
+ | Me.IgnoreCase = True | ||
+ | End Sub | ||
+ | |||
+ | #End Region | ||
+ | |||
+ | #Region " | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Public Function GetMatch(ByVal word1 As String, ByVal word2 As String) As Int32 | ||
+ | ' | ||
+ | If Me.IgnoreCase Then | ||
+ | word1 = word1.ToLower | ||
+ | word2 = word2.ToLower | ||
+ | End If | ||
+ | |||
+ | ' | ||
+ | If word1 = word2 Then | ||
+ | Return 100 | ||
+ | ElseIf word1 = Nothing OrElse word2 = Nothing Then | ||
+ | Return 0 | ||
+ | Else | ||
+ | 'Clear variable for new compare | ||
+ | totalPointsValue = 0 | ||
+ | 'Start calculation | ||
+ | FindCommon(word1, | ||
+ | ' | ||
+ | Return Convert.ToInt32((totalPointsValue * 200) / (word1.Length + word2.Length)) | ||
+ | End If | ||
+ | End Function | ||
+ | |||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Public Function GetMatch(ByVal word1 As String, ByVal word2 As String, ByVal minimumScore As Int32) As Boolean | ||
+ | Dim matchPercentage As Int32 = Me.GetMatch(word1, | ||
+ | Return matchPercentage >= minimumScore | ||
+ | End Function | ||
+ | |||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | Private Sub FindCommon(ByVal word1 As String, ByVal word2 As String) | ||
+ | 'Make sure name1 is the longest string | ||
+ | If word1.Length < word2.Length Then | ||
+ | Dim buf As String = word2 | ||
+ | word2 = word1 | ||
+ | word1 = buf | ||
+ | End If | ||
+ | Dim placeHolder As Int32 | ||
+ | Dim tempBuffer As String | ||
+ | Dim commonString As String = String.Empty | ||
+ | For i As Int32 = 0 To word1.Length - 1 | ||
+ | 'reset substring length | ||
+ | placeHolder = Me.MinimumSubstringLength | ||
+ | While placeHolder <= (word1.Length - i) AndAlso placeHolder <= word2.Length | ||
+ | tempBuffer = word1.Substring(i, | ||
+ | If word2.IndexOf(tempBuffer) >= 0 Then | ||
+ | If tempBuffer.Length > commonString.Length Then | ||
+ | commonString = tempBuffer | ||
+ | End If | ||
+ | placeHolder += 1 | ||
+ | Else | ||
+ | Exit While | ||
+ | End If | ||
+ | End While | ||
+ | Next | ||
+ | totalPointsValue += commonString.Length | ||
+ | 'Stop recursion when strings get too small | ||
+ | If commonString <> Nothing Then | ||
+ | Select Case Me.MatchType | ||
+ | Case MatchTypes.Fast | ||
+ | 'Run routine for concatonated data (faster but less accurate) | ||
+ | FindCommon(word1.Remove(word1.IndexOf(commonString), | ||
+ | Case MatchTypes.Accurate | ||
+ | 'Run routine for data on the right | ||
+ | FindCommon(word1.Substring(0, | ||
+ | 'Run routine for data on the left | ||
+ | FindCommon(word1.Substring(word1.IndexOf(commonString) + commonString.Length), | ||
+ | End Select | ||
+ | End If | ||
+ | End Sub | ||
+ | #End Region | ||
+ | |||
+ | Public Enum MatchTypes | ||
+ | Fast = 1 | ||
+ | Accurate = 2 | ||
+ | End Enum | ||
+ | |||
+ | End Class</ | ||
+ | |||
+ | http:// | ||
+ | |||
+ | |||
+ | [[trados]] | ||
+ | |||
+ | |||
+ | * 출처: [[|]] | ||
+ | |||
+ | ^ 누구나 수정하실 수 있습니다. | ||
+ | |||