开发者

Reconstructing Position in the Original Array from the Position in a Stripped Down Array

开发者 https://www.devze.com 2022-12-24 11:26 出处:网络
I have a text file that contains a number of the following: <ID> <Time 1> --> <Time 2>

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.

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.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号