find_concordances
Locate word occurrences with surrounding context in documents from Norwegian digital collections to analyze usage patterns and linguistic context.
Instructions
Find concordances (contexts) for a word in a specific document.
Args: urn: URN identifier for the document word: Word to find concordances for window: Number of words before and after the match (default: 25) limit: Maximum number of concordances to return (default: 100)
Returns: JSON string containing concordance results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| urn | Yes | ||
| word | Yes | ||
| window | No | ||
| limit | No |
Implementation Reference
- src/dhlab_mcp/server.py:87-119 (handler)The handler function for the 'find_concordances' tool. It is decorated with @mcp.tool(), which registers it with the FastMCP server. The function retrieves concordances (contextual occurrences) of a specified word within a document identified by URN using the dhlab library, returning results as JSON.@mcp.tool() def find_concordances( urn: str, word: str, window: int = 25, limit: int = 100, ) -> str: """Find concordances (contexts) for a word in a specific document. Args: urn: URN identifier for the document word: Word to find concordances for window: Number of words before and after the match (default: 25) limit: Maximum number of concordances to return (default: 100) Returns: JSON string containing concordance results """ try: # Create corpus from URN corpus = dhlab.Corpus.from_identifiers([urn]) if len(corpus.corpus) == 0: return f"No document found for URN: {urn}" # Get concordances using corpus method concs = corpus.conc(words=word, window=window, limit=limit) if concs.concordance is not None and len(concs.concordance) > 0: return concs.concordance.to_json(orient='records', force_ascii=False) return "No concordances found" except Exception as e: return f"Error finding concordances: {str(e)}"