RIF4J

Description

RIF4J is a reasoning engine for RIF-BLD that provides a Java object model for RIF-BLD and supports the parsing and serialization of RIF-BLD formulas. Furthermore, it provides a prototype implementation of a RIF-BLD consumer based on the Datalog engine IRIS. It is an open-source library licensed under the Apache License 2.0 and hosted on Sourceforge.

Installation

RIF4J is developed as an Apache Maven project and is being deployed on a daily basis to the STI Maven repository. To get releases and snapshots of RIF4J and the dependent components, the following repositories have to be added to the project object model (POM) file:

<repositories>
  <repository>
    <id>sti2-archiva-external</id>
    <url>http://maven.sti2.at/archiva/repository/external</url>
  </repository>
  <repository>
    <id>sti2-archiva-snapshots</id>
    <url>http://maven.sti2.at/archiva/repository/snapshots</url>
  </repository>
</repositories>

The object model, parser and serializers can be used by by adding at.sti2.rif4j:rif4j-impl as dependency to the POM file:

<dependency>
  <groupId>at.sti2.rif4j</groupId>
  <artifactId>rif4j-impl</artifactId>
  <version>0.3.1</version>
</dependency>

In order to use the prototype reasoner based on IRIS, the following dependency needs to be added to the POM file:

<dependency>
  <groupId>at.sti2.rif4j</groupId>
  <artifactId>rif4j-iris</artifactId>
  <version>0.3.1</version>
</dependency>

For reasoning with combinations of RIF and RDF under the Simple Entailment semantics, the following dependency needs to be included:

<dependency>
  <groupId>at.sti2.rif4j</groupId>
  <artifactId>rif4j-rdf</artifactId>
  <version>0.3.1</version>
</dependency>

Usage Example

import java.net.URI;

import at.sti2.rif4j.condition.Formula;
import at.sti2.rif4j.manager.DocumentLoadingException;
import at.sti2.rif4j.manager.DocumentManager;
import at.sti2.rif4j.reasoner.Reasoner;
import at.sti2.rif4j.reasoner.ReasonerFactory;
import at.sti2.rif4j.reasoner.ReasoningException;
import at.sti2.rif4j.reasoner.iris.IrisRifReasonerFactory;
import at.sti2.rif4j.rule.Document;

public class Example {

    public static void main(String[] args) throws DocumentLoadingException,
            ReasoningException {
        // The URI of the premise document.
        URI premiseUri = URI
                .create("http://www.w3.org/2005/rules/test/repository/"
                        + "tc/Class_Membership/Class_Membership-premise.rif");

        // The URI of the conclusion formula.
        URI conclusionUri = URI
                .create("http://www.w3.org/2005/rules/test/repository/"
                        + "tc/Class_Membership/Class_Membership-conclusion.rif");

        // Use the DocumentManager to load the premise and the conclusion.
        DocumentManager manager = new DocumentManager();
        Document premise = manager.loadDocument(premiseUri);
        Formula conclusion = manager.loadFormula(conclusionUri);

        // Create a RIF-BLD reasoner based on the IRIS Datalog system.
        ReasonerFactory factory = new IrisRifReasonerFactory();
        Reasoner reasoner = factory.createReasoner();

        // Register the premise document.
        reasoner.register(premise);

        // Check if the premise entails the conclusion.
        boolean entails = reasoner.entails(conclusion);

        if (entails) {
            // Do something.
        }
    }

}