nlp3

NLP3Tree Code Analysis - Quick Start

🚀 Installation

# Clone the repository
git clone https://github.com/wronai/nlp2tree.git
cd nlp2tree

# Install dependencies
pip install -r requirements.txt

# For semantic search (optional but recommended)
pip install sentence-transformers scikit-learn

🎯 Quick Demo

1. Analyze Current Project

# Run all 30 use cases on current directory
python examples/code_analysis_demo.py .

# Analyze specific project
python examples/code_analysis_demo.py /path/to/your/project

2. Use NLP3Tree CLI

# Find functions parsing JSON
nlp3 query "znajdĹş funkcjÄ™ parsujÄ…cÄ… JSON" /path/to/project

# Show all TODOs
nlp3 query "pokaĹĽ TODO" /path/to/project

# Find async functions
nlp3 query "gdzie jest async" /path/to/project

# Find security issues
nlp3 query "gdzie mamy eval" /path/to/project

3. Python API Usage

from pathlib import Path
from nlp3.adapters.code_use_cases import CodeAnalysisUseCases

# Initialize analyzer
analyzer = CodeAnalysisUseCases(Path("/path/to/project"))

# Run specific analysis
todos = analyzer.find_todo_comments()
security_issues = analyzer.find_security_hotspots()
async_functions = analyzer.find_async_code()

print(f"Found {len(todos)} TODOs")
print(f"Found {len(security_issues)} security issues")
print(f"Found {len(async_functions)} async functions")

đź“‹ Available Commands

Polish (PL)

English (EN)

đź”§ Advanced Features

from nlp3.adapters.semantic_search import SemanticSearchEngine

# Initialize semantic engine
semantic_engine = SemanticSearchEngine()
semantic_engine.build_semantic_index(code_engine, project_path)

# Find functions by description
results = semantic_engine.find_functions_by_description("parse CSV data")
results = semantic_engine.find_functions_by_description("authenticate user")

# Find similar functions
similar = semantic_engine.find_similar_functions("parse_json")

Code Intelligence

from nlp3.adapters.code_intelligence import CodeIntelligenceEngine

# Initialize engine
engine = CodeIntelligenceEngine()
engine.build_index(project_path)

# Find unused functions
unused = engine.find_unused_functions()

# Get call graph
call_graph = engine.get_call_graph("main_function")

# Calculate metrics
metrics = engine.calculate_metrics(project_path)

📊 Output Formats

# Table format (default)
nlp3 query "find functions" /path/to/project --format table

# Tree format
nlp3 query "find functions" /path/to/project --format tree

# JSON format
nlp3 query "find functions" /path/to/project --format json

# HTML report
nlp3 query "find functions" /path/to/project --format html

đź§Ş Testing

# Run all tests
pytest tests/test_code_analysis.py

# Run with coverage
pytest --cov=nlp3/adapters tests/test_code_analysis.py

# Run specific test
pytest tests/test_code_analysis.py::TestCodeAnalysisUseCases::test_find_todo_comments

📚 Examples

Example 1: Find All TODOs

from nlp3.adapters.code_use_cases import CodeAnalysisUseCases

analyzer = CodeAnalysisUseCases(Path("."))
todos = analyzer.find_todo_comments()

for file_path, line_num, todo_text in todos:
    print(f"{file_path}:{line_num} - {todo_text}")

Example 2: Security Analysis

from nlp3.adapters.code_intelligence import CodeIntelligenceEngine

engine = CodeIntelligenceEngine()
engine.build_index(Path("."))

security_issues = engine.find_security_hotspots()
for issue in security_issues:
    print(f"SECURITY: {issue.docstring}")
    print(f"Location: {issue.name} at line {issue.line_start}")
from nlp3.adapters.semantic_search import SemanticSearchEngine

semantic_engine = SemanticSearchEngine()
semantic_engine.build_semantic_index(code_engine, Path("."))

# Find functions that handle authentication
results = semantic_engine.search_by_intent("authenticate", "user login password")
for function, score in results:
    print(f"{function.name} (similarity: {score:.2f})")

🎯 Tips & Tricks

  1. Start Broad, Then Narrow - Begin with general queries, then add specifics
  2. Use Both Languages - Try both Polish and English queries
  3. Combine Keywords - Use multiple terms for better results
  4. Check Semantic Search - For conceptual searches, use semantic engine
  5. Explore Call Graphs - Understand function dependencies

🔍 Common Use Cases

Code Review

# Find potential issues
nlp3 query "find security hotspots" /path/to/project
nlp3 query "show TODOs" /path/to/project
nlp3 query "find unused functions" /path/to/project

Onboarding

# Understand codebase structure
nlp3 query "find entry points" /path/to/project
nlp3 query "find main functions" /path/to/project
nlp3 query "show API endpoints" /path/to/project

Refactoring

# Find related code
nlp3 query "find functions calling database" /path/to/project
nlp3 query "find async functions" /path/to/project
nlp3 query "find logging code" /path/to/project

📞 Support


Happy Code Exploration! 🚀