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.

225 lines
6.8 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 = "UriQueries"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Private m_strUri As String
  16. Private m_QuestionsList As Scripting.Dictionary
  17. Private m_dictKw As Scripting.Dictionary
  18. Private m_lCountTimesSetKw As Long
  19. Private m_lngNewKeywords As Long
  20. Private m_lngNewPhonyKeywords As Long
  21. Private m_lngModifiedKeywords As Long
  22. Private m_lngModifiedPhonyKeywords As Long
  23. Private Type UserQuestion
  24. strQuestion As String
  25. strKw() As String
  26. End Type
  27. Private Sub Class_Initialize()
  28. Set m_QuestionsList = New Scripting.Dictionary
  29. Set m_dictKw = New Scripting.Dictionary
  30. m_lngNewKeywords = 0
  31. m_lngNewPhonyKeywords = 0
  32. m_lngModifiedKeywords = 0
  33. m_lngModifiedPhonyKeywords = 0
  34. m_lCountTimesSetKw = 0
  35. End Sub
  36. Public Property Get Uri() As String
  37. Uri = m_strUri
  38. End Property
  39. Public Property Let Uri(ByVal i_strUri As String)
  40. m_strUri = i_strUri
  41. End Property
  42. Sub AddQuestion(strQuestion As String)
  43. Dim arrKw() As String
  44. arrKw = p_GetQuestionKeywords(strQuestion)
  45. ' Really, we do not need the questions, only the Keywords
  46. With m_QuestionsList
  47. If (Not .Exists(strQuestion)) Then
  48. .Add strQuestion, arrKw
  49. End If
  50. End With
  51. If (Len(arrKw(0)) = 0) Then GoTo Common_Exit
  52. ' Here we need to make sure that only 1 and 2 word queries
  53. ' are indeed prioritized. 3 word queries we do not care
  54. ' because they are already sufficiently scoped.
  55. Dim intUBound As Long: intUBound = UBound(arrKw)
  56. Dim lngProposedPri As Long, lngCurrPri As Long
  57. Select Case (intUBound)
  58. Case 0 To 1 ' Only 1 and 2 word queries get priority.
  59. lngProposedPri = 10000 / (intUBound + 1)
  60. Case Else
  61. lngProposedPri = 0
  62. End Select
  63. Dim iX As Long, strKw As String
  64. For iX = 0 To intUBound
  65. strKw = arrKw(iX)
  66. If (Not m_dictKw.Exists(strKw)) Then
  67. m_dictKw.Add strKw, 0
  68. End If
  69. lngCurrPri = m_dictKw.Item(strKw)
  70. If (lngProposedPri > lngCurrPri) Then
  71. m_dictKw.Item(strKw) = lngProposedPri
  72. End If
  73. Next iX
  74. Common_Exit:
  75. End Sub
  76. Private Function p_GetQuestionKeywords( _
  77. i_strQuestion As String _
  78. ) As String()
  79. ReDim p_GetQuestionKeywords(0)
  80. Dim strWork As String
  81. Dim arrRawWords() As String, arrKw() As String
  82. Dim ixKw As Long
  83. Dim intUBound As Long
  84. Dim intIndex As Long
  85. ReDim arrKw(0)
  86. arrKw(0) = ""
  87. strWork = RemoveOperatorShortcuts(LCase$(i_strQuestion))
  88. strWork = frmMain.p_RemoveStopSigns(strWork)
  89. strWork = RemoveExtraSpaces(strWork)
  90. arrRawWords = Split(strWork)
  91. ixKw = -1
  92. intUBound = UBound(arrRawWords)
  93. For intIndex = 0 To intUBound
  94. strWork = arrRawWords(intIndex)
  95. If (strWork = "") Then
  96. MsgBox "Empty work string"
  97. Stop
  98. End If
  99. If (Not IsVerbalOperator(strWork)) Then
  100. If (Not frmMain.g_dictStopWords.Exists(strWork)) Then
  101. ixKw = ixKw + 1
  102. ReDim Preserve arrKw(ixKw)
  103. arrKw(ixKw) = strWork
  104. End If
  105. End If
  106. Next
  107. p_GetQuestionKeywords = arrKw
  108. Common_Exit:
  109. End Function
  110. Sub SetTaxonomyEntryKeywords(ByRef DOMNodeEntry As IXMLDOMNode)
  111. ' First we validate that the URI indeed corresponds
  112. If (StrComp(m_strUri, LCase$(XMLGetAttribute(DOMNodeEntry, "URI")), vbBinaryCompare) <> 0) Then
  113. MsgBox "Oops, I was called for the wrong URI"
  114. GoTo Common_Exit
  115. End If
  116. ' Then IF everything is correct, we now proceed to set the Keywords
  117. ' on the Entry.
  118. Dim strKw As Variant, strXpathQuery As String, lngProposedPri As Long
  119. For Each strKw In m_dictKw.Keys
  120. ' intIndex = 0 To UBound( m_dictKW'intUBound
  121. If (Len(strKw) = 0) Then
  122. MsgBox "UriQueries::SetTaxonomyEntryKeywords: Empty Keyword"
  123. Stop
  124. End If
  125. lngProposedPri = m_dictKw.Item(strKw)
  126. Dim Dom As DOMDocument: Set Dom = DOMNodeEntry.ownerDocument
  127. Dom.setProperty "SelectionLanguage", "XPath"
  128. strXpathQuery = "KEYWORD[" & _
  129. "translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" & _
  130. strKw & "']"
  131. Dim DOMNodeListKw As IXMLDOMNodeList, Element As IXMLDOMElement
  132. Set DOMNodeListKw = DOMNodeEntry.selectNodes(strXpathQuery)
  133. If (DOMNodeListKw.length = 0) Then
  134. ' This Keyword does not exist so we need to create it
  135. Set Element = DOMNodeEntry.ownerDocument.createElement(HHT_KEYWORD_C)
  136. Element.Text = strKw
  137. If (lngProposedPri > 0) Then
  138. XMLSetAttribute Element, HHT_PRIORITY_C, lngProposedPri
  139. End If
  140. DOMNodeEntry.appendChild Element
  141. m_lngNewPhonyKeywords = m_lngNewPhonyKeywords + 1
  142. Else
  143. ' The Keyword exists so we set the right priority if apropriate
  144. Set Element = DOMNodeListKw(0)
  145. Dim strPriority As String
  146. strPriority = XMLGetAttribute(Element, HHT_PRIORITY_C)
  147. If (strPriority = "") Then
  148. XMLSetAttribute Element, HHT_PRIORITY_C, lngProposedPri
  149. m_lngModifiedPhonyKeywords = m_lngModifiedPhonyKeywords + 1
  150. ElseIf (CLng(strPriority) < lngProposedPri) Then
  151. If (lngProposedPri > 0) Then
  152. XMLSetAttribute Element, HHT_PRIORITY_C, lngProposedPri
  153. End If
  154. End If
  155. End If
  156. Next ' strKW
  157. ' Statistics elements.
  158. If (m_lCountTimesSetKw = 0) Then
  159. m_lngNewKeywords = m_lngNewPhonyKeywords
  160. m_lngModifiedKeywords = m_lngModifiedPhonyKeywords
  161. End If
  162. m_lCountTimesSetKw = m_lCountTimesSetKw + 1
  163. Common_Exit:
  164. End Sub
  165. Public Property Get CountTimesSetKw() As Long
  166. CountTimesSetKw = m_lCountTimesSetKw
  167. End Property
  168. Public Property Get NewKeywords() As Long
  169. NewKeywords = m_lngNewKeywords
  170. End Property
  171. Public Property Get NewPhonyKeywords() As Long
  172. NewPhonyKeywords = m_lngNewPhonyKeywords
  173. End Property
  174. Public Property Get ModifiedKeywords() As Long
  175. ModifiedKeywords = m_lngModifiedKeywords
  176. End Property
  177. Public Property Get ModifiedPhonyKeywords() As Long
  178. ModifiedPhonyKeywords = m_lngModifiedPhonyKeywords
  179. End Property