Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
whether given two words are synonyms or not

In this task, your job will be to write a program that can decide whether two words are synonyms or not. You will get a synonym dictionary describing pairs of synonymous words. Afterwards, you will answer several queries asking whether given two words are synonyms or not. Both dictionary of synonym pairs and queries for your program will be included in the input file.

Use the following rules to decide:

  1. If the pair of words is declared synonymous in the input, then they are synonyms.
  2. Being synonyms doesn't depend on order, e.g. if big is a synonym for large then large is a synonym for big.
  3. We can derive the synonymous relationship indirectly: if big is a synonym for large and large is a synonym for huge then big is a synonym for huge.
  4. If two words differ only by case, they are synonyms, e.g. same is a synonym for both SAmE, SAME and also same (itself).
  5. If none of the above rules can be used to decide whether two words are synonyms, then they are not.

Input :

Input starts with a number of test cases T (0 < T < 100). Each test case begins with a line containing a single number N (0 N s 100) — the length of a synonym dictionary. On each of the following N lines, there is exactly one pair of synonyms separated by a single space. Next line contains a single number Q (0 Q 100) — number of queries. Each of the following lines contains a pair of query words separated by a single space. Each word consists only of English alphabet letters ( [a- zA-Z] ) and is at most 20 characters long.

Output :

For each pair of query words output either string synonyms or different .

Sample input

2
4 
big large 
large huge 
small little 
apple banana
6 
same same 
big huge 
huge big 
apple peach 
big tall 
peach PEACH
5 
wood FORest 
meadoW PrAirIe 
WOOD Lumber 
lumber forest 
lumber forest
2 
wood LUMBER 
mEADOw fire

Sample output

synonyms 
synonyms 
synonyms 
different 
different 
synonyms 
synonyms 
different

Explanation of the sample problem

In the first test-case there are 6 queries:

  1. Words are the same.
  2. Words are derived synonyms.
  3. Symmetric to 2nd query.
  4. No rule can be used to derive the synonym pair.
  5. No rule can be used to derive the synonym pair, even though they are synonyms in English.
  6. Words differ only in case. 2 nd test case:
  7. Defined as synonyms by 3rd rule. The case does not matter.
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Harvard University and Google in 2010 estimated a total of 1,022,000 words and that the number would grow by several thousand each year.

So, logically your code should know about all of them in order to work properly. Such database of words, their linkage and access methods are provided by external APIs. Your applicatin should search for synonyms using one of these APIs.

Here are some of them-

https://openbase.com/categories/js/best-nodejs-dictionary-api-libraries

about 4 years ago · Juan Pablo Isaza Relatório

0

There's no built in function in Node to test whether some word is a synonym or not. But (fortunately) there are some libraries to do that.

Here's an example: First, install the synonyms package from NPM:

npm i synonyms

Then, in your JS file:

const synonyms = require("synonyms"); // Import the "synonyms" library
const fs = require("fs");

fs.readFile("path/to/file", "utf-8", (err, file) => {
  // Read the file
  const lines = file.split("\n"); // Each line is split into an array
  let result = lines.map(i => {
    return i.split(" ");
  }); // "result" holds an array of arrays. Index 0 is word 1 and index 1 is word 2

  result.forEach(item => {
    // Loop through our words
    const s = synonyms(item[0].toLowerCase()); // Call the function
    let allSynonyms = [];
    for (let q in s) {
      s[q].forEach(i => {
        if(typeof i === "object")
          i.forEach(allSynonyms.push);
        else allSynonyms.push(i);
      });
    }
    if (allSynonyms.includes(item[1].toLowerCase())) {
      console.log(`Yes, "${item[0]}" is a synonym with "${item[1]}"!`); // Yes
    } else {
      // Nope!
      console.log(`Nope, "${item[0]}" is not a synonym with "${item[1]}".`);
    }
  });
});

Just an example :) You can check the result here. Just run npm start.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda