-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |