scriptparser

package module
v0.0.0-...-5cbdaa6 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const NON_ACTOR = Actor("")

Variables

View Source
var StringComparatorExactSearch = StringComparator(func(s1 string, s2 string) bool { return s1 == s2 })

StringComparatorExactSearch `script.CreateSearchFunction(StringComparatorExactSearch)` gives you a SearchFunction that will look for a Line with an exact match with the target. Functions of the type StringSimplifier can be used to simplify strings before comparison.

View Source
var StringComparatorSubsetSearch = StringComparator(strings.Contains)

StringComparatorSubsetSearch `script.CreateSearchFunction(StringComparatorSubsetSearch)` gives you a SearchFunction that will look for a Line with a subset that matches the target. Functions of the type StringSimplifier can be used to simplify strings before comparison.

View Source
var StringSimplifierAlphabetOnly = StringSimplifierSkipIfRune(func(r rune) bool {
	return r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z'
})

StringSimplifierAlphabetOnly is a StringSimplifier that extracts only alphabets from the string

View Source
var StringSimplifierIgnoreCase = StringSimplifier(strings.ToUpper)

StringSimplifierIgnoreCase is a StringSimplifier that will have the comparator ignoring case

Functions

This section is empty.

Types

type Actor

type Actor = string

type Line

type Line struct {
	Speaker     string
	LineNumbers []int
	Dialogue    string
}

type RawLine

type RawLine struct {
	Actor       string
	Line        string
	LineNumbers []int
}

type Script

type Script struct {
	Actors            []Actor
	MapRepresentation map[Actor][]Line
	ArrRepresentation []Line
}

func NewScript

func NewScript(rawDialogues []RawLine) *Script

func (Script) ConvertToCsv

func (s Script) ConvertToCsv(splitAtNewLine bool, wr io.Writer)

func (Script) CreateSearchFunction

func (s Script) CreateSearchFunction(comparator StringComparator, simplifiers ...StringSimplifier) SearchFunction

type ScriptParser

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

func (*ScriptParser) CreateDialogueRegex

func (s *ScriptParser) CreateDialogueRegex(prefixRegexp, actorRegexp, postfixRegexp string, isMultiLineDialogue bool)

CreateDialogueRegex creates a regexp pattern for identifying the start of a dialogue. Note that it will be combined in the form: `^{prefixRegexp}{actorRegexp}{postfixRegexp}{dialogue}`. If isMultiString is turned on, dialogue will include every line afterwards until `^{prefixRegexp}{actorRegexp}{postfixRegexp}` is found on the next line. Do not use capturing groups inside the input regexp. Note: any errors will cause a panic to simplify client code.

func (*ScriptParser) LoadTranscript

func (s *ScriptParser) LoadTranscript(reader io.Reader) *Script

func (*ScriptParser) LoadTranscriptFromFilePath

func (s *ScriptParser) LoadTranscriptFromFilePath(filepath string)

LoadTranscriptFromFilePath will attempt to load from filepath, and panic immediately if it does not work.

func (*ScriptParser) UseSkipRegexps

func (s *ScriptParser) UseSkipRegexps(skipRegexps []*regexp.Regexp)

UseSkipRegexps to skip over non-dialogue lines if isMultilineDialog is turned on. Unlike CreateDialogRegex, this is not combined with anything else and will be used as is. As such, the regex should use ^ and $ to ensure multiline dialogs that contain a match do not get skipped over. Note: Only has an effect if isMultilineDialog is true.

type SearchFunction

type SearchFunction = func(string) (bool, Line)

type StringComparator

type StringComparator = func(string, string) bool

func CreateWildcardComparator

func CreateWildcardComparator(wildcard regexp.Regexp) StringComparator

CreateWildcardComparator creates a wildcard aware StringComparator. It takes in a wildcard regex pattern and treats any matches in the target string as wildcards. Note that it only looks to match the resulting target as a subset of dialogues, not an exact match.

type StringSimplifier

type StringSimplifier = func(string) string

func StringSimplifierSkipIfRune

func StringSimplifierSkipIfRune(skipIfTrue func(r rune) bool) StringSimplifier

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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