Documentation
¶
Overview ¶
(c) 2018-2022 by Carl Kingsford (carlk@cs.cmu.edu). See LICENSE.txt.
(c) 2018-2022 by Carl Kingsford (carlk@cs.cmu.edu). See LICENSE.txt.
(c) 2018-2022 by Carl Kingsford (carlk@cs.cmu.edu). See LICENSE.txt.
Index ¶
- Constants
- func HasQuote(w string) bool
- func IsStrangeCase(s string) bool
- type Author
- type BibTeXError
- type BraceNode
- func (bn *BraceNode) AllSpace() bool
- func (bn *BraceNode) ContainsNoBraces() bool
- func (bn *BraceNode) EndWithSpace() bool
- func (bn *BraceNode) Flatten() string
- func (bn *BraceNode) FlattenForSorting() string
- func (bn *BraceNode) FlattenToMinBraces() string
- func (bn *BraceNode) IsEntireStringBraced() bool
- func (bn *BraceNode) IsLeaf() bool
- func (b *BraceNode) PrintBraceTree(indent int)
- type Database
- func (db *Database) CanonicalBrace()
- func (db *Database) CheckASCII()
- func (db *Database) CheckAllFields(check func(string, *Value) string)
- func (db *Database) CheckAuthorLast()
- func (db *Database) CheckDuplicateKeys()
- func (db *Database) CheckEtAl()
- func (db *Database) CheckField(tag string, check func(*Value) string)
- func (db *Database) CheckLoneHyphenInTitle()
- func (db *Database) CheckPageRanges()
- func (db *Database) CheckRedundantSymbols()
- func (db *Database) CheckRequiredFields()
- func (db *Database) CheckUndefinedSymbols()
- func (db *Database) CheckUnmatchedDollarSigns()
- func (db *Database) CheckYearsAreInt()
- func (db *Database) ConvertIntStringsToInt()
- func (db *Database) ConvertTitlesToMinBraces()
- func (db *Database) FindDupsByTitle() map[string][]*Entry
- func (db *Database) FixHyphensInPages()
- func (db *Database) FixTruncatedPageNumbers()
- func (db *Database) Less(v1 *Value, v2 *Value) bool
- func (db *Database) NormalizeAuthors()
- func (db *Database) NormalizeWhitespace()
- func (db *Database) PrintErrors(w io.Writer)
- func (db *Database) RemoveContainedEntries()
- func (db *Database) RemoveDupsByTitle()
- func (db *Database) RemoveEmptyFields()
- func (db *Database) RemoveExactDups()
- func (db *Database) RemoveNonBlessedFields(additional []string)
- func (db *Database) RemovePeriodFromTitles()
- func (db *Database) RemoveWholeFieldBraces()
- func (db *Database) ReplaceAbbrMonths()
- func (db *Database) ReplaceAuthorEtAl()
- func (db *Database) ReplaceSymbols()
- func (db *Database) SortByField(field string, reverse bool)
- func (db *Database) SymbolValue(symb *Value, depth int) *Value
- func (db *Database) TitleCaseJournalNames()
- func (db *Database) TransformEachField(trans func(string, *Value) *Value)
- func (db *Database) TransformField(tag string, trans func(string, *Value) *Value)
- func (db *Database) WriteDatabase(w io.Writer)
- type Entry
- type EntryKind
- type FieldType
- type Parser
- type ParserError
- type Value
Constants ¶
const ( Deleted EntryKind = "**DELETED**" Comment = "comment" Other = "other" String = "string" Preamble = "preamble" Article = "article" Book = "book" Booklet = "booklet" InBook = "inbook" InCollection = "incollection" InProceedings = "inproceedings" Manual = "manual" MastersThesis = "mastersthesis" Misc = "misc" PhdThesis = "phdthesis" Proceedings = "proceedings" TechReport = "techreport" Unpublished = "unpublished" )
Variables ¶
This section is empty.
Functions ¶
func IsStrangeCase ¶
IsStrangeCase returns true iff s has a capital letter someplace other than the first position and not preceded by a - (so Whole-Genome is not in strange case. We also ignore punctuation at the start, so "(Whole-Genome" is also not in strange case. mRNA is.
Types ¶
type Author ¶
Author represents an Author and the various named parts.
func NormalizeName ¶
NormalizeName returns an Author object parsed from a name string. We try to follow BibTeX's (ridiculous) rules for parsing names.
type BibTeXError ¶
BibTeXError holds an error found in a bibtex file.
type BraceNode ¶
func ParseBraceTree ¶
ParseBraceTree converts a string into a tree of BraceNodes.
func (*BraceNode) ContainsNoBraces ¶
ContainsNoBraces returns true if the tree contains no {}-delimitated substrings.
func (*BraceNode) EndWithSpace ¶
EndWithSpace returns true iff the leaf node ends with a space.
func (*BraceNode) FlattenForSorting ¶
FlattenForSorting is like Flatten, but won't include any {}.
func (*BraceNode) FlattenToMinBraces ¶
FlattenToMinBraces tries to smartly {}-delimitated the smallest regions in the text that correspond to things that need {}-delimitation: strange-case (mRNA) and quotes ("). This will *only* change strings if it looks like the user didn't put any thought into it: specifically, only if the entire string is {] or none of the string is {}.
func (*BraceNode) IsEntireStringBraced ¶
IsEntireStringBraced returns true iff the entire string is enclosed in a {} {Moo}{Bar} returns false, but {Moo Bar} returns true. Technically, this is checked by testing whether the root node has a single child that is itself a braceNode (and not a leaf).
func (*BraceNode) PrintBraceTree ¶
PrintBraceTree is used for debugging --- it prints the brace tree to stdout in a simple format.
type Database ¶
type Database struct { Pubs []*Entry Symbols map[string]*Value Preamble []string Errors []*BibTeXError }
Database is a collection of entries plus symbols and preambles.
func (*Database) CanonicalBrace ¶
func (db *Database) CanonicalBrace()
BraceQuotes replaces any word foo"bar with {foo"bar"}. the most common situation is foo\"{e}bar. Note that word here is defined as a whitespace separated string of chars. We do *not* take into account the {} structure so: {hi\"{e} there} because {{hi\"{e}} there}.
func (*Database) CheckASCII ¶
func (db *Database) CheckASCII()
CheckASCII reports errors where non-ASCII are used in any field.
func (*Database) CheckAllFields ¶
CheckAllFields is a helper that runs the given check function for each field.
func (*Database) CheckAuthorLast ¶
func (db *Database) CheckAuthorLast()
CheckAuthorLast checks for authors where the last name parsed like "J H" or "JH" or "J.H." or if the last name is all lowercase. Must have called db.NormalizeAuthors(), otherwise this is a no-op.
func (*Database) CheckDuplicateKeys ¶
func (db *Database) CheckDuplicateKeys()
CheckDuplicateKeys finds entries with duplicate keys.
func (*Database) CheckEtAl ¶
func (db *Database) CheckEtAl()
CheckEtAl reports the error of using "et al" within a author list.
func (*Database) CheckField ¶
CheckField is a helper function that checks the `tag` field in entries using the given `check` function.
func (*Database) CheckLoneHyphenInTitle ¶
func (db *Database) CheckLoneHyphenInTitle()
CheckLoneHyphenInTitle reports errors where - is used when --- is probably meant.
func (*Database) CheckPageRanges ¶
func (db *Database) CheckPageRanges()
CheckPageRanges reports errors where a pages looks like X--Y where X > Y.
func (*Database) CheckRedundantSymbols ¶
func (db *Database) CheckRedundantSymbols()
CheckRedudantSymbols finds groups of @string definitions that define the same string.
func (*Database) CheckRequiredFields ¶
func (db *Database) CheckRequiredFields()
CheckRequiredFields reports any missing required fields.
func (*Database) CheckUndefinedSymbols ¶
func (db *Database) CheckUndefinedSymbols()
CheckUndefinedSymbols reports symbols that are not defined.
func (*Database) CheckUnmatchedDollarSigns ¶
func (db *Database) CheckUnmatchedDollarSigns()
CheckUnmatchedDollarSigns checks whether a string has an odd number of unescaped dollar signs.
func (*Database) CheckYearsAreInt ¶
func (db *Database) CheckYearsAreInt()
CheckYearsAreInt adds errors if a year is not an integer.
func (*Database) ConvertIntStringsToInt ¶
func (db *Database) ConvertIntStringsToInt()
ConvertIntStringsToInt looks for values that are marked as strings but that are really integers and converts them to ints. This happens when a bibtex file has, e.g., volume = {9} instead of volume = 9.
func (*Database) ConvertTitlesToMinBraces ¶
func (db *Database) ConvertTitlesToMinBraces()
ConvertTitlesToMinBraces makes sure that all strange-case words are in {}
func (*Database) FindDupsByTitle ¶
FindDupsByTitle returns sets of entries with the same title.
func (*Database) FixHyphensInPages ¶
func (db *Database) FixHyphensInPages()
FixHyphensInPages will replace pages fields that look like NUMBER - NUMBER or NUMBER -- NUMBER with NUMBER--NUMBER.
func (*Database) FixTruncatedPageNumbers ¶
func (db *Database) FixTruncatedPageNumbers()
FixTruncatedPageNumbers performs the transformation: for page fields that match aaaa--bb, and where aaaa and bb are integers, replace with aaaa-aabb.
func (*Database) NormalizeAuthors ¶
func (db *Database) NormalizeAuthors()
NormalizeAuthors parses every listed author and puts them into normal form. It also populates the Authors field of each entry with the list of *Authors. Call this function before working with the Authors field.
func (*Database) NormalizeWhitespace ¶
func (db *Database) NormalizeWhitespace()
NoramalizeWhitespace replaces errant whitespace with " " characters.
func (*Database) PrintErrors ¶
PrintErrors writes all the saved errors to the `w` stream.
func (*Database) RemoveContainedEntries ¶
func (db *Database) RemoveContainedEntries()
RemoveContainedEntries tries to find entries that are contained in others.
func (*Database) RemoveDupsByTitle ¶
func (db *Database) RemoveDupsByTitle()
RemoveDupsByTitle removes entries found by FindDupsByTitle if they are equal or one is a subset of the other.
func (*Database) RemoveEmptyFields ¶
func (db *Database) RemoveEmptyFields()
RemoveEmptyField removes string fields whose value is the empty string.
func (*Database) RemoveExactDups ¶
func (db *Database) RemoveExactDups()
RemoveExactDups find entries that are Equal and that have the same Key and deletes one of them.
func (*Database) RemoveNonBlessedFields ¶
RemoveNonBlessedFields removes any field that isn't 'blessed'. The blessed fields are (a) any fields in the required or optional global variables, any that are in the blessed global variable, plus any fields listed in the additional parameter.
func (*Database) RemovePeriodFromTitles ¶
func (db *Database) RemovePeriodFromTitles()
Removes unneeded "." from the end of the titles. The . must be the last character and it must be preceded by a lowercase letter.
func (*Database) RemoveWholeFieldBraces ¶
func (db *Database) RemoveWholeFieldBraces()
RemoveWholeFieldBraces removes the braces from fields that look like: {{foo bar baz}}.
func (*Database) ReplaceAbbrMonths ¶
func (db *Database) ReplaceAbbrMonths()
Find month fields that contain abbreviated text or numbers. Note that we don't need to handle fields that list the full month name since those are handled by the pre-defined symbols.
func (*Database) ReplaceAuthorEtAl ¶
func (db *Database) ReplaceAuthorEtAl()
ReplaceAuthorEtAl changes a terminnating "et al." to the correct "and others" inside of author fields.
func (*Database) ReplaceSymbols ¶
func (db *Database) ReplaceSymbols()
ReplaceSymbols tries to find strings that are uniquely represented by a symbol and replaces the use of those strings with the symbol. It requires (a) that the strings match exactly and (b) there is only 1 symbol that matches the string.
func (*Database) SortByField ¶
SortByField sorts the database by the given field. Missing fields will come before non-missing fields. Within the missing fields, entries will be sorted by Key. Uses the value.Less function to determine the order. If reverse is true, this order will be reversed.
func (*Database) SymbolValue ¶
SymbolValue expands symbol definitions to their defined values; if an expansion expands to a symbol itself, then that symbol will be expanded and so on, up to `depth` recursions. If an undefined symbol is found, we return the unexpanded symbol (at that point). If we exceed the depth, we return where we got to for that depth. These rules mean that the function is a no-op for non-Symbols and undefined Symbols.
func (*Database) TitleCaseJournalNames ¶
func (db *Database) TitleCaseJournalNames()
TitleCaseJournalNames converts the journal name so that big words are capitalized
func (*Database) TransformEachField ¶
TransformEachField is a helper function that applies the parameter trans to every tag/value pair in the database.
func (*Database) TransformField ¶
TransformField applies the given transformation to each field named "tag".
func (*Database) WriteDatabase ¶
writeDatabase writes the entire database to w.
type Entry ¶
type Entry struct { Kind EntryKind EntryString string Key string Fields map[string]*Value AuthorList []*Author LineNo int }
Entry represents some publication or entry in the database.
func (*Entry) Equals ¶
Equals returns true if the two entries are equal. Entries e1 and e2 are equal if they are the same Kind, have the exact same set of tags, and have exactly the same values for each tag. Note that the entry's KEY does not play a role in Equality testing, nor does the parsed author list -- two entries would be unequal if they had the same author list encoded differently.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func NewParser ¶
NewParser creates a new BibTeX parser reading form the given io.Reader. [curToken will be the first token in the stream]
func (*Parser) ParseBibTeX ¶
ParseBibTeX reads the bibtex given to the parser when it was created and returns a database of entries.
func (*Parser) PrintErrors ¶
PrintErrors writes the stored error messages to the given Writer.
type ParserError ¶
type ParserError struct {
// contains filtered or unexported fields
}
ParserError holds a parser error.