Wikipedia API

The Wikipedia API allows users to perform text analysis tasks on Wikipedia articles. It provides two primary endpoints:

  1. Word Frequency Analysis Endpoint
  2. Search History Endpoint

Table of Contents

  1. Introduction
  2. Setup Instructions
  3. Endpoint Usage
  4. Examples
  5. Testing

Introduction

The Wikipedia API allows users to analyze Wikipedia articles by providing insights into word frequency and search history.

Setup Instructions

  1. Clone the Repository:

    git clone https://github.com/itsRkator/wiki-text-analyzer.git
    cd wikipedia_api
  2. Create a Virtual Environment:

    python -m venv venv
  3. Activate the Virtual Environment:

    • For Windows:
      venv\Scripts\activate
    • For Unix or MacOS:
      source venv/bin/activate
  4. Install Dependencies:

    pip install -r requirements.txt
  5. Run the Application:

    python app.py
  6. Access the API: The API will be running at http://127.0.0.1:5000/. Use this base URL for making requests.

Endpoint Usage

Word Frequency Analysis Endpoint

  • URL: /word_frequency
  • Method: POST
  • Parameters:
    • topic (string): Subject of the Wikipedia article.
    • n (integer): Number of top frequent words to return.

Request

{
  "topic": "Python",
  "n": 5
}

Response

{
  "topic": "Python",
  "top_words": [
    { "word": "python", "frequency": 10 },
    { "word": "language", "frequency": 5 }
    // ...
  ]
}

Search History Endpoint

  • URL: /search_history
  • Method: GET

Response

[
  {
    "topic": "Python",
    "top_words": [
      { "word": "python", "frequency": 10 },
      { "word": "language", "frequency": 5 }
      // ...
    ]
  }
  // ...
]

Examples

Examples: Word Frequency Analysis Endpoint

Example 1: Successful Request

curl -X POST -H "Content-Type: application/json" -d '{"topic": "Python", "n": 5}' http://127.0.0.1:5000/word_frequency

Example 2: Missing Parameter in Request

curl -X POST -H "Content-Type: application/json" -d '{"n": 5}' http://127.0.0.1:5000/word_frequency

Examples: Search History Endpoint

Example: Retrieve Search History

curl http://127.0.0.1:5000/search_history

Testing

To run unit tests, use the following command:

python test_app.py