2003-04-02 14:57:50 +01:00
|
|
|
=================================================================
|
|
|
|
Logtalk - Object oriented extension to Prolog
|
2004-03-03 04:07:59 +00:00
|
|
|
Release 2.16.0
|
2003-04-02 14:57:50 +01:00
|
|
|
|
2004-02-09 14:18:27 +00:00
|
|
|
Copyright (c) 1998-2004 Paulo Moura. All Rights Reserved.
|
2003-04-02 14:57:50 +01:00
|
|
|
=================================================================
|
|
|
|
|
|
|
|
|
|
|
|
% DCG rules implementing a simple calculator:
|
|
|
|
|
|
|
|
| ?- calculator::parse("1+2-3*4", Result).
|
|
|
|
|
|
|
|
Result = -9
|
|
|
|
yes
|
|
|
|
|
|
|
|
|
|
|
|
% recognizing gramatically correct sentences
|
|
|
|
|
|
|
|
| ?- sentence::parse([the, girl, likes, the, boy], Result).
|
|
|
|
|
|
|
|
Result = true
|
|
|
|
yes
|
|
|
|
|
|
|
|
| ?- sentence::parse([the, girl, scares, the, boy], Result).
|
|
|
|
|
|
|
|
Result = false
|
|
|
|
yes
|
|
|
|
|
|
|
|
|
|
|
|
% generating parse trees for sentences
|
|
|
|
|
|
|
|
| ?- parsetree::parse([the, girl, likes, the, boy], Tree).
|
|
|
|
|
|
|
|
Tree = Tree = s(np(d(the), n(girl)), vp(v(likes), np(d(the), n(boy))))
|
|
|
|
yes
|
2003-07-09 01:20:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
% conversion between compound terms and XML
|
|
|
|
|
|
|
|
| ?- xml::convert(word(child, children), word(singular, plural), XML).
|
|
|
|
|
|
|
|
XML = '<word><singular>child</singular><plural>children</plural></word>'
|
|
|
|
yes
|
|
|
|
|
|
|
|
| ?- xml::convert(Term, Interpretation, '<word><singular>child</singular><plural>children</plural></word>').
|
|
|
|
|
|
|
|
Term = word(child, children)
|
|
|
|
Interpretation = word(singular, plural)
|
|
|
|
yes
|
|
|
|
|
|
|
|
|
|
|
|
% parsing URLs
|
|
|
|
|
|
|
|
| ?- url::parse("http://www.logtalk.org", Components).
|
|
|
|
|
|
|
|
Components = [protocol(http), address([www, logtalk, org]), path([]), file('')]
|
|
|
|
yes
|
|
|
|
|
|
|
|
| ?- url::parse("http://www.logtalk.org/", Components).
|
|
|
|
|
|
|
|
Components = [protocol(http), address([www, logtalk, org]), path(['']), file('')]
|
|
|
|
yes
|
|
|
|
|
|
|
|
| ?- url::parse("http://www.logtalk.org/cvs", Components).
|
|
|
|
|
|
|
|
Components = [protocol(http), address([www, logtalk, org]), path([cvs]), file('')]
|
|
|
|
yes
|
|
|
|
|
|
|
|
| ?- url::parse("http://www.logtalk.org/cvs.html", Components).
|
|
|
|
|
|
|
|
Components = [protocol(http), address([www, logtalk, org]), path([]), file('cvs.html')]
|
|
|
|
yes
|
|
|
|
|
|
|
|
| ?- url::parse("http://193.136.64.5/files/update", Components).
|
|
|
|
|
|
|
|
Components = [protocol(http), address([193, 136, 64, 5]), path([files, update]), file('')]
|
|
|
|
yes
|