home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / EXAMPLES.ARC / CH13EX04.PRO < prev    next >
Encoding:
Prolog Source  |  1988-06-21  |  1.3 KB  |  65 lines

  1. /*
  2.    Turbo Prolog 2.0 Chapter 13, Example Program 4
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.    
  6. */
  7.    
  8. domains
  9.    sentence    = s(noun_phrase,verb_phrase)
  10.  
  11.    noun_phrase = noun(noun) ; noun_phrase(detrm,noun)
  12.    noun        = string
  13.  
  14.    verb_phrase = verb(verb) ; verb_phrase(verb,noun_phrase)
  15.    verb        = string
  16.  
  17.    detrm       = string
  18.  
  19. predicates
  20.     s_sentence(string,sentence)
  21.     s_noun_phrase(string,string,noun_phrase)
  22.     s_verb_phrase(string,verb_phrase)
  23.     d(string)
  24.     n(string)
  25.     v(string)
  26.  
  27. clauses
  28.    s_sentence(Str, s(N_Phrase,V_Phrase) ):-
  29.       s_noun_phrase(Str, Rest, N_Phrase),
  30.       s_verb_phrase(Rest, V_Phrase).
  31.  
  32.   s_noun_phrase(Str, Rest, noun_phrase(Detr,Noun)):-
  33.       fronttoken(Str,Detr,Rest1),
  34.       d(Detr),
  35.       fronttoken(Rest1,Noun,Rest),
  36.       n(Noun).
  37.  
  38.   s_noun_phrase(Str,Rest,noun(Noun)):-
  39.       fronttoken(STR,Noun,Rest),
  40.       n(Noun).
  41.  
  42.   s_verb_phrase(Str, verb_phrase(Verb,N_Phrase)):-
  43.       fronttoken(Str,Verb,Rest1),
  44.       v(Verb),
  45.       s_noun_phrase(Rest1,"",N_Phrase).
  46.  
  47.   s_verb_phrase(Str,verb(Verb)):-
  48.       fronttoken(STR,Verb,""),
  49.       v(Verb).
  50.  
  51. /* determiner */
  52.  
  53.    d("the").
  54.    d("a").
  55.  
  56. /* nouns */
  57.  
  58.    n("bill").
  59.    n("dog").
  60.    n("cat").
  61.  
  62. /* verbs */
  63.  
  64.    v("is").
  65.