Skip to content

Trayshmhirk/nlp-string-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HNG13 String Analyzer API

A lightweight Node.js REST API that analyzes strings, detects palindromes, computes hashes, counts characters, and even supports natural language filters.

This project was built as part of the HNG Internship 13 — Backend Stage 1 Task.


🚀 Features

  • Analyze and store string data in memory
  • Detect palindromes, compute SHA-256 hashes
  • Count characters, words, and unique letters
  • Filter strings via query parameters
  • Interpret natural language filters like:
    • “all single word palindromic strings”
    • “strings longer than 10 characters”
    • “strings containing the letter z”

🧰 Tech Stack

  • Node.js (v18+)
  • Express.js
  • In-memory store (Map)
  • CORS + JSON middleware

🧩 Project Structure

nlp-string-analyzer/
│
├── src/
│   ├── app.js                  # Express app setup
│   ├── routes/
│   │   └── string.js           # Routes for /strings endpoints
│   ├── services/
│   │   └── analyzer.js         # Core string analysis functions
│   ├── storage/
│   │   └── memory-store.js     # In-memory store implementation
│   └── utils/
│       └── nlp-parser.js       # Natural language filter parser
│
├── server.js                   # Entry point
└── package.json

⚙️ Setup Instructions

1️⃣ Clone the Repository

git clone https://github.com/Trayshmhirk/nlp-string-analyzer.git
cd nlp-string-analyzer

2️⃣ Install Dependencies

npm install

3️⃣ Start the Server

npm start

Server will run at:

http://localhost:3000

🧪 API Endpoints

1. POST /strings

Analyze and save a new string.

Request

{
  "value": "racecar"
}

Response

{
  "id": "e00f9ef5...",
  "value": "racecar",
  "properties": {
    "length": 7,
    "is_palindrome": true,
    "unique_characters": 4,
    "word_count": 1,
    "sha256_hash": "e00f9ef5...",
    "character_frequency_map": { "r": 2, "a": 2, "c": 2, "e": 1 }
  },
  "created_at": "2025-10-21T10:12:48.844Z"
}

2. GET /strings/:string_value

Retrieve a single analyzed string by value.

Example:
GET /strings/racecar

Response

{
  "id": "...",
  "value": "racecar",
  "properties": { "length": 7, "is_palindrome": true, ... }
}

3. GET /strings

List all stored strings. Supports query filters.

Query Params

Param Type Example Description
is_palindrome boolean true Filter by palindrome
min_length number 5 Minimum length
max_length number 10 Maximum length
word_count number 1 Exact word count
contains_character string a Must contain this letter

4. GET /strings/filter-by-natural-language?query=...

Interpret and apply filters from plain English.

Examples:

Query Meaning
all single word palindromic strings Palindromes with one word
strings longer than 5 characters Strings with length ≥ 6
strings containing the letter y Strings containing "y"

Example Request:

GET /strings/filter-by-natural-language?query=all%20single%20word%20palindromic%20strings

Response

{
  "data": [...],
  "count": 2,
  "interpreted_query": {
    "original": "all single word palindromic strings",
    "parsed_filters": {
      "word_count": 1,
      "is_palindrome": true
    }
  }
}

5. DELETE /strings/:string_value

Delete a stored string by its value.

Example:
DELETE /strings/hello%20world

Response

{ "message": "String deleted" }

🌐 Deployment (Railway)

  1. Push your repo to GitHub
  2. Go to Railway → “Deploy from GitHub”
  3. Select this repo
  4. Railway will detect it’s a Node app automatically
  5. Add the start command in package.json if needed:
"scripts": {
  "start": "node server.js"
}
  1. After deployment, your API will be live at:
https://<your-app-name>.up.railway.app

Author

Micheal Osunbajo

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published