Lalit Agarwal
Lalit Agarwal

Reputation: 173

Highlighting similar meaning words using javascript

I am trying to work on a web-application using crowd-sourcing to detect cross-lingual plagiarism. The interface contains text in 2 different languages and the user has to decide whether they find the text to be similar (plagiarised) or not. I need help with a text highlighting feature which is similar to the one provided by Google Translate. Whenever the user hovers over a word, not only that word gets highlighted but also words similar in meaning to that word in the other language also gets highlighted. The interface also contains a list of top 10 words in each language. And whenever

Here is a screenshot of the web-app till now-
It currently highlights same words only, I want to extend it to highlighting similar meaning words

I am running a ML algorithm at the backend which gives a list of similar meaning words. I am using PHP, JavaScript for the frontend. Till now I am able to implement a feature which highlight same words but I want to extend this idea to highlighting words which mean the same.

I would like to know how can I create a list of multiple arrays so that whenever the user hovers upon a word, all the words in that array also get highlighted. Can I do it dynamically using a database rather than manually creating these arrays because there will be many such documents ?

Upvotes: 0

Views: 725

Answers (1)

Sagar
Sagar

Reputation: 455

It'd be good to see an example of what you want. Assuming you get an array of similar words for every word from your server -

You could possibly do this by maintaining a simple JSON object as follows (which would act as a dictionary or hashmap).

Something like this -

var dict = {
    'hello': ['hi', 'hola', 'bonjour'],
    'world': ['world', 'monde'] 
}

You could create it like this in JavaScript.

var dict = {};

var word = 'hello';
var similar_words = ['hi', 'hola', 'bonjour']; //returned by your server

//push the word into your random access dictionary
dict[word] = similar_words;

//In the hover callback you could access the array you want directly using dict[word].

Alternatively you could also create a similar JSON object on your server and pre-compute all similar words dictionaries and store the JSON documents in a database like MongoDB.

Upvotes: 1

Related Questions