-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for connection to JProbLog
- Loading branch information
1 parent
f2b39da
commit 42cf4fe
Showing
13 changed files
with
8,101 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...owlapi/src/test/java/de/tudresden/inf/lat/born/owlapi/processor/ProblogProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')). | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.