In my previous post, I introduced AI::Prolog, a Prolog engine written in Perl. AI::Prolog is easy to use; however, the speed may be not satisfying. Language::Prolog::Yaswi refers to Yet Another interface to SWI-Prolog; the performance of Language::Prolog::Yaswi is better than that of AI::Prolog.
Before using Yaswi, You need a SWI-Prolog complier in your system. You can get it from SWI-Prolog website.
First, you need to write a Prolog knowledge base. You may write it in the Perl script of in a seperated file. Say we have a knowledge base file train.pro.
Second, you have to load the knowledge base. In this case, we also load :query for later use.
If you want to directly write your knowledge base into the Perl script, use swi_inline.
Then, you can query the knowledge base. The query are wrapped by Language::Prolog::Sugar. Therefore, you may follow the document there. Finally, print out the result.
For extra credit, I write a Perl script to compare the performance difference between Language::Prolog::Yaswi and AI::Prolog. Obviously, the former outperforms the latter much.