Wednesday, August 8, 2012

Installing Sesame Server on Ubuntu 12.04

I'm currently checking triple stores and wanted to install one of the most popular ones: Sesame. I hope seeing Ali Baba in few days :) But before that I had some issues while installing Sesame on Ubuntu 12.04.

Sesame offers a built-in console utility. And there is also a web interface: Sesame Openrdf-Workbench which seems to be easier than Sesame console. Current version of Sesame is OpenRDF Sesame 2.6.8 SDK.

In order to install Sesame server, there are two war files that need to be deployed to a java servlet container. And thus, it is expected that you have java (5 or 5+) installed in your system. 

As a java servlet container, I used Tomcat 7. First of all, I installed it via ubuntu software center. Default configuration creates a new user, tomcat7. /usr/share/tomcat7 is default home directory for this user. Once you install tomcat, you can start the server as:

/etc/init.d/tomcat7 start

stop and restart commands can be used in the same way. Once the server is up, you can see tomcat page in http://localhost:8080/. Now, try to use manager webapp in order to deploy Sesame wars. Note that you have to configure users by editing tomcat-users.xml. The sample entry has to be something similar to:

<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="admin"/>
  <user name="admin" password="admin" roles="manager-gui,admin"/>
</tomcat-users>

After deploying the wars, you'll see that Sesame Workbench is not working and gives an error like: java.io.IOException: Unable to create logging directory /usr/share/tomcat7/.aduna/openrdf-sesame/logs

You get this error because Sesame tries to write to home directory, but tomcat7 has no write access to that folder. You can simply solve the problem with this:

sudo mkdir -p /usr/share/tomcat7/.aduna
sudo chown -R tomcat7:tomcat7 /usr/share/tomcat7 

Once you restart the tomcat server with:

/etc/init.d/tomcat7 restart

And try to access: http://localhost:8080/openrdf-workbench

You'll see that it works! By default, Sesame comes with a System repository. And it is possible to create new repositories, delete existing ones, querying and so much. Open Sesame!!

Wednesday, November 30, 2011

XML (w/o) Higlighting in Latex + using it in a figure - 2

Well.. I had a style conflict with my previous solution. So I gave up using a highlighted version, but just an XML text (with correct tab indentations of course!). I also needed to put a frame outside my xml document, and got this I found a nice Latex package called "fancyvrb". With a simple "frame" attribute, it works great.. Hope it helps!..

\begin{figure}[htbp]
\begin{Verbatim}[frame=single]
<task id="..." performer="..." type="...">
    <name>...</name>           
    <description>...</description>       
    <params>
        <param type="..." name="..." datatype="..."/>
        .
        .
    </params>  
</task>
\end{Verbatim}
% \vskip
\label{fig:spec_task}
\end{figure}

Monday, November 28, 2011

XML Higlighting in Latex + using it in a figure

It's been a while that I did not have time to write something.. It doesn't mean that I don't have anything to write about.. and.. of course I have! :)

I'm busy with writing my thesis using Latex, it's sometimes a great tool to use.. And other times, you're getting really frustrated to achieve what you really wanna do!


This time I was trying to simply put an XML content in a table/figure or such, because I needed to refer to it later on in my thesis.. I cannot just put the content as it is.. If you are in trouble just like me, am sure you found two great XML highlighters: "minted" and using "listings" package. Both work like a charm, but the problem is when you wanna put XML content in a table/figure. Well, highlighting sucks in such cases.

One solution that I found is as the following:

\begin{figure}[htbp]
\begin{minted}{xml}
   <book isbn="978-0452284234"> 
      <name<Nineteen Eighty Four</name>
      <author<George Orwell</author>
   </book>
\end{minted}
\caption[XML Representation Example]{XML Representation Example}
% \vskip
\label{fig:xml}
\end{figure}

I did not try for "listings" package, but I think it will also work.. With this, you'll get a result as the following:
Photobucket

Hope it helps!..

Sunday, August 28, 2011

Format a disk with HFS+ using GParted on Ubuntu

If you have a Mac, it means that you always have trouble :P

You are using Ubuntu or any other linux dist, and have an external drive. You HAVE to format it with HFS+ because you want to use it with a Mac. Grrr...

No panic.. You are able to format your external drive using Ubuntu.. First thing to do is that you have to install "hfsprogs" package. Simply install it by typing the following in a terminal:

sudo apt-get install hfsprogs


Then, you can just use GParted to format your drive. Go to System > Administration > Gparted, select your external drive from the dropdown menu on the right. When you choose to format your disk/partition, you'll see "HFS+" as an option. Select it and wait a little bit. And.. Da daaa.. Now you can use your external drive with a Mac!

Hope it helps!.. Enjoy..

Python on the Fly Code Generator

Hey everyone,

I know that I'm not blogging for a while. It doesn't mean that I don't have anything to share :P
I'm currently working on my master thesis and I'm using Python for coding part. Today, I was looking for a python library to be able to generate python code on the fly. Of course, first idea is to create a file, adding imports, classes, methods and so on.. I only found a helper class written by Fredrik Lundh in this blog post.

I liked this idea and extended the code just a little bit. I want to work on a more complete library in few months. Do not forget to check my blog for the updates. And here is the simple class code:

#
# a Python code generator backend
#
# fredrik lundh, march 1998
#
# fredrik@pythonware.com
# http://www.pythonware.com
#
# extended by Nadin Kokciyan
# nadin.kokciyan@boun.edu.tr
#
import sys, string

class PyGen:

    def __init__(self):
        self.code = []
        self.tab = "    "
        self.level = 0

    def end(self):
        return string.join(self.code, "")

    def write(self, string):
        self.code.append(self.tab * self.level + string + "\n")

    def newline(self, no=1):
        res=""        
        i = 1        
        while(i<=no):
            res += "\n"
            i += 1
        self.code.append(res)

    def indent(self):
        self.level = self.level + 1

    def dedent(self):
        if self.level == 0:
            raise SyntaxError, "internal error in code generator"
        self.level = self.level - 1
Example Usage:
c = PyGen()

c.write("for i in range(1000):")
c.indent()
c.write("print 'code generation is trivial'")
c.write("print i")
c.dedent()

c.newline(no=5) # adding 5 new lines
c.write("print 'end of my code'") 
print c.end()
And the output is:
for i in range(1000):
    print 'code generation is trivial'
    print i




print 'end of my code'

Of course, you will create an empty py file and write this generated content to it.. Hope it helps!..