bib

package
v0.0.0-...-2f62ff3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: BSD-3-Clause Imports: 9 Imported by: 1

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

View Source
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 HasQuote

func HasQuote(w string) bool

HasQuote returns true iff the string has a " someplace in it.

func IsStrangeCase

func IsStrangeCase(s string) bool

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

type Author struct {
	Others bool
	First  string
	Last   string
	Von    string
	Jr     string
}

Author represents an Author and the various named parts.

func NormalizeName

func NormalizeName(name string) *Author

NormalizeName returns an Author object parsed from a name string. We try to follow BibTeX's (ridiculous) rules for parsing names.

func (*Author) Equals

func (a *Author) Equals(b *Author) bool

Equals returns true iff an author structure is exactly equal to another.

func (*Author) String

func (a *Author) String() string

String converts an author to a normalized name string. We always use the von Last, First or von Last, Jr, First formats depending on whether Jr is empty or not.

type BibTeXError

type BibTeXError struct {
	BadEntry *Entry
	Tag      string
	Msg      string
}

BibTeXError holds an error found in a bibtex file.

type BraceNode

type BraceNode struct {
	Children []*BraceNode
	Leaf     string
}

func ParseBraceTree

func ParseBraceTree(s string) (*BraceNode, int)

ParseBraceTree converts a string into a tree of BraceNodes.

func (*BraceNode) AllSpace

func (bn *BraceNode) AllSpace() bool

AllSpace returns true iff the brace tree node is all whitespace.

func (*BraceNode) ContainsNoBraces

func (bn *BraceNode) ContainsNoBraces() bool

ContainsNoBraces returns true if the tree contains no {}-delimitated substrings.

func (*BraceNode) EndWithSpace

func (bn *BraceNode) EndWithSpace() bool

EndWithSpace returns true iff the leaf node ends with a space.

func (*BraceNode) Flatten

func (bn *BraceNode) Flatten() string

Flatten returns the string represented by the tree as a string.

func (*BraceNode) FlattenForSorting

func (bn *BraceNode) FlattenForSorting() string

FlattenForSorting is like Flatten, but won't include any {}.

func (*BraceNode) FlattenToMinBraces

func (bn *BraceNode) FlattenToMinBraces() string

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

func (bn *BraceNode) IsEntireStringBraced() bool

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) IsLeaf

func (bn *BraceNode) IsLeaf() bool

IsLeaf returns true if this BraceNode represents a leaf.

func (*BraceNode) PrintBraceTree

func (b *BraceNode) PrintBraceTree(indent int)

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 NewDatabase

func NewDatabase() *Database

NewDatabase creates a new empty database

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

func (db *Database) CheckAllFields(check func(string, *Value) string)

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

func (db *Database) CheckField(tag string, check func(*Value) string)

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

func (db *Database) FindDupsByTitle() map[string][]*Entry

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) Less

func (db *Database) Less(v1 *Value, v2 *Value) bool

Less returns true iff v1 < v2.

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

func (db *Database) PrintErrors(w io.Writer)

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

func (db *Database) RemoveNonBlessedFields(additional []string)

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

func (db *Database) SortByField(field string, reverse bool)

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

func (db *Database) SymbolValue(symb *Value, depth int) *Value

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

func (db *Database) TransformEachField(trans func(string, *Value) *Value)

TransformEachField is a helper function that applies the parameter trans to every tag/value pair in the database.

func (*Database) TransformField

func (db *Database) TransformField(tag string, trans func(string, *Value) *Value)

TransformField applies the given transformation to each field named "tag".

func (*Database) WriteDatabase

func (db *Database) WriteDatabase(w io.Writer)

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

func (e1 *Entry) Equals(e2 *Entry) bool

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.

func (*Entry) IsSubset

func (e1 *Entry) IsSubset(e2 *Entry) bool

IsSubset returns true if this entry is a subset of the given one. An e1 is a subset of e2 if they (a) have the same type, and (b) every field in e1 appears in e2 with the exact same value.

func (*Entry) Tags

func (e *Entry) Tags() []string

Tags returns the list of tag names of the entry's fields.

type EntryKind

type EntryKind string

EntryKind are the known types of BibTeX entries.

type FieldType

type FieldType int

FieldType represents the type of a data entry

const (
	StringType FieldType = iota
	NumberType
	SymbolType
)

type Parser

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

func NewParser

func NewParser(f io.Reader) *Parser

NewParser creates a new BibTeX parser reading form the given io.Reader. [curToken will be the first token in the stream]

func (*Parser) NErrors

func (p *Parser) NErrors() int

NErrors() returns the number of errors encountered while parsing.

func (*Parser) ParseBibTeX

func (p *Parser) ParseBibTeX() *Database

ParseBibTeX reads the bibtex given to the parser when it was created and returns a database of entries.

func (*Parser) PrintErrors

func (p *Parser) PrintErrors(w io.Writer)

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.

type Value

type Value struct {
	T FieldType
	S string
	I int
}

Value is the value of an item in an entry.

func (*Value) Equals

func (v1 *Value) Equals(v2 *Value) bool

Equals returns true if v1 == v2.

Jump to

Keyboard shortcuts

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