prg2p

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 5 Imported by: 0

README

logo

Grapheme-to-phoneme converter for Polish in Go

The prg2p package implements a grapheme-to-phoneme rule based converter for Polish.

It provides a standalone command-line program to process data efficiently on the terminal and exposes the public API components of the package for code reuse.

Consult the package documentation or check Usage section below to see how to use prg2p in your code.

Installation

To add package to a Go project dependencies run the following command:

go get github.com/mdm-code/prg2p

In order to use the CLI program, you need to use this command:

go install github.com/mdm-code/prg2p@latest

Here, you can use the @latest or any version you find appropriate for that matter.

Usage

Type prg2p -h from the terminal after installing executables as described here to see how to use prg2p command-line interface.

Here is how you can use the public API of the prg2p package in your code:

package main

import (
	"fmt"

	"github.com/mdm-code/prg2p"
)

func main() {
	r := prg2p.Rules()
	g2p, err := prg2p.Load(r)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Iterate over words to get their phonemic transcripts
	var trans []string
	for _, w := range []string{"ala", "ma", "kota"} {
		t, err := g2p.Transcribe(w, false)
		if err != nil {
			fmt.Println(err)
			continue
		}
		trans = append(trans, t...)
	}
	for _, t := range trans {
		fmt.Println(t)
	}
}

Development

All necessary development tools are in the Makefile. Calling make test consecutively invokes go fmt, go vet, golint and go test. CI/CD is handled by Github workflows. Remember to install golint before testing and building:

go install golang.org/x/lint/golint@latest

Happy coding!

License

Copyright (c) 2023 Michał Adamczyk.

This project is licensed under the MIT license. See LICENSE for more details.

Documentation

Overview

Package prg2p implements a grapheme-to-phoneme rule-based converter.

Usage

package main

import (
	"fmt"

	"github.com/mdm-code/prg2p"
)

func main() {
	r := prg2p.Rules()
	g2p, err := prg2p.Load(r)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Iterate over words to get their phonemic transcripts
	var trans []string
	for _, w := range []string{"ala", "ma", "kota"} {
		t, err := g2p.Transcribe(w, false)
		if err != nil {
			fmt.Println(err)
			continue
		}
		trans = append(trans, t...)
	}
	for _, t := range trans {
		fmt.Println(t)
	}
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rules

func Rules() *strings.Reader

Rules returns a default set of g2p rules.

Types

type G2P

type G2P struct {
	// contains filtered or unexported fields
}

G2P transcriber class that takes a populated double trie tree with parsed grapheme-to-phoneme rules. It exposes transcription interface that takes individual words and outputs their most likely transcripts.

func Load

func Load(r io.Reader) (*G2P, error)

Load returns a fully initialized G2P object with rules read from r.

Example
Output:

func (*G2P) Transcribe

func (g *G2P) Transcribe(w string, all bool) ([]string, error)

Transcribe word from graphemic to phonemic transcription. Use n to specify whether to return all possible transcriptions or just the first hit.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL