Tuesday 12 February 2013

Mobile apps for businesses?

I have recently been giving alot of thought about mobile apps for my business. And I thought "what the heck" I am going to make one for myself... but giving the amount of time that I had it wasn't possible to build a professional one. So I did a quick search on google and voila, I found a company that makes apps for businesses:

http://www.mobileappforyour.biz/ 

They are quite cheap. I couldn't really believe it how cheap and effective they are in comparison to other Australian companies. And they even created the home page risk free in just one day, just to show me how the app will look like. They listened carefully to all my comments when I had some. Very professional indeed. Just wanted to put the link out there since I was impressed.

Sunday 4 November 2012

Jena tutorial - Reasoning with user defined rules

Hi,

This tutorial will provide you with Java code and jar libraries that you need to run a simple rule reasoning example using the Jena framework.

I used Eclipse, so my tutorial will be around its functionality. This tutorial will also assume that you know the basics of Eclipse and Java.

At the end of the tutorial you should have an Eclipse project looking like:



1) So, first create a Java project in Eclipse, name it whatever you want (I call it SWIFC) and create a package inside the project where you will create your main class (I call it com.oanaureche.swifc).

2) Second, create a folder in your Eclipse project and name it lib. In here you will put all the jar libraries needed to run the main class.

3) Download the jars that you will need for running the main class and copy or cut and paste them in the lib directory. The figure above shows what libraries you will need for running the tutorial's code.

4) Add the libraries to the project's Build path in Eclipse. I will skip the instructions on how to do this. There is plenty material on the internet that show you how to do this. It's not that complicated really.

5) Create two text files inside the project and a) Add the dataset (raw data, RDF data) to the dataset.txt file and b) write the rule in the rule.txt file

These are the contents of the dataset.txt file:


@prefix : <http://oanaureche.com/prefix#> .
@prefix pre: <http://jena.hpl.hp.com/prefix#> .
:Joseph pre:father :Mary .
:John pre:brother :Joseph .


These are the contents of the rule.txt file:


@prefix pre: <http://jena.hpl.hp.com/prefix#>.
[rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle ?a)]

6) For your main class, create a class inside the package that you create in step 1 (I call it ReasonWithRules.java) . The contents of this file are:


package com.oanaureche.swifc;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.rdf.model.Statement;
import java.net.MalformedURLException;

public class ReasonWithRules {

/**
* @param args
* @throws MalformedURLException 
*/
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub

Model instances = ModelFactory.createDefaultModel();
instances.read ("file:dataset.txt","N3");
Reasoner reasoner = new  
                    GenericRuleReasoner(Rule.rulesFromURL("file:rule.txt"));
reasoner.setDerivationLogging(true);
InfModel inf = ModelFactory.createInfModel(reasoner, instances); 

        //print out the statements in the model
StmtIterator iter = inf.listStatements();
while (iter.hasNext()) {
   Statement stmt      = iter.nextStatement();  
   Resource  subject   = stmt.getSubject();     
   Property  predicate = stmt.getPredicate();   
   RDFNode   object    = stmt.getObject();      

   System.out.print(subject.toString());
   System.out.print(" " + predicate.toString() + " ");
   if (object instanceof Resource) {
      System.out.print(object.toString());
   } else {
       // object is a literal
       System.out.print(" \"" + object.toString() + "\"");
   }
   System.out.println(" .");

}
}

7) Run this Java application and you should see the following in the console:


http://oanaureche.com/prefix#John http://jena.hpl.hp.com/prefix#uncle http://oanaureche.com/prefix#Mary .

http://oanaureche.com/prefix#John http://jena.hpl.hp.com/prefix#brother http://oanaureche.com/prefix#Joseph .

http://oanaureche.com/prefix#Joseph http://jena.hpl.hp.com/prefix#father http://oanaureche.com/prefix#Mary .


The reasoner inferred a third statement: that John is the uncle of Mary. Pretty cool!


Sunday 21 October 2012

Source code to XML and RDF converters

I moved all the converters to one place:

http://swifc-converters.appspot.com/

I have developed two prototypes for converting PHP or Java code to XML and RDF. You can find them at the following addresses:

http://xmltranslator.appspot.com/sourcecodetoxml.html

and

http://rdfconverter.appspot.com/sourcecodetordf.html

As an extra tool, I also have running a general XML to RDF converter:

http://xmltordf.appspot.com/xmltordf.html

If you encounter any issues, please leave a comment. I would be happy to fix whatever issues..



Wednesday 17 October 2012

Apache Tomcat HTTP Status 500 - javax.servlet.ServletException: java.lang.UnsupportedClassVersionError


HTTP Status 500 - javax.servlet.ServletException: java.lang.UnsupportedClassVersionError: com/namespace/project/class : Unsupported major.minor version 51.0 (unable to load class com.namespace.project.class)


If you've seen an error like this when trying to run a Tomcat project, the problem is that the JAVA version used to compile the class mentioned in the error is different than the JAVA version Tomcat uses. You can either recompile the class or change the JAVA version Tomcat uses.

To change the settings for Tomcat, in Windows, modify the catalina.bat file by adding the following line in red. You most probably have a different location for your JDK. This version is the version used for compiling the class that gives the error. After adding the line remember to restart Tomcat (shutdown.bat and startup.bat) if it is already running.

rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
rem
rem $Id: catalina.bat 1344732 2012-05-31 14:08:02Z kkolinko $
rem -----------------------------------------------------------

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_33

rem Suppress Terminate batch job on CTRL+C
if not ""%1"" == ""run"" goto mainEntry
if "%TEMP%" == "" goto mainEntry
if exist "%TEMP%\%~nx0.run" goto mainEntry

Wednesday 10 October 2012

Merge a branch into the trunk using Tortoise SVN

We'll assume you have done some changes in the branch that you are working on and you want to merge those changes into the trunk. Here I will outline some steps using the svn command line tool and the TortoiseSVN tool using Windows 7.

1) Checkout the branches and trunk from SVN (if you do not have a local copy) using command line for example:

    svn checkout link_to_svn_repository WRK --username your_username

2) Browse to the folder where your working copy is located (e.g, where you previously checked out) and using TortoiseSVN tool, right click on trunk and choose Merge...


After choosing Merge, next choose reintegrate a branch:




click Next and choose which one of the existing branches to reintegrate:

4) Click Next -> Merge and wait for completion

5) The trunk has now new changes, so commit the changes back into the SVN:


    svn commit -m "Reintegrate branch 1.2"







Tuesday 9 October 2012

How to run multiple python test cases

If you have the following situation: multiple python test cases in a directory and you want to automatically run them with only one command, first you need to install the discover python module, which is actually called python nose module. In Ubuntu you would typically run the following from command line:


$ sudo apt-get install python-nose

After successfully installing the discovery module, navigate to the folder where your test cases are located and just run:

$ nosetests

This will automatically find the tests and run them for you. 

Note: I believe that the test file names need to follow a convention; please consult the documentation of the module. I tried with "name_test.py" and it worked.

Monday 8 October 2012

How to run an XQuery script


First, for the XQuery processor (the one that I use in the following steps) to work you need to have Java installed.

1) Download an XQuery processor for Java. I used Saxon. If you don't have material resources (like myself) download the home edition. You'll need to pay for the commercial ones if you choose to use one. When I wrote this article I downloaded SaxonHE9-4-0-6J.zip from the following link:

http://sourceforge.net/projects/saxon/files/Saxon-HE/9.4/

2) Extract the zip file to a path you can remember. It will result in 2 jar files:
3) Run your XQuery script by adding the extracted saxon9he.jar file to your java classpath:

java -classpath C:\.....\saxon9he.jar net.sf.saxon.Query my.xquery

where my.xquery is your xquery script, e.g.


<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:bibterms="http://www.book-stuff.com/terms/">

    <rdf:Description rdf:about="http://www.book-stuff.com/bib">
    {
        for $book in doc( "bib.xml" )//book
        return 
            <bibterms:book rdf:parseType="Resource">
            </bibterms:book>
    }
    </rdf:Description>

</rdf:RDF>

This command will output the resulting RDF file on the console. If you prefer having the result in a file, just add > filename.ext to the command, e.g:


java -classpath C:\.....\saxon9he.jar net.sf.saxon.Query my.xquery > result.rdf