首页 > 解决方案 > 如何在相同文本(电子书)的不同修订版中找到相同的文本字符串?

问题描述

我在电子书中突出显示了一串文本。这本电子书每隔几年就会推出新的修订版。我想以编程方式在所有这些更新的电子书版本中重新定位这个亮点。我将如何解决这个问题?(假设我已经阅读了突出显示的原始电子书的访问权限。)


以下是数据结构的样子。loc只是相对于作为单个字符串布置的书的整个文本的字符索引。toc是目录。

// a single highlight
{
  "start_loc": 5000,
  "end_loc": 5044,
  "end_loc_of_book": 10000,
  "highlighted_text": "The quick brown fox jumps over the lazy dog.",
  "toc_path": ["Chapter 5: Animal Relationships", "Foxes and dogs"],
}

// an ebook
{
  "toc": [
    {
      "heading_title": "Chapter 1: All work and no play makes Jack a dull boy",
      "heading_start_loc": 0,
      "heading_end_loc": 2000,
      // each heading can have nested subheadings within
      // the range of its start_loc and end_loc
      "subheadings": [
        {
          "heading_title": "Jack is still a dull boy",
          "heading_start_loc": 300,
          "heading_end_loc": 500,
          // each heading can have nested subheadings within
          // the range of its start_loc and end_loc
          "subheadings": []
        },
        // ...
      ]
    },
    // ...
    {
      "heading_title": "Chapter 5: Animal Relationships",
      "heading_start_loc": 4000,
      "heading_end_loc": 6000,
      "subheadings": [
        {
          "heading_title": "Foxes and dogs",
          "heading_start_loc": 4500,
          "heading_end_loc": 5500,
          "subheadings": []
        },
        // ...
      ]
    },
    // ...
  ],
  "full_book_text": "Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. In fermentum et sollicitudin ac 
orci phasellus.

...

The quick brown fox jumps over the lazy dog.

...

Praesent semper feugiat nibh sed pulvinar proin. Augue 
eget arcu dictum varius duis at consectetur lorem donec.
Adipiscing elit duis tristique sollicitudin."
}

标签: searchtext-searchsentence-similarity

解决方案


这个问题的解决方案是模糊锚定,由hypothesis.is 详细说明

简而言之,保存一堆独立于文档结构的选择器,并使用近似策略对新文档中高亮的位置进行有根据的猜测。

这包括:

  1. 指向原始文档中元素的 XPath 选择器
  2. 相对于原始文档全文的开始和结束偏移量
  3. 原始突出显示前缀的 32 个字符和原始突出显示后缀的 32 个字符

推荐阅读