gmtrn

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 7 Imported by: 0

README

==========================================================
 gmtrn - Parser and CLI tool for http://www.multitran.com
==========================================================

Gmtrn is a parser for http://www.multitran.com written in Go.

This project contains parser library and simple CLI client.

Install
-------

Install Go and set up Go language environment (`official docs`_).

Simple installation of CLI tool::

 git clone https://github.com/vladimir-g/gmtrn/
 cd gmtrn/cmd/gmtrn-cli
 go build .

These commands would generate ``gmtrn-cli`` binary.

Library also can be installed without CLI::

 go get github.com/vladimir-g/gmtrn

For new versions of golang import statement is enough.

CLI usage
---------

Simple usage::

 $GOPATH/bin/gmtrn-cli translation string

More usage options available in help::

 $GOPATH/bin/gmtrn-cli -h

If name of the binary looks too long just add alias for it.

Example script with xsel and freedesktop notifications::

 #/bin/sh
 notify-send -t 0 \
   "<span font='monospace'>$(xsel | xargs -0 gmtrn-cli | fold -sw 100)</span>"

Another example with zenity::

 #/bin/sh

 xsel | xargs -0 gmtrn-cli | fold -sw 120 | zenity --no-wrap --text-info --width=800 --height=500

CLI app can also output results in JSON format that may be parsed with
some utility.

Library usage
-------------

Use this code::

 result, err := gmtrn.Query("Query string",
                            gmtrn.Languages["english"],
                            gmtrn.Languages["russian"])

More documentation in `doc.go`_


Known issues
------------

* Site has autodetection algorithm, so sometimes even uses different
  source/target languages, depending on query. It mostly ok though.

* Only default site interface language is implemented.

* There is no tests.

License
=======

This library released under MIT license, see LICENSE file.

.. _official docs: https://golang.org/doc/install
.. _doc.go: doc.go

Documentation

Overview

Package gmtrn implements http client library for multitran.com

Usage:

   result, err := gmtrn.Query("Query string",
		       gmtrn.Languages["english"], // source language (from)
                       gmtrn.Languages["russian"]) // target language (to)

How multitran works

Requested query is splitted into multiple parts depending on found
translations. Results page contains corresponding part of the
query, list of words and links to other pages with other parts of
query (if exist).

For example, query "first second third" may be splitted by
multitran to pages with "first second" and "third".

How this library works

   Library makes request to the site and extracts first page. If this
   page contains links to other pages with separate word translations,
   they are requested next.

   Every requested page is splitted into Words that have multiple
   Meanings, and combined into WordList. For example, for query
   "translation library" there would be two WordList objects, one for
   "translation", other for "library". First one would contain
   multiple words ("translation" (verb, noun), "translations" etc),
   and every Word would have list of Meanings. Word also may contain
   optional pre- and post-parts that provide some context, and also
   optional phonetic spelling. Every object also contains a link to
   corresponding page that may be used by library user.

   Description of types in site terms:

	Meaning - one line with multiple definitions in specific topic.
	  eng.    | chain; complex; structure; type; integer (essence);
	  ^ topic   ^ MeaningWord

	MeaningWord - word from Meaning line.
	  integer (essence)
	  ^ word   ^ add (additional info)

	Word - list of Meanings for word.
	  общее число [...] π сущ. // Word.Pre, Word.Word, Word.Post, Word.Spelling, Word.Part (part of speech)
	     genet. number; date; figure; numeric; // Meaning
	     autom. digit                          // Meaning

	WordList - part of initial query with corresponding words.
	  числа // WordList.Query
	    число, ...  // Words

   How it looks on site:

	Word
	  topic   meaning, meaning, meaning
	  topic   meaning, meaning, meaning
	  ...
	Word
	  topic   meaning, meaning, meaning
	  topic   meaning, meaning, meaning
	...

Known issues

  • Site has autodetection algorithm, so sometimes even uses different source/target languages, depending on query. It mostly ok though.

  • Only default site interface language is implemented.

  • Thesaurus is parsed as simple translation table.

  • There is no tests.

Index

Constants

This section is empty.

Variables

View Source
var Languages = map[string]int{
	"english":    1,
	"russian":    2,
	"german":     3,
	"french":     4,
	"spanish":    5,
	"croatian":   8,
	"arabic":     10,
	"portuguese": 11,
	"lithuanian": 12,
	"romanian":   13,
	"polish":     14,
	"bulgarian":  15,
	"czech":      16,
	"chinese":    17,
	"danish":     22,
	"italian":    23,
	"dutch":      24,
	"latvian":    27,
	"estonian":   26,
	"japanese":   28,
	"swedish":    29,
	"norwegian":  30,
	"afrikaans":  31,
	"turkish":    32,
	"ukrainian":  33,
	"esperanto":  34,
	"kalmyk":     35,
	"finnish":    36,
	"latin":      37,
	"greek":      38,
	"korean":     39,
	"hungarian":  42,
	"irish":      49,
	"slovak":     60,
	"slovene":    67,
	"maltese":    78,
}

Available languages

Functions

This section is empty.

Types

type Meaning

type Meaning struct {
	Words []MeaningWord
	Topic,
	Link,
	Title string
}

Meaning of some word by topic. Optional Title extracted from link tooltip.

func (Meaning) String

func (d Meaning) String() string

type MeaningWord

type MeaningWord struct {
	Word,
	Link,
	Add,
	Translator,
	TranslatorLink,
	TranslatorTitle string
}

Single part of definition that contains a single word, link to the word page and additional information. Link often couldn't be opened without multitran.com referer for access. If translation was provided by some user, information is extracted into Translator (username), TranslatorLink (link to profile) and TranslatorTitle (link title, contains date of translation)

func (MeaningWord) String

func (w MeaningWord) String() string

type Word

type Word struct {
	Meanings []Meaning
	Word,
	Link,
	Pre,
	Post,
	Spelling,
	Part string
}

Word with list of meanings. Pre, Post and Spelling are optional parts. Pre is displayed before and Post after the word to provide translation context. Spelling is written in phonetic alphabet. Part describes part of speech.

func (*Word) AddMeaning added in v0.3.0

func (w *Word) AddMeaning(meaning Meaning)

func (Word) String

func (w Word) String() string

type WordList

type WordList struct {
	Words []Word
	Query,
	Link string
}

List of words at page

func Query

func Query(query string, langFrom int, langTo int) (result []WordList, err error)

Run HTTP query to multitran.com and return parsed results or error. Function may return error if translation isn't found or something wrong happens.

  • query - query string
  • langFrom - integer from Languages map, source language
  • langTo - integer from Languages map, target language

func (*WordList) AddWord added in v0.3.0

func (w *WordList) AddWord(word Word)

func (WordList) String

func (w WordList) String() string

Directories

Path Synopsis
cmd
gmtrn-cli
Command-line interface for http://www.multitran.ru/
Command-line interface for http://www.multitran.ru/

Jump to

Keyboard shortcuts

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