diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-01-15 14:19:48 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-01-15 14:19:48 (GMT) |
commit | 333348d70b9cb6dab149ff57bdf9345cdee9e0ef (patch) | |
tree | 01a062266363c30355833217e712aed2c332c454 /test | |
parent | a0013f1457494b00f2caca1eb4f23a3475be2259 (diff) | |
download | uscxml-333348d70b9cb6dab149ff57bdf9345cdee9e0ef.zip uscxml-333348d70b9cb6dab149ff57bdf9345cdee9e0ef.tar.gz uscxml-333348d70b9cb6dab149ff57bdf9345cdee9e0ef.tar.bz2 |
Started prolog datamodel
Diffstat (limited to 'test')
-rw-r--r-- | test/samples/uscxml/prolog/likes.pl | 38 | ||||
-rw-r--r-- | test/samples/uscxml/test-prolog.scxml | 11 | ||||
-rw-r--r-- | test/src/test-prolog-swi.cpp | 72 |
3 files changed, 102 insertions, 19 deletions
diff --git a/test/samples/uscxml/prolog/likes.pl b/test/samples/uscxml/prolog/likes.pl new file mode 100644 index 0000000..22395ed --- /dev/null +++ b/test/samples/uscxml/prolog/likes.pl @@ -0,0 +1,38 @@ +%% Demo coming from http://clwww.essex.ac.uk/course/LG519/2-facts/index_18.html +%% +%% Please load this file into SWI-Prolog +%% +%% Sam's likes and dislikes in food +%% +%% Considering the following will give some practice +%% in thinking about backtracking. +%% ?- likes(sam,dahl). +%% ?- likes(sam,chop_suey). +%% ?- likes(sam,pizza). +%% ?- likes(sam,chips). +%% ?- likes(sam,curry). + +likes(sam,Food) :- + indian(Food), + mild(Food). +likes(sam,Food) :- + chinese(Food). +likes(sam,Food) :- + italian(Food). +likes(sam,chips). + +indian(curry). +indian(dahl). +indian(tandoori). +indian(kurma). + +mild(dahl). +mild(tandoori). +mild(kurma). + +chinese(chow_mein). +chinese(chop_suey). +chinese(sweet_and_sour). + +italian(pizza). +italian(spaghetti). diff --git a/test/samples/uscxml/test-prolog.scxml b/test/samples/uscxml/test-prolog.scxml index 75a1c64..85d45bc 100644 --- a/test/samples/uscxml/test-prolog.scxml +++ b/test/samples/uscxml/test-prolog.scxml @@ -1,14 +1,19 @@ <scxml datamodel="prolog" initial="start" binding="late"> <datamodel> - <data id="facts"> + <!-- data id="facts"> cat(tom). animal(X):- cat(X). - </data> + </data --> + <data id="likes" src="prolog/likes.pl" /> </datamodel> - <script> + <!-- script> cat(tom). cat(X). animal(X). + </script --> + <script> + likes(sam,curry). + likes(sam,chips). </script> <state id="start"> </state> diff --git a/test/src/test-prolog-swi.cpp b/test/src/test-prolog-swi.cpp index 85815f5..5fa1cb4 100644 --- a/test/src/test-prolog-swi.cpp +++ b/test/src/test-prolog-swi.cpp @@ -1,20 +1,60 @@ -#include "uscxml/Interpreter.h" -#include "uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h" +#include <iostream> +#include <SWI-Prolog.h> +#include <SWI-cpp.h> -int main(int argc, char** argv) { - if (argc != 2) { - std::cerr << "Expected path to test-prolog.scxml" << std::endl; - exit(EXIT_FAILURE); - } +using namespace std; - using namespace uscxml; - using namespace Arabica::DOM; - using namespace Arabica::XPath; +int main(void){ + + static char * av[] = { + "/Users/sradomski/Documents/TK/Code/uscxml/contrib/prebuilt/darwin-i386/clang/lib/swipl-6.3.5/bin/x86_64-darwin12.2.0/swipl", +// "--quiet", +// "-s", +// "/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl", + NULL}; + if( ! PL_initialise(1,av)){ + cout<<"error initializing"<<endl; + PL_halt(1); + }else { + cout<<"success initializing!"<<endl; + } + +// unsigned long fid = PL_open_foreign_frame(); - uscxml::Factory::pluginPath = "/Users/sradomski/Documents/TK/Code/uscxml/build/xcode/lib"; - Interpreter* scxml = Interpreter::fromURI(argv[1]); -// scxml->start(); -// scxml->join(); -// tthread::this_thread::sleep_for(tthread::chrono::milliseconds(500)); + int rval; + PlFrame frame; + rval = PlCall("system", "load_files", PlTermv("/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl")); + PlQuery query("user", "likes", PlTermv("sam", "chips")); + if (query.next_solution() > 0) { + std::cout << "Yes!" << std::endl; + } else { + std::cout << "No!" << std::endl; + } -}
\ No newline at end of file + PlQuery q("call", PlTermv(PlCompound("likes(sam,curry).")) + +// PlCompound compound("likes(sam,curry)."); +// PlQuery query2(compound.name(), PlTermv(compound)); +// if (query2.next_solution() > 0) { +// std::cout << "Yes!" << std::endl; +// } else { +// std::cout << "No!" << std::endl; +// } + +// std::cout << compound.name() << std::endl; +// PlTermv filename("/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl"); +// PlQuery loadFiles("system", "load_files", filename); + +// predicate_t loadFiles = PL_predicate("load_files",1,"system"); +// term_t h0 = PL_new_term_refs(1); + +// int rval; +// const char * expression = "/Users/sradomski/Documents/TK/Code/pl-devel/demo/likes.pl"; +// PL_put_atom_chars(h0,expression); +// rval = PL_call_predicate(NULL, PL_Q_NORMAL, loadFiles, h0); + +// PL_halt( rval ? 0 : 1 ); + +// PL_close_foreign_frame(fid); + return 0; +} |