Rdf_save_turtle expand and rdf literals

Hi. Thanks for the quick answer on the other post.
The second problem I’m experiencing, which I don’t know how to resolve is how to use the expand option in rdf_save_turtle. Reading the docs, it seems obvious to me that it can be used to select different tuples than the default ones, so it may be used to create a filter based on Subject and Predicate.

    rdf_save_turtle(StreamResponse, [
        expand(query_filter(Subject, Predicate))
    ]).

query_filter(Subject, Predicate, S, P, O, _G) :-
    Subject = S,
    Predicate = P,
    rdf(S, P, O).

However, when O is a literal, there’s a type error:

Type error: `rdf_literal' expected, found `^^("Blablabla",'http://www.w3.org/2001/XMLSchema#string')' (a compound)

When O is also an URI I don’t have problems, and the code filters as expected.

But I thought ^^(str, type) was a representation of a literal so I don’t know which is the problem.

My tuples are loaded like this in other place, that might be the problem:

    rdf_read_turtle(atom(Input), Triples, []),
    forall(member(Triple, Triples), (
        Triple = rdf(S, P, O),
        rdf_assert(S, P, O)
    )),

TLDR; I want do a filter of triples that get saved in the Turtle output, but it fails when encounters a literal.

Thanks in advance

Never considered that use of the expand feature. Seems quite useful though. You are faced with the compatibility of the old RDF and new (rdf11) Prolog representation for RDF literals. I’ve pushed a fix. This isn’t well tested, but appears to do the basics. If you want to help, please help adding tests.

Program tested, dumping all triples for http://sws.geonames.org/2745324/'

:- module(t,
          [ t/0
          ]).
:- use_module(library(semweb/rdf11)).
:- use_module(library(semweb/turtle)).

t :-
    Subject = 'http://sws.geonames.org/2745324/',
    setup_call_cleanup(
        open('t.ttl', write, Out),
        rdf_save_turtle(Out,
                        [ expand(query_filter(Subject, Predicate))
                        ]),
        close(Out)).

query_filter(Subject, Predicate, S, P, O, _G) :-
    Subject = S,
    Predicate = P,
    rdf(S, P, O).

Note that the query filter is easier written as

query_filter(S, P, S, P, O, _G) :-
    rdf(S, P, O).

Oh, I didn’t know I found a bug. Thanks for the quick patch! I will upgrade to 8.1.25 as soon as it gets released.

I could help adding tests but I don’t know how to run them.