Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:keyword_in_context [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Keyword in context ======
 +{{tag>​keywords}}
 +===== Description =====
 +Producing a keyword in context (KWIC) index
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{keyword_in_context.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +   ​kwic(Titles,​KWTitles) :-
 + KWTitles is a KWIC index of the list of titles Titles.
 +*/
 +:-  op( 900, fy, not).
 +
 +     ​kwic(Titles,​KWTitles) :-
 +        setof(Ys,​Xs^(member(Xs,​Titles),​rotate_and_filter(Xs,​Ys)),​KWTitles).
 +
 +/*
 +   ​rotate_and_filter(Xs,​Ys) :-
 + Ys is a rotation of the list Xs such that
 + the first word of Ys is significant and |
 + is inserted after the last word of Xs.
 +*/
 +
 +     ​rotate_and_filter(Xs,​Ys) :-
 +        append(As,​[Key|Bs],​Xs), ​
 +        not insignificant(Key), ​
 + append([Key|Bs],​[`|`|As],​Ys).
 +
 +% Vocabulary
 +
 +     ​insignificant(a). ​       insignificant(the).
 +     ​insignificant(in). ​      ​insignificant(for).
 +
 +% Testing and data
 +
 +test_kwic(Books,​Kwic) :-
 + titles(Books,​Titles),​ kwic(Titles,​Kwic).
 +
 +titles(lp,​[[logic,​for,​problem,​solving],​
 +    ​[logic,​programming],​
 +    ​[algorithmic,​program,​debugging],​
 +    ​[programming,​in,​prolog]]).
 +
 +%  Program 16.7   ​Producing a keyword in context (KWIC) index
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/keyword_in_context.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0