Skip to content

Commit

Permalink
Add library
Browse files Browse the repository at this point in the history
  • Loading branch information
neurlang authored and Your Name committed Oct 27, 2024
1 parent 4704595 commit c63ede7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/lib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Package lib implements IPA g2p phonemizer for 64+ languages
package lib

import (
. "github.com/martinarisk/di/dependency_injection"
)
import "github.com/neurlang/goruut/dicts"
import "github.com/neurlang/goruut/usecases"
import "github.com/neurlang/goruut/models/requests"
import "github.com/neurlang/goruut/models/responses"
import "github.com/neurlang/goruut/repo/interfaces"

type Phonemizer struct {
uc usecases.IPhonemizeUsecase
}

type dummy struct {
}

func (dummy) GetIpaFlavors() map[string]map[string]string {
return make(map[string]map[string]string)
}
func (dummy) GetPolicyMaxWords() int {
return 99999999999
}

// NewPhonemizer creates a new phonemizer. Parameter di can be nil.
func NewPhonemizer(di *DependencyInjection) *Phonemizer {
if di == nil {
di = NewDependencyInjection()
di.Add((interfaces.DictGetter)(dicts.DictGetter{}))
di.Add((interfaces.IpaFlavor)(dummy{}))
di.Add((interfaces.PolicyMaxWords)(dummy{}))
}
uc := usecases.NewPhonemizeUsecase(di)
return &Phonemizer{
uc: uc,
}
}

// Sentence runs the algorithm on a sentence string in a specific language.
func (p *Phonemizer) Sentence(r requests.PhonemizeSentence) responses.PhonemizeSentence {
return p.uc.Sentence(r)
}
15 changes: 15 additions & 0 deletions lib/lib_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package lib

import "testing"
import "github.com/neurlang/goruut/models/requests"

func TestOne(t *testing.T) {
p := NewPhonemizer(nil)
resp := p.Sentence(requests.PhonemizeSentence{
Sentence: "hello world",
Language: "English",
})
for i := range resp.Words {
println(resp.Words[i].Phonetic)
}
}

0 comments on commit c63ede7

Please sign in to comment.