booktools

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2018 License: Apache-2.0 Imports: 7 Imported by: 2

README

Booktools

===============

GoDoc

Install:

go get github.com/TheGrum/booktools
cd github.com/TheGrum/booktools/booktools
go build

=====

Booktools is a simple tool to read a raw text file containing a manuscript and parse its structure, to then provide information about it.

Usage
Usage:
  booktools process [command]

Available Commands:
  chapter              Displays the contents of a chapter
  chapterCharacters    Lists the characters in each chapter
  characterFrequencies Lists the characters and the frequency with which they appear.
  characters           Lists the characters in the book
  display              Displays the processed structure
  serve                Starts booktools as a webservice

Flags:
  -r, --chapterRegex string   Regular expression which if matched on a line will trigger a chapter.
  -h, --help                  help for process

Global Flags:
      --config string   config file (default is $HOME/.temp.yaml)
Example
> ./booktools process serve mybook.txt
To access booktools, open a webbrowser and
navigate to http://localhost:8080/


Documentation

Index

Constants

View Source
const (
	Word      = iota
	Sentence  = iota
	Paragraph = iota
	Section   = iota
	Chapter   = iota
	Work      = iota
)

Variables

This section is empty.

Functions

func CharacterFrequencies

func CharacterFrequencies(root *Chunk, minAppearance int, minNonFirst int) map[string]int

func DigestChunks

func DigestChunks(c chan *Chunk, out chan *Chunk)

func IdentifyCharacters

func IdentifyCharacters(root *Chunk, minAppearance int, minNonFirst int) []string

func PrintLines

func PrintLines(ss []string)

func PrintNameFrequency

func PrintNameFrequency(nf map[string]int)

func SortAndPrintLines

func SortAndPrintLines(ss []string)

func UnitToString

func UnitToString(unit int) string

Types

type Chunk

type Chunk struct {
	Position int64
	Length   int64
	Unit     int
	Word     string
	Children []*Chunk
}

func (*Chunk) GetChapter

func (c *Chunk) GetChapter(chapter int) string

func (*Chunk) GetChapterHTML

func (c *Chunk) GetChapterHTML(chapter int) string

func (*Chunk) GetFirstSentence

func (c *Chunk) GetFirstSentence() string

func (*Chunk) GetNthSentence

func (c *Chunk) GetNthSentence(n int) string

func (*Chunk) GetSpecificWordCount

func (c *Chunk) GetSpecificWordCount(w string) int

func (*Chunk) GetWordCount

func (c *Chunk) GetWordCount() int

func (*Chunk) HTML

func (c *Chunk) HTML() string

func (*Chunk) PrintChapter

func (c *Chunk) PrintChapter(chapter int)

func (*Chunk) PrintStructure

func (c *Chunk) PrintStructure(includeSentences bool, maxDepth int) string

func (*Chunk) PrintTopXCharactersPerChapter

func (c *Chunk) PrintTopXCharactersPerChapter(includeSentences bool, includeXthSentence int, topX int, tabDelimit bool, wordCount bool)

func (*Chunk) String

func (c *Chunk) String() string

type ChunkIterator

type ChunkIterator struct {
	FirstWordInSentence    bool
	FirstSentenceInSection bool
	// contains filtered or unexported fields
}

func NewChunkIterator

func NewChunkIterator(root *Chunk) *ChunkIterator

func (*ChunkIterator) GetDepth

func (c *ChunkIterator) GetDepth() int

func (*ChunkIterator) NextChunk

func (c *ChunkIterator) NextChunk() *Chunk

func (*ChunkIterator) NextWord

func (c *ChunkIterator) NextWord() *Chunk

func (*ChunkIterator) Value

func (c *ChunkIterator) Value() *Chunk

type Chunker

type Chunker struct {
	OnSentence       func(c *Chunker, s string)
	OnBeforeSentence func(c *Chunker, s string)
	// contains filtered or unexported fields
}

func NewChunker

func NewChunker(r io.Reader, out chan *Chunk) *Chunker

NewChunker creates a Chunker to chunk the contents of io.Reader into channel out

func (*Chunker) Chapter

func (c *Chunker) Chapter()

func (*Chunker) Paragraph

func (c *Chunker) Paragraph()

func (*Chunker) Read

func (c *Chunker) Read(p []byte) (n int, err error)

func (*Chunker) Section

func (c *Chunker) Section()

func (*Chunker) Sentence

func (c *Chunker) Sentence()

func (*Chunker) Word

func (c *Chunker) Word()

type Pair

type Pair struct {
	Key   string
	Value int
}

type PairList

type PairList []Pair

func RankByFrequency

func RankByFrequency(freq map[string]int) PairList

func (PairList) Len

func (p PairList) Len() int

func (PairList) Less

func (p PairList) Less(i, j int) bool

func (PairList) Swap

func (p PairList) Swap(i, j int)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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