Skip to main content
Glama
marksverdhei

DHLAB MCP Server

by marksverdhei

find_concordances

Locate word contexts within documents from the National Library of Norway's digital collections to analyze usage patterns and textual occurrences.

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
NameRequiredDescriptionDefault
urnYes
wordYes
windowNo
limitNo

Implementation Reference

  • Handler function decorated with @mcp.tool(), implementing the logic to find concordances for a word in a document using dhlab.Corpus.conc method. Handles input parameters, performs the query, and returns JSON results or error messages.
    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)}"

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/marksverdhei/dhlab-mcp'

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