home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / pdprolog / atnbld.pro < prev    next >
Text File  |  1986-05-05  |  4KB  |  117 lines

  1. /*        PROGRAM TO BUILD PRIMARY AUGMENTED TRANSISTION NETWORK
  2.  
  3.                                 ATNBLD.PRO
  4.  
  5.                                  11/24/85
  6.  
  7. */
  8.  
  9.  
  10. /*  Build is the entry point into the program.  It requires that the
  11. program with standard routines and the program node, which is empty, have
  12. already been consulted.  */
  13.  
  14. /*  The program requests the start and terminal nodes, the paths and
  15. transistion conditions, then establishes a node program with a name
  16. specified by the user.  */
  17.  
  18. /*  Ret removes any data from memory which might iterfere with network
  19. construction.  Term([],[]) is required to prevent failure when checkint
  20. terminal conditions.  Qend identifies all nodes for which there is a path
  21. to a terminal node.  The start node is identified initially since the
  22. program will require this path be completed before any other can be
  23. constructed.  Termnode accepts the terminal nodes.  Flow accepts the
  24. transition arcs and conditions.  */
  25.  
  26.  
  27. build :- batch,ret(qend),nl,ret(arc),nl,ret(term),asserta(term([],[])),
  28.          nl,print('Enter the start node: '),read(Q0),
  29.          asserta(qend(Q0)),termnode,flow(Q0).
  30.  
  31.  
  32. termnode :-  print('Enter the next terminal node or the word done: '),
  33.              read(QT),
  34.              not(QT=done),
  35.              termck(QT),
  36.              assertfa(node,term(QT,[])),
  37.              asserta(qend(QT)),
  38.              termnode.
  39.  
  40. termnode  :-  !,true.
  41.  
  42.  
  43. /*  Flow requests transistions from node to node and adds each arc and new
  44. node to the database.  Qendck will continue to call flow until such time as
  45. a terminal node has been reached then allow a new path to be initiated.  */
  46.  
  47.  
  48.  
  49. flow(Q0)  :- nl,print('Transisition from ',Q0,' to ? '),read(Qnext),
  50.              print(' on condition ? '),read(Con),
  51.              con(Q0,Con),arcck(Q0,Qnext,Con),
  52.              assertfz(node,arc(Q0,Qnext,Con)),
  53.              qendck(Q0,Qnext).
  54.  
  55. con(Q0,Con) :- condition(Con).
  56.  
  57. con(Q0,Con) :- nl,print(Con,' is an invalid condition. '),
  58.                flow(Q0).
  59.  
  60. termck(Qt)  :-  not(term(Qt,[]));
  61.                 nl,print('Terminal node ',Qt,' already entered'),nl.
  62.  
  63. arcck(Q0,Qn,Z)  :-  not(arc(Q0,Qn,Z));
  64.                     nl,print('Arc from ',Q0,' to ',Qn,' on ',Z,' exits.').
  65.  
  66. qendck(Q0,Qnext)  :-  qend(Qnext),(qend(Q0);asserta(qend(Q0))),nextnode.
  67.  
  68. qendck(Q0,Qnext)  :-  (qend(Q0);asserta(qend(Q0))),flow(Qnext).
  69.  
  70.  
  71. /*  Nextnode allows a new path to be initiated or the program to be
  72. terminated.  Before termination it calls pthck to insure there is a path to
  73. each terminal node.  Checkstart prevents an isolated node from being
  74. entered.  */
  75.  
  76.  
  77.  
  78. nextnode :-  nl,print('Enter next start node or the word done ? '),
  79.              read(Ns),
  80.              not(Ns=done),
  81.              ((checkstart(Ns),
  82.              flow(Ns));nextnode).
  83.  
  84.  
  85. nextnode :-  pthck,
  86.              !,retract(term([],[])),
  87.              nl,print('Network completed'),
  88.              listing(arc),listing(term),
  89.              nl,print('Enter name of new ATN file '),read(S),
  90.              update(node,S).
  91.  
  92.  
  93. nextnode :-  nextnode.
  94.  
  95.  
  96. pthck   :-    term(Q,[]),not(Q=[]),not(arc(_,Q,_)),
  97.               nl,print('No path to terminal node ',Q),
  98.               !,fail.
  99.  
  100. pthck    :-  term([],[]).
  101.  
  102.  
  103. checkstart(Ns) :-  qend(Ns);
  104.                    nl,print(Ns,' is an invalid node '),fail.
  105.  
  106.  
  107. /*  Condition lists the acceptable conditions for a transistion.   */
  108.  
  109.  
  110. condition(verb).
  111. condition(noun).
  112. condition(aux).
  113. condition(prep).
  114. condition(aux).
  115. condition(pp).
  116. condition(np).
  117.