<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss1full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns="http://purl.org/rss/1.0/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">

<channel rdf:about="http://www.biais.org/blog/index.php/">
  <title>biais.org</title>
  <description><![CDATA[Python, art and chicken pie.]]></description>
  <link>http://www.biais.org/blog/index.php/</link>
  <dc:language>en</dc:language>
  <dc:creator />
  <dc:rights />
  <dc:date>2009-11-08T19:16:24+01:00</dc:date>
  <admin:generatorAgent rdf:resource="http://www.dotclear.net/" />
  
  <sy:updatePeriod>daily</sy:updatePeriod>
  <sy:updateFrequency>1</sy:updateFrequency>
  <sy:updateBase>2009-11-08T19:16:24+01:00</sy:updateBase>
  
  <items>
  <rdf:Seq>
    <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2009/11/08/78-stupnik-my-first-iphone-game-available-in-the-appstore" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2009/10/09/77-wwwscala-frorg-french-blog-about-the-scala-language" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2009/10/02/76-calculating-how-much-time-you-spend-writing-tests" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2009/09/20/75-understanding-the-_-underscore-in-scala" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2009/09/04/74-orange-slice-iphone-game-development" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2009/04/02/73-where-the-world-sees-junk-africa-recycles-maker-faire-africa" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2009/01/05/72-genetic-algorithm-in-python-to-generate-file-converters" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2008/12/06/71-opencalais-semantic-analysis-web-service" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2008/12/05/70-dbpedia-32-including-dbpedia-ontology" />
  <rdf:li rdf:resource="http://www.biais.org/blog/index.php/2008/09/17/69-ruby-for-a-python-programmer" />
  </rdf:Seq>
  </items>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/biais" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /></channel>

<item rdf:about="http://www.biais.org/blog/index.php/2009/11/08/78-stupnik-my-first-iphone-game-available-in-the-appstore">
  <title>Stupnik: my first iPhone game available in the Appstore</title>
  <link>http://feedproxy.google.com/~r/biais/~3/imU3f1635IE/78-stupnik-my-first-iphone-game-available-in-the-appstore</link>
  <dc:date>2009-11-08T19:16:24+01:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>iPhone</dc:subject>
  <description>My first iPhone game has been accepted in the Appstore. I worked on it during february 2009 and I stopped because of lack of motivation and lack of graphic design talents ;). Recently, I took 2 full days to work on it, I polished some things (sounds and online high scores) and decided to submit it...</description>
  <content:encoded><![CDATA[ <p>My first iPhone game has been accepted in the Appstore. I worked on it during february 2009 and I stopped because of lack of motivation and lack of graphic design talents ;). Recently, I took 2 full days to work on it, I polished some things (sounds and online high scores) and decided to submit it for free. A few days ago, Apple sent me an email telling me that the game was <a href="http://bit.ly/1sFgUO" hreflang="en">downloadable in the Appstore</a>. 
</p>

<p>Here is a short video of the game:</p>
<object width="320" height="480"><param name="movie" value="http://www.youtube.com/v/RcWxIuxirXU&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RcWxIuxirXU&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="480"></embed></object><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/biais?a=imU3f1635IE:Q0_j9IYNa1k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/biais?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=imU3f1635IE:Q0_j9IYNa1k:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/biais?i=imU3f1635IE:Q0_j9IYNa1k:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=imU3f1635IE:Q0_j9IYNa1k:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/biais?i=imU3f1635IE:Q0_j9IYNa1k:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=imU3f1635IE:Q0_j9IYNa1k:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/biais?d=cGdyc7Q-1BI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/imU3f1635IE" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2009/11/08/78-stupnik-my-first-iphone-game-available-in-the-appstore</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2009/10/09/77-wwwscala-frorg-french-blog-about-the-scala-language">
  <title>www.scala-fr.org: French Blog About the Scala Language</title>
  <link>http://feedproxy.google.com/~r/biais/~3/v0IPymmaWTo/77-wwwscala-frorg-french-blog-about-the-scala-language</link>
  <dc:date>2009-10-09T16:41:30+02:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>Scala</dc:subject>
  <description>For french readers, I just started a blog in french about the Scala language. Some translations from the original english documentation, but also articles and news about scala. The name is quite original : http://www.scala-fr.org/ ;)....</description>
  <content:encoded><![CDATA[ <p>For french readers, I just started a blog in french about the Scala language. Some translations from the original english documentation, but also articles and news about scala. The name is quite original : <strong><a href="http://www.scala-fr.org/" hreflang="fr">http://www.scala-fr.org/</a></strong> ;).</p>


<p><img src="/blog/images/scala-fr-website-screenshot.png" alt="" /></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/biais?a=v0IPymmaWTo:fFIMz3kdxB4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/biais?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=v0IPymmaWTo:fFIMz3kdxB4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/biais?i=v0IPymmaWTo:fFIMz3kdxB4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=v0IPymmaWTo:fFIMz3kdxB4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/biais?i=v0IPymmaWTo:fFIMz3kdxB4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=v0IPymmaWTo:fFIMz3kdxB4:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/biais?d=cGdyc7Q-1BI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/v0IPymmaWTo" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2009/10/09/77-wwwscala-frorg-french-blog-about-the-scala-language</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2009/10/02/76-calculating-how-much-time-you-spend-writing-tests">
  <title>Calculating How Much Time You Spend Writing Tests</title>
  <link>http://feedproxy.google.com/~r/biais/~3/GDuhf3XMu7E/76-calculating-how-much-time-you-spend-writing-tests</link>
  <dc:date>2009-10-02T23:39:16+02:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>Misc</dc:subject>
  <description>I like testing piece of code I write. Because I often rewrite things, optimize and try to make things better (maybe i'm bad in doing the best thing at first time ?). When I'm working, I have constraints : time, coworkers, boss. In some of the companies I worked for, tests were only an option on...</description>
  <content:encoded><![CDATA[ <p>I like testing piece of code I write. Because I often rewrite things, optimize and try to make things better (maybe i'm bad in doing the best thing at first time ?). When I'm working, I have constraints : time, coworkers, boss. In some of the companies I worked for, tests were only an option on particular code. I'm trying to convince that testing everything is good (In my current job, I'm actualy happy about that, because I'm not the only one who want to write tests ;) ). I never had the idea to do that, but I think this is something I should have done before : <a href="http://googletesting.blogspot.com/2009/10/cost-of-testing.html" hreflang="en">calculating how much time you spend testing</a>.</p>


<p>The estimation done by the author reveals a 10% of his time writing tests and 90% writing the actual software :</p>


<blockquote><p>The number of hours spent on the project is my best estimate, as I have not kept track of these numbers. Also, the 10% breakdown comes from keeping track of my coding habits for the last two weeks of coding. But, these are my best guesses.</p></blockquote><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/biais?a=GDuhf3XMu7E:1zmu513eB0g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/biais?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=GDuhf3XMu7E:1zmu513eB0g:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/biais?i=GDuhf3XMu7E:1zmu513eB0g:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=GDuhf3XMu7E:1zmu513eB0g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/biais?i=GDuhf3XMu7E:1zmu513eB0g:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=GDuhf3XMu7E:1zmu513eB0g:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/biais?d=cGdyc7Q-1BI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/GDuhf3XMu7E" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2009/10/02/76-calculating-how-much-time-you-spend-writing-tests</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2009/09/20/75-understanding-the-_-underscore-in-scala">
  <title>Understanding the _ (underscore) in Scala</title>
  <link>http://feedproxy.google.com/~r/biais/~3/14sbSUqjRME/75-understanding-the-_-underscore-in-scala</link>
  <dc:date>2009-09-20T17:27:46+02:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>Scala</dc:subject>
  <description>I started to learn Scala. I started by reading some code snippets and then write my own program.  Scala integrates features of object-oriented and functional languages. When reading code example I saw that a reserved keyword was often used, it's the Scala wildcard: the underscore (_). And it's used...</description>
  <content:encoded><![CDATA[ <p>I started to learn <a href="http://www.scala-lang.org/" hreflang="en">Scala</a>. I started by reading some code snippets and then write my own program.  Scala integrates features of object-oriented and functional languages. When reading code example I saw that a reserved keyword was often used, it's the Scala wildcard: the underscore (_). And it's used in different ways.</p>


<h5>Underscore and anonymous parameters</h5>

<p>I read some examples that use the Scala wildcard character: _ (the underscore). Here is one:</p>

<pre>[java]
val sum = List(1, 2, 3).reduceLeft(_+_)
</pre>


<p>Note that the <code>reduceLeft</code> method apply a function of two arguments cumulatively to the items of the <code>List</code>. That means <code>_+_</code> is a function of t two arguments. This example can be translated to:</p>

<pre>[java]
val sum = List(1, 2, 3).reduceLeft((x, y) =&gt; x + y)
</pre>


<p><code>(x) =&gt; x</code> is the Scala notation to write anonymous functions. For pythoners, this is the equivalent to <code>lambda x: x</code>.</p>


<p>As described in the <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf" hreflang="en">Scala language specification</a>. Implicit anonymous functions using underscores in parameter position. Some examples below. The expressions in the left column are each  function values which expand to the anonymous functions on their right:</p>
<pre>
_ + 1                 x =&gt; x + 1 
_ * _                 (x1, x2) =&gt; x1 * x2 
(_: int) * 2          (x: int) =&gt; (x: int) * 2 
if (_) x else y       z =&gt; if (z) x else y 
_.map(f)              x =&gt; x.map(f) 
_.map(_ + 1)          x =&gt; x.map(y =&gt; y + 1)
</pre>


<p>Another example, I think, a bit harder to see where the anonymous function is hidden (note that foreach takes a function of one argument):</p>
<pre>[java]
object Test extends Application {
    private def printAddition(a: Int, b: Int)  {
        println(a + b)
    }
 
    List(1, 2, 3).foreach(printAddition(5, _))
}
</pre>

<p>is equivalent to:</p>
<pre>[java]
object Test extends Application {
    private def printAddition(a: Int, b: Int)  {
        println(a + b)
    }
 
    List(1, 2, 3).foreach((x) =&gt; printAddition(5, x))
}
</pre>


<h5>Underscore and partially applied function</h5>

<p>Let's write a simple function that return a function:</p>
<pre>[java]
object Test extends Application {
    private def createAddFunc(a: Int) = {
      (x: Int) =&gt; a + x
    }
    
    val add100 = createAddFunc(100) // createAddFunc return a function, 
                                // so add100 references a function
    add100(3) // call add100 method (returns 100 + 3)

    // We can also write this:
    createAddFunc(100)(3)

    // Or affect createAddFunc to another name (note the trailing _)
    var createAddFuncCopy = createAddFunc _
}
</pre>

<p>In the last line of code of this example, the trailing underscore tells the compiler to look at createAddFunc as a functional, and not invoke it.</p>


<h5>Underscore and pattern matching</h5>

<p>Scala has a pattern matching mechanism (first-match policy). In this case, the underscore matches everything that has not be matched before:</p>

<pre>[java]
object Test extends Application {
    private def cardColor(symbol: String) : String = symbol match {
      case &quot;heart&quot; =&gt; &quot;red&quot;
      case &quot;diamond&quot; =&gt; &quot;red&quot;
      case &quot;spade&quot; =&gt; &quot;black&quot;
      case &quot;club&quot; =&gt; &quot;black&quot;
      case _ =&gt; &quot;typo ?&quot; 
    }
    
    println(cardColor(&quot;club&quot;))
    println(cardColor(&quot;clubb&quot;))
}
</pre>


<p>prints:</p>

<pre>
black
typo ?
</pre>


<p>In this case, the Scala underscore is the equivalent to the underscore in OCaml, it matches everything that has not be matched:</p>
<pre>
let cardColor = function
      &quot;heart&quot; | &quot;diamond&quot; -&gt; &quot;red&quot;
    | &quot;spade&quot; | &quot;club&quot;    -&gt; &quot;black&quot;
    | _       -&gt; &quot;typo ?&quot;;;

print_endline (cardColor &quot;club&quot;);;
print_endline (cardColor &quot;clubb&quot;);;
</pre>


<p>Note the previous Scala code can also be written à la OCaml using the "|" symbol:</p>

<pre>[java]
private def cardColor(symbol: String) : String = symbol match {
    case &quot;heart&quot; | &quot;diamond&quot; =&gt; &quot;red&quot;
    case &quot;spade&quot; | &quot;club&quot; =&gt; &quot;black&quot;
    case _ =&gt; &quot;typo ?&quot; 
}
</pre>


<h5>Underscore and package imports</h5>

<p>Another use of the _ is to import all tje classes of a package:</p>
<pre>[java]
import scala.io._
</pre>


<p>THe equivalent of the java syntax:</p>
<pre>[java]
import java.util.*;
</pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/biais?a=14sbSUqjRME:lz2hk3ighFQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/biais?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=14sbSUqjRME:lz2hk3ighFQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/biais?i=14sbSUqjRME:lz2hk3ighFQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=14sbSUqjRME:lz2hk3ighFQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/biais?i=14sbSUqjRME:lz2hk3ighFQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=14sbSUqjRME:lz2hk3ighFQ:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/biais?d=cGdyc7Q-1BI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/14sbSUqjRME" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2009/09/20/75-understanding-the-_-underscore-in-scala</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2009/09/04/74-orange-slice-iphone-game-development">
  <title>Orange Slice: iPhone game development</title>
  <link>http://feedproxy.google.com/~r/biais/~3/ynl-OrubOag/74-orange-slice-iphone-game-development</link>
  <dc:date>2009-09-04T16:15:16+02:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>iPhone</dc:subject>
  <description>I'm currently working on an iPhone game during a part of my spare time. The project name is OrangeSlice. It's based on the very good 2D graphics library cocos2d-iphone

Here is a video I captured from the iPhone Simulator (that doesn't support accelerometer, so the all the game features are not...</description>
  <content:encoded><![CDATA[ <p>I'm currently working on an iPhone game during a part of my spare time. The project name is OrangeSlice. It's based on the <em>very good</em> 2D graphics library <a href="http://code.google.com/p/cocos2d-iphone/" hreflang="en">cocos2d-iphone</a></p>

<p>Here is a video I captured from the iPhone Simulator (that doesn't support accelerometer, so the all the game features are not showed):</p>

<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/CClZZE_sq3g&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/CClZZE_sq3g&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/biais?a=ynl-OrubOag:C-BO7HtNzIk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/biais?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=ynl-OrubOag:C-BO7HtNzIk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/biais?i=ynl-OrubOag:C-BO7HtNzIk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=ynl-OrubOag:C-BO7HtNzIk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/biais?i=ynl-OrubOag:C-BO7HtNzIk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=ynl-OrubOag:C-BO7HtNzIk:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/biais?d=cGdyc7Q-1BI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/ynl-OrubOag" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2009/09/04/74-orange-slice-iphone-game-development</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2009/04/02/73-where-the-world-sees-junk-africa-recycles-maker-faire-africa">
  <title>Where the World Sees Junk, Africa Recycles: Maker Faire Africa</title>
  <link>http://feedproxy.google.com/~r/biais/~3/cbN9m1saMj0/73-where-the-world-sees-junk-africa-recycles-maker-faire-africa</link>
  <dc:date>2009-04-02T05:36:08+02:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>Misc</dc:subject>
  <description>Maker Faire Africa (MFA), a celebration of African ingenuity, innovation and invention, will take place August 13-15 at the Ghana-India Kofi Annan Centre of Excellence in ICT in Ghana's capital, Accra.


You also should check out the Afrigadget website:

dedicated to showcasing African ingenuity....</description>
  <content:encoded><![CDATA[ <p><a href="http://makerfaireafrica.com/" hreflang="en"><img src="http://makerfaireafrica.com/wp-content/uploads/2009/04/mfa-banner-3j.jpg" alt="" /></a></p>


<p><a href="http://makerfaireafrica.com/" hreflang="en">Maker Faire Africa (MFA)</a>, a celebration of African ingenuity, innovation and invention, will take place August 13-15 at the Ghana-India Kofi Annan Centre of Excellence in ICT in Ghana's capital, Accra.</p>


<p>You also should check out the <a href="http://www.afrigadget.com/" hreflang="en">Afrigadget</a> website:</p>

<blockquote><p>dedicated to showcasing African ingenuity. A team of bloggers and readers contribute their pictures, videos and stories from around the continent. The stories of innovation are inspiring. It is a testament to Africans bending the little they have to their will, using creativity to overcome life’s challenges.</p></blockquote><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/biais?a=cbN9m1saMj0:IZx6NAiv6_w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/biais?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=cbN9m1saMj0:IZx6NAiv6_w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/biais?i=cbN9m1saMj0:IZx6NAiv6_w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=cbN9m1saMj0:IZx6NAiv6_w:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/biais?i=cbN9m1saMj0:IZx6NAiv6_w:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/biais?a=cbN9m1saMj0:IZx6NAiv6_w:cGdyc7Q-1BI"><img src="http://feeds.feedburner.com/~ff/biais?d=cGdyc7Q-1BI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/cbN9m1saMj0" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2009/04/02/73-where-the-world-sees-junk-africa-recycles-maker-faire-africa</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2009/01/05/72-genetic-algorithm-in-python-to-generate-file-converters">
  <title>Genetic Algorithm in Python to Generate File Converters</title>
  <link>http://feedproxy.google.com/~r/biais/~3/IUsiAbU6gaM/72-genetic-algorithm-in-python-to-generate-file-converters</link>
  <dc:date>2009-01-05T16:51:25+01:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>Python</dc:subject>
  <description>In an old post I wrote about a metaheuristic: particle swarm optimization (PSO). It was the simplest code to demonstrate what PSO looks like. Today I'm writing about genetic algorithm, another metaheuristic inspired by evolution of species. You can read the description of the algorithm on the...</description>
  <content:encoded><![CDATA[ <p><img src="/blog/images/chromosome2.jpg" alt="" /></p>


<p>In an old post I wrote about a metaheuristic: <a href="http://www.biais.org/blog/index.php/2007/01/14/13-metaheuristic-particle-swarm-optimization-pso-in-python">particle swarm optimization (PSO)</a>. It was the simplest code to demonstrate what PSO looks like. Today I'm writing about genetic algorithm, another metaheuristic inspired by evolution of species. You can read the description of the algorithm on the <a href="http://en.wikipedia.org/wiki/Genetic_algorithm">genetic algorithm article</a> on Wikipedia.</p>


<p>I applied the algorithm to a problem that is not really one: trying to help lazy programmers to write file converters. I had to write file converters to unify all (more or less) formated input files into one kind of <a href="http://en.wikipedia.org/wiki/Comma-separated_values">CSV file</a>. Each of these converters is made using the right combination of filtering / regexp matching / line splitting.</p>


<p>So I wrote a program based on genetic algorithm where an individual is composed by 3 "genes":</p>
<ul>
<li>a list of filters (remove consecutive spaces, replace tabs by spaces, ...)</li>
<li>a list of basics regexp (int, float, date, line separator, ...)</li>
<li>a list of cleaning functions (remove empty cell, merge cells, ...)</li>
</ul>

<p>The fitness of an individual is calculated using a sample file to parse that goes through the genes (filters / regexp / cleaning functions). The result of this process is a CSV file that can be compared to the expected sample result (that I wrote manually). The comparison uses the SequenceMatcher of the difflib Python stantard module, it returns the fitness: a float. A fitness close to 1.0 means the results is close to the expected CSV format. When the fitness is exaclty 1.0, that means the converter works perfectly for the sample.</p>



<p>Here is a sample file I wanted to convert:</p>
<pre>
08/12   	 Hello world 06/12
Paris 121231231 	  	- 22,29
08/12 	Something something ... 04/12
1111 1111 1111 1111 	  	- 14,35
08/12 	something else
	  	- 12,96
26/11 	Vir AAAAA
AAAAAA 2008	  	264,51
</pre>


<p>into this csv file:</p>
<pre>
&quot;08/12&quot;,&quot;Hello world 06/12&quot;,&quot;Paris 121231231&quot;,&quot;-22,29&quot;
&quot;08/12&quot;,&quot;Something something ... 04/12&quot;,&quot;1111 1111 1111 1111&quot;,&quot;-14,35&quot;
&quot;08/12&quot;,&quot;something else&quot;,&quot;&quot;,&quot;-12,96&quot;
&quot;26/11&quot;,&quot;Vir AAAAA&quot;,&quot;AAAAAA 2008&quot;,&quot;264,51&quot;
</pre>



<p>The program prints for each generation the 5 bests individual (I'm using elitism, so the best individual is always kept from a generation to the next one). A sample run:</p>
<pre>
$ python ga.py tests/sample1.txt tests/sample1.expected result1.pickled
Generation: 0 (mutation rate=10)
0.53772
0.42507
0.30406
0.28598
0.26389
Generation: 1 (mutation rate=10)
0.53772
0.42507
0.32684
0.30406
0.26799

...

Generation: 271 (mutation rate=15)
1.0
0.96025
0.95107
0.91779
0.87886
&quot;08/12&quot;,&quot;Hello world 06/12&quot;,&quot;Paris 121231231&quot;,&quot;-22,29&quot;
&quot;08/12&quot;,&quot;Something something ... 04/12&quot;,&quot;1111 1111 1111 1111&quot;,&quot;-14,35&quot;
&quot;08/12&quot;,&quot;something else&quot;,&quot;&quot;,&quot;-12,96&quot;
&quot;26/11&quot;,&quot;Vir AAAAA&quot;,&quot;AAAAAA 2008&quot;,&quot;264,51&quot;

filters: str_remove_consecutive_spaces, str_remove_somespaces, str_strip, str_remove_consecutive_spaces
regex: ([0-9]{2}/[0-9]{2})(.+?)(
)(.+?)(-?[0-9]+[.,]+[0-9]+)
cleaners: clean_strip, _in, _in, _in
</pre>



<h5>Conclusion</h5>


<p>The good:</p>
<ul>
<li>It's fun to see your program evolve ;)</li>
<li>You are lazy and don't want to write _many_ of this kind of file converters</li>
<li>With a good interface and if the basic functions and genes size are well defined, a non-programmer can create his own parser (I think this is the only argument to use it).</li>
</ul>

<p>The bad:</p>
<ul>
<li>The resulted parsers are not optimal</li>
</ul>

<p>The ugly:</p>
<ul>
<li>Of course it's quite easy to write such genes by hand</li>
<li>It may never converge to 1.0 and generated parsers of fitness != 1.0 are useless (this may not be the case for other kind of GA applications)</li>
<li>You need many well chosen primitives to cover a wide set of solutions</li>
</ul>

<h5>Download</h5>

<p><a href="http://www.biais.org/blog/data/gaparser-0.1.tar.bz2">gaparser-0.1.tar.bz2</a>: source code and examples.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/biais?a=mbz3ef0h"><img src="http://feeds.feedburner.com/~f/biais?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=3touXCyh"><img src="http://feeds.feedburner.com/~f/biais?i=3touXCyh" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=x4HZZafH"><img src="http://feeds.feedburner.com/~f/biais?i=x4HZZafH" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=PGUomcBU"><img src="http://feeds.feedburner.com/~f/biais?d=131" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/IUsiAbU6gaM" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2009/01/05/72-genetic-algorithm-in-python-to-generate-file-converters</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2008/12/06/71-opencalais-semantic-analysis-web-service">
  <title>OpenCalais: Semantic Analysis Web Service</title>
  <link>http://feedproxy.google.com/~r/biais/~3/7ClmSH6iOoA/71-opencalais-semantic-analysis-web-service</link>
  <dc:date>2008-12-06T02:40:27+01:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>NLP</dc:subject>
  <description>OpenCalais is a free web service that can perform semantic analysis on any English text. It processes the text sent in your request and respond with extracted concepts and relationships. It's a great tool if you want to play with semantics and if you want to add some nice features to your website...</description>
  <content:encoded><![CDATA[ <p><img src="http://www.opencalais.com/files/calais_logo.png" alt="" /></p>


<p><a href="http://www.opencalais.com/" hreflang="en">OpenCalais</a> is a free web service that can perform semantic analysis on any English text. It processes the text sent in your request and respond with extracted concepts and relationships. It's a great tool if you want to play with semantics and if you want to add some nice features to your website / blog.</p>


<p>As an example, I tried to send the text from a <a href="http://www.biais.org/blog/index.php/2008/09/17/69-ruby-for-a-python-programmer" hreflang="en">this small article about Ruby and Python</a>. Note : For readability I kept only interesting data from the response :</p>
<pre>[xml]
&lt;!-- 
Relations: 
ProgrammingLanguage: Python, Ruby
--&gt; 
&lt;rdf:RDF xmlns:rdf=&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot; xmlns:c=&quot;http://s.opencalais.com/1/pred/&quot;&gt;
  &lt;rdf:Description rdf:about=&quot;...&quot;&gt;
    &lt;!-- ProgrammingLanguage: Python; --&gt; 
    &lt;c:detection&gt;[similarities and differences between Ruby and ]Python[ but I didn't find any idioms list in Ruby, so if]&lt;/c:detection&gt; 
    &lt;c:prefix&gt;similarities and differences between Ruby and&lt;/c:prefix&gt; 
    &lt;c:exact&gt;Python&lt;/c:exact&gt; 
    &lt;c:suffix&gt;but I didn't find any idioms list in Ruby, so if&lt;/c:suffix&gt; 
    &lt;c:relevance&gt;0.543&lt;/c:relevance&gt; 
  &lt;/rdf:Description&gt;

  &lt;rdf:Description rdf:about=&quot;...&quot;&gt;
    &lt;!-- ProgrammingLanguage: Ruby; --&gt; 
    &lt;c:detection&gt;[ list in Ruby, so if you know one or if you are a ]Ruby[ programmer, please post a]&lt;/c:detection&gt; 
    &lt;c:prefix&gt;list in Ruby, so if you know one or if you are a&lt;/c:prefix&gt; 
    &lt;c:exact&gt;Ruby&lt;/c:exact&gt; 
    &lt;c:suffix&gt;programmer, please post a&lt;/c:suffix&gt; 
    &lt;c:relevance&gt;0.386&lt;/c:relevance&gt; 
  &lt;/rdf:Description&gt;
&lt;/rdf:RDF&gt;
</pre>


<p>The analyzed text is quite small but the results seems OK : 2 programming languages detected here, no animal, no gemtone...</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/biais?a=VG7yf55m"><img src="http://feeds.feedburner.com/~f/biais?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=RyGUoPIa"><img src="http://feeds.feedburner.com/~f/biais?i=RyGUoPIa" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=cZYLPDB4"><img src="http://feeds.feedburner.com/~f/biais?i=cZYLPDB4" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=0YBITbq3"><img src="http://feeds.feedburner.com/~f/biais?d=131" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/7ClmSH6iOoA" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2008/12/06/71-opencalais-semantic-analysis-web-service</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2008/12/05/70-dbpedia-32-including-dbpedia-ontology">
  <title>DBPedia 3.2 Including DBpedia Ontology</title>
  <link>http://feedproxy.google.com/~r/biais/~3/l-U5i7Ja1X0/70-dbpedia-32-including-dbpedia-ontology</link>
  <dc:date>2008-12-05T00:07:46+01:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>NLP</dc:subject>
  <description>If you like semantics or if you work on NLP projects, you should already know DBPedia. Database plus a set of tools that allow you to ask sophisticated queries against Wikipedia. Some days ago, DBPedia 3.2 was released and now, it includes DBpedia Ontology, a manually created cross-domain...</description>
  <content:encoded><![CDATA[ <p><img src="http://wiki.dbpedia.org/images/dbpedia_logo.png" alt="" /></p>


<p>If you like semantics or if you work on NLP projects, you should already know <a href="http://dbpedia.org" hreflang="en">DBPedia</a>. Database plus a set of tools that allow you to ask sophisticated queries against Wikipedia. Some days ago, DBPedia 3.2 was released and now, it includes <a href="http://wiki.dbpedia.org/Ontology" hreflang="en">DBpedia Ontology</a>, a manually created cross-domain ontology based on the most commonly used infoboxes within Wikipedia.</p>


<p>Read more on the <a href="http://blog.dbpedia.org/2008/11/17/dbpedia-version-32-released-including-the-new-dbpedia-ontology/" hreflang="en">official announcement</a></p>


<p>Note: I'm a bit late on this news, I will try to update the blog more often.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/biais?a=Os1PH3c2"><img src="http://feeds.feedburner.com/~f/biais?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=RbwzkPek"><img src="http://feeds.feedburner.com/~f/biais?i=RbwzkPek" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=Oc77pEP5"><img src="http://feeds.feedburner.com/~f/biais?i=Oc77pEP5" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=hE72VyFN"><img src="http://feeds.feedburner.com/~f/biais?d=131" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/l-U5i7Ja1X0" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2008/12/05/70-dbpedia-32-including-dbpedia-ontology</feedburner:origLink></item>
<item rdf:about="http://www.biais.org/blog/index.php/2008/09/17/69-ruby-for-a-python-programmer">
  <title>Ruby For a Python Programmer</title>
  <link>http://feedproxy.google.com/~r/biais/~3/kQSejDQ2va0/69-ruby-for-a-python-programmer</link>
  <dc:date>2008-09-17T14:54:40+02:00</dc:date>
  <dc:language>en</dc:language>
  <dc:creator>Maxime Biais</dc:creator>
  <dc:subject>Python</dc:subject>
  <description>I'm looking for a website comparing Ruby and Python idioms. I'm a Python programmer and I always use the same idioms to write programs (list and dict comprehension, loops on slices, ...). I found a good resource that describes some similarities and differences between Ruby and Python but I didn't...</description>
  <content:encoded><![CDATA[ <p>I'm looking for a website comparing Ruby and Python idioms. I'm a Python programmer and I always use the same idioms to write programs (list and dict comprehension, loops on slices, ...). I found a good resource that describes some <a href="http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/">similarities and differences between Ruby and Python</a> but I didn't find any idioms list in Ruby, so if you know one or if you are a Ruby programmer, please post a comment.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/biais?a=EvspHvwX"><img src="http://feeds.feedburner.com/~f/biais?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=nFkaILaF"><img src="http://feeds.feedburner.com/~f/biais?i=nFkaILaF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=lkh3Htkk"><img src="http://feeds.feedburner.com/~f/biais?i=lkh3Htkk" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/biais?a=Q6PUR2ca"><img src="http://feeds.feedburner.com/~f/biais?d=131" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/biais/~4/kQSejDQ2va0" height="1" width="1"/>]]></content:encoded>
<feedburner:origLink>http://www.biais.org/blog/index.php/2008/09/17/69-ruby-for-a-python-programmer</feedburner:origLink></item>

</rdf:RDF>
