!7 static LPair arrows = synchroList(); p-experiment { S text = lines(sentencesAfterLines_withPeriodOnly(mechList_raw("Simple Wikipedia: Peafowl"))); //jtextpane(text) JTextPane tp = swing(func -> JTextPane { ret new JTextPane { public void paint(Graphics _g) { Graphics2D g = cast _g; super.paint(g); pcall { Color arrowColor = colorWithAlpha(Color.red, 0.3); S text = getText(); for (Pair p : cloneList(arrows)) { Rect r1 = textComponent_substringRect(this, p.a); Rect r2 = textComponent_substringRect(this, p.b); if (r1 != null && r2 != null) { fillRect(g, r1, colorWithAlpha(Color.green, 0.2)); fillRect(g, r2, colorWithAlpha(Color.red, 0.2)); //drawArrowBetweenRects(g, r1, r2, arrowColor); drawArrowBetweenPoints(g, centerOfRect(r1), centerOfRect(r2), arrowColor); } else if (r1 != null) drawText(g, "?", centerTextInRect(g.getFontMetrics(), "?", r1), arrowColor); } } } }; }); setTextCaret0(tp, text); L tok = javaTok(text); addPair(arrows, tokenToCharRange(tok, indexOfIC(tok, "it")), tokenToCharRange(tok, indexOfIC(tok, "peafowl"))); Set set = mechSetCI("Backreferencing words"); Set have = asHashSet(firstOfPairs(arrows)); for (int i = 1; i < l(tok); i += 2) if (set.contains(tok.get(i)) && !arrows.contains(tokenToCharRange(tok, i))) addPair(arrows, tokenToCharRange(tok, i), null); // show question mark showFrame(setFontSize(30, tp)); hideConsole(); }