得到单词有效原子集合的算法.

超级大笨狼 2007-01-19 09:49:35
加精
原子:单词抠掉个别字母的子串,如:abc 中的ac bc ab abc注意:ca不算
有效原子:长度大于单词长60%的原子,可用于联想记忆,比较相似单词.

<SCRIPT LANGUAGE="vbScript">

str="aaccb"
''创建全局字典对象,用来存储所有得到的原子结果
Set dict=CreateObject("Scripting.Dictionary")

Dim a(100)
strLength=Len(str)
''原子
atomyLength=round(strLength*0.6)

For x=atomyLength To strLength
a(0)=x
''计算5选3,5选4,5选5组合
combine strLength,x
next



sub combine(m, k)
''计算组合在m里面选k个元素的全部组合情况,添加到字典对象里
i=0
j=0
For i=m To k Step -1
a(k)=i
if (k>1) then
combine i-1,k-1
else
tempStr=""
for j=1 To a(0)
tempStr=tempStr & Mid(str,a(j),1)
Next
''排除重复的,加到字典里
If Not dict. Exists(tempStr) then dict.add tempStr,Len(tempStr)
End if
next
End sub

Main()

Sub Main
''输出显示结果
For i=0 To dict.count-1
Document.write dict.keys()(i) & "  "
next
End sub
</SCRIPT>

...全文
2498 32 打赏 收藏 转发到动态 举报
写回复
用AI写文章
32 条回复
切换为时间正序
请发表友善的回复…
发表回复
后浪 2010-05-10
  • 打赏
  • 举报
回复
收藏了,以后看!..
audryhepburn 2009-11-04
  • 打赏
  • 举报
回复
用正则对象就行!比这简单!
akenter 2009-02-26
  • 打赏
  • 举报
回复
非常感谢,正在研究分词的技术^_^。另外,分词之后如何再归类也是很头痛的问题。
cpring 2008-09-26
  • 打赏
  • 举报
回复
mark
会用得着的
lbt777777 2008-09-24
  • 打赏
  • 举报
回复
楼主能不能把vb换成vc实现啊,不懂vb。net,谢拉!
牙签是竹子的 2008-09-18
  • 打赏
  • 举报
回复
mark
「已注销」 2008-09-17
  • 打赏
  • 举报
回复
mark
lightnightcat 2008-06-04
  • 打赏
  • 举报
回复
留个记号,回头细读
ymle1228 2008-03-28
  • 打赏
  • 举报
回复
收藏,以后再研究
折射光 2007-02-28
  • 打赏
  • 举报
回复
mark
细细rainbow 2007-02-26
  • 打赏
  • 举报
回复
收了!
xk2y 2007-02-26
  • 打赏
  • 举报
回复
收了```
tsxnb 2007-02-25
  • 打赏
  • 举报
回复
收藏
ahhisoft 2007-02-25
  • 打赏
  • 举报
回复
收藏
kencorn 2007-02-25
  • 打赏
  • 举报
回复
mark
超级大笨狼 2007-02-09
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string word = this.textBox1.Text ;
List <string> list = new List<string>();
char[] Arr = word.ToCharArray();
int a = 0;
int b = 0;
pictureBox1.Show();
button1.Enabled = false;
DateTime T = DateTime.Now;
string result = "";
int strLength=word.Length;
int atomyLength = Convert.ToInt32(Math.Round(strLength * 0.6));
DateTime T1 = DateTime.Now;
//开始结算
for (int x = Convert.ToInt32(Math.Pow(2, atomyLength)); x <Convert.ToInt32(Math.Pow(2, strLength)); x++)
{
b = 0;
a = x;
while (a != 0)
{
if (a % 2 != 0)
{
result += Arr[b];
}
b++;
a >>= 1;
Application.DoEvents();
}
Application.DoEvents();
if (!list.Contains(result) && result.Length >= atomyLength)
{
list.Add(result);
}
result = "";
}
pictureBox1.Hide();
string time = (DateTime.Now - T1).ToString();
textBox2.Text = "输入\"" + textBox1.Text + "\"产生" + list.Count + "个原子,用时:" + time;
this.listBox1.DataSource = list;
button1.Enabled = true;
}







}
}
超级大笨狼 2007-02-09
  • 打赏
  • 举报
回复
输入"superdullwolf"产生1771个原子,用时:00:00:03.5933590
超级大笨狼 2007-02-09
  • 打赏
  • 举报
回复
输入:
"superdullwolf"

---------------------------

---------------------------
程序运行时间:00:00:03.7488720
---------------------------
OK
---------------------------
超级大笨狼 2007-02-09
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string word = this.textBox1.Text ;
List <string> list = new List<string>();
char[] Arr = word.ToCharArray();
int a = 0;
int b = 0;
pictureBox1.Show();
button1.Enabled = false;
DateTime T = DateTime.Now;
string result = "";
int strLength=word.Length;
int atomyLength = Convert.ToInt32(Math.Round(strLength * 0.6));
DateTime T1 = DateTime.Now;
//开始结算
for (int x = Convert.ToInt32(Math.Pow(2, atomyLength)); x <Convert.ToInt32(Math.Pow(2, strLength)); x++)
{
b = 0;
a = x;
while (a != 0)
{
if (a % 2 != 0)
{
result += Arr[b];
}
b++;
a >>= 1;
Application.DoEvents();
}
Application.DoEvents();
if (!list.Contains(result) && result.Length >= atomyLength)
{
list.Add(result);
}
result = "";
}
pictureBox1.Hide();
string time = (DateTime.Now - T1).ToString();
MessageBox.Show("程序运行时间:" + time);
this.listBox1.DataSource = list;
button1.Enabled = true;
}







}
}
Red_angelX 2007-02-09
  • 打赏
  • 举报
回复
来接一点点分就走...
加载更多回复(11)

4,008

社区成员

发帖
与我相关
我的任务
社区描述
它是一种微软环境下的轻量级的解释型语言,它使用COM组件、WMI、WSH、ADSI访问系统中的元素,对系统进行管理。
社区管理员
  • vbScript社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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