我有一个包含 100 万个 URL 的列表,我想将相似的 URL 聚集在一起。该过程的输出将是一个正则表达式或模式列表。理想情况下,我想使用 Ruby 来派生数据。我最初的想法是使用机器学习分类器,但我不确定从哪里开始或使用哪种数据挖掘技术。
可能的例子:
输入:
http://www.example.com/folder-A/file.html
http://www.example.com/folder-A/dude.html
http://www.example.com/folder-B/huh.html
http://www.example.com/folder-C/what-ever.html
输出:
http://www\.example\.com/folder-A/[a-z]\.html
http://www\.example\.com/folder-[A-C]/[-a-z]\.html
最佳答案
这个程序:
#!/usr/bin/env perl
use strict;
use warnings;
# the following is a CPAN module requiring independent installation:
use Regexp::Assemble;
my @url_list = qw(
http://www.example.com/folder-A/file.html
http://www.example.com/folder-A/dude.html
http://www.example.com/folder-B/huh.html
http://www.example.com/folder-C/what-ever.html
);
my $asm = Regexp::Assemble->new;
for my $url (@url_list) {
$asm->add($url);
}
my $pat = $asm->re;
for ($pat) {
s/^.*?://;
s/\)$//;
}
print "$pat\n";
运行时,打印出来:
http://www.example.com/folder-(?:A/(?:dud|fil)e|C/what-ever|B/huh).html
这就是你要找的吗?
关于ruby - 给定大量 URL,将 URL 分组为模式或正则表达式的最佳数据挖掘方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7182224/