Loading...
Given multiple documents (one per line), build a document-term matrix where each row represents a document and each column represents a unique word from the vocabulary.
The vocabulary should be sorted alphabetically. Each cell contains the count of that word in that document. All words should be lowercased.
Input format:
Output: Print each row of the matrix as a list of integers.
2 the cat sat the dog sat
[1, 0, 1, 1] [0, 1, 1, 1]
Step 1: Collect vocabulary All unique words (sorted): ["cat", "dog", "sat", "the"]
Step 2: Count words per document Doc 1 "the cat sat": cat=1, dog=0, sat=1, the=1 → [1, 0, 1, 1] Doc 2 "the dog sat": cat=0, dog=1, sat=1, the=1 → [0, 1, 1, 1]