Wiktionary Parser

repository·master·Indexed 18 days ago

https://github.com/suyashb95/wiktionaryparser

A Python library for downloading and parsing content from English Wiktionary into a structured JSON format. It supports extracting etymologies, definitions, pronunciations, and related words via the WiktionaryParser API.

Tokens
793
Snippets
3
Records
3
Agent score
14%

What's inside wiktionaryparser

  1. Install Wiktionary Parser

    master

    You can install the package via pip or by installing from the source code.

    Using pip:

    pip install wiktionaryparser

    From Source:

    1. Clone the repository or download the zip file.
    2. Navigate to the project folder.
    3. Install dependencies using:
    pip install -r "requirements.txt"
    pip install wiktionaryparser
  2. Use the WiktionaryParser API

    master

    To use the parser, import the WiktionaryParser class, initialize it, and use the fetch method to retrieve data for a specific word and language.

    Core Methods:

    • fetch(word, language=None): Downloads and parses the article content. If no language is provided, it uses the current default language.
    • set_default_language(language): Changes the default language used when fetch is called without a language argument.
    • include_part_of_speech(part_of_speech): Specifies which parts of speech to include in the parsing.
    • exclude_part_of_speech(part_of_speech): Specifies which parts of speech to exclude.
    • include_relation(relation): Specifies which word relations to include.
    • exclude_relation(relation): Specifies which word relations to exclude.
    from wiktionaryparser import WiktionaryParser
    parser = WiktionaryParser()
    word = parser.fetch('test')
    another_word = parser.fetch('test', 'french')
  3. Understand the parsed JSON structure

    master

    The fetch method returns data in a structured JSON format. The current parser supports etymologies, definitions, pronunciations, examples, audio links, and related words.

    JSON Schema:

    [
      {
        "pronunciations": {
          "text": ["pronunciation text"],
          "audio": ["pronunciation audio"]
        },
        "definitions": [
          {
            "relatedWords": [
              {
                "relationshipType": "word relationship type",
                "words": ["list of related words"]
              }
            ],
            "text": ["list of definitions"],
            "partOfSpeech": "part of speech",
            "examples": ["list of examples"]
          }
        ],
        "etymology": "etymology text"
      }
    ]
    [
        {
            "pronunciations": {
                "text": ["pronunciation text"],
                "audio": ["pronunciation audio"]
            },
            "definitions": [{
                "relatedWords": [{
                    "relationshipType": "word relationship type",
                    "words": ["list of related words"]
                }],
                "text": ["list of definitions"],
                "partOfSpeech": "part of speech",
                "examples": ["list of examples"]
            }],
            "etymology": "etymology text",
        }
    ]