semantic-seo-ai / rewrite_engine.py
coingimp's picture
Update rewrite_engine.py
a3a0694 verified
from scoring import analyze_content
def truncate(text: str, limit: int = 3500) -> str:
return (text or "")[:limit]
def rewrite_content(queries: str, competitors: str, content: str, mode: str = "Free Local") -> str:
"""
Semantic SEO content adapter.
Analyzes content and adds structured SEO expansion sections.
Works fully offline — no model downloads required.
"""
analysis = analyze_content(queries, competitors, content)
missing = analysis.get("missing_entities", "")
weak = analysis.get("weak_queries", "")
recommendations = analysis.get("recommendations", "")
global_score = analysis.get("global_score", "")
expansion = f"""
---
## Semantic SEO Analysis
Global Score: {global_score}
## Weak Query Coverage
The following queries need stronger coverage in the text:
{truncate(weak, 800)}
## Missing Topical Entities
These entities should be naturally integrated to improve topical authority:
{truncate(missing, 1000)}
## SEO Recommendations
{truncate(recommendations, 1200)}
## Content Improvement Notes
To outrank competitors, this page should:
- Cover all query intents listed in the query pool
- Include explanations of key entities and concepts
- Add FAQ, comparison, and practical usage sections where relevant
- Use clear H2/H3 structure for each major topic
- Avoid keyword stuffing while maintaining high semantic density
"""
return content.strip() + expansion