Prolog wildcard for line termination

I am currently stuck with the prologue issue.

So far I have:

film(Title) :- movie(Title,_,_).

(Where ' movie(T,_,_,)

' is a link to my database)

namesearch(Title, Firstword) :- film(Title), contains_term(Firstword, Title).

      

It's hard to explain what I need help with, but basically there is a wildcard that I can use to search for all movies starting with a certain word, like if I were looking for all movies starting with the word "".

Is there a wildcard that will allow me to type as such namesearch(X,'The*')

:?

I tried using an asterisk like this and it doesn't work,

Thanks for your help.

+3


source to share


1 answer


It all depends on how the title is displayed.

Atom

If it is represented as an atom, you need sub_atom(Atom, Before, Length, After, Sub_atom)

?- Title = 'The Third Man', sub_atom(Title, 0, _, _, 'The').
Title = 'The Third Man'.

      

List of codes

If it is a list of codes, which is called a chain in Prolog in the Edinburgh tradition, you can either "hard code" it with append/3

, or use general grammar grammars of a certain type for general patterns.

?- set_prolog_flag(double_quotes,codes).
true.

?- append("The",_, Pattern), Title = "The Third Man", Pattern = Title.
Pattern = Title, Title = [84, 104, 101, 32, 84, 104, 105, 114, 100|...].

?- Title = "The Third Man", phrase(("The",...), Title).
Title = [84, 104, 101, 32, 84, 104, 105, 114, 100|...] ;
false.

      



Note that 84 is the code for the T character, etc.

phrase/2

is a "record" in grammar. Cm.... The following definition is used above:

... --> [] | [_], ... .

      

List of symbols

Like a list of codes, a list of symbols provides a more readable representation that still has the benefits of being compatible with list predicates and literate markers with specific parameters:

?- set_prolog_flag(double_quotes,chars).
true.

?- append("The",_, Pattern), Title = "The Third Man", Pattern = Title.
Pattern = Title, Title = ['T', h, e, ' ', 'T', h, i, r, d|...].

?- Title = "The Third Man", phrase(("The",...), Title).
Title = ['T', h, e, ' ', 'T', h, i, r, d|...] ;
false.

      

See also this answer .

+4


source







All Articles