Skip to main content
Glama

analyze_full_text

Analyze dramatic texts, including dialogue and stage directions, by specifying a corpus and play name. This tool supports detailed exploration of play content through context-aware methods.

Instructions

Analyze the full text of a play, including dialogue and stage directions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
corpus_nameYes
play_nameYes

Implementation Reference

  • Registration of the analyze_full_text tool using the @mcp.tool decorator.
    @mcp.tool("analyze_full_text")
  • The handler function implementing the analyze_full_text tool. It fetches TEI XML or fallback text, parses structure with regex (title, authors, acts, scenes, speeches, stage directions), retrieves play info and characters, and returns comprehensive analysis including text length and ratios.
    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)}
  • Input schema defined by function parameters: corpus_name (str), play_name (str). Output: Dict with play info, characters, text, optional TEI analysis, and basic metrics.
    def analyze_full_text(corpus_name: str, play_name: str) -> Dict:

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/stijn-meijers/dracor-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server