Not understanding how to use rdf_register_prefix/2

I have this program:

    :- autoload(library(semweb/rdf11)).
    :- autoload(library(semweb/rdf_prefixes)).

    :- rdf_register_prefix(foo,'http://example.org/foo#').

    rdf_represents_member_of_class(Class,rdf(_, rdf:type, Class)).

I can confirm that the prefixes are registered:

    ?- rdf_current_prefix(foo,X).
    X = 'http://example.org/foo#'.

    ?- rdf_current_prefix(rdf,X).
    X = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'.

Yet these queries show that I am not getting the expected behavior:

% This is expected behavior
?- rdf_represents_member_of_class(foo:someClass, rdf(foo:nicholas,rdf:type, foo:someClass)).
true.

% But I would also expect this query to give true
?- rdf_represents_member_of_class(foo:someClass, rdf('http://example.org/foo#nicholas',rdf:type, 'http://example.org/foo#someClass')).
false.

% Likewise I would also expect this query to give true
rdf_represents_member_of_class(foo:someClass, rdf(foo:nicholas,'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', foo:someClass)).
false.

Please let me know what I am not understanding.

The fact that foo:nicholas is expanded to 'http://example.org/foo#nicholas' at compile time. For this to happen you must tell the compiler that some argument is an RDF resource. In this case you’d need

:- rdf_meta rdf_represents_member_of_class(r,t).

which tells the first argument is an RDF resource and the second is a Prolog term that may contain RDF prefix notation sub terms. See rdf_meta/1 for details.

2 Likes