mugy_mb's blog

By mugy_mb, history, 18 months ago, In English

hey

I am trying to solve this problem for the last 2 days but I am not able to solve it ,can any of you please solve it in JavaScript?

###

Exercise

As part of a Natural Language Processing application, we want to build a simple module that can detect if two sentences are similar. The first version of this module will have a simple, naive implementation.

Function and Input

Create a function called isSimilar(sentence1, sentence2, similarWords)

Both sentence1 and sentence2 are plain strings (without most punctuation)

E.g. We are doing fine

similarWords is an array of arrays that contains all the words that are similar to each other

E.g. [ ['fine', 'great'], ['happy', 'glad', 'cheery'] ]

Algorithm

The function should do the following to determine if the two sentences are similar, and if so return true or false:

Check both sentences have an equal number of words

Ignore casing

Check words not in similarWords appear as-is in the second sentence

Check words in simlarWords have the same or an alternate word in the same position in the second sentence

Example

Sentence 1: "The Greatest Trick"
Sentence 2: "The supreme con"
Similar Words: [ ["supreme", "greatest"], ["trick", "hoax", "con"] ]
Output: true


Example 2

Sentence 1: "I'm very glad"
Sentence 2: "I am super happy"
Similar Words: [ ["happy", "glad", "cheery"], ["very", "super", "extremely"] ]
Output: false

Full text and comments »

  • Vote: I like it
  • -10
  • Vote: I do not like it

By mugy_mb, history, 18 months ago, In English

hey

---------------------------------------------------------------------------------------------------------------------------------- I am trying to solve this problem for the last 2 days but I am not able to solve it ,can any of you please solve it in JavaScript? ----------------------------------------------------------------------------------------------------------------------------------

###

Exercise

As part of a Natural Language Processing application, we want to build a simple module that can detect if two sentences are similar. The first version of this module will have a simple, naive implementation.

Function and Input

Create a function called isSimilar(sentence1, sentence2, similarWords)

Both sentence1 and sentence2 are plain strings (without most punctuation)

E.g. We are doing fine

similarWords is an array of arrays that contains all the words that are similar to each other

E.g. [ ['fine', 'great'], ['happy', 'glad', 'cheery'] ]

Algorithm

The function should do the following to determine if the two sentences are similar, and if so return true or false:

Check both sentences have an equal number of words

Ignore casing

Check words not in similarWords appear as-is in the second sentence

Check words in simlarWords have the same or an alternate word in the same position in the second sentence

Example

Sentence 1: "The Greatest Trick"
Sentence 2: "The supreme con"
Similar Words: [ ["supreme", "greatest"], ["trick", "hoax", "con"] ]
Output: true


Example 2

Sentence 1: "I'm very glad"
Sentence 2: "I am super happy"
Similar Words: [ ["happy", "glad", "cheery"], ["very", "super", "extremely"] ]
Output: false

Full text and comments »

  • Vote: I like it
  • -24
  • Vote: I do not like it