brwords

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 6 Imported by: 0

README

brwords

DISCLAIMER

Please DO NOT flood dicio website with requests. Using it from CLI is fine, but you must use some cache if you are going to use it in a project that processes many words.

Overview

The brwords package is a Go package that provides an easy way to extract word meanings, synonyms, etymologies, and usage examples from the Dicio website (a popular Brazilian Portuguese dictionary). The package includes a Command Line Interface (CLI) tool that enables users to access these features directly from the terminal.

Features

  • Extract Word Meanings: Retrieve the definition of any word in Portuguese from Dicio.
  • Synonyms: Get a list of synonyms for the word you're querying.
  • Etymology: Retrieve the origin and history of the word.
  • Examples: Fetch real-life example sentences showing the word in context.
  • Command-Line Interface: Access the functionality directly from the terminal.
  • Simple Installation: Install the CLI with a single command.

Usage - Full documentation here

Note: the output is completely in Brazilian Portuguese, but the code and exposed interfaces are in English.

First, add the package using the following command:

go get github.com/bruceneco/brwords

Next, import and use it in your code:

package main

import (
	"encoding/json"
	"fmt"
	"github.com/bruceneco/brwords"
)

func main() {
	s := brwords.NewScrap()
	word, _ := s.Word("sandice")
	res, _ := json.MarshalIndent(word.Meanings, "", "\t")
	fmt.Println(string(res))
}
/*  go run main.go
[
	{
		"conteudo": "Característica, condição, particularidade de quem se comporta ou se comunica através de tolices, de modo tolo ou simplório."
	},
	{
		"conteudo": "Característica, ação ou discurso que denota tolice, ignorância ou ausência de inteligência; tolice, idiotice, parvoíce."
	},
	{
		"conteudo": "Discurso, comportamento, ação que demonstra ausência de lógica; loucura."
	},
	{
		"conteudo": "Abatimento demonstrado com o passar dos anos; fraqueza mental relacionada à idade; senilidade."
	}
]
*/

Installation (CLI)

To use brwords as CLI tool, you can easily install it via Go using the following command:

go install github.com/bruceneco/brwords/cmd/br@latest

This will install the br command into your $GOPATH/bin (or $HOME/go/bin if using Go modules).

Make sure you have Go installed and set up on your system before running the command.

Usage (CLI)

Once installed, you can use the br command to query word meanings, synonyms, etymologies, etymologies, and examples from Dicio.

Basic Command Syntax
br <word>

Where <word> is the word you want to look up.

Example Usage
  1. Get the meaning of a word:
br sandice

This will return the definition of the word "sandice" (love) from Dicio.

  1. Get synonyms of a word:
br sandice --sy

This will list synonyms for the word "sandice".

  1. Get etymologies of a word:
br sandice -et

This will list etymologies for the word "sandice".

  1. Get example usage:
br sandice -ex

This will display example sentences showing the usage of "sandice".

Flags

The CLI supports the following flags to narrow down the results:

  • -sy: Fetch synonyms for the word.
  • -et: Fetch antonyms for the word.
  • -ex: Fetch example usage sentences.
  • -m | -d: Fetch meanings.
  • -json | -j: Output the result in JSON format.
  • -h: Display help information.

For example, to get both the meaning and synonyms:

br sandice -sy

Contributing

Feel free to open issues or contribute to the project by creating pull requests. If you encounter any bugs or have feature requests, please raise an issue on the GitHub repository.

Contact

For any issues or inquiries, feel free to reach out to the maintainer via the GitHub repository or email.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCantVisit means that the page could not be found or is not accessible.
	ErrCantVisit = errors.New("failed to visit page")
)

Functions

This section is empty.

Types

type Meaning

type Meaning struct {
	// Tag is the type of meaning
	Tag string `json:"tipo,omitempty"`
	// Content is the meaning itself
	Content string `json:"conteudo"`
}

Meaning is the definition of a word

type Phrase

type Phrase struct {
	// Content is the phrase itself.
	Content string `json:"conteudo"`
	// By is the source of the Phrase.
	By string `json:"autor"`
}

Phrase is an example of word usage.

type Scrap

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

Scrap is the base instance to make word

func NewScrap

func NewScrap() *Scrap

NewScrap creates a Scrap instance.

func (*Scrap) Slug

func (*Scrap) Slug(word string) string

Slug generates a slug based on a word, sanitizing it.

func (*Scrap) Word

func (w *Scrap) Word(rawWord string) (Word, error)

Word populates an instance of Word based on extracted content.

type Scrapper

type Scrapper interface {
	Word(rawWord string) (Word, error)
}

Scrapper is definition of what the Scrap implements.

type Word

type Word struct {
	// Content is the word itself
	Content string `json:"palavra"`
	// Meanings are a list of possible meanings
	Meanings []Meaning `json:"significados"`
	// Synonyms are a list of possible synonyms
	Synonyms []string `json:"sinonimos"`
	// Etymologies are a list of possible etymologies
	Etymologies []string `json:"etimologias"`
	// Phrases are a list of example phrases
	Phrases []Phrase `json:"frases"`
}

Word is the core result of an extraction.

Directories

Path Synopsis
cmd
br command

Jump to

Keyboard shortcuts

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