morph

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: GPL-3.0 Imports: 15 Imported by: 6

README

morph License GoDoc Pipeline status

A morphological analyzer for Russian language, using dictionaries from pymorphy2.

Install

The package:

go get -u gitlab.com/opennota/morph

And the dictionaries:

pip install --user pymorphy2-dicts-ru

Use

package main
import (
    "fmt"
    "gitlab.com/opennota/morph"
)
func main() {
    // loading the dictionary data;
    // you can also use morph.InitWith("path/to/the/dictionary")
    if err := morph.Init(); err != nil {
        panic(err)
    }
    // parsing
    words, norms, tags := morph.Parse("все")
    for i := range words {
        fmt.Printf("%-4s %-5s %s\n", words[i], norms[i], tags[i])
    }
}

Output:

все  весь  ADJF,Subx,Apro plur,nomn
все  весь  ADJF,Subx,Apro inan,plur,accs
всё  всё   PRCL
всё  весь  ADJF,Subx,Apro neut,sing,nomn
всё  весь  ADJF,Subx,Apro neut,sing,accs

Documentation

Overview

Package morph provides a simple morphological analyzer for Russian language, using the compiled dictionaries from pymorphy2.

Example
words, norms, tags := Parse("криком")
for i := range words {
	fmt.Println(words[i], norms[i], tags[i])
}
Output:
криком крик NOUN,inan,masc sing,ablt

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyInitialized = errors.New("already initialized")
)

Functions

func Init

func Init() error

Init tries to find the path to the installed pymorphy2 dictionaries by invoking python and calls InitWith with the found directory.

func InitWith

func InitWith(dir string) error

InitWith loads the pymorphy2 dictionary data from the given directory.

func InitWithFS added in v1.0.2

func InitWithFS(fsys fs.FS, dir string) error

InitWithFS loads the pymorphy2 dictionary data from the given directory in the fsys filesystem.

func Parse

func Parse(word string) (words, norms, tags []string)

Parse analyzes the (lowercase) word and returns three slices of the same length. Each triple (words[i], norms[i], tags[i]) represents an analysis, where: - words[i] is the word with the letter ё fixed; - norms[i] is the normal form of the word; - tags[i] is the grammatical tag, consisting of the word's grammemes. The analyzes are sorted by probability (the first one is the most probable).

func XParse

func XParse(word string) (words, norms, tags []string)

XParse analyzes the word (which might not be in the dictionary) and returns three slices of the same length. Each triple (words[i], norms[i], tags[i]) represents an analysis, where: - words[i] is the word with the letter ё fixed; - norms[i] is the normal form of the word; - tags[i] is the grammatical tag, consisting of the word's grammemes. If the word is in the dictionary, XParse is equivalent to Parse. Otherwise it tries several other analyzers to analyze the unknown word.

Types

This section is empty.

Jump to

Keyboard shortcuts

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