Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.4 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Keywordifier"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Private p_clsKeywords As Keywords
  16. Private p_dictKIDs As Scripting.Dictionary
  17. Private p_dictStopWords As Scripting.Dictionary
  18. Private p_dictStopSigns As Scripting.Dictionary
  19. Private Sub Class_Initialize()
  20. Dim clsStopWords As StopWords
  21. Dim clsStopSigns As StopSigns
  22. Dim rs As ADODB.Recordset
  23. Set clsStopWords = New StopWords
  24. Set clsStopSigns = New StopSigns
  25. Set rs = New ADODB.Recordset
  26. Set p_clsKeywords = New Keywords
  27. Set p_dictKIDs = New Scripting.Dictionary
  28. Set p_dictStopWords = New Scripting.Dictionary
  29. Set p_dictStopSigns = New Scripting.Dictionary
  30. p_dictKIDs.CompareMode = TextCompare
  31. p_clsKeywords.GetAllKeywordsDict p_dictKIDs
  32. p_dictStopWords.CompareMode = TextCompare
  33. clsStopWords.GetAllStopWordsRs rs
  34. Do While (Not rs.EOF)
  35. p_dictStopWords.Add rs("StopWord").Value, True
  36. rs.MoveNext
  37. Loop
  38. clsStopSigns.GetAllStopSignsRs rs
  39. Do While (Not rs.EOF)
  40. p_dictStopSigns.Add rs("StopSign").Value, rs("Context").Value
  41. rs.MoveNext
  42. Loop
  43. End Sub
  44. Private Sub Class_Terminate()
  45. Set p_clsKeywords = Nothing
  46. Set p_dictKIDs = Nothing
  47. Set p_dictStopWords = Nothing
  48. Set p_dictStopSigns = Nothing
  49. End Sub
  50. Public Function CreateKeywordsFromTitle( _
  51. ByVal i_strTitle As String _
  52. ) As String
  53. Dim str As String
  54. Dim arrStr() As String
  55. Dim intIndex As Long
  56. Dim arrKeywords() As String
  57. Dim intKeywordIndex As Long
  58. Const NUM_WORDS_C As Long = 2
  59. ReDim arrKeywords(NUM_WORDS_C)
  60. intKeywordIndex = 0
  61. str = RemoveOperatorShortcuts(i_strTitle)
  62. str = p_RemoveStopSigns(str)
  63. str = RemoveExtraSpaces(str)
  64. ' Create a mondo keyword from the title
  65. ' CreateKeywordsFromTitle = " " & GetKID(str, True) & " "
  66. CreateKeywordsFromTitle = " "
  67. arrStr = Split(str)
  68. For intIndex = LBound(arrStr) To UBound(arrStr)
  69. str = arrStr(intIndex)
  70. If (str <> "") Then
  71. If (Not IsVerbalOperator(str)) Then
  72. If (Not p_dictStopWords.Exists(str)) Then
  73. CreateKeywordsFromTitle = CreateKeywordsFromTitle & _
  74. GetKID(str) & " "
  75. ' If (intKeywordIndex < NUM_WORDS_C) Then
  76. ' intKeywordIndex = intKeywordIndex + 1
  77. ' arrKeywords(intKeywordIndex) = str
  78. ' End If
  79. End If
  80. End If
  81. End If
  82. Next
  83. ' str = " "
  84. ' For intIndex = 1 To intKeywordIndex
  85. ' If (intIndex = 1) Then
  86. ' str = arrKeywords(intIndex)
  87. ' Else
  88. ' str = str & " " & arrKeywords(intIndex)
  89. ' CreateKeywordsFromTitle = CreateKeywordsFromTitle & GetKID(str) & " "
  90. ' End If
  91. ' Next
  92. CreateKeywordsFromTitle = FormatKeywordsForTaxonomy(CreateKeywordsFromTitle)
  93. End Function
  94. Public Function GetKID( _
  95. ByRef i_strKeyword As String, _
  96. Optional ByVal i_blnMinValidation As Boolean = False _
  97. ) As String
  98. Dim intKID As Long
  99. If (p_dictKIDs.Exists(i_strKeyword)) Then
  100. GetKID = p_dictKIDs(i_strKeyword)
  101. Else
  102. intKID = p_CreateKeyword(i_strKeyword, i_blnMinValidation)
  103. If (intKID <> INVALID_ID_C) Then
  104. p_dictKIDs.Add i_strKeyword, intKID
  105. GetKID = intKID
  106. End If
  107. End If
  108. End Function
  109. Private Function p_CreateKeyword( _
  110. ByRef i_strKeyword As String, _
  111. ByVal i_blnMinValidation As Boolean _
  112. ) As Long
  113. On Error GoTo LErrorHandler
  114. p_CreateKeyword = p_clsKeywords.Create(i_strKeyword, i_blnMinValidation)
  115. Exit Function
  116. LErrorHandler:
  117. p_CreateKeyword = INVALID_ID_C
  118. End Function
  119. Private Function p_RemoveStopSigns( _
  120. ByVal i_strText As String _
  121. ) As String
  122. Dim intIndex As Long
  123. Dim intLength As Long
  124. Dim str As String
  125. Dim char As String
  126. str = i_strText
  127. intLength = Len(str)
  128. For intIndex = intLength To 1 Step -1
  129. char = Mid$(str, intIndex, 1)
  130. If (p_dictStopSigns.Exists(char)) Then
  131. If (p_dictStopSigns(char) = CONTEXT_ANYWHERE_E) Then
  132. ' Replace the character with a space
  133. str = Mid$(str, 1, intIndex - 1) & " " & Mid$(str, intIndex + 1)
  134. ElseIf (intIndex > 1) Then
  135. ' Context is CONTEXT_AT_END_OF_WORD_E, and this isn't the first char
  136. If (Mid$(str, intIndex - 1, 1) <> " ") Then
  137. ' Previous character is not a space
  138. If ((intIndex = intLength) Or (Mid$(str, intIndex + 1, 1) = " ")) Then
  139. ' This is the last character or the next character is a space
  140. ' Replace the character with a space
  141. str = Mid$(str, 1, intIndex - 1) & " " & Mid$(str, intIndex + 1)
  142. End If
  143. End If
  144. End If
  145. End If
  146. Next
  147. p_RemoveStopSigns = str
  148. End Function