.md →
TextCompare API#
TextCompare shows two texts in side-by-side panels and highlights every run of matching
words, with min_match_words setting how long a run has to be before it counts. Hover a
highlight and the other panel scrolls to the same passage, which is what makes shared or
lifted text quick to spot between two documents. The matches traitlet hands the same
list back to Python with start and end offsets and a word count per match.
See also: HoverZoom for inspecting image detail with the same hover gesture, LiveEdit for reading a Python run instead of prose, and ApiDoc for putting reference text next to the code it describes.
Bases: AnyWidget
Side-by-side text comparison widget with hover-based match highlighting.
Compares two texts and highlights matching word sequences, useful for plagiarism detection or finding shared passages between documents.
Examples:
import marimo as mo
from wigglystuff import TextCompare
compare = mo.ui.anywidget(TextCompare(
text_a="The quick brown fox jumps over the lazy dog.",
text_b="A quick brown fox leaps over a lazy dog."
))
compare
Create a TextCompare widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_a
|
str
|
First text to compare. |
''
|
text_b
|
str
|
Second text to compare. |
''
|
min_match_words
|
int
|
Minimum number of consecutive words to consider a match. |
3
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in wigglystuff/text_compare.py
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
text_a |
str |
First text to compare. |
text_b |
str |
Second text to compare. |
matches |
list |
List of detected matches, each with start_a, end_a, start_b, end_b, text, and word_count. |
selected_match |
int |
Index of the currently hovered match (-1 if none). |
min_match_words |
int |
Minimum consecutive words to consider a match (default: 3). |