Thursday, 28 February 2008

Transforming Pojo / Web / Enterprise Services into Semantic Services / Agents using jSemanticService

Let's suppose that you have an existing service (pojo in this case) in a Spring context, (or that you need to write a new service) that needs to use semantics.

How would you do that? Well, in just three steps:

First Step

Writing a SemanticServiceFactory bean (and it's collaborators if needed) in the Spring Context file.

Second Step.

Either inject a reference to the SemanticServiceFactory directly in the service or extend the SemanticServiceSupport abstract class.

public class EvenService {

private SemanticSessionFactory semanticSessionFactory = null;

public Collection check(Collection numbers) {
SemanticSession session = semanticSessionFactory.getInstance();

Collection results = session.execute(numbers);
session.dispose();
session = null;
return results;
}


public void semanticSessionFactory(SemanticSessionFactory semanticSessionFactory){
this.semanticSessionFactory = semanticSessionFactory:
}

}


Now a method that uses the new added semantics functionality can be written. For that matter there is a method in the base class: getInstance(). This method returns a Semantic Session instance that is bound to the current thread. If we dispose the session then we'll get a new one. If not, the same session will be reused.

Third Step

Inject the Semantic Session Factory in the service bean.

And that's all, now the Semantic Service is ready to roll!.

Read the complete article in:

http://code.google.com/p/jservicerules/wiki/TransformServicesIntoSemantics

Sunday, 24 February 2008

About the jServiceRules alpha working release.

Well, after some months of development (well, not really that much but as I do it in my spare time, clocks that long) I've finally been able to release an alpha working version. 
In fact, it´s a stripped down version compared what I had in mind, but it's more focused (service oriented) and it can be used as a base for future developments.

Even though it's functional and I've tested it in different enviroments (windows, linux, mac os) using unit and stress testing, still some bugs could appear. Also I'm still improving it, so minor changes could be found in the next version. But that's the reason it's an alpha release :) .

About the release.

This release includes the dist binaries, dependencies (if you choose so), API docs, and two examples. 

It does not include the support package therefore there is no Spring (and the rest of the bunch)  integration yet, so the only option to use and configure the framework is through code (see examples and further posts). I'll release it at the end of this week or early next.


About the examples.

The even numbers example is simple, just a service that returns if a number is even or not. Two  simpe rules are produced to do that. The objective of this example is to show how to use the basic features.

The Energy example is a more complex one producing  the energy invoice of a customer, giving his personal data and energy readings. In this case, a number of rules are produced to generate the Tariffs available.


Saturday, 23 February 2008

JServiceRules alpha 01 working version released.

Transform existing (or new) Enterprise Services in Semantic Services in no time. Based on a implementation of a generic Business Rules Engine (an implementation using Drools 4 is provided).

Features

# Quick and easy configuration (code or Spring based).


# Easy integration in existing services/applications (code or Spring based).

# Hides the complexity behind a BRE (configuration/development), allowing developers to concentrate in the development of the business logic and rules.

# Agnostic and focused API with the most common features that you'd need (plus new ones).

# New features that helps the BRE to interact with the environment (internal/external), for example invoking external services by rules (that are located in a external Spring context).

# Support package that provides integration out of the box for SpringHibernateMule etc..

Project Home

http://code.google.com/p/jservicerules

Binaries

http://jservicerules.googlecode.com/files/jservicerules-alpha1.tar

http://jservicerules.googlecode.com/files/jservicerules-alpha01-nodep.tar

Source Code

http://code.google.com/p/jservicerules/source/checkout

Quick Guide

http://code.google.com/p/jservicerules/wiki/IntroductionGuide

Monday, 18 February 2008

jSemantic-Core Beta 1 released.

The beta 1 for the jSemantic-Core has been released.

This package is the API for the jServiceRules framework, that allows to transform your regular Enterprise Services to Semantic Services on the fly backed by a rules engine.

This is an "agnostic" API, so it doesn't contain any references or dependencies to any rules engine.

This release contains binaries, API docs and dependencies.

Project Home

http://code.google.com/p/jservicerules

Binaries

http://jservicerules.googlecode.com/files/jsemantic-core-beta1.tar

Source Code

http://code.google.com/p/jservicerules/source/checkout

Quick Guide

http://code.google.com/p/jservicerules/wiki/IntroductionGuide

Sunday, 17 February 2008

jServiceRules (I). The Semantic Core.

The first package of the jServiceRules framework is the jSemanticCore, that contains all the interfaces, abstract factories, helpers so a Semantic Session could be implemented.

The Semantic Session is a core concept within the jServiceRules framework and is just a Working Memory object "on steroids". Essentially it offers a focused interface, improves the communication of the WM with the execution enviroment (internal/external) and hides all the complexity behind the backed rules engine. Also helps to manage some external knowledge we could need through the Knowledge Database.

Let's say that you want to execute some business stateless rules. To produce this is as simple as:
  • Creating a Semantic Session Factory associated to the rules file.
  • Getting an instance of the Semantic Session (stateless by default), produced by the factory.
  • Passing some facts to the session (related to the rules you want to evaluate).
  • The rules will be automatically evaluated and some results will be returned.
  • The session could be disposed.
SemanticSessionFactory factory = new SemanticSessionFactoryImpl("org/jservicerules/rules/test.drl");

SemanticSession session = factory.getInstance();

Collection results = session.execute(new Integer(10));

session.dispose();

A template to produce the rules files is provided with the package:

package org.jsemantic.templates
global org.jsemantic.core.context.SemanticContext ctx;

rule "rule_one"
when
then
end
.........
rule "rule_n"
when
then
end

For example, we'd like to know if a number it's even:

rule "even"
when
number:Integer()
eval(number.intValue() % 2 == 0)
then
ctx.addObject(number, "Number: " + number + " is even");
end

The Semantic Context is the object that allows to interact with the enviroment. One way is returning results of the rules evaluation through the addObject(id, value) method. There are other ways of interacting as using the ExternalContext or the Session Variables. I'll explain this in future posts.

Saturday, 9 February 2008

It´s been a long time since I ...

Well yes!, it´s been a long time since the last time I wrote in this blog.. and a lot of things happened as well. The thing is, that I have been doing a lot of stuff lately and I´m going to share some of it, starting with a little set of frameworks related to the main topic of this blog: semantics.

First of all, a little of history :D

My first experience with semantic programming was some years ago, when I was assigned (with 2 colleagues) to a "highly urgent project" :P for Telefonica. It was a use case simulator for testing, so we had a lot of different input/output cases.

In order to relate the thousands of different input/output (a group of inputs/outputs would be a use case, depending on some conditions) we used a rule engine to generate and filter them.

Why did we use a rule engine? Because we could declare the different use cases and it's driven conditions, using rules in a declarative fashion (that is, semantic programming), being easily read, changed or updated. Also we could filter the cases using the same rules.

At that time (2003 I think it was) the best open source option was Drools (http://labs.jboss.com/drools/) and still is in my opinion. JRules from iLog, it´s a very good one rules engine but it´s a commercial option though.

I starting using rules engines over the years, collecting a few utility/helper classes.Then last year after the summer, I started working with these classes expanding them with a lot of improvements and concepts, always having Drools 3 as a core.

Then Drools 4 was released, and it had some of the concepts and improvements I´d already added :D to my little framework (well done guys! by the way). For example, changing the concept of WorkingMemory to RulesSession (stateless & stateful). I got something similar, but I went further creating the SemanticSession, a concept that I´ll explain latter.

Anyway, at that point I decided:
  • first of all, to create an agnostic and simplified API, with the most common features that anyone would use (based in my own experience) and not related to a specific rules engine. It also expands some of the concepts and features. This API would become the jSemanticCore package.
  • Second of all, to create an implementation based on Drools 4, using its new features and adding/removing others. Also it implements the new concepts, as the SemanticSession, SemanticContext, KnowledgeDatabase etc. This would become the jServiceRules package.
  • And finally, a support package that provides integration classes for Spring, Hibernate, Mule etc..

I will be releasing all this packages the next 2 weeks through http://code.google.com/p/jservicerules/, in a alpha/beta state. Also, I will be publishing entries in the blog explaining how to use it, technical aspects and examples.