|
|
To start working with the InteGraal library, you need to setup your work environment. This means having the minimum configuration needed to run InteGraal.
|
|
|
|
|
|
## Configuration of the work environment
|
|
|
|
|
|
### Java
|
|
|
|
|
|
You need Java version >= 11 to use InteGraal.
|
|
|
- If you are not sure which version you have, you can open a terminal and use the `java --version` command.
|
|
|
- You can install java by following [the official oracle website](https://www.oracle.com/fr/java/)
|
|
|
|
|
|
### IDE
|
|
|
|
|
|
We recommand the use of an IDE [such as Eclipse](https://www.eclipse.org/downloads/) to work with java but this is not needed.
|
|
|
|
|
|
If using Eclipse, you may need to configure it to use the correct version of Java
|
|
|
```
|
|
|
In Window > Preferences:
|
|
|
Java/Installed JREs >
|
|
|
Check that jdk >= 11 exists and is checked
|
|
|
Otherwise
|
|
|
click Add...
|
|
|
select Standard VM
|
|
|
select the JRE home from your computer
|
|
|
it is the root folder with "bin", "conf", ... folders in it
|
|
|
click Finish
|
|
|
Check that jdk >= 11 is checked
|
|
|
click Apply
|
|
|
```
|
|
|
|
|
|
### Maven
|
|
|
|
|
|
If you plan on using InteGraal through [Maven](https://maven.apache.org/index.html), you may need to [install it](https://maven.apache.org/install.html) unless your IDE comes with it already included.
|
|
|
|
|
|
Please note that this is not necessary if using only the provided jar.
|
|
|
|
|
|
### Git
|
|
|
|
|
|
If you plan on extending InteGraal, you will need to clone the git repository. [Git](https://www.git-scm.com/) is already installed on most system but you can find it [here](https://www.git-scm.com/downloads).
|
|
|
|
|
|
## First example
|
|
|
|
|
|
In this step we will explain how to use InteGraal with a given application using the provided jar as dependency.
|
|
|
|
|
|
The first step is to create a new java project for this tutorial. Then, you need to add the InteGraal jar as dependency for this project.
|
|
|
If you are using Eclipse, you can do so by followinf this steps :
|
|
|
```
|
|
|
In Project > Properties:
|
|
|
Java Build path >
|
|
|
select Libraries > Classpath
|
|
|
click Add External JARs...
|
|
|
select the jar
|
|
|
click Apply
|
|
|
```
|
|
|
|
|
|
Next, you can create the main file for this example. You can find it at https://notes.inria.fr/z7uLn0irTsKVAh2jEfr4pA.
|
|
|
- Please note that this content assumes that the file is named `Main.java`. You can change the name of the class according to the name of your file.
|
|
|
|
|
|
You will also need to create a file `example.dlgp` at the root of the java project with the following content :
|
|
|
|
|
|
```
|
|
|
@facts
|
|
|
r(a).
|
|
|
r(b).
|
|
|
r(c).
|
|
|
s(c).
|
|
|
s(d).
|
|
|
u(c, c).
|
|
|
|
|
|
@rules
|
|
|
s(X) :- r(X).
|
|
|
t(X) :- s(X).
|
|
|
|
|
|
@queries
|
|
|
?(Y) :- t(Y).
|
|
|
?(Y) :- s(Y).
|
|
|
```
|
|
|
|
|
|
When you execute the given example, the `example.dlgp` file is parsed and a factbase and rulebase are created. Then, the queries are evaluated over the factbase and the answers are printed on the standard output.
|
|
|
|
|
|
## Adding reasoning parts
|
|
|
|
|
|
The previous example included rules but they are not taken into account for answering the queries. In this step we will add the reasoning part with a saturation approach.
|
|
|
|
|
|
If you want to familiarize with the library you can try to do so by yourself
|
|
|
- Hint : There is 2 lines of code to copy from the documentation
|
|
|
|
|
|
Otherwise, you can add the following 2 lines at line 77, between the parsing of the data file and the evaluation of the queries :
|
|
|
```
|
|
|
ForwardChainingAlgorithm chase = ChaseBuilder.defaultChase(fb, rb, termfactory);
|
|
|
chase.execute();
|
|
|
```
|
|
|
- Don't forget the corresponding imports
|
|
|
|
|
|
When you execute the given example, the factbase and rulebase are created. Then, the factbase is saturated with the rulebase and the queries are evaluated over the saturated factbase. |
|
|
\ No newline at end of file |