source_sink error in prolog using rdf_load - prolog

I want to load rdf url from this rule:
getActorFilms(Actor_Name,Films):-
my_replace(Actor_Name, ' ', '_', Correct_Syntax_Of_Actor_Name),
string_concat('http://dbpedia.org/data/',Correct_Syntax_Of_Actor_Name, URL_TO_LOAD),
string_concat(URL_TO_LOAD,'.rdf',RDF_URL),
rdf_load(RDF_URL),
rdf(Films, 'http://dbpedia.org/ontology/starring', Object)
.
when the input is e.g. for an example 'Hugh Jackman'
it tells the error:
ERROR: [Thread pdt_console_client_0_Default Process] source_sink `http://dbpedia.org/data/Hugh_Jackman.rdf' does not exist
I'm really concerned about the ` character between http and source_sink
I think it should be '
although the url is correct, so what to do with that error?

You should pass an atom to rdf_load, not a string. This behavior (the misleading error message, not accepting a string) is probably a bug.
This works for me:
?- use_module(library('semweb/rdf_db')).
true.
?- use_module(library('semweb/rdf_http_plugin')).
true.
?- rdf_load('http://dbpedia.org/data/Hugh_Jackman.rdf').
% Parsed "http://dbpedia.org/data/Hugh_Jackman.rdf" in 0.02 sec; 371 triples
true.
?- string_to_atom(S, 'http://dbpedia.org/data/Hugh_Jackman.rdf'), rdf_load(S).
ERROR: source_sink `http://dbpedia.org/data/Hugh_Jackman.rdf' does not exist
I hope this solves your problem.

Related

Prolog: Arguments not sufficiently instantiated

I am trying to compile and query this code:
got('no').
inMap(X,Y):- print("From inMap").
mask(1,3).
doctor(2,1).
verify(X,Y):-
(inMap(X,Y), ((\+(got('mask'); got('vaccine')),farCovid(X,Y)); True),
(print(X), print(Y); True),
(doctor(X,Y), print(X), print(Y); True)).
When my query is:
?- verify(2,1).
It returns:
"From inMap""From farCovid"2121
true .
But when my query is:
?- verify(1,1).
It returns:
"From inMap""From farCovid"11
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR: [10] verify(1,1)
ERROR: [9] <user>
Can somebody explain to me what is wrong here please, wasn't it supposed to pass in (1,1) in the second query to doctor(X,Y) and return false?
Thanks in advance!

Prolog - is the following query satisfied?

I am doing exercise from the following link
Here is knowledge base:
house_elf(dobby).
witch(hermione).
witch(’McGonagall’).
witch(rita_skeeter).
magic(X):- house_elf(X).
magic(X):- wizard(X).
magic(X):- witch(X).
I am expecting the following query to return true:
?- magic(’McGonagall’).
However, my SWI-Prolog (AMD64, Multi-threaded, version 7.6.4) on Windows 7 returns the following:
ERROR: Stream user_input:450:4 Syntax error: Unexpected end of clause
?- magic('McGonagall').
ERROR: Undefined procedure: wizard/1
ERROR: In:
ERROR: [9] wizard('McGonagall')
ERROR: [8] magic('McGonagall') at c:/users/some_user/google drive/projects/nlp/prolog/code/ex2_2.pl:6
ERROR: [7] <user>
Exception: (9) wizard('McGonagall') ? creep
Exception: (8) magic('McGonagall') ? creep
?-
Why does it fail?
In the magic/1 predicate, you call wizard/1, which is not defined:
magic(X):- house_elf(X).
magic(X):- wizard(X).
magic(X):- witch(X).
The result is that Prolog errors, since it calls a predicate that is nowhere defined.
You can for example define a wizard/1 predicate that always fails:
% a world without wizards (if you do not specify extra wizards)
wizard(_) :- fail.
or populate your "world" with wizards, like:
wizard(dumbledore).
wizard(remus_lupin).
%% ...

How to make list constructors (e.g .(a,[]) == [a].) work in Prolog?

I am learning Prolog and .(a,[]) == [a]. should return true in SWI-Prolog, but it gives me an error saying
ERROR: Type error: `dict' expected, found `a' (an atom)
ERROR: In:
ERROR: [11] throw(error(type_error(dict,a),_4020))
ERROR: [10] '$type_error'(dict,a) at /Applications/SWI-
Prolog.app/Contents/swipl/boot/init.pl:3369
ERROR: [9] '$dicts':'.'(a,[],_4086) at /Applications/SWI-
Prolog.app/Contents/swipl/boot/dicts.pl:46
ERROR: [8] '<meta-call>'(user:(...,...)) <foreign>
ERROR: [7] <user>
Anyone knows how to fix this?
Start the SWI Prolog executable with the --traditional command line option (comment due to user:false).
Then it works:
1 ?- .(a,[]) == [a].
true.
2 ?- current_prolog_flag( traditional, X).
X = true.
3 ?- set_prolog_flag( traditional, false).
ERROR: set_prolog_flag/2: No permission to modify flag `traditional'
4 ?-
This is mentioned in the documentation here (see "traditional", near the bottom of the page).
As can be seen, attempting to change it from within the running SWI session, fails.

Existence error on lists

I am using gprolog allong with gplc and I get fatal error: redefining built-in predicate member/2 when I try to compile the following code. I also get uncaught exception: error(existence_error(procedure,member/0),member/0) when I try to consult the same code.
Code:
member(X,[X|T]).
member(X,[H|T]) :- member(X,T).
The query I give:
| ?- member(X,[a,b,c,d,e]).
X = a ? ;
uncaught exception: error(existence_error(procedure,member/0),member/0)

Prolog syntax error: illegal start of term

So I'm trying to test my the predicate reduce/4 defined as following:
:- op(20,xfy,?=).
reduce(R,X ?=Y,P,Q) :-
R=rename,
regle(X ?=Y,R),
length(P,N),
trouve(Y,P,N,M),
remove(N,M,P,Q).
but i keep getting this error:
?- reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q].
ERROR: Syntax error: Illegal start of term
ERROR: reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],
ERROR: ** here **
ERROR: Q] .
I'm new to Prolog so maybe it is something stupid.
You use ] instead of ) to close the bracket of reduce
reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q].
% ^open ^close
You can fix this with:
?- reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q).
I cannot validate if this solves your problem, because you did not provide a definition for regle/2, etc. But the fact that I get a semantic error, seems to solve the syntax error nevertheless.

Resources