Showing posts with label csv. Show all posts
Showing posts with label csv. Show all posts

Tuesday, September 8, 2026

braillebaseio

import json
import csv
import xml.etree.ElementTree as ET

# 0
def read_file(path: str) -> list:
    with open(path, "r", encoding="utf-8") as f:
        return read_string(f.read())

# 1
def read_string(data: str) -> list:
    data = data.strip()

    if data.startswith("[") or data.startswith("{"):
        return _from_json(data)

    if data.startswith("<?xml") or data.startswith("<"):
        return _from_xml(data)

    return _from_csv(data)


def _from_json(data: str):
    raw = json.loads(data)
    result = []

    for item in raw:
        braille_raw = item.get("braille")

        if isinstance(braille_raw, str):
            braille = [b.strip() for b in braille_raw.split(",")]
        else:
            braille = braille_raw

        result.append((
            item.get("letter"),
            braille,
            int(item.get("pattern"))
        ))

    return result


def _from_csv(data: str):
    result = []
    reader = csv.reader(data.splitlines())

    for row in reader:
        if len(row) < 3:
            continue

        letter, braille_raw, pattern = row
        braille = [b.strip() for b in braille_raw.split(",")]

        result.append((
            letter,
            braille,
            int(pattern)
        ))

    return result


def _from_xml(data: str):
    root = ET.fromstring(data)
    result = []

    for item in root.findall("item"):
        letter = item.findtext("letter")
        braille_raw = item.findtext("braille")
        pattern = item.findtext("pattern")

        braille = [b.strip() for b in braille_raw.split(",")]

        result.append((
            letter,
            braille,
            int(pattern)
        ))

    return result



LICENSE


braillebaseio — CC0 1.0 Universal


This software is released under the Creative Commons Zero v1.0 Universal (CC0 1.0) license.


To the extent possible under law, the author has waived all copyright and related or neighboring rights to this work.

You may copy, modify, distribute, and use this software for any purpose, including commercial purposes, without asking permission.


Full legal text:

https://creativecommons.org/publicdomain/zero/1.0/



README


🙏 Thanks

This project exists thanks to the support, collaboration, and tools provided by many people and communities.

My sincere appreciation goes to:

Microsoft – Copilot

  • For providing an accessible AI assistant that played a fundamental role in the growth and refinement of this system.

Microsoft – Visual Studio Code

  • For offering a powerful, free, and accessible development environment.

Python Community

  • For maintaining a free, open, and expressive programming language that makes projects like this possible.

Developers Who Came Before

  • For building the foundations, tools, and knowledge that allow new accessibility technologies to exist today.

Nagao Yuji

  • For creating and maintaining BrailleBase, designing its architecture, and developing its core features with a focus on accessibility and education.


pyproject.toml

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "braillebaseio"
version = "1.0.3"
description = "Universal Braille Data Loader: Reads CSV, XML, or JSON sheets and converts them into a unified structure containing Letter, Braille cell, and Pattern classification."
authors = [
    { name = "Nagao Yuji" }
]
readme = "README.md"
license = { text = "CC0-1.0" }
requires-python = ">=3.6"
keywords = ["braille", "csv", "json", "xml", "braillebase", "blind", "education", "loader"]

[project.urls]
Homepage = "https://github.com/DukaCrazy/braillebaseio"
Documentation = "https://github.com/DukaCrazy/braillebaseio"
Source = "https://github.com/DukaCrazy/braillebaseio"

braillebaseuniversalset

  class BrailleBaseBniversalSet : def braille_base_universal_set (): #LOWER return [[ "a" , [ "⠁...