Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-145

Query Expansion with Synonyms

Problem

Expand query tokens with a synonym map. First collect the original tokens with duplicates removed, then for each original token in order append its synonyms in map order.

Skip any token that is already present, including synonyms repeated across entries.

Hint

A list preserves order while the membership checks enforce uniqueness.

Test cases

case 1
in: [["car","fast"],{"car":["auto","vehicle"],"fast":["quick"]}]
expected: ["car","fast","auto","vehicle","quick"]
case 2
in: [["a","b"],{"a":["b"]}]
expected: ["a","b"]
case 3
in: [[],{"a":["b"]}]
expected: []
case 4
in: [["x"],{}]
expected: ["x"]
case 5
in: [["a","a"],{"a":["a","z"]}]
expected: ["a","z"]
Starter codePython
def query_expansion_synonyms(query_tokens, synonyms):
    # Your code here
    pass

5 test cases · run your code against them in the editor