从剥离向下阵列中的位置重建原始阵列中的位置

时间:2022-09-26 13:26:12

I have a text file that contains a number of the following:

我有一个包含以下内容的文本文件:

<ID>
<Time 1> --> <Time 2>
<Quote (potentially multiple line>
<New Line Separator>

<ID>
<Time 1> --> <Time 2>
<Quote (potentially multiple line>
<New Line Separator>

<ID>
<Time 1> --> <Time 2>
<Quote (potentially multiple line>
<New Line Separator>

I have a very simple regex for stripping these out into a constant block so it's just:

我有一个非常简单的正则表达式,用于将这些解析为一个常量块,所以它只是:

<Quote>
<Quote>
<Quote>

What I'd like to do is present the quotes as a block to the user, and have them select it (using jQuery.fieldSelection) and then use the selected content to back out to the original array, so I can get timing and IDs.

我想做的是将引号作为一个块呈现给用户,并让它们选择它(使用jQuery.fieldSelection)然后使用所选内容返回到原始数组,这样我就可以得到时间和ID 。

Because this has to go out to HTML, and the user has to be able to select the text on the screen, I can't do anything like hidden divs or hidden input fields. The only data I will have is the character range selected on screen.

因为这必须用于HTML,并且用户必须能够在屏幕上选择文本,所以我不能做任何像隐藏的div或隐藏的输入字段。我将拥有的唯一数据是在屏幕上选择的字符范围。

To be specific, this is what it looks like:

具体来说,这就是它的样子:

1
0:00 --> 0:05
He was bored. So bored. His great intellect, seemingly inexhaustible, 
was hungry for new challenges but he was the last of the great innovators

2
0:05 --> 0:10
- society's problems had all been solved.

3
0:11 --> 0:20
All seemingly unconnected disciplines had long since been found to be related in
horrifically elusive and contrived ways and he had mastered them all.

And this is what I'd like to present to the user for selection:

这就是我想要呈现给用户选择的内容:

He was bored. So bored. His great intellect, seemingly inexhaustible, was hungry for new challenges but he was the last of the great innovators - society's problems had all been solved. All seemingly unconnected disciplines had long since been found to be related in horrifically elusive and contrived ways and he had mastered them all.

他很无聊。很无聊。他的伟大智慧,似乎无穷无尽,渴望迎接新的挑战,但他是最伟大的创新者 - 社会的问题都得到了解决。所有看似无关紧要的学科早已被发现与可怕的难以捉摸和人为的方式有关,他已经掌握了所有这些。

Has anyone com across something like this before? Any ideas how to take the selected text, or selection position, and go backwards to the original meta-data?

以前有没有人喜欢这样的事情?任何想法如何采取选定的文本,或选择位置,并回到原始的元数据?

1 个解决方案

#1


1  

This isn't possible in the general case because there's no guarantee that an element in a list (or even a series of elements shorter than half the length of the total result) will be unique. If we put the constraint that any text fragment will only appear once, we can simply search the original list for the text and see where it occurs (though this will be inefficient). In general, the best solution would be to attach a reference to the original fragment to the stripped-down version. If you're doing the transformation with Javascript, this is very simple — just have the transformation function wrap each result sentence in a span and set thisSpan.original = 3 or whatever.

这在一般情况下是不可能的,因为不能保证列表中的元素(或者甚至是短于总结果长度一半的一系列元素)将是唯一的。如果我们设置任何文本片段只出现一次的约束,我们可以简单地在原始列表中搜索文本并查看它出现的位置(尽管这样效率很低)。通常,最好的解决方案是将原始片段的引用附加到精简版本。如果您正在使用Javascript进行转换,这非常简单 - 只需让转换函数将每个结果句子包装在一个范围内并设置thisSpan.original = 3或其他。

#1


1  

This isn't possible in the general case because there's no guarantee that an element in a list (or even a series of elements shorter than half the length of the total result) will be unique. If we put the constraint that any text fragment will only appear once, we can simply search the original list for the text and see where it occurs (though this will be inefficient). In general, the best solution would be to attach a reference to the original fragment to the stripped-down version. If you're doing the transformation with Javascript, this is very simple — just have the transformation function wrap each result sentence in a span and set thisSpan.original = 3 or whatever.

这在一般情况下是不可能的,因为不能保证列表中的元素(或者甚至是短于总结果长度一半的一系列元素)将是唯一的。如果我们设置任何文本片段只出现一次的约束,我们可以简单地在原始列表中搜索文本并查看它出现的位置(尽管这样效率很低)。通常,最好的解决方案是将原始片段的引用附加到精简版本。如果您正在使用Javascript进行转换,这非常简单 - 只需让转换函数将每个结果句子包装在一个范围内并设置thisSpan.original = 3或其他。