Skip to content

Commit

Permalink
Add tests for connection to JProbLog
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmendez committed Dec 31, 2023
1 parent f2b39da commit 42cf4fe
Show file tree
Hide file tree
Showing 13 changed files with 8,101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.tudresden.inf.lat.born.owlapi.processor;


import java.io.*;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.IntStream;

import de.tudresden.inf.lat.jproblog.JProblog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Test class for ProblogProcessor.
*
* @author Julian Mendez
*/
public class ProblogProcessorTest {

String INPUT_FOR_PROBLOG = "input_for_problog.txt";

String OUTPUT_FROM_PROBLOG = "output_from_problog.txt";

public String readFile(String fileName) {
try {
return new String(Files.readAllBytes(Paths.get((getClass().getResource(fileName).toURI()))));
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}

}

/**
* This tests the example ontologies.
*/
@Test
public void testApply() {
ProcessorConfiguration conf = new ProcessorConfigurationImpl();
JProblog queryProcessor = new JProblog();
conf.setQueryProcessor(queryProcessor);
IntStream.range(0, 6).forEach(index -> {
String input = readFile(File.separator + index + File.separator + INPUT_FOR_PROBLOG);
String expected = readFile(File.separator + index + File.separator + OUTPUT_FROM_PROBLOG);
String obtained = conf.getQueryProcessor().apply(input);
Assertions.assertEquals(expected, obtained);
});
}

}
114 changes: 114 additions & 0 deletions born-owlapi/src/test/resources/0/input_for_problog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

%% EL completion rules



% Rules to interpret the queries
sub(X, B) :-
con(X),
con(B),
subx(X, B).
inst(X, B) :-
indiv(X),
con(B),
subx(X, B).
inst(R, X, B) :-
role(R),
indiv(X),
indiv(B),
subx(X, exists(R, A)),
subx(A, B).

% Rules to process individuals
coni(X) :- con(X).
coni(X) :- indiv(X).

% Basic rules for the completion
subx(X, X) :- coni(X).
subx(X, top) :- coni(X).
subx(X, B) :- gci(X, B).

% EL complettion rules
subx(X, B) :-
gci(A, B),
subx(X, A),
coni(X),
coni(A),
coni(B).
subx(X, B) :-
gci(and(A1, A2), B),
subx(X, A1),
subx(X, A2),
coni(X),
coni(A1),
coni(A2),
coni(B).
subx(X, exists(R, B)) :-
gci(A, exists(R, B)),
subx(X, A),
coni(X),
coni(A),
coni(B),
role(R).
subx(X, B) :-
gci(exists(R, A), B),
subx(X, exists(R, Y)),
subx(Y, A),
coni(X),
coni(Y),
coni(A),
coni(B),
role(R).

% Rules to avoid empty predicates of entities
con(-).
role(-).
indiv(-).


%% Ontology

con('https://lat.inf.tu-dresden.de/systems/born/born-example#c').
con('https://lat.inf.tu-dresden.de/systems/born/born-example#d').
con('https://lat.inf.tu-dresden.de/systems/born/born-example#e').
con('https://lat.inf.tu-dresden.de/systems/born/born-example#a').
con('https://lat.inf.tu-dresden.de/systems/born/born-example#b').
role('https://lat.inf.tu-dresden.de/systems/born/born-example#r').
role('https://lat.inf.tu-dresden.de/systems/born/born-example#s').
gci('https://lat.inf.tu-dresden.de/systems/born/born-example#a', 'https://lat.inf.tu-dresden.de/systems/born/born-example#c') :- x4.
gci(and('https://lat.inf.tu-dresden.de/systems/born/born-example#c', 'https://lat.inf.tu-dresden.de/systems/born/born-example#d'), 'https://lat.inf.tu-dresden.de/systems/born/born-example#e') :- x5.
gci(exists('https://lat.inf.tu-dresden.de/systems/born/born-example#r', 'https://lat.inf.tu-dresden.de/systems/born/born-example#b'), 'https://lat.inf.tu-dresden.de/systems/born/born-example#d') :- \+x2.
gci('https://lat.inf.tu-dresden.de/systems/born/born-example#a', exists('https://lat.inf.tu-dresden.de/systems/born/born-example#r', 'https://lat.inf.tu-dresden.de/systems/born/born-example#b')) :- x0.
gci('https://lat.inf.tu-dresden.de/systems/born/born-example#b', exists('https://lat.inf.tu-dresden.de/systems/born/born-example#s', 'https://lat.inf.tu-dresden.de/systems/born/born-example#c')) :- \+x3.
gci('https://lat.inf.tu-dresden.de/systems/born/born-example#c', 'https://lat.inf.tu-dresden.de/systems/born/born-example#e') :- x3.


%% Bayesian Network


0.3::x0.
0.4::x1.
0.8::x2.
0.3::x3.
0.3::x4.
0.7::x5.
0.9::x6.
0.3::x7.
0.2::x8.
0.1::x9.
0.5::x10.
0.8::x11.
0.3::x12.
0.8::x13.
0.9::x14.
0.6::x15.
0.5::x16.


%% Queries


query(sub('https://lat.inf.tu-dresden.de/systems/born/born-example#a', 'https://lat.inf.tu-dresden.de/systems/born/born-example#e')).



1 change: 1 addition & 0 deletions born-owlapi/src/test/resources/0/output_from_problog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sub('https://lat.inf.tu-dresden.de/systems/born/born-example#a','https://lat.inf.tu-dresden.de/systems/born/born-example#e'): 0.09882
Loading

0 comments on commit 42cf4fe

Please sign in to comment.