Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3841180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:37:05+00:00 2026-05-19T15:37:05+00:00

consider I have a string1 = hello hi goodmorning evening […] and I have

  • 0

consider I have a

string1 = "hello hi goodmorning evening [...]"

and I have some minor keywords

compare1 = "hello evening"
compare2 = "hello hi"

I need a function that returns the affinity between the text and keywords. Example:

function(string1,compare1);  // returns: 4
function(string1,compare2);  // returns: 5 (more relevant)

Please note 5 and 4 are just for example.

You could say – write a function that counts occurrences – but for this example this would not work because both got 2 occurrences, but compare1 is less relevant because “hello evening” isn’t exactly found in string1 (the 2 words hello and evening are more distant than hello hi)

are there any known-algorithm to do this?

ADD1:

algos like Edit Distance in this case would NOT work.
Because string1 is a complete text (like 300-400 words) and the comparing strings are max 4-5 word.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:37:05+00:00Added an answer on May 19, 2026 at 3:37 pm

    A Dynamic Programing Algorithm

    It seems what you are looking for is very similar to what the Smith–Waterman algorithm does.

    From Wikipedia:

    The algorithm was first proposed by Temple F. Smith and Michael S. Waterman in 1981. Like the Needleman-Wunsch algorithm, of which it is a variation, Smith-Waterman is a dynamic programming algorithm. As such, it has the desirable property that it is guaranteed to find the optimal local alignment with respect to the scoring system being used (which includes the substitution matrix and the gap-scoring scheme).

    Let’s see a practical example, so you can evaluate its usefulness.

    Suppose we have a text:

    text = "We the people of the United States, in order to form a more 
    perfect union, establish justice, insure domestic tranquility, 
    provide for the common defense, 
    
      promote the general welfare, 
    
      and secure the blessings of liberty to ourselves and our posterity, 
    do ordain and establish this Constitution for the United States of 
    America.";  
    

    I isolated the segment we are going to match, just for your easy of reading.

    We will compare the affinity (or similarity) with a list of strings:

    list = {
       "the general welfare",
       "my personal welfare",
       "general utopian welfare",
       "the general",
       "promote welfare",
       "stackoverflow rulez"
       };  
    

    I have the algorithm already implemented, so I’ll calculate the similarity and normalize the results:

    sw = SmithWatermanSimilarity[ text, #] & /@ list;
    swN = (sw - Min[sw])/(Max[sw] - Min[sw])  
    

    Then we Plot the results:

    enter image description here

    I think it’s very similar to your expected result.

    HTH!

    Some implementations (w/source code)

    • Smith-Waterman CUDA Source Code
      (GSW)
    • The S-M algorithm explained
      (presentation)
    • An interactive step-by-step demo
      applet
    • Java Source code
    • Python source code
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single AMQ queue that receives simple messages with string body. Consider
Consider I have a shared function:- Public Shared Function CalculateAreaFromRadius(ByVal radius As Double) As
consider that i have a migration as follows create_table :dummies do |t| t.decimal :the_dummy_number
Consider that i have the string, $string = 'tag2 display=users limit=5'; Using the preg_match_all
I have a Javascript function that is passed a string. The string that it
Consider I have a table, like below, that I am trying to populate with
Consider the following situation: We have two Localizable.string files, one in en.lproj and one
So in my string, I have certain sections with hashes. For example, consider the
Consider I have the following interface: public interface A { public void b(); }
Consider I have an array of elements out of which I want to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.