search - 如何在相同文本(电子书)的不同修订版中找到相同的文本字符串?
问题描述
我在电子书中突出显示了一串文本。这本电子书每隔几年就会推出新的修订版。我想以编程方式在所有这些更新的电子书版本中重新定位这个亮点。我将如何解决这个问题?(假设我已经阅读了突出显示的原始电子书的访问权限。)
以下是数据结构的样子。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."
}
解决方案
这个问题的解决方案是模糊锚定,由hypothesis.is 详细说明。
简而言之,保存一堆独立于文档结构的选择器,并使用近似策略对新文档中高亮的位置进行有根据的猜测。
这包括:
- 指向原始文档中元素的 XPath 选择器
- 相对于原始文档全文的开始和结束偏移量
- 原始突出显示前缀的 32 个字符和原始突出显示后缀的 32 个字符
推荐阅读
- amazon-s3 - 如何将多个文件从目录上传到 S3?
- python - 垃圾回收无 - del 差异
- java - Jackson custom serializer to use in Optional
- mongodb - MongoDB 文档密钥区分大小写的性质
- opengl - OpenGL,获取其他进程的Framebuffer
- java - How to use Primefaces galleria with user defined objects in jsf
- vba - 简单问题 - 范围对象 - 查找感兴趣单词的粗体版本
- java - Kotlin 中方法的返回类型应该是什么,该方法的值可以为 null 并且将从 Java 中调用?
- amazon-web-services - How to fix `user must specify LSN` when using AWS DMS for Postgres RDS
- javascript - Stack Navigator in React Native. Error "undefined is not an object (evaluating this.props.navigation)"