请问ASP怎样实现类似MSN聊天机器人的功能?学习学习

milo2 2007-02-18 09:05:14
怎样用ASP实现下面这个功能??
""""
<?xml version="1.0" encoding="UTF-8"?>
<chat>
<!--默认的聊天语句-->
<default>
<content>你在哪里?</content>
<content>你还是学生吗?</content>
.........
</default>
<!--回答指定关键词的语句序列-->
<answer>
<content key="怪"> 不怪</content>
<content key="慢">是啊,慢</content>
<content key="喂">什么事?</content>
<content key="88">再见</content>
<content key="谢">没什么好谢的</content>
<content key="滚">我不会滚,我会走</content>
......
<answer>
</chat>
////////////////////////////////////////////////////////////////////
以下是主要的源代码:
Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(0, 0)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.ReadOnly = True
Me.RichTextBox1.Size = New System.Drawing.Size(560, 304)
Me.RichTextBox1.TabIndex = 2
Me.RichTextBox1.Text = ""
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(0, 312)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(456, 21)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(472, 312)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Enter"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(560, 341)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.RichTextBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "青蛙王子"
Me.ResumeLayout(False)
End Sub
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
readxml()
End Sub

Dim xmlFile As String = "./robot.xml"
Dim chatList As New ArrayList
Dim answerList As New Hashtable
Dim random As New System.Random
Private Sub readxml()
Try
Dim doc As XmlDocument = New XmlDocument
doc.Load(xmlFile)
Dim nodeList As XmlNodeList
Dim root As XmlElement = doc.DocumentElement
'--默认的聊天语句--
nodeList = root.SelectNodes("/chat/default/content")
Dim node As XmlNode
For Each node In nodeList
chatList.Add(node.InnerText)
Next
'回答指定关键词的语句序列--
nodeList = root.SelectNodes("/chat/answer/content")
For Each node In nodeList
answerList.Add(node.Attributes("key").Value, node.InnerText)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'RichTextBox1.SelectionBullet = True
Dim Content$ = TextBox1.Text.Trim
If (Content = "") Then
RichTextBox1.AppendText("请不要欺骗我的感情,谢谢!" + ControlChars.Lf)
Exit Sub
End If
If (Content.IndexOf(":") <> -1) Then
If learnNewWord(Content) Then
RichTextBox1.AppendText("我又学会了新的东西,谢谢!" + ControlChars.Lf)
End If
Exit Sub
End If
RichTextBox1.AppendText(Content + ControlChars.Lf)
Dim aStr$ = getSimilarContent(Content)
If (aStr = Nothing) Then
Dim i% = random.Next(1, chatList.Count)
aStr = chatList.Item(i)
End If
RichTextBox1.AppendText(aStr.Trim + ControlChars.Lf)
RichTextBox1.Refresh()
End Sub
'得到相似的字符串
Function getSimilarContent(ByVal content As String) As String
Dim keys As System.Collections.ICollection = answerList.Keys
Dim enumR As System.Collections.IEnumerator = keys.GetEnumerator
While (enumR.MoveNext)
Dim str$ = enumR.Current
If content.Equals(str) Then
Return answerList(str)
End If
End While
enumR.Reset()
While (enumR.MoveNext)
Dim str$ = enumR.Current
If (content.IndexOf(str) <> -1) Or (str.IndexOf(content) <> -1) Then
Return answerList(str)
End If
End While
Return Nothing
End Function
'添加新的语句
Function learnNewWord(ByVal content As String) As Boolean
Try
Dim doc As XmlDocument = New XmlDocument
Dim i% = content.IndexOf(":")
Dim str1$ = content.Substring(0, i)
Dim str2$ = content.Substring(i + 1)
doc.Load(xmlFile)
Dim elem As XmlElement = doc.CreateElement("content")
Dim attr As XmlAttribute = doc.CreateAttribute("key")
attr.Value = str1
elem.InnerText = str2
elem.Attributes.Append(attr)
'添加新的语句--
Dim root As XmlElement = doc.DocumentElement
Dim xmlNode As XmlNode = root.SelectSingleNode("/chat/answer")
xmlNode.AppendChild(elem)
answerList.Add(str1, str2)
doc.Save(xmlFile)
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar.Equals(ControlChars.Cr) Then
Button1_Click(Nothing, Nothing)
End If
End Sub
End Class
...全文
427 8 打赏 收藏 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
不耐烦 2010-01-16
  • 打赏
  • 举报
回复
太不小心了还能被骗 ?????? 不看到完整的程序哪能交钱
shenxian5 2010-01-05
  • 打赏
  • 举报
回复
上面说错了。。也许有更好的办法,呵呵
shenxian5 2010-01-05
  • 打赏
  • 举报
回复
没做过。。不过我个人理解,用最笨的办法,做一个后台数据录入,将需要的一些常用语句录入到数据库中,如果客户端提交问题,那么就是一个查询条件where?然后显示出相应的录入好的记录即可。当然where 的条件可以细一点?
也许是更好的解决方法。。
dylike 2010-01-03
  • 打赏
  • 举报
回复
无无语...
subasan 2007-02-19
  • 打赏
  • 举报
回复
强烈要求楼上的把 与 msn 接口方面的代码发上来。
李睿_Lee 2007-02-19
  • 打赏
  • 举报
回复
VB.Net?
【无人车路径跟踪】基于神经网络的数据驱动迭代学习控制(ILC)算法,用于具有未知模型和重复任务的非线性单输入单输出(SISO)离散时间系统的无人车的路径跟踪(Matlab代码实现)内容概要:本文介绍了基于神经网络的数据驱动迭代学习控制(ILC)算法,旨在解决具有未知模型和重复任务的非线性单输入单输出(SISO)离散时间系统中无人车的路径跟踪问题。该方法结合神经网络的学习能力与ILC的迭代优化机制,在无需精确系统模型的前提下,通过多次任务执行不断修正控制输入,以实现对期望轨迹的高精度跟踪。文章详细阐述了算法的设计原理、稳定性分析以及在无人车路径跟踪中的具体实现与仿真验证,展示了其在处理模型不确定性与提升跟踪精度方面的有效性。; 适合人群:具备自动控制、机器人或人工智能基础知识,从事无人车、自动化控制、智能系统研发的研究人员及工程师。; 使用场景及目标:①解决无人车在复杂环境下因系统模型未知或不精确导致的路径跟踪难题;②提升重复性作业中控制系统对理想轨迹的跟踪精度与鲁棒性;③为非线性、不确定性系统的先进控制策略设计提供理论参考与实践案例。; 阅读建议:建议读者结合Matlab代码实现进行学习,重点关注神经网络与ILC的融合机制、控制律的设计过程以及仿真结果的分析,以深入理解数据驱动方法在解决模型未知问题上的优势。

28,402

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧