我正在尝试从多个字符串中提取相似的部分。
此举旨在尝试从标题页的多个OCR处理结果中提取书名。
仅适用于字符串开头,字符串结尾不需要修剪,可以保持原样。
例如,我的字符串可能是:
$title[0]='the history of the internet, expanded and revised';
$title[1]='the history of the internet';
$title[2]='published by xyz publisher the historv of the internot, expanded and';
$title[3]='history of the internet';
基本上,我想要修剪每个字符串,以便从最可能的起点开始。考虑到可能存在OCR错误(例如“historv”,“internot”),我认为最好从每个单词中取出字符数,这将为每个字符串(因此是多维数组)提供一个包含每个单词长度的数组。然后可以使用它来查找运行匹配并将字符串的开头修剪到最有可能的位置。
应该将字符串切割为:
$title[0]='the history of the internet, expanded and revised';
$title[1]='the history of the internet';
$title[2]='the historv of the internot, expanded and';
$title[3]='XXX history of the internet';
因此我需要能够识别“互联网的历史”(7 2 3 8)是匹配所有字符串的运行,而前面的“the”很可能是正确的,因为它出现在>50%的字符串中,因此每个字符串的开头都被修剪为“the”,并且在缺少“the”的字符串上添加相同长度的占位符。
到目前为止,我已经得到:
function CompareSimilarStrings($array)
{
$n=count($array);
// Get length of each word in each string >
for($run=0; $run<$n; $run++)
{
$temp=explode(' ',$array[$run]);
foreach($temp as $key => $val)
$len[$run][$key]=strlen($val);
}
for($run=0; $run<$n; $run++)
{
}
}
你看,我卡在了找到正在运行的匹配项上。
有什么想法吗?