bibfuse

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 6 Imported by: 0

README

bibfuse

Test Docker Go Report Card codecov License GoDoc

A CLI tool to manage bibtex entries using nickng/bibtex.

bibfuse creates an SQLite database file (--db) from given BibTex files (*.bib), and generates a single clean .bib file (--out).

The filtering formats can be defined in the config file (--config). bibfuse takes the bibfuse.toml in this package by default.

If no .bib files are given, it just reads the database and updates the BibTex file.

Table of Contents

Synopsis

Install

% go get -u github.com/iomz/bibfuse/...

Usage

% bibfuse -h
Usage of bibfuse: [options] [.bib ... .bib]
  -config string
        The bibfuse.[toml|yml] defining the filters. (default "bibfuse.toml")
  -db string
        The SQLite file to read/write. (default "bib.db")
  -no-optional
        Suppress "OPTIONAL" fields in the resulting bibtex.
  -no-todo
        Suppress "TODO" fields in the resulting bibtex.
  -out string
        The resulting bibtex to write (it overrides if exists). (default "out.bib")
  -show-empty
        Do not hide empty fields in the resulting bibtex.
  -smart
        Use oneof selectively filters when importing bibtex.
  -verbose
        Print verbose messages.
  -version
        Print version.
Example
% cat ref.bib
@article{someone2021a,
    title     = {{A Journal Article}},
}
% bibfuse ref.bib
2021/10/17 15:47:32 parsing ref.bib
2021/10/17 15:47:32 +1 new entries
2021/10/17 15:47:32 bib.db contains 1 entries
2021/10/17 15:47:32 1 entries written to out.bib
% cat out.bib
@article{someone2021a,
    title       = {{A Journal Article}},
    author      = "(TODO)",
    url         = "(OPTIONAL)",
    doi         = "(OPTIONAL)",
    isbn        = "(OPTIONAL)",
    issn        = "(OPTIONAL)",
    journal     = "(TODO)",
    metanote    = "(OPTIONAL)",
    number      = "(OPTIONAL)",
    numpages    = "(OPTIONAL)",
    pages       = "(OPTIONAL)",
    publisher   = "(OPTIONAL)",
    volume      = "(OPTIONAL)",
    year        = "(TODO)",
}

Usage with Docker

% cat ref.bib
@article{someone2021a,
    title     = {{A Journal Article}},
}
% docker run -v $(pwd):$(pwd) -w $(pwd) --rm iomz/bibfuse ref.bib
2021/10/17 13:53:33 parsing ref.bib
2021/10/17 13:53:33 +0 new entries
2021/10/17 13:53:33 bib.db contains 1 entries
2021/10/17 13:53:33 1 entries written to out.bib
% sqlite3 bib.db "SELECT * FROM entries;"
1|someone2021a|article|(TODO)|{A Journal Article}||(OPTIONAL)||(OPTIONAL)|(OPTIONAL)||(TODO)|(OPTIONAL)||(OPTIONAL)||(OPTIONAL)|(OPTIONAL)|(OPTIONAL)|(OPTIONAL)||||(OPTIONAL)||(OPTIONAL)|(TODO)

bibfuse filters for BibTex format

bibfuse reflects rather subjective opinion to filter and flag the required fields depending on the type, aiming for the compatibility with most of the research publication requirements.

todos and optionals filters

bibfuse filters fields for each entry depending on the type: @article, @book, @incollection, @inproceedings, @mastersthesis, @misc, @phdthesis, @techreport, and @unpublished as defined in bibfuse.toml.

Mandatory fields are filled with (TODO) while optional fileds are filled with (OPTIONAL).

oneof_ filters with -smart

In addition, you can define additional filters whose name starting with oneof_ to selectively discard some fields in presence of a specific fields with the -smart option. For example, by default for the @article type the default bibfuse.toml has the following oneof_ filter:

oneof_doi_page = [
    "doi",
    "pages",
    "numpages"
]

This checks each field in the order "doi", "pages", and "numpages" then after finding the first one of neither empty, "(OPTIONAL)", nor "(TODO)", bibfuse discards the remaining fields and does NOT store them in the database. Note that if you want to retain those fields, you should not use this -smart option.

This feature enables rather concise bibliography in your manuscript while maintaining the accessibility to the cited documents through more efficient identities (e.g., DOI).

Citation Types

Journal articles
@article{mizutani2021article
    title     = {{Title of the Article}},
    author    = "(TODO)",
    journal   = "(TODO)",
    year      = "(TODO)",
    doi       = "(OPTIONAL)",
    isbn      = "(OPTIONAL)", % removed if doi exists
    issn      = "(OPTIONAL)", % removed if doi exists
    metanote  = "(OPTIONAL)",
    number    = "(OPTIONAL)", % removed if doi exists
    numpages  = "(OPTIONAL)", % removed if doi exists
    pages     = "(OPTIONAL)", % removed if doi exists
    publisher = "(OPTIONAL)", % removed if doi exists
    url       = "(OPTIONAL)", % removed if doi exists
    volume    = "(OPTIONAL)", % removed if doi exists
}
Books
@book{mizutani2021book,
    title     = {{Title of the Book}},
    author    = "(TODO)"
    publisher = "(TODO)",     % removed if doi exists
    year      = "(TODO)",
    doi       = "(OPTIONAL)",
    edition   = "(OPTIONAL)", % removed if doi exists
    isbn      = "(OPTIONAL)", % removed if doi exists
    issn      = "(OPTIONAL)", % removed if doi exists
    metanote  = "(OPTIONAL)",
    url       = "(OPTIONAL)", % removed if doi exists
}
Chapters or articles in a book
@incollection{mizutani2012incollection,
    title     = {{Title of the Book Chapter}},
    author    = "(TODO)"
    booktitle = "(TODO)",
    publisher = "(TODO)",     % removed if doi exists
    year      = "(TODO)",
    doi       = "(OPTIONAL)",
    isbn      = "(OPTIONAL)", % removed if doi exists
    issn      = "(OPTIONAL)", % removed if doi exists
    metanote  = "(OPTIONAL)",
    numpages  = "(OPTIONAL)", % removed if doi exists
    pages     = "(OPTIONAL)", % removed if doi exists
    series    = "(OPTIONAL)",
    url       = "(OPTIONAL)", % removed if doi exists
}
Conference papers, lecture notes, extended abstract, etc.
@inproceedings{mizutani2012inproceedings,
    title     = {{Title of the Conference Paper}},
    author    = "(TODO)"
    booktitle = "(TODO)",
    year      = "(TODO)",
    doi       = "(OPTIONAL)",
    isbn      = "(OPTIONAL)", % removed if doi exists
    issn      = "(OPTIONAL)", % removed if doi exists
    metanote  = "(OPTIONAL)",
    numpages  = "(OPTIONAL)", % removed if doi exists
    pages     = "(OPTIONAL)", % removed if doi exists
    publisher = "(OPTIONAL)", % removed if doi exists
    series    = "(OPTIONAL)",
    url       = "(OPTIONAL)", % removed if doi exists
}
Master's theses
@mastersthesis{mizutani2021mastersthesis,
    title       = {{Title of the Master's Thesis}},
    author      = "(TODO)",
    url         = "(OPTIONAL)",
    metanote    = "(OPTIONAL)",
    school      = "(TODO)",
    year        = "(TODO)",
}

Online resources, artifacts, etc.
@misc{mizutani2021misc,
    title       = "Title of the Resource",
    author      = "(TODO)"
    note        = "(TODO)",
    url         = "(TODO)",
    year        = "(TODO)",
    institution = "(OPTIONAL)",
    metanote    = "(OPTIONAL)",
}
Ph.D. theses / dissertations
@phdthesis{mizutani2021phdthesis,
    title       = {{Title of the Ph.D. Thesis}},
    author      = "(TODO)",
    url         = "(OPTIONAL)",
    metanote    = "(OPTIONAL)",
    school      = "(TODO)",
    year        = "(TODO)",
}
Standards, specifications, white papers, etc.
@techreport{mizutani2021techreport,
    title       = {{Title of the Technical Document}},
    author      = "(TODO)",
    institution = "(TODO)",
    year        = "(TODO)",
    metanote    = "(OPTIONAL)",
    series      = "(OPTIONAL)",
    url         = "(OPTIONAL)",
    version     = "(OPTIONAL)",
}
Documents not formally published.
@unpublished{mizutani2021unpublished,
    title       = {{Title of the Unpublished Work}},
    author      = "(TODO)",
    url         = "(TODO)",
    metanote    = "(OPTIONAL)",
    note        = "(TODO)",
}

Contribution

See CONTRIBUTING.md.

License

See LICENSE.

Author

Iori Mizutani (@iomz)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackslashCleaner added in v1.0.2

func BackslashCleaner(line string) string

BackslashCleaner minimizes sequences of backslashes

func FirstNameCleaner added in v1.0.2

func FirstNameCleaner(firstName string) (string, error)

FirstNameCleaner returns a cleaned-up first name

func LastNameCleaner added in v1.0.2

func LastNameCleaner(lastName string) (string, error)

LastNameCleaner returns a cleaned-up first name

Types

type Author added in v1.0.2

type Author struct {
	FirstName string `default:"" sqlite3:"fist_name"` // this can be empty
	LastName  string `default:"" sqlite3:"last_name"`
}

Author holds an author information

func NewAuthor added in v1.0.2

func NewAuthor(firstName, lastName string) (*Author, error)

NewAuthor returns a new Author

type Authors added in v1.0.2

type Authors []*Author

Authors are a slice of multiple Author

func NewAuthors added in v1.0.2

func NewAuthors(authorFieldValue string) (Authors, error)

NewAuthors return a new Authors

func (Authors) String added in v1.0.2

func (as Authors) String() string

String returns a string for the author field

type BibItem

type BibItem struct {
	CiteName       string `default:"" bibtex:"cite_name"`
	CiteType       string `default:"" bibtex:"cite_type"`
	Title          string `default:"" bibtex:"title"`
	Author         string `default:"" bibtex:"author"`
	Booktitle      string `default:"" bibtex:"booktitle"`
	DOI            string `default:"" bibtex:"doi"`
	Edition        string `default:"" bibtex:"edition"`
	ISBN           string `default:"" bibtex:"isbn"`
	ISSN           string `default:"" bibtex:"issn"`
	Institution    string `default:"" bibtex:"institution"`
	Journal        string `default:"" bibtex:"journal"`
	Metanote       string `default:"" bibtex:"metanote"`
	Note           string `default:"" bibtex:"note"`
	Number         string `default:"" bibtex:"number"`
	Numpages       string `default:"" bibtex:"numpages"`
	Pages          string `default:"" bibtex:"pages"`
	Publisher      string `default:"" bibtex:"publisher"`
	School         string `default:"" bibtex:"school"`
	Series         string `default:"" bibtex:"series"`
	TechreportType string `default:"" bibtex:"type"`
	URL            string `default:"" bibtex:"url"`
	Version        string `default:"" bibtex:"version"`
	Volume         string `default:"" bibtex:"volume"`
	Year           string `default:"" bibtex:"year"`
}

BibItem holds all the possible fields

func NewBibItem

func NewBibItem() BibItem

NewBibItem returns a BibItem with default field value

func (BibItem) AllFields

func (bi BibItem) AllFields(bio BibItemOption) map[string]string

AllFields returns a string map of all the fileds

func (*BibItem) SetFieldByBibTexName

func (bi *BibItem) SetFieldByBibTexName(fieldName, fieldValue string) error

SetFieldByBibTexName update the field value specified by bibtex field name

func (BibItem) ToBibEntry

func (bi BibItem) ToBibEntry() *bibtex.BibEntry

ToBibEntry creates a new bibtex.BibEntry from BibItem and return the pointer

type BibItemOption

type BibItemOption int64

BibItemOption specifies the option for AllFields()

const (
	// ByFieldName use filed names as keys
	ByFieldName BibItemOption = iota
	// ByBibTexName use bibtex names as keys
	ByBibTexName
)

type Filter

type Filter map[string][]string

Filter has TODO and OPTIONAL fields for a citation type

func NewFilter

func NewFilter() Filter

NewFilter initialize a Filter

func (Filter) HasField

func (f Filter) HasField(fieldType, fieldName string) bool

HasField checks if the field exists in a given field type (e.g., TODO or OPTIONAL)

type Filters

type Filters map[string]Filter

Filters have TODO and OPTIONAL fields for each citation type

func (Filters) BuildBibItem added in v1.0.0

func (fs Filters) BuildBibItem(entry *bibtex.BibEntry, smart bool, oneofs Oneofs) (BibItem, error)

BuildBibItem returns BibItem with the filter

func (Filters) HasFilter

func (fs Filters) HasFilter(filterType string) bool

HasFilter checks if the filter of a citation type exists

type Oneof added in v1.1.0

type Oneof [][]string

Oneof defines the one of the fields

func NewOneof added in v1.1.0

func NewOneof() *Oneof

NewOneof initialize a Oneof

func (*Oneof) AddOneof added in v1.1.0

func (of *Oneof) AddOneof(fields []string)

AddOneof adds a oneof fields

type Oneofs added in v1.1.0

type Oneofs map[string]*Oneof

Oneofs is a oneof map for each citeType

func (Oneofs) HasOneof added in v1.1.0

func (os Oneofs) HasOneof(citeType string) bool

HasOneof checks if the filter of a citation type exists

Directories

Path Synopsis
cmd
bibfuse command

Jump to

Keyboard shortcuts

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