Skip to content

Modernizing Sirocco from C# and SharpNLP to Java and Apache OpenNLP

Tl;dr: Automatic conversion from C# to Java is possible!

When we set out developing Cuesense in late 2000s, my partners and I standardized on the Microsoft stack mostly for skills reasons. Our sentiment analysis piece was built using SharpNLP, the C# clone of OpenNLP. It worked fine for the time, but when I decided to put it back to action recently, I faced a predictable challenge — the SharpNLP project was mothballed and I had my doubts that I would find many people interested in maintaining the C# version. On the other hand, OpenNLP’s Java branch actually graduated to the Top Level Project status at Apache and showed promise of consistent maintenance.

Java was not new to me, in fact, I used to develop pretty complex distributed systems in it before the first Internet bubble (Telco CLEC OSSes, anyone?). Moreover, C# is not that different from Java and I was hoping I could find an automated converter that would help me at least with part of the rewrite exercise.

In addition to converting the C# code base to Java and replacing SharpNLP with the latest Apache OpenNLP version 1.6, I also needed to convert the analytics database that was implemented in MySQL, with a bunch of stored procedures doing trends calculations. I will focus this blog post on the C# conversion and will write more about MySQL conversion in a later post.

I googled “C# to Java conversions” and came across this StackOverflow post. It listed several options for automated converters:

Long story short, the CS2J tool did a pretty awesome job, although it did require installing Mono and running a Windows-native app on my Mac. Here are the steps I took to do the initial conversion of my code base:

  1. Install Mono to run CS2J

2. Install GitHub Desktop (because I could never remember the git commands, after polluting my memory with subversion, Visual SourceSafe and a bunch of other source control systems)

3. Get CS2J from GitHub or download from http://www.cs2j.com/

4. Install Homebrew to be able to install ant and maven

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

5. Run CS2J

cd cs2j
mono CS2JTranslator/bin/cs2j.exe -net-templates-dir=./NetFramework/ -out-java-dir=<project-dir>/JavaOutput -app-dir=<project-dir>/Common -cs-dir=<project-dir>/Common
mono CS2JTranslator/bin/cs2j.exe -net-templates-dir=./NetFramework/ -out-java-dir=<project-dir>/JavaOutput -app-dir=<project-dir>/Servers -cs-dir=<project-dir>/Servers

The JavaOutput directory was the directory were I wanted my Java code to end up, and the Common and Servers directories were folders were I kept my C# code to be converted.

SUCCESS!

Now that I had the initial output of the converter, the fun was just starting, as there were hundreds of compile errors that I had to resolve. But more on this in a future blog post.

Leave a Reply