From 7fb18fae908d4a180bf48a6f51fb7d1020b201b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20W=C3=BCrbel?= <eric.wurbel@univ-amu.fr> Date: Wed, 25 Jan 2023 14:42:21 +0100 Subject: [PATCH] config management. TODO test --- config.pl | 16 ++++++++++++++++ wbel.pl | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 config.pl diff --git a/config.pl b/config.pl new file mode 100644 index 0000000..93cf11d --- /dev/null +++ b/config.pl @@ -0,0 +1,16 @@ +:- module(config, [ + load_config/2 + ]). + +:- use_module(library(yaml)). + +%! load_config(+Filename, -Config) is det +% +% Load a configuration file. +load_config(Filename, Config) :- + expand_file_name(Filename, [ExpFilename|_]), + absolute_file_name(ExpFilename, AbsFilename), + yaml_read(AbsFilename, Config), + ! + . +load_config(_, nil). diff --git a/wbel.pl b/wbel.pl index 548b59a..56c242d 100644 --- a/wbel.pl +++ b/wbel.pl @@ -14,6 +14,7 @@ :- use_module(generator). :- use_module(logic). :- use_module(evidence). +:- use_module(config). optspec([ [opt(raw), type(boolean), default(false), shortflags([r]), longflags([raw]), @@ -54,6 +55,8 @@ go :- full_evidence_computation(Opts, PosArgs) :- [BFile, MuFile] = PosArgs, + load_config('~/.wbel.cfg', Config), + set_config(Config), nb_setval(clasppath, '/home/wurbel/local/anaconda3/envs/potassco/bin/clingo'), init_form_atom, init_subform_atom, @@ -128,6 +131,20 @@ test_wbel(Beliefs) :- print_beliefs(Beliefs, Assoc) . +%! set_config(+Config) +set_config(Config) :- + is_dict(Config), + Config.get(clasppath) = ClaspPath, + nb_setval(clasppath, ClaspPath), + ! + . +set_config(_) :- + nb_setval(clasppath, '/home/wurbel/local/anaconda3/envs/potassco/bin/clingo') + . + + + + %! print_raw_beliefs(+Bels) is det print_raw_beliefs([]). -- GitLab