Skip to main content

Python package

Greek Language Utilties from the WMU Hecurlaneum Project.

This package provides a set of utilities for working with Greek text. It is designed to be used in conjunction with the WMU Herculaneum Project, but can be used independently.

Installation

poetry add wmu_greek_utils

Usage

Normalization Options

The Normalizer class provides several options for normalizing Greek text. These options can be combined to achieve the desired normalization effect. Below are the available options:

  • LOWERCASE: Converts all characters to lowercase.
  • UPPERCASE: Converts all characters to uppercase.
  • REMOVE_SPACES: Removes all spaces from the text.
  • REMOVE_NEWLINES: Removes all newline characters from the text.
  • REMOVE_PUNCTUATION: Removes all punctuation marks from the text.
  • REMOVE_ACCENTS: Removes all accent marks from the text.
  • REMOVE_BREATHING: Removes all breathing marks from the text.
  • IOTA_ADSCRIPT: Converts iota subscript to iota adscript.
  • NORMALIZE_SIGMA: Normalizes all sigma characters to a single form.
  • NORMALIZE_THETA: Normalizes all theta characters to a single form.
  • NORMALIZE_PHI: Normalizes all phi characters to a single form.
  • NORMALIZE_APOSTROPHE: Normalizes all apostrophe characters to a single form.

Example Usage

from normalize import Normalizer, NormalizationOptions

# Standard normalization is LOWERCASE | NORMALIZE_THETA | NORMALIZE_PHI | NORMALIZE_APOSTROPHE
normalize = Normalizer()
# notice odd thetas
text = "Ἐν ἀρχῇ ἦν ὁ Λόγος, καὶ ὁ Λόγος ἦν πρὸς τὸν ϑεόν, καὶ ϑεὸς ἦν ὁ Λόγος."
normalized_text = normalize(text)
print(normalized_text)  # Output: "ἐν ἀρχῇ ἦν ὁ λόγος, καὶ ὁ λόγος ἦν πρὸς τὸν θεόν, καὶ θεὸς ἦν ὁ λόγος."

# Create a normalizer with multiple options

from normalize import UPPERCASE, REMOVE_SPACES, REMOVE_NEWLINES, REMOVE_PUNCTUATION, REMOVE_ACCENTS, REMOVE_BREATHING, IOTA_ADSCRIPT, NORMALIZE_SIGMA, NORMALIZE_THETA, NORMALIZE_PHI, NORMALIZE_APOSTROPHE

radical_normalizer = Normalizer(config=UPPERCASE
        | REMOVE_SPACES
        | REMOVE_NEWLINES
        | REMOVE_PUNCTUATION
        | REMOVE_ACCENTS
        | REMOVE_BREATHING
        | IOTA_ADSCRIPT
        | NORMALIZE_SIGMA
        | NORMALIZE_THETA
        | NORMALIZE_PHI
        | NORMALIZE_APOSTROPHE
)

# The above is equivalent to Normalizer(config=NORMALIZATION_OPTIONS.ALL)

normalized_text = radical_normalizer(text)
print(normalized_text)  # Output: "ΕΝΑΡΧΗΙΗΝΟΛΟΓΟϹΚΑΙΟΛΟΓΟϹΗΝΠΡΟϹΤΟΝΘΕΟΝΚΑΙΘΕΟϹΗΝΟΛΟΓΟϹ"

AGDT morphological parsing

parse_mophology

The parse_morphology function can be used to parse the morphology field of a morphological code.

Examples:

  1. Parsing a verb morphology code:
>>> parse_morphology("v3sasm---", include_names=False)
['verb', 'third person', 'singular', 'aorist', 'subjunctive', 'middle', None, None, None]
  1. Parsing a noun morphology code:
>>> parse_morphology("n-s---mn-", include_names=False)
['noun', None, 'singular', None, None, None, 'masculine', 'nominative', None]
  1. Including the position names in the output:
   >>> list(parse_morphology("n-s---mn-"))
    [('part_of_speech', 'noun'), ('person', None), ('number', 'singular'), ('tense', None), ('mood', None), ('voice', None), ('gender', 'masculine'), ('case', 'nominative'), ('degree', None)]

morphology_string

Given a list of forms, produce the morphology string to the best of our ability.

Examples:

  1. Basic usage with a list of forms:
>>> morphology_string(['noun', 'masculine', 'singular', 'nominative'])
'n-s---mn-'
  1. Usage with a randomized list of forms (in other words, the order of the forms does not matter):
>>> list = ['noun', 'masculine', 'singular', 'nominative']
>>> random.shuffle(list)
>>> morphology_string(list)
'n-s---mn-'
  1. Usage with abbreviated forms:
>>> morphology_string(['masc', 'sing', 'nom', 'n'])
'n-s---mn-'
  1. Usage with a more complex list of forms:
>>> morphology_string(['verb', 'third person', 'singular', 'aorist', 'subjunctive', 'middle', None, None, None])
'v3sasm---'
  1. Usage with a partial list of forms:
>>> morphology_string(['verb', 'third person', 'singular', 'aorist', 'subjunctive', 'middle'])
'v3sasm---'

position_to_name

""" Given a 0-based position, return the name of the position.

'part_of_speech' >>> position_to_name(8)
'degree'

name_to_position

Given a name, return the 0-based position. Can use some short or alternate names for the name.

    >>> name_to_position('part_of_speech')
    0
    >>> name_to_position('pos')
    0
    >>> name_to_position('degree')
    8

recreate_sentence

Given a list of words and a list of morphologies, recreate the sentence, along with the positions in the sentence.

words = [
        ("The", "det"),
        ("cat", "noun"),
        (",", "punctuation"),
        ("the", "det"),
        ("dog", "noun"),
        (",", "punctuation"),
        ("and", "conj"),
        ("the", "det"),
        ("frog", "noun"),
        ("sat", "verb"),
        ("on", "prep"),
        ("the", "det"),
        ("mat", "noun"),
        (".", "punctuation"),
    ]
sentence, poss = agdt.recreate_sentence(words)
assert sentence == "The cat, the dog, and the frog sat on the mat."
assert poss == [
        (0, 2),
        (4, 6),
        (7, 7),
        (9, 11),
        (13, 15),
        (16, 16),
        (18, 20),
        (22, 24),
        (26, 29),
        (31, 33),
        (35, 36),
        (38, 40),
        (42, 44),
        (45, 45),
    ]

Acknowledgements

This package was developed by the WMU Herculaneum Project.

I am grateful for James Tauber's greek_normalisation package, which was used as a reference for the normalization options in this package; some of that package is used.

Metadata

Release files for wmu-greek-utils 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wmu-greek-utils 0.3.1
File Size Uploaded Provenance Actions
wmu_greek_utils-0.3.1.tar.gz 7.3 kB Without provenance Details for wmu_greek_utils-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wmu-greek-utils 0.3.1
File Interpreter ABI Platform Actions
wmu_greek_utils-0.3.1-py3-none-any.whl Python 3 none any Details for wmu_greek_utils-0.3.1-py3-none-any.whl

Total release size: 15.8 kB

Release files / wmu_greek_utils-0.3.1.tar.gz

Download URL wmu_greek_utils-0.3.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f63640c7c6dc417e3451c1686a6a23dffc15527348451feca7abc31cb4b4c649
BLAKE2b-256 checksum
How to use checksums
4c98e7b3050854c94a6ee804eb8ca3757ec0df28c27c2dcb679e8a283fe8faec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0

Release files / wmu_greek_utils-0.3.1-py3-none-any.whl

Download URL wmu_greek_utils-0.3.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94acff3e960d9eb7b3f5715d5e2659be87126c3ba4b9f0b6e08085b575326fb5
BLAKE2b-256 checksum
How to use checksums
01d3eb19ba1a91ec2d5e00df52bae57872f2f9f684b7ffc6650904514d53a32a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0

Security for wmu-greek-utils 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page