<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>punctuation on S Anand</title>
    <link>https://www.s-anand.net/blog/tag/punctuation/</link>
    <description>Recent content in punctuation on S Anand</description>
    <generator>Hugo -- 0.164.0</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 26 Apr 2007 12:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.s-anand.net/blog/tag/punctuation/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Splitting a sentence into words</title>
      <link>https://www.s-anand.net/blog/splitting-a-sentence-into-words/</link>
      <pubDate>Thu, 26 Apr 2007 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/splitting-a-sentence-into-words/</guid>
      <description>&lt;p&gt;I often need to extract words out of sentences. It&amp;rsquo;s one of the things I used to build the &lt;a href=&#34;https://www.s-anand.net/blog/statistically-improbable-phrases-2/&#34;&gt;Statistically Improbable Phrases for Calvin and Hobbes&lt;/a&gt;. But splitting a sentence into words isn&amp;rsquo;t as easy as you think.&lt;/p&gt;
&lt;p&gt;Think about it. &lt;strong&gt;What is a word&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;Something that has spaces around it? OK, let&amp;rsquo;s start with the simplest way to get words: &lt;strong&gt;split by spaces&lt;/strong&gt;. Consider this piece:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&amp;#34;I&amp;#39;d look at McDonald&amp;#39;s,&amp;#34; he said.
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&amp;#34;They sell over 3,000,000 burgers a day -- at $1.50 each.&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;High-fat foods were the rage. For e.g., margins in fries
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;were over 50%... and (except for R&amp;amp;M &amp;amp; Dyana [sic]) everyone
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;was at ~30% net margin; growing at 25% too!
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Splitting this by spaces (consider new lines, tabs, etc as spaces too.), we get the following:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&amp;#34;I&amp;#39;d
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;look
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;at
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;McDonald&amp;#39;s,&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, some of these like &amp;ldquo;I&amp;rsquo;d&amp;rdquo; are words. But &amp;ldquo;McDonald&amp;rsquo;s&amp;rdquo; isn&amp;rsquo;t. I mean, there&amp;rsquo;s a full-stop and a double-quotes at the end. Clearly we need to remove the punctuation as well. But, if we do that, &lt;code&gt;I&#39;d&lt;/code&gt; becomes &lt;code&gt;Id&lt;/code&gt;. So we need to be careful about which punctuation to remove. Let&amp;rsquo;s take a closer look.&lt;/p&gt;
&lt;p&gt;The following punctuation marks are &lt;strong&gt;clear word separators&lt;/strong&gt;: spaces, the exclamation mark, the question mark, semicolon, brackets of any kind, and double-quotes (not single quotes). No word has these in the middle. If we use these as separators, our list of words is better, but we still have some words with punctuation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;McDonald&amp;#39;s,
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;e.g.,
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;High-fat
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;R&amp;amp;M
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;...
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The issue is, these punctuation marks are &lt;strong&gt;ambiguous word separators&lt;/strong&gt;: comma, hyphen, single-quote, ampersand, period and slash. These usually separate words, but there are exceptions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Comma&lt;/strong&gt;: Not inside numbers: 3,000,000.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hyphen&lt;/strong&gt;: Not for hyphenated words: High-fat.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Single-quote&lt;/strong&gt;: Not for possessives: McDonald&amp;rsquo;s. Not for joint words: I&amp;rsquo;d.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ampersand&lt;/strong&gt;: Not for abbreviations: R&amp;amp;M&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Period&lt;/strong&gt;: Not for abbreviations: O.K. Not for URLs: &lt;a href=&#34;https://www.s-anand.net&#34;&gt;www.s-anand.net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slash&lt;/strong&gt;: Not for fractions: 3/4. Not for URLs: google.com/search&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Colon is ambiguous too. In normal English usage, it would be a separator. But URLs like &lt;a href=&#34;http://www.s-anand.net/&#34;&gt;http://www.s-anand.net/&lt;/a&gt; use these characters, and it doesn&amp;rsquo;t make sense to separate them.&lt;/p&gt;
&lt;p&gt;So here are my current rules for splitting a sentence into words. (It&amp;rsquo;s a &lt;a href=&#34;http://www.perl.com/doc/manual/html/pod/perlre.html&#34;&gt;Perl regular expression&lt;/a&gt;. Don&amp;rsquo;t worry. &lt;a href=&#34;http://forums.speedguide.net/showthread.php?t=166822&#34;&gt;Cooper&amp;rsquo;s Law&lt;/a&gt;: If you do not understand a particular word in a piece of technical writing, ignore it. The piece will make perfect sense without it.)&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Split by clear word separators&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;/       &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\s&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\!&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\?&lt;/span&gt; &lt;span class=&#34;se&#34;&gt;\;\(\)\[\]\{\}\&amp;lt;\&amp;gt;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34; ]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;# ... by COMMA, unless it has numbers on both sides: 3,000,000
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       (?&amp;lt;=\D) ,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       , (?=\D)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;# ... by FULL-STOP, SINGLE-QUOTE, HYPHEN, AMPERSAND, unless it has a letter on both sides
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       (?&amp;lt;=\W) [\.\-\&amp;amp;]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       [\.\-\&amp;amp;] (?=\W)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;# ... by QUOTE, unless it follows a letter (e.g. McDonald&amp;#39;s, Holmes&amp;#39;)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       (?&amp;lt;=\W) [&amp;#39;]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;# ... by SLASH, if it has spaces on at least one side. (URLs shouldn&amp;#39;t be split)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       \s \/
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       \/ \s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;# ... by COLON, unless it&amp;#39;s a URL or a time (11:30am for e.g.)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;|       \:(?!\/\/|\d)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s2&#34;&gt;/x;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This doesn&amp;rsquo;t even scratch the surface of the issue, though. Here are some issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lots of files &lt;strong&gt;split words&lt;/strong&gt; into two at the end of a line. How do we handle that?&lt;/li&gt;
&lt;li&gt;How do we handle &lt;strong&gt;incorrect punctuation&lt;/strong&gt;? For instance, if someone types &amp;ldquo;done.Yet,&amp;rdquo; without leaving a space after the full-stop, I&amp;rsquo;ll think it&amp;rsquo;s an abbreviation.&lt;/li&gt;
&lt;li&gt;What about &lt;strong&gt;other separators&lt;/strong&gt;? Like the ± symbol or the £ symbol for instance.&lt;/li&gt;
&lt;li&gt;What about &lt;strong&gt;other languages&lt;/strong&gt;?!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And you thought it was easy!&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Kasi&lt;/strong&gt; &lt;em&gt;27 Apr 2007 10:18 pm&lt;/em&gt;:
Hi Anand, Nice site..It was good talking to you! When u find time, pls do visit my humble less visited blog at &lt;a href=&#34;https://www.raconteurkasi.blogspot.com&#34;&gt;www.raconteurkasi.blogspot.com&lt;/a&gt; !&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ramya&lt;/strong&gt; &lt;em&gt;3 May 2007 7:52 am&lt;/em&gt;:
Hi Anand, Can u guide me through the interview process of INSEAD MBA . Can you share your wisdom with me to crack the interview, and one more question .. do u sleep for less than 5 hrs a day ?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Andrew&lt;/strong&gt; &lt;em&gt;26 Apr 2007 12:00 pm&lt;/em&gt;:
Thanks, this is very helpful.&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Economist Style Guide</title>
      <link>https://www.s-anand.net/blog/economist-style-guide/</link>
      <pubDate>Sun, 03 Feb 2002 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/economist-style-guide/</guid>
      <description>&lt;p&gt;The Economist &lt;a href=&#34;http://www.economist.com/library/StyleGuide/index.cfm&#34;&gt;Style Guide&lt;/a&gt;. The part on &lt;a href=&#34;http://www.economist.com/library/styleGuide/index.cfm?page=805701&#34;&gt;inverted commas&lt;/a&gt; is insightful, especially in contrast with &lt;a href=&#34;http://www.economist.com/library/styleGuide/index.cfm?page=673943&#34;&gt;brackets&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Punctuation is critical</title>
      <link>https://www.s-anand.net/blog/punctuation-is-critical/</link>
      <pubDate>Wed, 20 Oct 1999 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/punctuation-is-critical/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://www.smartbiz.com/sbs/arts/tpl4.htm&#34;&gt;Punctuation&lt;/a&gt; is critical. Believe me, mistakes can be glaring!&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
