help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
nlp-text-analysis-bot
RSK World
nlp-text-analysis-bot
NLP Text Analysis Bot - Python + NLP + Flask + Machine Learning + Text Analysis + AI
nlp-text-analysis-bot
  • static
  • templates
  • .gitignore393 B
  • ADVANCED_FEATURES.md5.4 KB
  • CHANGELOG.md1.3 KB
  • FINAL_CHECK.md4.6 KB
  • GITHUB_RELEASE_INSTRUCTIONS.md4.1 KB
  • LICENSE1.2 KB
  • PROJECT_INFO.md2.7 KB
  • PROJECT_STATUS.md4 KB
  • QUICKSTART.md3.1 KB
  • README.md5.8 KB
  • RELEASE_NOTES.md3.8 KB
  • advanced_keywords.py3.9 KB
  • app.py3 KB
  • config.py668 B
  • emotion_detection.py4.3 KB
  • entity_recognition.py3 KB
  • example_usage.py2.7 KB
  • install.bat853 B
  • install.sh808 B
  • language_detection.py2.7 KB
  • nlp_pipeline.py7.1 KB
  • pos_tagging.py2.9 KB
  • readability_analysis.py3.5 KB
  • requirements.txt334 B
  • semantic_understanding.py4 KB
  • sentiment_analysis.py3.9 KB
  • setup.py1.4 KB
  • test_analysis.py2.5 KB
  • text_classification.py5 KB
  • text_preprocessing.py4.2 KB
  • text_similarity.py4.1 KB
  • text_summarization.py5 KB
  • validate_project.py4.2 KB
pos_tagging.pyemotion_detection.py
pos_tagging.py
Raw Download
Find: Go to:
"""
Part-of-Speech Tagging Module
Performs advanced POS tagging and analysis

Developer: RSK World
Website: https://rskworld.in
Email: help@rskworld.in
Phone: +91 93305 39277
Year: 2026
"""

import spacy
from collections import Counter
from text_preprocessing import TextPreprocessor

class POSTagger:
    """
    Part-of-Speech tagging class
    Developer: RSK World - https://rskworld.in
    """
    
    def __init__(self):
        """Initialize POS tagger"""
        try:
            self.nlp = spacy.load("en_core_web_sm")
        except OSError:
            print("Warning: spaCy model not found for POS tagging")
            self.nlp = None
        
        self.preprocessor = TextPreprocessor()
    
    def tag_text(self, text):
        """
        Tag all words with their part of speech
        
        Args:
            text (str): Input text
            
        Returns:
            dict: POS tagging results
        """
        if self.nlp is None:
            return {
                'error': 'spaCy model not available'
            }
        
        try:
            doc = self.nlp(text)
            
            tagged_words = []
            pos_counts = Counter()
            
            for token in doc:
                if not token.is_punct and not token.is_space:
                    tagged_words.append({
                        'word': token.text,
                        'pos': token.pos_,
                        'tag': token.tag_,
                        'lemma': token.lemma_,
                        'description': spacy.explain(token.pos_)
                    })
                    pos_counts[token.pos_] += 1
            
            return {
                'tagged_words': tagged_words,
                'pos_distribution': dict(pos_counts),
                'total_words': len(tagged_words),
                'unique_pos': len(pos_counts)
            }
        except Exception as e:
            print(f"Error in POS tagging: {e}")
            return {
                'error': str(e)
            }
    
    def get_pos_statistics(self, text):
        """
        Get statistics about parts of speech
        
        Args:
            text (str): Input text
            
        Returns:
            dict: POS statistics
        """
        result = self.tag_text(text)
        
        if 'error' in result:
            return result
        
        pos_dist = result['pos_distribution']
        total = result['total_words']
        
        # Calculate percentages
        pos_percentages = {
            pos: (count / total * 100) if total > 0 else 0
            for pos, count in pos_dist.items()
        }
        
        return {
            'pos_distribution': pos_dist,
            'pos_percentages': pos_percentages,
            'total_words': total,
            'most_common_pos': max(pos_dist.items(), key=lambda x: x[1])[0] if pos_dist else None
        }

107 lines•2.9 KB
python
emotion_detection.py
Raw Download
Find: Go to:
"""
Emotion Detection Module
Detects emotions in text beyond basic sentiment

Developer: RSK World
Website: https://rskworld.in
Email: help@rskworld.in
Phone: +91 93305 39277
Year: 2026
"""

from transformers import pipeline
import re

class EmotionDetector:
    """
    Emotion detection class
    Developer: RSK World - https://rskworld.in
    """
    
    def __init__(self):
        """Initialize emotion detector"""
        try:
            # Emotion classification model
            self.emotion_classifier = pipeline(
                "text-classification",
                model="j-hartmann/emotion-english-distilroberta-base",
                device=-1  # Use CPU
            )
        except Exception as e:
            print(f"Warning: Could not load emotion classifier: {e}")
            self.emotion_classifier = None
    
    def detect_emotions(self, text):
        """
        Detect emotions in text
        
        Args:
            text (str): Input text
            
        Returns:
            dict: Emotion detection results
        """
        if self.emotion_classifier is None:
            return self.keyword_based_emotion(text)
        
        try:
            # Truncate if too long
            max_length = 512
            if len(text) > max_length:
                text = text[:max_length]
            
            result = self.emotion_classifier(text, return_all_scores=True)
            
            if result and len(result) > 0:
                emotions = result[0]
                sorted_emotions = sorted(emotions, key=lambda x: x['score'], reverse=True)
                
                return {
                    'primary_emotion': sorted_emotions[0]['label'],
                    'primary_score': sorted_emotions[0]['score'],
                    'all_emotions': [
                        {'emotion': emo['label'], 'score': emo['score']}
                        for emo in sorted_emotions
                    ],
                    'top_3_emotions': [
                        {'emotion': emo['label'], 'score': emo['score']}
                        for emo in sorted_emotions[:3]
                    ]
                }
        except Exception as e:
            print(f"Error in emotion detection: {e}")
            return self.keyword_based_emotion(text)
    
    def keyword_based_emotion(self, text):
        """
        Fallback keyword-based emotion detection
        
        Args:
            text (str): Input text
            
        Returns:
            dict: Emotion detection results
        """
        text_lower = text.lower()
        
        # Emotion keywords
        emotion_keywords = {
            'joy': ['happy', 'joy', 'excited', 'delighted', 'pleased', 'glad', 'cheerful'],
            'sadness': ['sad', 'unhappy', 'depressed', 'sorrow', 'grief', 'melancholy'],
            'anger': ['angry', 'mad', 'furious', 'rage', 'annoyed', 'irritated'],
            'fear': ['afraid', 'scared', 'fear', 'worried', 'anxious', 'terrified'],
            'surprise': ['surprised', 'amazed', 'shocked', 'astonished', 'wow'],
            'disgust': ['disgusted', 'revolted', 'sickened', 'repulsed'],
            'neutral': ['okay', 'fine', 'normal', 'alright']
        }
        
        emotion_scores = {}
        for emotion, keywords in emotion_keywords.items():
            score = sum(1 for keyword in keywords if keyword in text_lower)
            emotion_scores[emotion] = score
        
        # Normalize scores
        total_score = sum(emotion_scores.values())
        if total_score > 0:
            emotion_scores = {k: v / total_score for k, v in emotion_scores.items()}
        else:
            emotion_scores = {'neutral': 1.0}
        
        sorted_emotions = sorted(emotion_scores.items(), key=lambda x: x[1], reverse=True)
        
        return {
            'primary_emotion': sorted_emotions[0][0],
            'primary_score': sorted_emotions[0][1],
            'all_emotions': [
                {'emotion': emo, 'score': score}
                for emo, score in sorted_emotions
            ],
            'top_3_emotions': [
                {'emotion': emo, 'score': score}
                for emo, score in sorted_emotions[:3]
            ]
        }

125 lines•4.3 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer