Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>A Dynamic Programing Algorithm</h2> <p>It seems what you are looking for is very similar to what the <a href="http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm" rel="noreferrer"><strong>Smith–Waterman algorithm</strong></a> does. </p> <p>From Wikipedia: </p> <blockquote> <p>The algorithm was first proposed by Temple F. Smith and Michael S. Waterman in 1981. Like the <a href="http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm" rel="noreferrer">Needleman-Wunsch</a> algorithm, of which it is a variation, Smith-Waterman is a <a href="http://en.wikipedia.org/wiki/Dynamic_programming" rel="noreferrer">dynamic programming algorithm</a>. 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). </p> </blockquote> <p>Let's see a practical example, so you can evaluate its usefulness. </p> <p>Suppose we have a text: </p> <pre><code>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."; </code></pre> <p>I isolated the segment we are going to match, just for your easy of reading. </p> <p>We will compare the affinity (or similarity) with a list of strings: </p> <pre><code>list = { "the general welfare", "my personal welfare", "general utopian welfare", "the general", "promote welfare", "stackoverflow rulez" }; </code></pre> <p>I have the algorithm already implemented, so I'll calculate the similarity and normalize the results: </p> <pre><code>sw = SmithWatermanSimilarity[ text, #] &amp; /@ list; swN = (sw - Min[sw])/(Max[sw] - Min[sw]) </code></pre> <p>Then we Plot the results: </p> <p><img src="https://i.stack.imgur.com/TCZfC.png" alt="enter image description here"></p> <p>I think it's very similar to your expected result. </p> <p>HTH!</p> <p><b>Some implementations (w/source code)</b> </p> <ul> <li><a href="http://www2.engr.arizona.edu/~rcl/gsw.html" rel="noreferrer">Smith-Waterman CUDA Source Code (GSW)</a></li> <li><a href="http://www.maths.tcd.ie/~lily/pres2/sld012.htm" rel="noreferrer">The S-M algorithm explained (presentation)</a></li> <li><a href="http://baba.sourceforge.net/" rel="noreferrer">An interactive step-by-step demo applet</a></li> <li><a href="http://jaligner.sourceforge.net/" rel="noreferrer">Java Source code</a></li> <li><a href="http://narnia.cs.ttu.edu/drupal/node/104" rel="noreferrer">Python source code</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload