Skip to main content
Glama
marksverdhei

DHLAB MCP Server

by marksverdhei

ngram_frequencies

Analyze word frequency trends over time in Norwegian books and newspapers using NGram data from the National Library of Norway's Digital Humanities Lab.

Instructions

Get word frequency trends over time using NGram analysis.

Args: words: List of words to analyze corpus: Corpus type. Options: 'bok' (books), 'avis' (newspapers). Default: 'bok' from_year: Start year (default: 1810) to_year: End year (default: 2020) smooth: Smoothing parameter for the frequency curve (default: 1)

Returns: JSON string containing frequency data over time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
wordsYes
corpusNobok
from_yearNo
to_yearNo
smoothNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'ngram_frequencies' tool. It is decorated with @mcp.tool() for registration and implements the core logic using dhlab's Ngram classes to compute frequency trends over time for given words in specified corpora.
    @mcp.tool()
    def ngram_frequencies(
        words: list[str],
        corpus: str = "bok",
        from_year: int = 1810,
        to_year: int = 2020,
        smooth: int = 1,
    ) -> str:
        """Get word frequency trends over time using NGram analysis.
    
        Args:
            words: List of words to analyze
            corpus: Corpus type. Options: 'bok' (books), 'avis' (newspapers). Default: 'bok'
            from_year: Start year (default: 1810)
            to_year: End year (default: 2020)
            smooth: Smoothing parameter for the frequency curve (default: 1)
    
        Returns:
            JSON string containing frequency data over time
        """
        try:
            if corpus == "avis":
                ng = dhlab.NgramNews(words, from_year=from_year, to_year=to_year, smooth=smooth)
            else:
                ng = dhlab.NgramBook(words, from_year=from_year, to_year=to_year, smooth=smooth)
    
            if hasattr(ng, 'frame') and ng.frame is not None:
                return ng.frame.to_json(orient='index', force_ascii=False)
            return "No frequency data available"
        except Exception as e:
            return f"Error getting ngram frequencies: {str(e)}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool returns 'JSON string containing frequency data over time', which gives some output context, but fails to address critical aspects like rate limits, error handling, data sources, or performance characteristics. For a tool with 5 parameters and no annotations, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the core purpose, followed by a structured 'Args' and 'Returns' section. Every sentence earns its place by defining parameters and output without redundancy. It's efficient and well-organized for a tool with multiple parameters.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 5 parameters, 0% schema coverage, no annotations, but an output schema exists, the description is moderately complete. It covers parameter semantics well and notes the return format, but lacks behavioral details like data accuracy, limitations, or error cases. The output schema reduces the need to explain return values, but more context on tool behavior would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It effectively adds meaning by explaining each parameter's purpose: 'words' as a list to analyze, 'corpus' with options ('bok' for books, 'avis' for newspapers), and default values for 'from_year', 'to_year', and 'smooth'. This provides clear semantics beyond the bare schema, though it could elaborate on 'smooth' effects.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get word frequency trends over time using NGram analysis.' It specifies the verb ('Get'), resource ('word frequency trends'), and method ('NGram analysis'), making it distinct from siblings like 'find_collocations' or 'lookup_word_lemma'. However, it doesn't explicitly differentiate from all siblings, such as 'get_corpus_statistics', which might overlap in scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It lacks context about scenarios where NGram frequency analysis is preferred over other tools like 'search_texts' or 'word_concordance', and offers no exclusions or prerequisites. Usage is implied through the description but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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