Review Token Tagging
Asked at Airbnb
Reported by the problem's creator, not verified
A review site marks the names it knows. You get a review text and a map tokens that maps each token to a label. Write tag_review(review, tokens), which returns the review with every occurrence of a token wrapped as [label]{text}, where text is the occurrence exactly as it appears in the review.
Matching ignores case, so the token san francisco matches San Francisco, and the wrapped text keeps the casing of the review. A token may contain spaces and punctuation, and it matches only that exact sequence of characters (a single space matches a single space). A token matches anywhere, including inside a longer word. Everything outside matches is copied unchanged.
Examples
Example 1
Input:
{"review":"I booked a house on Airbnb for my trip to San Francisco. It was a lovely experience.","tokens":{"Airbnb":"business","san francisco":"city"}}Output:
I booked a house on [business]{Airbnb} for my trip to [city]{San Francisco}. It was a lovely experience.Explanation:
Airbnbmatches itself, andsan franciscomatchesSan Franciscoacross the space. Each match keeps the casing the review used, so the label wrapsSan Francisco, notsan francisco.