figuring out if an apostrophe is a quote or contraction
<p>I am looking for a way to go through a sentence to see if an apostrophe is a quote or a contraction so I can remove punctuation from the string, and then normalize all words.</p>

<p>My test sentence is: <code>don't frazzel the horses. 'she said wow'.</code></p>

<p>In my attempts I have split the sentence into words parts tokonizing on words and non words like so:</p>

<pre><code>contractionEndings = ["d", "l", "ll", "m", "re", "s", "t", "ve"]

sentence = "don't frazzel the horses. 'she said wow'.".split(/(\w+)|(\W+)/i).reject! { |word| word.empty? }
</code></pre>

<p>This returns <code>["don", "'", "t", " ", "frazzel", " ", "the", " ", "horses", ". '", "she", " ", "said", " ", "wow", "'."]</code></p>

<p>Next I want to be able to iterate sentence looking for apostrophes <code>'</code> and when one is found, compare the next element to see if it is included in the <code>contractionEndings</code> array. If it is included I want to join the prefix, the apostrophe <code>'</code>, and the suffix into one index, else remove the apostrophes.</p>

<p>In this example, <code>don</code>, <code>'</code>, and <code>t</code> would be joined into <code>don't</code> as a single index, but <code>. '</code> and <code>'.</code> would be removed.</p>

<p>Afterwards I can run a regex to remove other punctuation from the sentence so that I can pass it into my stemmer to normalize the input.</p>

<p>The final output I am after is <code>don't frazzel the horses she said wow</code> in which all punctuation will be removed besides apostrophes for contractions.</p>

<p>If anyone has any suggestions to make this work or have a better idea on how to solve this problem I would like to know.</p>

<p>Overall I want to remove all punctuation from the sentence except for contractions.</p>

<p>Thanks</p>