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

193
Visualizações
Find the position of the most similar word sequence within larger text

I have some sequence of words as input (e.g. a sentence or part of a sentence). I'm looking for a way to find the position and contents of the most similar substring within a larger text, as well as some sort of similarity score.

The matching substring can contain typos, similarly sounding words, or fewer/extra words, compared to the input string.

Is there an established way to do this? I could only find answers for how to directly compare two strings for similarity, but nothing about finding the position and similarity score of the closest match within a text.

I'm more interested in matches in terms of characters and/or how stuff sounds, rather than meaning.

Ideally looking for a way to achieve this in JavaScript, but language-agnostic suggestions are also welcome.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you want to use is dynamic time warping.

It's an algorithm for calculating a similarity score between two sequences, but it can also be used to find the places where the similarities are. Consider the pseudocode in the linked article (May 3rd 2022, if it has changed in the meantime). You probably want to use the second version which includes the locality constraint.

Extend the algorithm as follows: after calculating the DTW array, you can iterate your way backwards from DTW[n,m] towards DTW[0,0] by always going towards the previous minimum value. I. e. if your current position is [i,j] then your next position is [k,l] for which DTW[k,l] is minimal out of the three possible positions

  1. k=i-1, l=j
  2. k=i-1, l=i-1
  3. k=i, l=j-1

Assuming your text is in the first dimension and your "substring" on the second one, you have the following correspondences:

  1. The text has a character at position i that doesn't appear in the best matching.
  2. The text has a character at position i that appears at position j in the best matching.
  3. The text does not contain the character at position j in the best matching string.

The greatest k for which [k,0] appears in the backwards iteration and the smallest l for which [l,m] appears will be the beginning and end of the best matching sequence in your text.

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