Tagging Review Text with Metadata Based on Keywords

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2019-11-16

Problem Statement

Designing and implementing a Tagging Engine that analyzes customer reviews (text input) and attaches relevant metadata tags based on predefined keywords or patterns. This system should be modular and extensible, allowing new keywords, rules, or tag categories to be added easily in the future.


✅ Functional Requirements

1.<span></span>Input:
2.<span></span>A review text string (e.g., "The delivery was fast but the product quality is poor").
3.<span></span>Processing:
4.<span></span>Parse the review text.
5.<span></span>Match against a set of predefined keyword → tag mappings.
6.<span></span>Keywords can belong to multiple categories (e.g., "delivery" → ["logistics"], "quality" → ["product"]).
7.<span></span>Case-insensitive matching.
8.<span></span>Output:
9.<span></span>Return a set of metadata tags for the review.
10.<span></span>Example:
11.<span></span>Input: "Great packaging but slow delivery"
12.<span></span>Output: ["packaging", "logistics"]
13.<span></span>Extensibility:
14.<span></span>Ability to add new keywords and categories without modifying core logic.
15.<span></span>Support for regex-based patterns (e.g., detecting "1 star", "5/5", etc.).


⚙️ Non-Functional Requirements

1.<span></span>Modular design (separate components for parsing, matching, and tagging).
2.<span></span>Scalable (should handle thousands of reviews efficiently).
3.<span></span>Configurable (tags and keywords defined externally via config/DB).
4.<span></span>Testable (each component—parsing, matching, tagging—should be independently testable).


🔐 Constraints

1.<span></span>Review length ≤ 5000 characters.
2.<span></span>Keywords ≤ 10,000.
3.<span></span>UTF-8 text input.


🧱 Key Classes / Methods to Model

1.<span></span>TaggingEngine → main orchestrator.
2.<span></span>addKeyword(keyword, tag)
3.<span></span>tagReview(text) → returns list of tags.
4.<span></span>KeywordStore → stores keyword-to-tag mapping.
5.<span></span>loadKeywords() (from config, file, or DB).
6.<span></span>TextParser → handles normalization (case-folding, punctuation removal, tokenization).
7.<span></span>Matcher → responsible for keyword/pattern matching.
8.<span></span>ReviewTagResult → data class for final output.


🧪 Example Flow

<div><div><br /></div><div>Keywords Mapping:</div><div>"delivery" → ["logistics"]</div><div>"packaging" → ["packaging"]</div><div>"refund" → ["customer_support"]</div><div>"quality" → ["product"]</div><div><br /></div><div>Input Review:</div><div>"The delivery was late but the packaging was excellent."</div><div><br /></div><div>Processing:</div><div>- Normalize text → ["the", "delivery", "was", "late", "but", "the", "packaging", "was", "excellent"]</div><div>- Match keywords → "delivery" → logistics, "packaging" → packaging</div><div><br /></div><div>Output Tags:</div><div>["logistics", "packaging"]</div></div>


👉 This LLD problem tests a candidate’s ability to:

1.<span></span>Build a modular and extensible system.
2.<span></span>Use OOP principles (encapsulation, separation of concerns).
3.<span></span>Design for scalability and maintainability.


Solution

Comments