|
| 1 | +# TextRazor API Integration |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +This API integration provides natural language processing capabilities using TextRazor's powerful NLP service. It offers entity extraction, sentiment analysis, topic classification, and relationship extraction from text documents. The application features a clean HTML/CSS/JavaScript frontend for interactive text analysis and a Node.js backend for API integration. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +1. **Entity Extraction** - Identify and extract entities (people, places, organizations, etc.) from text |
| 10 | +2. **Sentiment Analysis** - Analyze the emotional tone and sentiment of text content |
| 11 | +3. **Topic Classification** - Automatically categorize text into relevant topics |
| 12 | +4. **Relationship Extraction** - Discover relationships between entities in the text |
| 13 | +5. **Language Detection** - Automatically detect the language of input text |
| 14 | +6. **Interactive Web Interface** - User-friendly HTML/CSS/JavaScript frontend for text analysis |
| 15 | + |
| 16 | +## Requirements |
| 17 | + |
| 18 | +- Node.js (v14 or higher) |
| 19 | +- npm or yarn |
| 20 | +- TextRazor API key (free tier available) |
| 21 | +- Modern web browser |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +### 1. Clone the Repository: |
| 26 | + |
| 27 | +```bash |
| 28 | +git clone <repository-url> |
| 29 | +cd TextRazor_API |
| 30 | +``` |
| 31 | + |
| 32 | +### 2. Install Server Dependencies: |
| 33 | + |
| 34 | +```bash |
| 35 | +cd server |
| 36 | +npm install |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. Setup Environment Variables: |
| 40 | + |
| 41 | +Create a `.env` file in the server directory: |
| 42 | + |
| 43 | +```env |
| 44 | +TEXTRAZOR_API_KEY=your_textrazor_api_key_here |
| 45 | +PORT=5000 |
| 46 | +``` |
| 47 | + |
| 48 | +### 4. Get TextRazor API Key: |
| 49 | + |
| 50 | +1. Visit [TextRazor](https://www.textrazor.com/) |
| 51 | +2. Sign up for a free account |
| 52 | +3. Get your API key from the dashboard |
| 53 | +4. Add it to your `.env` file |
| 54 | + |
| 55 | +## Usage |
| 56 | + |
| 57 | +### Start the Server: |
| 58 | + |
| 59 | +```bash |
| 60 | +cd server |
| 61 | +npm start |
| 62 | +``` |
| 63 | + |
| 64 | +### Access the Application: |
| 65 | + |
| 66 | +The server serves both the API and the web interface: |
| 67 | + |
| 68 | +- **Web Interface**: Open your browser and go to `http://localhost:5000` |
| 69 | +- **API Endpoints**: Available at `http://localhost:5000/api/` |
| 70 | + |
| 71 | +Alternatively, you can directly open the HTML file: |
| 72 | + |
| 73 | +```bash |
| 74 | +# Navigate to server/public and open index.html in your browser |
| 75 | +cd server/public |
| 76 | +# Open index.html in your default browser (double-click or right-click -> Open with -> Browser) |
| 77 | +``` |
| 78 | + |
| 79 | +## API Endpoints |
| 80 | + |
| 81 | +### 1. Analyze Text |
| 82 | + |
| 83 | +```http |
| 84 | +POST /api/analyze |
| 85 | +Content-Type: application/json |
| 86 | +
|
| 87 | +{ |
| 88 | + "text": "Your text to analyze here", |
| 89 | + "extractors": ["entities", "sentiment", "topics", "relations", "language"] |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### 2. Extract Entities Only |
| 94 | + |
| 95 | +```http |
| 96 | +POST /api/entities |
| 97 | +Content-Type: application/json |
| 98 | +
|
| 99 | +{ |
| 100 | + "text": "Your text here" |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +### 3. Sentiment Analysis Only |
| 105 | + |
| 106 | +```http |
| 107 | +POST /api/sentiment |
| 108 | +Content-Type: application/json |
| 109 | +
|
| 110 | +{ |
| 111 | + "text": "Your text here" |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +### 4. Topic Classification |
| 116 | + |
| 117 | +```http |
| 118 | +POST /api/topics |
| 119 | +Content-Type: application/json |
| 120 | +
|
| 121 | +{ |
| 122 | + "text": "Your text here" |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +### 5. Language Detection |
| 127 | + |
| 128 | +```http |
| 129 | +POST /api/language |
| 130 | +Content-Type: application/json |
| 131 | +
|
| 132 | +{ |
| 133 | + "text": "Your text here" |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +## Example Response |
| 138 | + |
| 139 | +### Entity Extraction Response: |
| 140 | + |
| 141 | +```json |
| 142 | +{ |
| 143 | + "success": true, |
| 144 | + "entities": [ |
| 145 | + { |
| 146 | + "id": "Apple Inc.", |
| 147 | + "type": "Company", |
| 148 | + "confidence": 0.95, |
| 149 | + "relevanceScore": 0.8, |
| 150 | + "matchedText": "Apple" |
| 151 | + } |
| 152 | + ], |
| 153 | + "sentiment": { |
| 154 | + "score": 0.2, |
| 155 | + "label": "positive" |
| 156 | + }, |
| 157 | + "topics": [ |
| 158 | + { |
| 159 | + "id": "Technology", |
| 160 | + "score": 0.85 |
| 161 | + } |
| 162 | + ] |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +### Language Detection Response: |
| 167 | + |
| 168 | +```json |
| 169 | +{ |
| 170 | + "success": true, |
| 171 | + "language": { |
| 172 | + "code": "eng", |
| 173 | + "isReliable": true |
| 174 | + }, |
| 175 | + "metadata": { |
| 176 | + "textLength": 150 |
| 177 | + } |
| 178 | +} |
| 179 | +``` |
| 180 | + |
| 181 | +## Technology Stack |
| 182 | + |
| 183 | +- **Frontend**: HTML5, CSS3, JavaScript (Vanilla) |
| 184 | +- **Backend**: Node.js, Express.js |
| 185 | +- **API**: TextRazor NLP API |
| 186 | +- **HTTP Client**: Fetch API (built-in) |
| 187 | + |
| 188 | +## Features Demo |
| 189 | + |
| 190 | +1. **Text Input**: Large textarea for entering text to analyze with auto-resize functionality |
| 191 | +2. **Analysis Options**: Checkboxes to select which analysis to perform (entities, sentiment, topics, relations, language) |
| 192 | +3. **Results Display**: Organized sections showing entities, sentiment, topics, relationships, and language detection |
| 193 | +4. **Visual Indicators**: Color-coded sentiment results and confidence scores |
| 194 | +5. **Export Results**: Download analysis results as JSON file |
| 195 | +6. **Responsive Design**: Works on desktop, tablet, and mobile devices |
| 196 | +7. **Real-time Feedback**: Loading states and error handling |
| 197 | +8. **Sample Texts**: Pre-loaded example texts for quick testing |
| 198 | + |
| 199 | +## Notes |
| 200 | + |
| 201 | +- Free TextRazor account includes 500 requests per day |
| 202 | +- Ensure your API key is kept secure and not committed to version control |
| 203 | +- The application handles various text formats and languages |
| 204 | +- Error handling is implemented for API failures and network issues |
| 205 | +- The server serves both API endpoints and the web interface on the same port |
| 206 | + |
| 207 | +## Contributing |
| 208 | + |
| 209 | +Please follow the project's contributing guidelines and ensure all code is properly tested before submitting pull requests. |
| 210 | + |
| 211 | +## License |
| 212 | + |
| 213 | +This project is licensed under the MIT License. |
| 214 | + |
| 215 | +## Project Structure |
| 216 | + |
| 217 | +``` |
| 218 | +TextRazor_API/ |
| 219 | +├── README.md |
| 220 | +├── PROJECT_SUMMARY.md |
| 221 | +└── server/ |
| 222 | + ├── package.json |
| 223 | + ├── package-lock.json |
| 224 | + ├── server.js |
| 225 | + ├── .env.example |
| 226 | + ├── .env |
| 227 | + ├── node_modules/ |
| 228 | + ├── routes/ |
| 229 | + │ └── textrazor.js |
| 230 | + └── public/ |
| 231 | + ├── index.html |
| 232 | + ├── styles.css |
| 233 | + └── script.js |
| 234 | +``` |
0 commit comments