Keyword Classifier
Classify a text into one of three categories based on keyword matching:
- sports: contains any of ["goal", "team", "player", "match", "score"]
- tech: contains any of ["code", "software", "computer", "algorithm", "data"]
- food: contains any of ["recipe", "cook", "ingredient", "meal", "dish"]
Check categories in the order: sports → tech → food. Return the first matching category. If no keywords match, return "other".
All matching is case-insensitive and checks if the keyword appears as a whole word in the text.
Input: A single line of text.
Example
The team scored a goal
sports
- Input:
textis one sentence, hereThe team scored a goal. It is made of five words: The, team, scored, a, goal. Capital letters don't matter, so "The" counts the same as "the". - Sports first: compare the sentence's words with the sports list. "team" and "goal" are both on it. "scored" is not a match: the keyword is "score", and only whole words count, so a keyword sitting inside a longer word doesn't qualify.
- Decision: sports has at least one hit, so the answer is settled here and tech and food are never consulted. How many keywords match doesn't matter, only whether any do.
- Output: the string
sports. - Notice that priority decides ties: "The team cooked a meal" also has a food word ("meal"), but it still comes out as sports because sports is checked first. A sentence with no keywords at all gives "other".
Constraints
- Case-insensitive word matching
- Check sports first, then tech, then food
- Return first matching category
- If no match, return "other"