Code Monkey home page Code Monkey logo

wordcounter's Introduction

Word Counter Application

Flask based HTTP service to consume text and return the number of words.

wordcounterexample

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Linux system: Ubuntu 16.04 (Xenial) or later
python 3.5.2
pip

Installing

Clone source code from git repo

$ git clone https://github.com/fernandorovai/WordCounter.git

Setup and activate virtual environment

$ virtualenv WordCounter -p python3
$ cd WordCounter
$ source ./bin/activate

Install python dependencies via pip

$ pip install -r requirements.txt   # python libraries
$ python -m spacy download en       # download english model

Running the Server

Start the webserver

$ cd WordCounter 
$ python init.py

# to run webserver in debug mode, set app.debug var in init.py
app.debug = True

Expected output

 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Request text processing (API)

Receive the number of words based on user's input text. Server is expecting to receive a POST message with a determined field.

requestUrl    : http://localhost:5000/processText
method        : POST
dataStructure : bagOfText:"This is an example of text"              

Expected output:

outputStructure : {
                    "errorMsg": null,
                    "wordCounter": "6"
                  }

Request text processing (Web)

Receive the number of words based on form user's input text.

1. Go to http://localhost:5000
2. Fill the form with text
3. Press submit button to receive the number of words

Running the tests

The script webServerTestCase.py runs the following tests

  • test_invalid_request : send a post request without form content
  • test_complete_post : send a post request with complete form content
  • test_empty_post : send a post request with empty value
  • test_multiple_requests : send multi-thread post requests

To start the test case:

$ cd WordCounter
$ python webServerTestCase

Expected output:

Ran 4 tests in 500ms
OK

Deployment

Flask’s built-in server is not suitable for production. Consider deploying the application to a WSGI Server.

For more information, check Flask Documentation

Built With

  • Flask - Microframework for Python
  • spaCY - Package for Natural Language Processing

Authors

  • Fernando Rodrigues Jr - Initial work - Fernando

wordcounter's People

Contributors

fernandorovai avatar

Watchers

James Cloos avatar  avatar

wordcounter's Issues

Problem with submitting the text on local server

I get the following error when I attempt to submit the form when running the local server on port 5000:
Failed to load http://localhost:5000/processText: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://0.0.0.0:5000' is therefore not allowed access.

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.