poole@CPSC-M-POOLE01 ch15 % cd ~/World/cs312/2024/prolog poole@CPSC-M-POOLE01 prolog % swipl Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit https://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- [bstreec]. true. ?- val(4,d,T), val(1,a,T), val(2,b,T), val(1,V,T). T = bnode(4, d, bnode(1, a, _, bnode(2, b, _, _)), _), V = a ; T = bnode(4, d, bnode(1, a, _, bnode(_A, _, bnode(2, b, _, _), _)), _), V = a, _A in 3..sup . ?- val(K,V,bnode(2,22, bnode(1,57,empty,empty), | bnode(5,105,empty,empty))), V #< 99. K = 2, V = 22 ; K = 1, V = 57 ; false. ?- V #< 99, val(K,V,bnode(2,22, | bnode(1,57,empty,empty), | bnode(5,105,empty,empty))). V = 22, K = 2 ; V = 57, K = 1 ; false. ?- append([a,b,c],R,L), append([1,2,3],S,R). R = [1, 2, 3|S], L = [a, b, c, 1, 2, 3|S]. ?- R = [1, 2, 3|S], L=[a,b,c|R]. R = [1, 2, 3|S], L = [a, b, c, 1, 2, 3|S]. ?- [geography_CFG]. ERROR: /Users/poole/World/cs312/2024/prolog/geography_CFG.pl:50:15: Syntax error: Illegal start of term true. ?- [geography_CFG]. true. ?- noun_phrase(["a", "country", "that", "borders", "Chile"], L2). L2 = [] ; L2 = ["that", "borders", "Chile"] ; L2 = [] ; L2 = ["that", "borders", "Chile"] ; L2 = ["country", "that", "borders", "Chile"]. ?- ^D % halt poole@CPSC-M-POOLE01 prolog % swipl Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit https://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- [geography_DB]. true. ?- [geography_CFG]. true. ?- noun_phrase(["a", "Spanish", "speaking", "country", "that", "borders", "Chile"], L3). L3 = [] ; L3 = ["that", "borders", "Chile"] ; L3 = [] ; L3 = ["that", "borders", "Chile"] ; L3 = [] ; L3 = ["that", "borders", "Chile"] ; L3 = [] ; L3 = ["that", "borders", "Chile"] ; L3 = ["speaking", "country", "that", "borders", "Chile"] . ?- ^D % halt poole@CPSC-M-POOLE01 prolog % swipl Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit https://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- [geography_QA]. true. ?- q(Ans). Ask me: What is the name of the capital of a Spanish speaking country that borders Argentina? Ans = "Santiago" ; Ans = "AsunciĆ³n" ; No more answers Ask me: q. false. ?- noun_phrase(["a", "Spanish", "speaking", "country"], L1, I1). L1 = [], I1 = argentina ; L1 = [], I1 = chile ; L1 = [], I1 = paraguay ; L1 = [], I1 = peru ; L1 = ["speaking", "country"], I1 = spanish ; false. ?- noun_phrase(["a", "country", "that", "borders", "Chile"], L2, I2). L2 = [], I2 = argentina ; L2 = ["that", "borders", "Chile"], I2 = argentina ; L2 = ["that", "borders", "Chile"], I2 = brazil ; L2 = ["that", "borders", "Chile"], I2 = chile ; L2 = ["that", "borders", "Chile"], I2 = paraguay ; L2 = [], I2 = peru ; L2 = ["that", "borders", "Chile"], I2 = peru ; false. ?- noun_phrase(["Chile", "rest"], L2, I2). L2 = ["rest"], I2 = chile. ?- noun_phrase(["a","country","bordering","Chile"], L2, I2). L2 = [], I2 = argentina ; L2 = ["bordering", "Chile"], I2 = argentina ; L2 = ["bordering", "Chile"], I2 = brazil ; L2 = ["bordering", "Chile"], I2 = chile ; L2 = ["bordering", "Chile"], I2 = paraguay ; L2 = [], I2 = peru ; L2 = ["bordering", "Chile"], I2 = peru ; false. ?- noun_phrase(["a","country","bordering","Chile"], [], I2). I2 = argentina ; I2 = peru ; false. ?- noun_phrase(["a","country","bordering","Chile","bordering","Brazil"], [], I2). false. ?- noun_phrase(["a","country","bordering","Chile","bordering","Brazil"], R, I2). R = ["bordering", "Brazil"], I2 = argentina ; R = ["bordering", "Chile", "bordering", "Brazil"], I2 = argentina . ?- noun_phrase(["a","country","bordering","a", "country","bordering","Brazil"], R, I2). R = ["bordering", "Brazil"], I2 = argentina ; R = [], I2 = argentina ; R = ["bordering", "Brazil"], I2 = argentina ; R = ["bordering", "Brazil"], I2 = argentina . ?-