Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ jobs:

- name: Install SWI-Prolog (Windows)
if: matrix.os == 'windows-latest'
run: choco install -y swi-prolog
run: |
choco install -y swi-prolog
$swiplHome = "C:\Program Files\swipl"
$swiplBin = Join-Path $swiplHome "bin"
Add-Content -Path $env:GITHUB_PATH -Value $swiplBin
Add-Content -Path $env:GITHUB_ENV -Value "SWI_HOME_DIR=$swiplHome"
& (Join-Path $swiplBin "swipl.exe") --version

- name: Install SWI-Prolog (macOS)
if: matrix.os == 'macos-latest'
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def kb_add_ground():
@pytest.fixture
def kb_add_prolog():
if platform.system() == "Darwin":
return
pytest.skip("Prolog tests are skipped on macOS")
kb = PrologKB(pseudo_label_list=list(range(10)), pl_file="examples/mnist_add/add.pl")
return kb

Expand All @@ -219,7 +219,7 @@ def kb_hwf2():
@pytest.fixture
def kb_hed():
if platform.system() == "Darwin":
return
pytest.skip("Prolog tests are skipped on macOS")
kb = HedKB(
pseudo_label_list=[1, 0, "+", "="],
pl_file="examples/hed/reasoning/learn_add.pl",
Expand Down
25 changes: 9 additions & 16 deletions tests/test_reasoning.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from ablkit.reasoning import PrologKB, Reasoner


PROLOG_SKIP_ON_DARWIN = pytest.mark.skipif(
platform.system() == "Darwin",
reason="Prolog tests are skipped on macOS",
)


class TestKBBase(object):
def test_init(self, kb_add):
assert kb_add.pseudo_label_list == list(range(10))
Expand Down Expand Up @@ -55,37 +61,28 @@ def test_abduce_candidates_ground(self, kb_add_ground):
assert result == ([(1, 0)], [1])


@PROLOG_SKIP_ON_DARWIN
class TestPrologKB(object):
def test_init_pl1(self, kb_add_prolog):
if platform.system() == "Darwin":
return
assert kb_add_prolog.pseudo_label_list == list(range(10))
assert kb_add_prolog.pl_file == "examples/mnist_add/add.pl"

def test_init_pl2(self, kb_hed):
if platform.system() == "Darwin":
return
assert kb_hed.pseudo_label_list == [1, 0, "+", "="]
assert kb_hed.pl_file == "examples/hed/reasoning/learn_add.pl"

def test_prolog_file_not_exist(self):
if platform.system() == "Darwin":
return
pseudo_label_list = [1, 2]
non_existing_file = "path/to/non_existing_file.pl"
with pytest.raises(FileNotFoundError) as excinfo:
PrologKB(pseudo_label_list=pseudo_label_list, pl_file=non_existing_file)
assert non_existing_file in str(excinfo.value)

def test_logic_forward_pl1(self, kb_add_prolog):
if platform.system() == "Darwin":
return
result = kb_add_prolog.logic_forward([1, 2])
assert result == 3

def test_logic_forward_pl2(self, kb_hed):
if platform.system() == "Darwin":
return
consist_exs = [
[1, 1, "+", 0, "=", 1, 1],
[1, "+", 1, "=", 1, 0],
Expand All @@ -101,8 +98,6 @@ def test_logic_forward_pl2(self, kb_hed):
assert kb_hed.logic_forward(inconsist_exs) is False

def test_revise_at_idx(self, kb_add_prolog):
if platform.system() == "Darwin":
return
result = kb_add_prolog.revise_at_idx([1, 2], 2, [0.1, -0.2, 0.2, -0.3], [0])
assert result == ([[0, 2]], [2])

Expand Down Expand Up @@ -190,9 +185,8 @@ def test_batch_abduce_ground(self, kb_add_ground, data_examples_add):
(7, 3),
]

@PROLOG_SKIP_ON_DARWIN
def test_batch_abduce_prolog(self, kb_add_prolog, data_examples_add):
if platform.system() == "Darwin":
return
reasoner1 = Reasoner(kb_add_prolog, "confidence", max_revision=1, require_more_revision=0)
reasoner2 = Reasoner(kb_add_prolog, "confidence", max_revision=1, require_more_revision=1)
reasoner3 = Reasoner(kb_add_prolog, "confidence", max_revision=2, require_more_revision=0)
Expand All @@ -212,9 +206,8 @@ def test_batch_abduce_prolog(self, kb_add_prolog, data_examples_add):
[7, 3],
]

@PROLOG_SKIP_ON_DARWIN
def test_batch_abduce_zoopt(self, kb_add_prolog, data_examples_add):
if platform.system() == "Darwin":
return
reasoner1 = Reasoner(kb_add_prolog, "confidence", use_zoopt=True, max_revision=1)
reasoner2 = Reasoner(kb_add_prolog, "confidence", use_zoopt=True, max_revision=2)
assert reasoner1.batch_abduce(data_examples_add) == [[1, 7], [7, 1], [], [1, 9]]
Expand Down
Loading