GithubHelp home page GithubHelp logo

swi-prolog / pengines Goto Github PK

View Code? Open in Web Editor NEW
56.0 21.0 16.0 3 MB

Pengine and Prolog scratchpad

License: BSD 2-Clause "Simplified" License

Prolog 10.59% CSS 5.23% HTML 61.71% JavaScript 22.47%

pengines's Introduction

A Prolog Engine application server

This repository provides a demo application server for the SWI-Prolog pengines package. An online version of this server is available at http://pengines.swi-prolog.org.

The application server currently hosts two applications:

  • Scratchpad allows you to create interactive web applications that query Prolog. This demonstrates how pengines are supposed to be used: Prolog acts as a modular query language, while JavaScript handles the results of Prolog queries to vizualise the result.

  • SWISH provides a Prolog environment for trying Prolog, teaching, make a piece of code available for inspection to others, collaboratively solve a problem, etc. SWISH runs also as a stand-alone server

Local installation installation

Running this software typically requires the latest development version of SWI-Prolog. After cloning the pengines repository, the server can be started by loading run.pl into SWI-Prolog. On MS-Windows, this implies opening run.pl in the explorer. On Unix systems, run

swipl run.pl

By default, only Scratchpad is available. See below for adding SWISH.

Installing SWISH locally

First, add the swish submodule by running this command

git submodule update --init

Next, install bower for your platform, go to the directory apps/swish and run

bower install
make src

Finally, restart the pengines server.

Docker

A Docker file is available from https://github.com/ninjarobot/pengines-dockerfile

pengines's People

Contributors

felixbb avatar janwielemaker avatar sebgod avatar torbjornlager avatar triska avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pengines's Issues

Pengines website down

Browsing to http://pengines.swi-prolog.org/

Produces the following error message:

Internal server error

I/O error in write on stream <stream>(0x7fc0ac0293e0) (Disk quota exceeded)
In:
[12] format(<stream>(0x7fc0ac0293e0),'/*~s*/ request(~q, ~3f, ~q).~n',["Fri Apr 21 11:33:43 2017"|...])
[9] broadcast:broadcast(http(...)) at /usr/lib/swi-prolog/library/broadcast.pl:118
[8] httpd_wrapper:call_handler(http_unix_daemon:http_dispatch,23463,[...|...]) at /usr/lib/swi-prolog/library/http/http_wrapper.pl:299
[7] catch(httpd_wrapper: ...,error(...,...),httpd_wrapper:true) at /usr/lib/swi-prolog/boot/init.pl:274
[6] httpd_wrapper:handler_with_output_to(http_unix_daemon:http_dispatch,23463,[...|...],current_output,error(...,...)) at /usr/lib/swi-prolog/library/http/http_wrapper.pl:280
[5] httpd_wrapper:handler_with_output_to(http_unix_daemon:http_dispatch,23463,[...|...],<stream>(0x7fc07409cdc0),error(...,...)) at /usr/lib/swi-prolog/library/http/http_wrapper.pl:290
[4] httpd_wrapper:http_wrapper(http_unix_daemon:http_dispatch,<stream>(0x7fc07409c3a0),<stream>(0x7fc07409c4d0),_G4666,[...|...]) at /usr/lib/swi-prolog/library/http/http_wrapper.pl:106
[3] thread_httpd:http_process(http_unix_daemon:http_dispatch,<stream>(0x7fc07409c3a0),<stream>(0x7fc07409c4d0),[...|...]) at /usr/lib/swi-prolog/library/http/thread_httpd.pl:717
[2] catch(thread_httpd: ...,_G4710,thread_httpd:true) at /usr/lib/swi-prolog/boot/init.pl:274
[1] thread_httpd:http_worker([...|...]) at /usr/lib/swi-prolog/library/http/thread_httpd.pl:540
[0] <meta call>

SWI-Prolog httpd at pengines

queens demo broken

The queens demo is broken it's not returning any data to handlesuccess, that's as far as I got

Add README and LICENCE

It would be nice to have a README.md file with the general purpose of this module as well as installation and usage instructions. I also couldn't find any information regarding the licence.

Simple JS functions on top of the Pengines JS API?

Food for thought: Maybe a couple of simple JS functions should be defined on top of the JS API? Here for example is a function that will populate a DOM element identified by idwith the answer(s) to goal:

function populate(template, goal, id) {
    var pengine = new Pengine({
        ask: goal,
        template: template,
        onsuccess: function() {
            document.getElementById(id).innerHTML = this.data[0]
        }
    });
    return pengine;
}

Test with:

p = populate("X", "member(X, [1,2,3])", "mydiv");
p.next();
p.next();

populate("Xs", "findall(X, member(X, [1,2,3]), Xs)", "mydid");

Seems mostly useful for deterministic queries and should perhaps support only those? If so, we can replace the line

ask: goal,

with

ask: "once((" + goal + "))",

and we don't need populate() to return anything.

Does pengines support DCG?

I have imported DCG library into my main prolog file, though i get "error:"instantiated_error", data:"Sandbox restriction". (i'm thinking it's because of using --> from DCG).

Does pengines recognize --> from DCG?

Create a library to add SWISH to your application

It is very simple to add a pengine server to your application. It would be nice if it was
about as easy to embed a SWISH shell into your application! We should keep that in
mind if we rethink the modularization of this code.

plDoc and whitelisting

It would be quite convenient if plDoc generated html included some indication of which predicates were whitelisted.

Visually, we distinguish predicate types with gold vs light blue vs dark blue, etc. - maybe some elaboration of this scheme, or some icons, could do it

Not sure what we do about their being potentially more than one application.
Nor am I sure what to do about things that are conditionally whitelisted.

method of pulling output is painful

Having the httpRequest for pull_response wait until there is some is painful.

See for example the code

          if (proof.getNearestInt("X") < 3) {  // change this to a larger number to see it hang
              // this hangs on the last proof
              // This is referred to in https://github.com/SWI-Prolog/pengines/issues/19
              String out = io.getOutput();
              if(out != null) {
                  System.out.println("I got " + out + " from the server");
              }
          }

in ManualAsk.java in JavaPengines.

Am I off in the weeds here, or is this just painful?

Portray to HTML

We need a way to make print/1, calling portray/1 to display terms as HTML instead of plain text. For example:

html_portray(Link) :-
    is_uri(Link),
    html(a(href(Link), Link).

http://pengines.swi-prolog.org/ internal error

The pengine site http://pengines.swi-prolog.org/ is defunct with this error:

Internal server error

I/O error in write on stream (0x7f1958025f60) (Disk quota exceeded)
In:
[12] format((0x7f1958025f60),'/~s/ request(~q, ~3f, ~q).~n',["Mon Jul 16 14:03:40 2018",235850|...])
[9] broadcast:broadcast('<garbage_collected>') at /usr/lib/swi-prolog/library/broadcast.pl:123
[8] httpd_wrapper:call_handler(http_unix_daemon:http_dispatch,235850,'<garbage_collected>') at /usr/lib/swi-prolog/library/http/http_wrapper.pl:319
[7] catch(httpd_wrapper:call_handler(...,235850,...),error(io_error(write,(0x7f1958025f60)),context(...,'Disk quota exceeded')),httpd_wrapper:true) at /usr/lib/swi-prolog/boot/init.pl:372
[6] httpd_wrapper:handler_with_output_to(http_unix_daemon:http_dispatch,235850,'<garbage_collected>',current_output,error(io_error(write,(0x7f1958025f60)),context(...,'Disk quota exceeded'))) at /usr/lib/swi-prolog/library/http/http_wrapper.pl:297
[5] httpd_wrapper:handler_with_output_to('<garbage_collected>',235850,'<garbage_collected>',(0x7f1938283430),error(io_error(write,(0x7f1958025f60)),context(...,'Disk quota exceeded'))) at /usr/lib/swi-prolog/library/http/http_wrapper.pl:309

Note: some frames are missing due to last-call optimization.
Re-run your program in debug mode (:- debug.) to get more detail.
SWI-Prolog httpd at pengines

Demo server out of memory

The scratchpad demo server isn't working anymore:

Service Unavailable Not enough resources: no_memory In: [13] thread_create(wrap_spawned((0x7f5c4c86ea90),...),69,[...]) [12] thread_httpd:http_spawn(http_dispatch: ...,[]) at /usr/lib/swi-prolog/library/http/thread_httpd.pl:796 [8]

screenshot from 2015-06-01 23 16 26

not really destroying

tl;dr - this turned out to be me

I don't fully have a repro case for this yet, but wanted to start an issue so we can track it.

Yesterday I was working on JavaPengines. The test server I'm using just starts an http server and loads pengines. I'm not changing the timeout.

I start my Java client back up and sent a /create message and get this back

{"answer":{"data":[{"X":{"args":["taco"],"functor":"a"},"Y":3}],"event":"success","id":"03d18c99-6da2-4434-8eac-4144069f720a","more":true,"projection":["X","Y"],"time":0.000020260000000000243},"event":"create","id":"03d18c99-6da2-4434-8eac-4144069f720a","slave_limit":3}

Strange part is, that query is from yesterday!

I had a bunch of debug turned on, so captured this in the debug monitor. Notably, the pengine in question was destroyed.

So why is the server hanging onto that old query???

),answer(success('03d18c99-6da2-4434-8eac-4144069f720a',[json{'X':a(taco),'Y':3}],2.0260000000000243e-5,true))])
[Thread 13] Sending create('03d18c99-6da2-4434-8eac-4144069f720a',[slave_limit(3),answer(success('03d18c99-6da2-4434-8eac-4144069f720a',[json{'X':a(taco),'Y':3}],2.0260000000000243e-5,true))]), timout: 300
[Thread 9] Got create('03d18c99-6da2-4434-8eac-4144069f720a',[slave_limit(3),answer(success('03d18c99-6da2-4434-8eac-4144069f720a',[json{'X':a(taco),'Y':3}],2.0260000000000243e-5,true))]) from <message_queue>(0x7f634002d920)
[Thread 9] DESTROY? create('03d18c99-6da2-4434-8eac-4144069f720a',[slave_limit(3),answer(success('03d18c99-6da2-4434-8eac-4144069f720a',[json{'X':a(taco),'Y':3}],2.0260000000000243e-5,true))])
[Thread 9] Running hook: header
[Thread 9] Field: [cache_control('no-cache, no-store, must-revalidate'),pragma('no-cache'),expires('0'),content_type('application/json; charset=UTF-8')]
[Thread 9] Transfer-encoding: none
[Thread 9] Running hook: send_header
[Thread 9] Header: [connection('keep-alive'),cache_control('no-cache, no-store, must-revalidate'),pragma('no-cache'),expires('0'),content_type('application/json; charset=UTF-8')]
[Thread 9] Running hook: close
[Thread 9] [35] 200 OK (0.000 seconds; 326 bytes)
[Thread 9] Wiping posted data
[Thread httpd@9900_4] Got job requeue((0x7f6368026e80),(0x7f6368027a70),user:http_dispatch,[protocol(http),peer(ip(127,0,0,1)),pool(client('httpd@9900',user:http_dispatch,(0x7f6368026e80),(0x7f6368027a70)))])
[Thread httpd@9900_4] Waiting for keep-alive ...
[Thread httpd@9900_4] Timeout on keep-alive connection
[Thread httpd@9900_4] Closing connection from ip(127,0,0,1)
[Thread httpd@9900_4] Waiting for a job ...
[Thread 11] '9be79c5f-6050-4081-8477-516588fd186e': 6 = destroy => 1
[Thread 11] Reply to <message_queue>(0x7f634002abd0): destroy('9be79c5f-6050-4081-8477-516588fd186e')
[Thread 11] Sending destroy('9be79c5f-6050-4081-8477-516588fd186e'), timout: 300
[Thread 12] 'c9c19ec8-d5b9-44e2-8bcb-8208b23eada8': 6 = destroy => 1
[Thread 12] Reply to <message_queue>(0x7f634002c490): destroy('c9c19ec8-d5b9-44e2-8bcb-8208b23eada8')
[Thread 12] Sending destroy('c9c19ec8-d5b9-44e2-8bcb-8208b23eada8'), timout: 300

Oddity with JSON response to next

I'm sending next events as x-prolog with body

next

and getting back this strange beastie when it goes to destroy:

{
  "data": {
    "data": [{"X": "c"}],
    "event": "success",
    "id": "4c53430f-9570-4e05-9036f6b5fc63dd8c",
    "more": false,
    "time": 3.951999999999992e-05
  },
  "event": "destroy",
  "id": "4c53430f-9570-4e05-9036-f6b5fc63dd8c"
}

I'd count this as an oddity.

Created a Dockerfile - please include

I created a Dockerfile that builds SWI-Prolog from source, clones Pengines, and runs a server. It would be great if this could be included in this repo or some other official SWI-Prolog repository and then become an official image (or images) on Docker hub. Can you please review the attached and let me know if what I am doing here is suitable? If so, should I submit a PR here or would this best to go in a new repository?

Pengines Dockerfile

Thanks for all your great work on Pengines.

finding the javascript docs is still painful

I'm at over 10 minutes now, trying to find the documentation for the javascript for pengines.

The document IS somewhere, I've seen it before, but finding it is a freaking mystery.

Code whose documentation is hidden can only be used by author and inner circle.
Code only used by author and inner circle is effectively worthless. 8c(

Trouble loading run.pl

Hi all,

I'm having trouble loading the SWI-Prolog server to be used for an app I'm writing in Node. I cloned the repo and when I ran ./run.pl, I'm getting an error message "Permission Denied". When I tried to load run.pl in SWI interpreter, it asked me to enter a username and password, and got the same permission denied error. (This is the actual error msg fyi: open/4: No permission to open source_sink `passwd' (Permission denied)) My SWI version is 7.3.24

Please help. Thank you,

Kevin

Alias?

Whats the use of the alias field?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.