-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
‘Chunking’ abstraction #85
Comments
@tilgovi alluded to this chunking idea in #75:
Just one idea this raised: would it go too far to just ask for a stream of characters, that we permit to be nested? A simple experiment:
I suppose such an approach may be elegant for a specification or reference implementation, but perhaps making a stricter structure could help increase performance (iterating through a string’s individual characters might anyhow be required when anchoring a TextPositionSelector, but for a TextQuoteSelector it could be superfluous?) |
I started playing with this idea in the branch chunking. In this first attempt a Chunk is anything that has a toString() method:
And we can point at a part of the text using a straightforward generalisation of
I made an abstracted version of the text quote matcher that accepts as its scope an
So one can throw any type of For the text quote matching this works fine (all tests pass). For describing a text quote however, it would be helpful to have more freedom to navigate the text, instead of only walking through it in a single pass (especially to find prefixes). I suppose our scope should have an API that is more like a TreeWalker than like a NodeIterator: jump to any spot, and then walk in either direction. @tilgovi: Any thoughts about the approach to try, before I go further down this rabbit hole? |
In recent calls we (especially @tilgovi — so feel free to improve my description) have discussed an approach to allow text selector matching/describing implementations on other ‘document models’ than the DOM. A typical use case would be a (web) application that uses some framework (ProseMirror, React, …) to display documents, and therefore would not want the result of anchoring an annotation to be a Range object, but rather something that matches their internal representation of the document.
A discussed requirement is also that the document can be provided piecemeal and asynchronously, so that an application can try anchor selectors on documents that are not fully available yet (or just not fully converted to text yet, think e.g. PDF.js). We have been calling such pieces of text ‘chunks’ for now.
Currently, our text quote anchoring function (in the dom package) is hard-coded to search for text quote using Range, NodeIterator, TreeWalker. When using the chunk approach, this functionality should be composed of two parts: one generic text quote anchoring function that takes a stream of Chunks of text; and one dom-to-chunk converter that uses TreeWalkers and such to present the DOM as a stream of text Chunks.
I am creating this issue to discuss what exactly a Chunk would be (a string?), and what a stream of chunks would be (an
AsyncIterable<Chunk>
?), and how our generalised anchoring functions interact with chunk providers (e.g. do we need an equivalent of Range, how do we pass back string offsets, …?). And also to discuss the assumptions and requirements (are we on the right track?).The text was updated successfully, but these errors were encountered: