Algorithm 计算反向索引中的单词接近度

Algorithm 计算反向索引中的单词接近度,algorithm,indexing,search-engine,information-retrieval,inverted-index,Algorithm,Indexing,Search Engine,Information Retrieval,Inverted Index,作为搜索引擎的一部分,我开发了一个反向索引 因此,我有一个列表,其中包含以下类型的元素 public struct ForwardBarrelRecord { public string DocId; public int hits { get; set; } public List<int> hitLocation; } public结构ForwardBarrelRecord { 公共字符串DocId; 公共int命中{get;set;} 公共位置列表;

作为搜索引擎的一部分,我开发了一个反向索引

因此,我有一个列表,其中包含以下类型的元素

public struct ForwardBarrelRecord
{
    public string DocId;
    public int hits { get; set; }
    public List<int> hitLocation;
}
public结构ForwardBarrelRecord
{
公共字符串DocId;
公共int命中{get;set;}
公共位置列表;
}
现在这张唱片只有一个词。hitLocation包含在文档中找到特定单词的位置

现在我想计算
List hitLocation
中的元素与另一个
List hitLocation
的接近度,然后如果列表中的元素相邻,则增加两个记录的权重


我面临的问题是找到一个适合这个目的的算法。非常感谢您提供的任何帮助

如果
命中位置
列表按顺序排列,这将是最简单的。因此,首先:

var word1List = word1.hitLocation.Orderby(s => s).ToList();
var word2List = word2.hitLocation.Orderby(s => s).ToList();
虽然如果你是为搜索引擎这样做的,那么你可能希望这些列表在你的反向索引中预先排序

在任何情况下,对列表进行排序后,查找匹配项都非常容易

int ix1 = 0;
int ix2 = 0;
while (ix1 < word1List.Count && ix2 < word2List.Count)
{
    int hit1 = word1List[ix1];
    int hit2 = word2List[ix2];
    if (hit1 < hit2)
    {
        if ((hit2 - hit1) == 1)
        {
            Console.WriteLine("Match at {0} and {1}", hit1, hit2);
        }
        ix1++;
    }
    else
    {
        ix2++;
    }
}          
intix1=0;
intix2=0;
而(ix1
这将定位word1后跟word2的匹配项。如果您还希望word2后跟word1,您可以在
else
子句中添加类似的复选框。

\include
#包括
#包括
使用名称空间std;
结构ForwardBarrelRecord
{
字符串DocId;
整数命中率;
列出地点;
};
无效合并(结构ForwardBarrelRecord&fa、结构ForwardBarrelRecord&fb)
{
列表&la=fa.hitLocation;
列表&lb=fb.hitLocation;
la.sort();
lb.sort();
std::list::迭代器ita=la.begin();
std::list::迭代器itb=lb.begin();
而(ita!=la.end()&&itb!=lb.end())
{
int loc_a=*ita;
int loc_b=*投标人须知;
如果(位置a<位置b)
{
如果(位置a+1==位置b)
{

你是否已经有了命中位置的列表,如果你把它们看作一个离散的函数呢?你可以将每个命中转换成一个范围(围绕每个索引,向下到两侧,总宽度取决于你希望单词的接近程度)。然后你基本上是两个“列表”之间的点积为了获得接近度分数,我认为这是我需要的。虽然这是一个简洁的评论,无法得到我需要的完整答案,但我真的很感激一些关于进一步获取知识的一般性建议:)好吧,为了它的价值-我在这里写了一个更详细的解释-尽管我在寻找权重,这似乎是这样的这是一个很好的起点。谢谢。你能更详细地解释一下你的答案吗?