Loading...
Given a document (list of words) and a query word, find the context window of size k around each occurrence of the query word. Return all unique context windows.
Input format:
Output: Each context window on a separate line (words joined by spaces). Matching is case-insensitive. Print windows in order of appearance.
the cat sat on the mat near the door the 1
the cat on the mat near the door
Step 1: Find occurrences of "the" (positions 0, 4, 7)
Step 2: Extract windows (k=1 on each side) Position 0: [max(0,0-1):0+1+1] = words[0:2] = "the cat" Position 4: words[3:6] = "on the mat" Position 7: words[6:9] = "near the door"