Clauses loaded from a command line are not visible from a module

I’m using: SWI-Prolog version 8.2.0 for x86_64-linux

I have a module with a predicate isa/2 that checks whether word1 is more specific (a direct hyponym of) than word2. For this, I use a prolog format of WordNet (WN). Given that WN can be language-specific, I would like to control from a command line what language WN I am loading.

My issue is that loaded WN facts are not visible from the module. Here is the MWE:

% module file named isa.pl
:- module(isa, [isa/2]).

:- multifile s/6, hyp/2.
% :- dynamic s/6. % makes no difference
% :- dynamic hyp/2.

isa(W1, W2) :-
    s(SS1,_,W1,_,_,_),  % facts are defined in WNProlog/wn_s
    s(SS2,_,W2,_,_,_), 
    hyp(SS1, SS2).      % facts are defined in WNProlog/wn_hyp

isa(dog, animal).
% WordNet wrapper file named wn.pl
:- ensure_loaded([
	'WNProlog/wn_hyp',
	'WNProlog/wn_s'
	]).

Command line behaviour shows that at least s/6 facts are not visible for isa/2.

swipl wn.pl  isa.pl
?- isa(man, person).
false.

?- isa(dog, animal).
true.

?- s(A,_,man,_,_,_), s(B,_,person,_,_,_), hyp(A, B).
A = 110289039,
B = 100007846 ;
false.

When a module directive :- module(isa, [isa/2]). is removed, isa(man, person) succeeds.

What is a proper way to load clauses from command line that are accessible from a predefined module?

Your design relies on the modules inheriting undefined predicates from the user module. That should work fine. However, using :- multifile s/6, hyp/2. you also create a local definition (declaring something as multifile or dynamic defines a predicates). As you now have a local definition inheritance from user no longer happens. So, just remove the multifile declaration.

Whether or not this is an elegant way to solve the problem is a different matter :slight_smile: In can be, but it depends on the rest of the lifecycle you want to handle.

Thank you for your answer.
I didn’t know that multifile creates a local definition for a module that blocks the inheritance.
P.S. I agree, the architecture is not perfect, but gives me modularity and an option for injection.