<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dikson Santos</title>
    <description>The latest articles on DEV Community by Dikson Santos (@diksown).</description>
    <link>https://dev.to/diksown</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F768262%2F17095e86-c7a3-42a8-82c2-d02000421b99.png</url>
      <title>DEV Community: Dikson Santos</title>
      <link>https://dev.to/diksown</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/diksown"/>
    <language>en</language>
    <item>
      <title>Generating poetry using gcc diagnostics</title>
      <dc:creator>Dikson Santos</dc:creator>
      <pubDate>Wed, 15 Dec 2021 09:31:10 +0000</pubDate>
      <link>https://dev.to/diksown/generating-poetry-using-gcc-diagnostics-302o</link>
      <guid>https://dev.to/diksown/generating-poetry-using-gcc-diagnostics-302o</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Our legions are brim-full, our cause is ripe.
invalid application of ‘sizeof’ to a void type

Thy worthie, manly heart, be yet unbroken,
expected primary-expression before ‘&amp;lt;’ token

Did utter forth a voice. Yes, thou must die:
two or more data types in declaration of ‘i’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Introducing... gado!
&lt;/h2&gt;

&lt;p&gt;After years tired of cold, apathetic error messages that couldn't look more computer generated, I've spared some time to find a more human way to display compiler diagnostics.&lt;/p&gt;

&lt;p&gt;That's how &lt;strong&gt;gado&lt;/strong&gt; (&lt;strong&gt;g&lt;/strong&gt;cc &lt;strong&gt;a&lt;/strong&gt;wesome &lt;strong&gt;d&lt;/strong&gt;iagnostics &lt;strong&gt;o&lt;/strong&gt;rchestrator) was born! Built in Python, it internally uses gcc (g++ is supported too) to compile a file, and display two rhyming lines to every compiler message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gado.dikson.xyz/" rel="noopener noreferrer"&gt;Website&lt;/a&gt; | &lt;a href="https://github.com/diksown/gado" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmajo1d32enmqz4bxnv6i.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmajo1d32enmqz4bxnv6i.gif" alt="gado compiling a file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Initial processing
&lt;/h3&gt;

&lt;p&gt;The essential problem to solve was &lt;strong&gt;given a compiler message, how to find a verse that rhyme with it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Initially, we have to find a place to take the verses from. For this project, I'm using a database of &lt;a href="https://www.gutenberg.org/ebooks/100" rel="noopener noreferrer"&gt;all of Shakespeare's works.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We also take the output from gcc when compiling a program. As we have a lot of unusual symbols such as &lt;code&gt;@ % &amp;amp; ; }&lt;/code&gt; on compiler messages, we simply remove them to make the matching easier, so we are left with just letters.&lt;/p&gt;

&lt;h3&gt;
  
  
  How rhymes (don't) work
&lt;/h3&gt;

&lt;p&gt;The next step is to get a verse from that database that rhymes with an error. And for two sentences to rhyme, we need the last word of each to rhyme. &lt;/p&gt;

&lt;p&gt;But how do we know if two words rhyme? For many cases, you can say by just checking if two strings end in the same way (like &lt;em&gt;potatoes&lt;/em&gt; and &lt;em&gt;tomatoes&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;... But things aren't so easy all the time, though. &lt;/p&gt;

&lt;p&gt;There are a lot of words that share a common ending but don't rhyme - for example, none of the words &lt;em&gt;"through, tough, thorough, trough, though"&lt;/em&gt; rhyme with each other, but there are words that don't even have a single letter in common but rhyme anyway, like &lt;em&gt;"eye"&lt;/em&gt; and &lt;em&gt;"high"&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Yes, &lt;a href="https://youtu.be/65CFesU4KVQ" rel="noopener noreferrer"&gt;English is weird.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Teaching computers to rhyme
&lt;/h3&gt;

&lt;p&gt;To address those problems, I used a Python library called &lt;code&gt;pronouncing&lt;/code&gt;. It internally uses the CMU Pronouncing Dictionary to get rhymes for words. &lt;/p&gt;

&lt;p&gt;But after some testing, another problem emerges. Compiler messages have a lot of words that don't exist in English Dictionaries, like &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;fpermissive&lt;/code&gt; or &lt;code&gt;arith&lt;/code&gt; (from pointer &lt;strong&gt;arith&lt;/strong&gt;metic). &lt;/p&gt;

&lt;p&gt;How to get these to match with normal words, taken from English poems written centuries before our first &lt;code&gt;Hello World!&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;For these, I have implemented a simpler matching - just looking for a common ending in strings, as initially stated.&lt;/p&gt;

&lt;p&gt;I know what you are thinking by now! This won't feature interesting rhymes like &lt;em&gt;"pause/paws"&lt;/em&gt; and can even display incorrect ones like &lt;em&gt;"though/tough"&lt;/em&gt;, but now we can match every compiler message to a line of our database, even with nonexistent words!&lt;/p&gt;

&lt;p&gt;To make it more fun, the rhymes are chosen at random, so it will generate two different poems even if you compile the same program twice. Nondeterminism FTW!&lt;/p&gt;

&lt;h2&gt;
  
  
  More examples &amp;amp; Source Code &amp;amp; Contribution
&lt;/h2&gt;

&lt;p&gt;I made &lt;a href="https://gado.dikson.xyz/" rel="noopener noreferrer"&gt;a website (gado.dikson.xyz)&lt;/a&gt; featuring some of rhymes generated by the program, so you can see some fun verses without having to install it.&lt;/p&gt;

&lt;p&gt;If you want to install gado or give a look the source code, you are more than welcome to see (and contribute to) &lt;a href="https://github.com/diksown" rel="noopener noreferrer"&gt;its GitHub repository&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>nlp</category>
      <category>gcc</category>
      <category>poetry</category>
      <category>python</category>
    </item>
  </channel>
</rss>
