home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / NL.LF < prev    next >
Text File  |  1996-06-04  |  15KB  |  420 lines

  1. % FILE. . . . . /_/udir7/_/hassan/life/nl.life
  2. % EDIT BY . . . Hassan Ait-Kaci
  3. % ON MACHINE. . Prlp22
  4. % STARTED ON. . Thu Mar 28 14:33:16 1991
  5.  
  6. %  Last modified on Mon Feb 22 04:47:50 1993 by Rmeyer
  7. %       modified on Wed Feb 26 18:59:18 1992 by Hassan
  8.  
  9. % The Type Hierarchy:
  10.  
  11. human_disease <| disease.
  12.  
  13. food := {vegetable;meat}.
  14.  
  15. inanimate := {food;information;tree}.
  16.  
  17. inanimate <| projectile.
  18.  
  19. animate := {human;inhuman;you}.
  20.  
  21. code <| computer.
  22.  
  23. inhuman := {dog;computer}.
  24.  
  25. % The Functions:
  26.  
  27. can_catch(human_disease) -> human.
  28. can_catch(disease) -> animate.
  29. can_catch(frisbee) -> {human; dog}.
  30. can_catch(projectile) -> human.
  31. can_catch(@) -> animate.
  32.  
  33. eaten_by(vegetarian) -> vegetable.
  34. eaten_by(carnivore) -> meat.
  35. eaten_by(omnivore) -> food.
  36. eaten_by(comp) -> information.
  37.  
  38. % The Parser:
  39.  
  40. nl_parse(List, Cat) :-
  41.     lookup(List, Defs),
  42.     nl_parsed(Defs, Cat, []).
  43.  
  44. nl_parsed([Def|Rest], Cat, Rest) :-
  45.     grammar_rule2(Def, Cat, Def).
  46.  
  47. nl_parsed([Def|Rest], Cat, S1) :-
  48.     grammar_rule(Def, Cat, Def, Needing),
  49.     nl_parsed(Rest, Needing, S1).
  50.  
  51. nl_parsed([Def|Rest], Cat, S1) :-
  52.     grammar_rule2(Def, Cat, Cat1),
  53.     nl_parsed([Def|Rest], Cat1, S1).
  54.  
  55. nl_parsed([Def|Rest], Cat, S1) :-
  56.     grammar_rule(Def, Cat, Cat1, Cat2),
  57.     nl_parsed([Def|Rest], Cat1, S2),
  58.     nl_parsed(S2, Cat2, S1).
  59.  
  60. grammar_rule2(@,
  61.     par(parsetree => tree(label => par, lhs => X), anaphora_out => B),
  62.     X:paragraph(anaphora_in => [], anaphora_out => B)).
  63.  
  64. grammar_rule(@,
  65.     paragraph(anaphora_in => A, anaphora_out => B, 
  66.           parsetree => tree(label => paragraph, lhs => X, rhs => Y)),
  67.     X:s(anaphora_in => A, anaphora_out => B),
  68.     Y:sstop).
  69.  
  70. grammar_rule2([], sstop, []).
  71.  
  72. grammar_rule(@,
  73.     paragraph(anaphora_in => A, anaphora_out => C, 
  74.           parsetree => tree(label => paragraph, lhs => X, rhs => Y)),
  75.     X:s(anaphora_in => A, anaphora_out => B),
  76.     moreps(anaphora_in => B, anaphora_out => C, parsetree => Y)).
  77.  
  78. grammar_rule([],
  79.     moreps(anaphora_in => A, anaphora_out => B,
  80.           parsetree => tree(label => moreps, lhs => X, rhs => Y)),
  81.     X:[],
  82.     paragraph(anaphora_in => A, anaphora_out => B, parsetree => Y)).
  83.     
  84. grammar_rule2(@,
  85.     s(form => X, parsetree => Y, anaphora_in => A, anaphora_out => B),
  86.     ss(form => X, parsetree => Y, anaphora_in => A, anaphora_out => B)).
  87.  
  88. grammar_rule(@,
  89.     s(form => conj(form => Z), anaphora_in => A, anaphora_out => C,
  90.       parsetree => tree(label => s, lhs => X, rhs => Y)),
  91.     ss(parsetree => X, form => Z, anaphora_in => A, anaphora_out => B),
  92.     cs(parsetree => Y, form => Z, anaphora_in => B, anaphora_out => C)).
  93.     
  94. grammar_rule(sconj,
  95.     cs(form => Z, parsetree => tree(label => cs, lhs => X, rhs => Y),
  96.        anaphora_in => A, anaphora_out => B),
  97.     X:sconj,
  98.     s(parsetree => Y, form => Z, anaphora_in => A, anaphora_out => B)).
  99.     
  100. grammar_rule({art;n;adj;pn;pron},
  101.     ss(form => statement, anaphora_in => A, anaphora_out => C,
  102.        parsetree => tree(label => ss, lhs => X, rhs => Y)),
  103.     np(number => N, class=>T, anaphora_in => A, anaphora_out => B, parsetree => X),
  104.     vp(number => N, subject=>T, anaphora_in =>B, anaphora_out => C, parsetree => Y)).
  105.  
  106. grammar_rule2({iv;tv},
  107.     ss(form => command, anaphora_in => A, anaphora_out => B,
  108.        parsetree => tree(label => ss, lhs => [you], rhs => X)),
  109.     vp(subject => you, tense => present, number => plural, parsetree => X,
  110.        anaphora_in => A, anaphora_out => B)).
  111.  
  112. grammar_rule(adv,
  113.     ss(form => statement, anaphora_in => A, anaphora_out => B,
  114.        parsetree => tree(label => ss, lhs => X, rhs => Y)),
  115.     X:adv,
  116.     ss(parsetree => Y, anaphora_in => A, anaphora_out => B)).
  117.  
  118. grammar_rule(modal,
  119.     ss(form => modal_question, anaphora_in => A, anaphora_out => C,
  120.        parsetree => tree(label => ss, lhs => X, rhs => Y)),
  121.     mnp(class=>S, parsetree => X, anaphora_in => A, anaphora_out => B),
  122.     vp(number => plural, tense => present, subject=>S, parsetree => Y,
  123.           anaphora_in => B, anaphora_out => C)).
  124.  
  125. grammar_rule2(interj,
  126.     ss(form => interj, parsetree => tree(label => ss, lhs => X),
  127.            anaphora_in => A, anaphora_out => A),
  128.     X:interj).
  129.  
  130. grammar_rule(interj,
  131.     ss(form => interj, parsetree => tree(label => ss, lhs => X, rhs => Y),
  132.        anaphora_in => A, anaphora_out => B),
  133.     X:interj, 
  134.     s(parsetree => Y, anaphora_in => A, anaphora_out => B)).
  135.  
  136. grammar_rule(modal,
  137.     mnp(class => T, parsetree => tree(label => np, rhs => X, lhs => Y),
  138.            anaphora_in => A, anaphora_out => B),
  139.     X:modal,
  140.     snp(class => T, parsetree => Y, anaphora_in => A, anaphora_out => B)).
  141.  
  142. grammar_rule2({art;adj;n;pn;pron},
  143.     np(number => N, class => T, parsetree => tree(label => np, lhs => X),
  144.        anaphora_in => A, anaphora_out => B),
  145.     snp(number => N, class => T, parsetree => X,
  146.         anaphora_in => A, anaphora_out => B)).
  147.     
  148. grammar_rule({art;adj;n;pn;pron},
  149.     np(number => @, class => @, anaphora_in => A, anaphora_out => C,
  150.        parsetree => tree(label => np, lhs => X, rhs => Y)),
  151.     snp(parsetree => X, anaphora_in => A, anaphora_out => B),
  152.     cnp(parsetree => Y, anaphora_in => B, anaphora_out => C)).
  153.  
  154. grammar_rule(art,
  155.     snp(number => N, class => T, anaphora_in => A, anaphora_out => B,
  156.         parsetree => tree(label => snp, lhs => X, rhs => Y)),
  157.     X:art(number => N),
  158.     ssnp(number => N, class => T, parsetree => Y, anaphora_in => A, 
  159.          anaphora_out => B)).
  160.  
  161. grammar_rule2({adj;n},
  162.     snp(number => N, class => T, anaphora_in => A, anaphora_out => B,
  163.         parsetree => tree(label => snp, lhs => X)),
  164.     ssnp(number => N, class => T, parsetree => X, anaphora_in => A, 
  165.         anaphora_out => B)).
  166. % N should be plural above, but breaks eating function calls then.
  167.  
  168. grammar_rule2(pn,
  169.     snp(number => N, class => T, anaphora_in => A, anaphora_out => [X|A],
  170.         parsetree => tree(label => snp, lhs => X)),
  171.     X:pn(number => N, class => T)).
  172.     
  173. grammar_rule2(pron,
  174.     snp(number => N, class => T, anaphora_in => A, anaphora_out => A,
  175.         parsetree => tree(label => snp, lhs => Anaphor)),
  176.     pron(number => N, gender => G, class => T)) :-
  177.    member(Anaphor:@(number => N, gender => G, class => T), A).
  178.     
  179. grammar_rule2(n, 
  180.     ssnp(number => N, class => T, anaphora_in => A, anaphora_out => [X|A],
  181.          parsetree => tree(label => ssnp, lhs => X)),
  182.     X:n(number => N, class => T)).
  183.  
  184. grammar_rule(n,
  185.     ssnp(number=>N, class => T, anaphora_in => A, anaphora_out => B,
  186.          parsetree => tree(label => ssnp, lhs => X, rhs => Y)),
  187.     X:n(number=>N, class => T),
  188.     pp(parsetree => Y, anaphora_in => [X|A], anaphora_out => B)).
  189.  
  190. grammar_rule(adj,
  191.     ssnp(number => N, class => T, anaphora_in => A, anaphora_out => B,
  192.          parsetree => tree(label => ssnp, lhs => X, rhs => Y)),
  193.     X:adj, 
  194.     ssnp(number=>N, class => T, parsetree => Y, anaphora_in => A,
  195.              anaphora_out => B)).
  196.  
  197. grammar_rule(conj,
  198.     cnp(parsetree => tree(label => cnp, lhs => X, rhs => Y),
  199.         anaphora_in => A, anaphora_out => B),
  200.     X:conj,
  201.     np(parsetree => Y, anaphora_in => A, anaphora_out => B)).
  202.  
  203. grammar_rule2({iv;tv;modal;adv},
  204.     vp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => B,
  205.        parsetree => tree(label => vp, lhs => X)),
  206.     svp(number => N, subject => S, tense => T, parsetree => X, anaphora_in => A, 
  207.             anaphora_out => B)).
  208.  
  209. grammar_rule({iv;tv;modal;adv},
  210.     vp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => C,
  211.        parsetree => tree(label => vp, lhs => X, rhs => Y)),
  212.     svp(parsetree => X, number => N, subject => S, tense => T, 
  213.         anaphora_in => A, anaphora_out => B),
  214.     cvp(parsetree => Y, number => N, subject => S, tense => T,
  215.         anaphora_in => B, anaphora_out => C)).
  216.  
  217. grammar_rule2(iv,
  218.     svp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => A,
  219.         parsetree => tree(label => svp, lhs => X)),
  220.     X:iv(number => N, subject => S, tense => T)).
  221.  
  222. grammar_rule(iv,
  223.     svp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => B,
  224.         parsetree => tree(label => svp, lhs => X, rhs => Y)),
  225.     X:iv(number => N, subject => S, tense => T),
  226.     pp(parsetree => Y, anaphora_in => A, anaphora_out => B)).
  227.  
  228. grammar_rule(iv,
  229.     svp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => A,
  230.         parsetree => tree(label => svp, lhs => X, rhs => Y)),
  231.     X:iv(number => N, subject => S, tense => T),
  232.     Y:adv).
  233.  
  234. grammar_rule(tv,
  235.     svp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => B,
  236.         parsetree => tree(label => svp, lhs => X, rhs => Y)),
  237.     X:tv(number => N, subject => S, object => O, tense => T),
  238.     np(class=>O, parsetree => Y, anaphora_in => A, anaphora_out => B)).
  239.  
  240. grammar_rule(modal,
  241.     svp(number => @, subject => S, tense => modal, anaphora_in => A, 
  242.             anaphora_out => B,
  243.         parsetree => tree(label => svp, lhs => X, rhs => Y)),
  244.     X:modal,
  245.     svp(subject => S, number => plural, tense => present, parsetree => Y,
  246.             anaphora_in => A, anaphora_out => B)).
  247.  
  248. grammar_rule(adv,
  249.     svp(number => N, subject => S, anaphora_in => A, 
  250.             anaphora_out => B,
  251.         parsetree => tree(label => svp, lhs => X, rhs => Y)),
  252.     X:adv,
  253.     svp(subject => S, number => N, tense => past, parsetree => Y,
  254.             anaphora_in => A, anaphora_out => B)).
  255.  
  256. grammar_rule(tv,
  257.     svp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => B,
  258.         parsetree => tree(label => svp, lhs => X, rhs => Y)),
  259.     X:tv(number => N, subject => S, object=>O, tense => T),
  260.     ppandnp(class=>O, parsetree => Y, anaphora_in => A, anaphora_out => B)).
  261.  
  262. grammar_rule(prep,
  263.     ppandnp(class => S, anaphora_in => A, anaphora_out => C,
  264.             parsetree => tree(label => ppandnp, lhs => X, rhs => Y)),
  265.     pp(parsetree => X, anaphora_in => A, anaphora_out => B),
  266.     np(class => S, parsetree => Y, anaphora_in => B, anaphora_out => C)).
  267.  
  268. grammar_rule(conj,
  269.     cvp(number => N, subject => S, tense => T, anaphora_in => A, anaphora_out => B,
  270.         parsetree => tree(label => cvp, lhs => X, rhs => Y)),
  271.     X:conj,
  272.     vp(parsetree => Y, number => N, subject => S, tense => T,
  273.         anaphora_in => A, anaphora_out => B)).
  274.  
  275. grammar_rule(prep, 
  276.     pp(parsetree => tree(label => pp, lhs => X, rhs => Y,
  277.            anaphora_in => A, anaphora_out => B)),
  278.     X:prep,
  279.     np(parsetree => Y, anaphora_in => A, anaphora_out => B)).
  280.  
  281. % The Lexicon:
  282.  
  283. dictionary(flu, n(number => singular, class => disease)).
  284. dictionary(malaria, n(number => singular, class => human_disease)).
  285. dictionary(frisbee, n(number => singular, class => frisbee)).
  286. dictionary(monk, n(number => singular, class => human(eating_habit => vegetarian))).
  287. dictionary(monks, n(number => plural, class => human(eating_habit => vegetarian))).
  288. dictionary(lunch, n(number => singular, class => food)).
  289. dictionary(lunches, n(number => plural, class => food)).
  290. dictionary(steak, n(number => singular, class => meat)).
  291. dictionary(steaks, n(number => plural, class => meat)).
  292. dictionary(salad, n(number => singular, class => vegetable)).
  293. dictionary(file, n(number => singular, class => information)).
  294. dictionary(files, n(number => plural, class => information)).
  295. dictionary(compiler, n(number => singular, 
  296.                class => code(eating_habit => comp))).
  297. dictionary(pascal, n(number => singular, 
  298.                class => code(eating_habit => comp))).
  299. dictionary(computer, n(number => singular, 
  300.                class => computer(eating_habit => comp))).
  301. dictionary(computers, n(number => plural, 
  302.             class => computer(eating_habit => comp))).
  303.  
  304. dictionary(mary, pn(number => singular, gender => female, 
  305.             class => human(eating_habit => omnivore))).
  306. dictionary(john, pn(number => singular, gender => male,
  307.             class => human(eating_habit => omnivore))).
  308. dictionary(pascal, pn(number => singular, gender => male,
  309.               class => human(eating_habit => omnivore))).
  310. dictionary(spot, pn(number => singular, 
  311.            class => dog(eating_habit => carnivore))).
  312. dictionary(life, pn(number => singular, gender => neuter,
  313.            class => code(eating_habit => comp))).
  314.  
  315. dictionary(she, pron(number => singular, gender => female, class => human)).
  316. dictionary(he, pron(number => singular, gender => male, class => human)).
  317. dictionary(it, pron(number => singular, gender => male, class => {inanimate;inhuman})).
  318.  
  319. dictionary(walks, iv(subject => animate, number => singular, tense => present)).
  320. dictionary(walk, iv(subject => animate, number => plural, tense => present)).
  321. dictionary(walked, iv(subject => animate, tense => past)).
  322. dictionary(runs, iv(subject => animate, number => singular, tense => present)).
  323. dictionary(run, iv(subject => animate, number => plural, tense => present)).
  324. dictionary(ran, iv(subject => animate, tense => past)).
  325. dictionary(compile, iv(subject => animate, number => plural, tense => present)).
  326. dictionary(compiles, iv(subject => animate, number => singular, tense => present)).
  327. dictionary(compiled, iv(subject => animate, tense => past)).
  328.  
  329. dictionary(compile, tv(subject => animate, number => plural, object => file,
  330.                tense => present)).
  331. dictionary(compiles, tv(subject => animate, number => singular, object => file,
  332.             tense => present)).
  333. dictionary(compiled, tv(subject => animate, object => file, tense => past)).
  334. dictionary(delete, tv(subject => animate, number => plural, object => file,
  335.                tense => present)).
  336. dictionary(deletes, tv(subject => animate, number => singular, object => file,
  337.                tense => present)).
  338. dictionary(deleted, tv(subject => animate, object => file, tense => past)).
  339. dictionary(eat, tv(subject => animate(eating_habit => EH), 
  340.             object => {food;information} & eaten_by(EH),
  341.             number => plural, tense => present)).
  342. dictionary(eats, tv(subject => animate(eating_habit => EH),
  343.             object => {food;information} & eaten_by(EH),
  344.             number => singular, tense => present)).
  345. dictionary(ate, tv(subject => animate(eating_habit => EH), 
  346.             object => {food;information} & eaten_by(EH),
  347.             tense => past)).
  348. dictionary(catch, tv(subject => animate & can_catch(Y),
  349.                      object => Y:{projectile; disease},
  350.              number => plural, tense => present)).
  351. dictionary(catches, tv(subject => animate & can_catch(Y),
  352.                        object => Y:{projectile; disease},
  353.                number => singular, tense => present)).
  354. dictionary(caught, tv(subject => animate & can_catch(Y),
  355.                        object => Y:{projectile; disease},
  356.                tense => past)).
  357.  
  358. dictionary(my, art(class => human)).
  359. dictionary(her, art(class => human)).
  360. dictionary(his, art(class => human)).
  361. dictionary(its, art).
  362. dictionary(the, art).
  363. dictionary(a, art(number => singular)).
  364. dictionary(some, art(number => plural)).
  365. dictionary(many, art(number => plural)).
  366.  
  367. dictionary(small, adj).
  368. dictionary(big, adj).
  369. dictionary(fast, adj).
  370. dictionary(slow, adj).
  371. dictionary(bad, adj).
  372. dictionary(good, adj).
  373.  
  374. dictionary(did, modal).
  375. dictionary(should, modal).
  376. dictionary(could, modal).
  377. dictionary(would, modal).
  378. dictionary(can, modal).
  379. dictionary(will, modal).
  380.  
  381. dictionary(and, conj).
  382. dictionary(or, conj).
  383.  
  384. dictionary(and, sconj).
  385. dictionary(but, sconj).
  386. dictionary(or, sconj).
  387.  
  388. dictionary(slowly, adv).
  389. dictionary(quickly, adv).
  390. dictionary(correctly, adv).
  391.  
  392. dictionary(in, prep).
  393. dictionary(over, prep).
  394. dictionary(from, prep).
  395. dictionary(of, prep).
  396. dictionary(to, prep).
  397. dictionary(who, prep).
  398. dictionary(with, prep).
  399. dictionary(which, prep).
  400.  
  401. dictionary(what, wh_word).
  402. dictionary(when, wh_word).
  403. dictionary(why, wh_word).
  404. dictionary(who, wh_word).
  405. dictionary(how, wh_word).
  406.  
  407. dictionary(hey, interj).
  408. dictionary(how, interj).
  409. dictionary(why, interj).
  410. dictionary(yes, interj).
  411. dictionary(no, interj).
  412.  
  413. dictionary([], []).
  414.  
  415. lookup([], []).
  416. lookup([Word|Rest], [Def|More]) :-
  417.     dictionary(Word, Def),
  418.     lookup(Rest, More).
  419.  
  420.