|
|
<%
adOpenStatic = 3
adOpenDynamic = 2
adOpenKeyset = 1
Question = Server.HTMLEncode(Request.Form("Question")&"")
PrevQuestion = Server.HTMLEncode(Request.Form("PrevQuestion")&"")
PrevAnswer = Request.Form("PrevAnswer")
If PrevAnswer = "" or IsNull(PrevAnswer) Then
PrevAnswer = 0
End If
PrivateRequest = Request.Form("Private")
If PrivateRequest = "True" Then
PrivateChecked = "Checked"
Else
PrivateRequest = "False"
PrivateChecked = ""
End If
If Not(IsNull(Question)) and Question <> "" Then
If Question = PrevQuestion Then
RepeatArray = Array("A bit repetitious", "Just when you say it - that's when you say it again", "You did not like my answer?", "Who'd have known you would be so predictable?")
Rnd(-1)
Randomize()
RandomNo = (CInt((3*Rnd) + 1))
Answer = RepeatArray(RandomNo - 1) & " Ask me something else."
Else
ReFormatQuestion = replace(Question,"?"," ")
ReFormatQuestion = replace(ReFormatQuestion,"'","")
ReFormatQuestion = replace(ReFormatQuestion,","," ")
ReFormatQuestion = replace(ReFormatQuestion,";"," ")
ReFormatQuestion = replace(ReFormatQuestion,"-"," ")
ReFormatQuestion = replace(ReFormatQuestion,"!"," ")
ReFormatQuestion = replace(ReFormatQuestion,"ü","u")
ReFormatQuestion = replace(ReFormatQuestion,"."," ")
ReFormatQuestion = replace(ReFormatQuestion,""","")
ReFormatQuestion = LCase(ReFormatQuestion)
QuestionWords= split(ReFormatQuestion," ")
IgnoreWords = Array("what", "whats","where", "when", "why","will","how","is","are","they", "them", "you","me","I","who","and","but","was","were","the","should","would","could", "does", "your", "with","there", "many", "have", "about", "like", "because", "ever", "doing", "some", "well", "then", "youre", "that", "going")
SearchWords = " "
i = 0
For Each QWord in QuestionWords
IgnoreIt = 0
For Each IWord in IgnoreWords
If QWord = IWord Then
IgnoreIt = 1
End If
Next
If Len(QWord) <= 3 and QWord <> "boo" and QWord <> "gay" and QWord <> "cow" and QWord <> "bye" and QWord <> "moo" and QWord <> "eat" and QWord <> "god" and QWord <> "cry" and QWord <> "sob" Then
IgnoreIt = 1
End If
If IgnoreIt = 0 Then
SearchWords = SearchWords & " or LCase(Quote) Like '%" & QWord & "%' or LCase(HiddenWords) Like '%" & QWord & "%'"
Else
QuestionWords(i) = ""
End If
i = i + 1
Next
Set DaveTable = CreateObject("ADODB.Recordset")
QueryString = "Select * from Quotes WHERE 1=0 " & SearchWords & " ORDER BY ((Second(Time())+35)^2*[id]) Mod 1223"
DaveTable.Open QueryString, "DSN=daveshead;"
Selected = 0
If Not(DaveTable.EOF) Then
MaxScore = 0
dim UsedWords(999)
Do Until DaveTable.EOF
Score = 0
Quote = DaveTable.Fields("Quote") & " " & DaveTable.Fields("HiddenWords")
ReFormatQuote = replace(Quote,"?"," ")
ReFormatQuote = replace(ReFormatQuote,"'","")
ReFormatQuote = replace(ReFormatQuote,","," ")
ReFormatQuote = replace(ReFormatQuote,";"," ")
ReFormatQuote = replace(ReFormatQuote,"-"," ")
ReFormatQuote = replace(ReFormatQuote,"!"," ")
ReFormatQuote = replace(ReFormatQuote,"ü","u")
ReFormatQuote = replace(ReFormatQuote,"."," ")
ReFormatQuote = replace(ReFormatQuote,""","")
ReFormatQuote = LCase(ReFormatQuote)
QuoteWords= split(ReFormatQuote," ")
z = 1
Do Until z > 999
UsedWords(z) = " "
z = z + 1
Loop
For Each QWord in QuestionWords
For Each QuoteWord in QuoteWords
if (QWord = QuoteWord or QWord = QuoteWord & "s" or QWord = QuoteWord & "'s" or QWord = QuoteWord & "ed" or QWord = QuoteWord & "er" or QWord = QuoteWord & "ing") or _
(QuoteWord = QWord & "s" or QuoteWord = QWord & "'s" or QuoteWord = QWord & "ed" or QuoteWord = QWord & "er" or QuoteWord = QWord & "ing") Then
AlreadyUsed = 0
u = 0
For Each UseWord in UsedWords
if UseWord <> "" Then
if QWord = UseWord Then
AlreadyUsed = 1
end if
u = u + 1
end if
Next
if AlreadyUsed = 0 Then
Score = Score + Len(QWord)
UsedWords(u) = QWord
end if
end if
Next
Next
If Score >= MaxScore and DaveTable.Fields("ID") <> CInt(PrevAnswer) Then
Answer = DaveTable.Fields("Quote")
AnswerID = DaveTable.Fields("ID")
MaxScore = Score
Selected = 1
End If
DaveTable.MoveNext
Loop
End If
If Not(DaveTable.EOF) or Selected = 0 Then
DaveTable.Close
Set DaveTable = CreateObject("ADODB.Recordset")
DaveTable.Open "Select * from Quotes ", "DSN=daveshead;", adOpenStatic
If NOT(DaveTable.EOF) Then
DaveTable.MoveLast
NumOfRecords = DaveTable.RecordCount
DaveTable.MoveFirst
Rnd(-1)
Randomize()
RandomRecord = (CInt((NumOfRecords*Rnd) + 1))
DaveTable.Move RandomRecord-1
Answer = DaveTable.Fields("Quote")
AnswerID = DaveTable.Fields("ID")
End If
DaveTable.Close
End If
Set DaveQTable = CreateObject("ADODB.Recordset")
DaveQTable.Open "QuestionsAsked", "DSN=daveshead;", 1, 3, 2
DaveQTable.AddNew
DaveQTable.Fields("Question") = Question
DaveQTable.Fields("Date") = Now()
DaveQTable.Fields("Answer") = AnswerID
DaveQTable.Fields("Private") = PrivateRequest
DaveQTable.Update
DaveQTable.Close
End If
Else
Answer = "Enter your question."
End If
PrevQuestion = Question
If AnswerID <> "" and Not(IsNull(AnswerID)) Then
PrevAnswer = AnswerID
End If
%>
Ask Dave's Head |
Dave's Head can sometimes channel Früvous wisdom in the form of Früvous lyrics - but you must be wise enough to decipher it. If Dave's Head is in a good mood, you will be provided with your answer.
|
|
|