analyze_full_text
Analyze complete play texts including dialogue and stage directions to extract insights from dramatic works across languages and periods.
Instructions
Analyze the full text of a play, including dialogue and stage directions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| corpus_name | Yes | ||
| play_name | Yes |
Implementation Reference
- dracor_mcp_fastmcp.py:655-747 (handler)The complete implementation of the 'analyze_full_text' tool. Includes the @mcp.tool decorator for registration and the full handler function that analyzes the play's TEI XML structure (acts, scenes, speeches, stage directions), metadata, characters, plain text stats, and returns a comprehensive dictionary with the analysis.@mcp.tool("analyze_full_text") def analyze_full_text(corpus_name: str, play_name: str) -> Dict: """Analyze the full text of a play, including dialogue and stage directions.""" try: # Get the TEI XML as primary source tei_result = get_tei_text(corpus_name, play_name) if "error" in tei_result: # Fall back to the plain text if TEI fails full_text = get_full_text(corpus_name, play_name) if "error" in full_text: return {"error": full_text["error"]} has_tei = False text_content = full_text["text"] else: has_tei = True tei_text = tei_result["tei_text"] # Simple XML parsing to extract basic structure # In a production environment, use a proper XML parser library import re # Extract title title_match = re.search(r'<title[^>]*>([^<]+)</title>', tei_text) title = title_match.group(1) if title_match else "Unknown" # Extract author(s) author_matches = re.findall(r'<author[^>]*>([^<]+)</author>', tei_text) authors = author_matches if author_matches else ["Unknown"] # Extract acts acts = re.findall(r'<div type="act"[^>]*>(.*?)</div>', tei_text, re.DOTALL) act_count = len(acts) # Extract scenes scenes = re.findall(r'<div type="scene"[^>]*>(.*?)</div>', tei_text, re.DOTALL) scene_count = len(scenes) # Extract speeches speeches = re.findall(r'<sp[^>]*>(.*?)</sp>', tei_text, re.DOTALL) speech_count = len(speeches) # Extract stage directions stage_directions = re.findall(r'<stage[^>]*>(.*?)</stage>', tei_text, re.DOTALL) stage_direction_count = len(stage_directions) # Also get the plain text for easier processing full_text = get_full_text(corpus_name, play_name) text_content = full_text.get("text", "") # Get play metadata play_info = get_play(corpus_name, play_name) if "error" in play_info: return {"error": play_info["error"]} # Get character list characters = get_characters(corpus_name, play_name) if "error" in characters: return {"error": characters["error"]} result = { "play": play_info.get("play", {}), "characters": characters.get("characters", []), "text": text_content, } # Add TEI-specific analysis if available if has_tei: result["tei_analysis"] = { "title": title, "authors": authors, "structure": { "acts": act_count, "scenes": scene_count, "speeches": speech_count, "stage_directions": stage_direction_count }, "text_sample": { "first_speech": speeches[0] if speeches else "", "first_stage_direction": stage_directions[0] if stage_directions else "" } } # Add basic text analysis in either case result["analysis"] = { "text_length": len(text_content), "character_count": len(characters.get("characters", [])), "dialogue_to_direction_ratio": text_content.count("\n\nDIALOGUE:") / (text_content.count("\n\nSTAGE DIRECTIONS:") or 1) } return result except Exception as e: return {"error": str(e)}
- dracor_mcp_fastmcp.py:655-655 (registration)The MCP tool registration decorator specifically naming this tool 'analyze_full_text'.@mcp.tool("analyze_full_text")