Skip to content
A lightweight JSON wrapper for simplenlg
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

nlgserv

nlgserv is a simple server that accepts JSON representations of sentences and generates English sentences from those.

It uses SimpleNLG (under the MPL 2.0 licence) available on github.com for natural language generation.

In order to use SimpleNLG (which is implemented in Java), Jython 2.7.0 is also bundled, under the terms of the PSF v.2.

Additionally, it uses Bottle v0.12.9 (under the MIT licence available on github.com for handling HTTP requests.

This was something I cobbled together to act as part of my PhD project. Consequently, I don't really have time to maintain it or fix bugs, as it suits the purposes I need it for.

Feel free to take the code and try and fix it, but I'm afraid I can't really help you. If you are able to use the Java library directly, I'd really recommend you do that instead.

Thanks, Darren

Steps in starting the nlg server on localhost:

  1. Install nlgserv package in local python environment using the command :

    pip install nlgserv

    Or you can even download the repo, extract it and use python setup.py install

  2. Type the following commands in the shell to start the nlg server :

    import nlgserv
    s = nlgserv.start_server("localhost",8000) # You can change the host and port here, use it same throughout
    

    To get the following output:

    Starting nlgserv on localhost:8000 <br>
    <subprocess.Popen object at 0x7fdc6e008290>
    

    Now the nlg server has started on localhost:8000

    In order to run simpleNLG on this server, a POST request should be sent to the server. The request should be in a proper Json format :

    For example

      {  
         "sentence":
        {  
            "subject":"John",
            "verb":"like",
            "object":
            {  
               "type":"coordinated_phrase",
               "coordinates":
               [  
                  "apples",
                  "oranges"
               ]
            },
            "modifiers":
            [  
               "very much"
            ],
            "indirect_object":"",
            "features":
            {  
               "tense":"present"
            }
         }
      }

    Note that the keys are the different components of the sentence we want to construct.

    The above Json request will get you the following response :

    John likes apples and oranges very much.
    

    To test the response, you can use the RESTED extention in Firefox. (You can even use Postman)
    Send a post request to http://localhost:8000/generateSentence
    The headers will contain the following :
    Name : content-type
    Value : application/json

    normal

    Adding the Json data in the body and getting a response: normal

Build status

Build Status Latest Version

You can’t perform that action at this time.