span

package module
v0.1.226 Latest Latest
Warning

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

Go to latest
Published: May 6, 2018 License: GPL-3.0 Imports: 16 Imported by: 3

README

Span

The span tools convert to and from an intermediate schema and support license tagging and quality assurance.

The intermediate schema is a normalization vehicle, spec: https://github.com/ubleipzig/intermediateschema


Install with

$ go get github.com/miku/span/cmd/...

or via deb or rpm packages.

Formats

Also:

Addings data sources

The following kinds of data shapes are supported at the moment:

  • A stream of XML, containing zero, one or more records, identified by an XML tag. Moderately fast.
  • Newline delimited JSON, containing zero, one or more records, one record per line. Fast.
  • Single records of arbitrary shape. Slow.

Use span, if metafacture or jq or a Python snippet are not sufficient.

Steps:

  • Add a new subpackage for your format, e.g. dummy.
  • Add a struct representing the original record (XML, JSON, bytes).
  • Implement the conversion functions required, e.g. ToIntermediateSchema
  • Add an entry into the format map for span-import
  • Decide, which kind of source this is (XML stream, newline delimited JSON, single records, something else)
  • Recompile and ship.

Ideas for span 0.2.0

TODO:

  • Do not require recompilation for mapping updates (allow various sources)
  • Decouple format from source. Things like SourceID and MegaCollection are per source, not format.
  • Allow loadable assets from ~/.config/span/maps, some specified location or a single JSON file.

More taggable formats:

Let formats implement a single function interface, that takes a filter value. How to make this filter generic? Or use Tag as an adapeter?

// Tag alters the document by applying a filter to it.
func (doc *Document) Tag(f Filter) error {
    // Adapt.
    record = FilterRecord{
	ISSN: doc.ISSN,
	Title: doc.CombinedTitle(),
	// ...
    }
    // Apply.
    return f.Apply(record)
}

DONE:

Licence

  • GPLv3
  • This project uses the Compact Language Detector 2 - CLD2, Apache License Version 2.0

Documentation

Overview

Package span implements common functions.

Copyright 2015 by Leipzig University Library, http://ub.uni-leipzig.de
                  The Finc Authors, http://finc.info
                  Martin Czygan, <martin.czygan@uni-leipzig.de>

This file is part of some open source application.

Some open source application is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Some open source application is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Foobar. If not, see <http://www.gnu.org/licenses/>.

@license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>

Index

Constants

View Source
const (
	// AppVersion of span package. Commandline tools will show this on -v.
	AppVersion = "0.1.226"
	// KeyLengthLimit was a limit imposed by the memcached protocol, which
	// was used for blob storage until Q1 2017. We switched the key-value
	// store, so this limit is somewhat obsolete.
	KeyLengthLimit = 250
)

Variables

View Source
var ISO639BibliographicToThree = map[string]string{

	"alb": "sqi",
	"arm": "hye",
	"baq": "eus",
	"bur": "mya",
	"chi": "zho",
	"cze": "ces",
	"dut": "nld",
	"fre": "fra",
	"geo": "kat",
	"ger": "deu",
	"gre": "ell",
	"ice": "isl",
	"mac": "mkd",
	"mao": "mri",
	"may": "msa",
	"per": "fas",
	"rum": "ron",
	"slo": "slk",
	"tib": "bod",
	"wel": "cym",
}

ISO639BibliographicToThree maps 639-2 identifier of the bibliographic applications to three-letter 639-3 identifier.

View Source
var ISO639NameToThree = map[string]string{}/* 7849 elements not displayed */

ISO639NameToThree maps a language name to three letter identifier.

View Source
var ISO639NameToThreeLower = map[string]string{}/* 7850 elements not displayed */
View Source
var ISO639OneToThree = map[string]string{}/* 184 elements not displayed */

ISO639OneToThree maps 639-1 identifier (two letters) (if there is one) to a three-letter 639-3 identifier.

View Source
var ISSNPattern = regexp.MustCompile(`[0-9]{4,4}-[0-9]{3,3}[0-9X]`)

ISSNPattern is a regular expression matching standard ISSN.

Functions

func DetectLang3

func DetectLang3(text string) (string, error)

DetectLang3 returns the best guess 3-letter language code for a given text.

func LanguageIdentifier added in v0.1.130

func LanguageIdentifier(s string) string

LanguageIdentifier returns the three letter identifier from any string. All data from http://www-01.sil.org/iso639-3/codes.asp.

func LoadSet added in v0.1.130

func LoadSet(r io.Reader, m map[string]struct{}) error

LoadSet reads the content of from a reader and creates a set from each line.

func ReadLines added in v0.1.130

func ReadLines(filename string) (lines []string, err error)

ReadLines returns a list of trimmed lines in a file. Empty lines are skipped.

func UnescapeTrim

func UnescapeTrim(s string) string

UnescapeTrim unescapes HTML character references and trims the space of a given string.

func UnfreezeFilterConfig added in v0.1.130

func UnfreezeFilterConfig(frozenfile string) (string, string, error)

UnfreezeFilterConfig takes the name of a zipfile (from span-freeze) and returns of the path the thawed filterconfig (along with the temporary directory and error). All URLs in the filterconfig have then been replaced by absolute path on the file system. Assumes default values for mapping.json and content file (blob). Cleanup of temporary directory is responsibility of caller.

Types

type ArrayFlags added in v0.1.130

type ArrayFlags []string

ArrayFlags allows to store lists of flag values.

func (*ArrayFlags) Set added in v0.1.130

func (f *ArrayFlags) Set(value string) error

Set appends a value.

func (*ArrayFlags) String added in v0.1.130

func (f *ArrayFlags) String() string

String representation.

type FileReader added in v0.1.130

type FileReader struct {
	Filename string
	// contains filtered or unexported fields
}

FileReader creates a ReadCloser from a filename. If postpones error handling up until the first read. TODO(miku): Throw this out.

func (*FileReader) Close added in v0.1.130

func (r *FileReader) Close() (err error)

Close closes the file.

func (*FileReader) Read added in v0.1.130

func (r *FileReader) Read(p []byte) (n int, err error)

Read reads from the file.

type LinkReader added in v0.1.130

type LinkReader struct {
	Link string
	// contains filtered or unexported fields
}

LinkReader implements io.Reader for a URL.

func (*LinkReader) Read added in v0.1.130

func (r *LinkReader) Read(p []byte) (int, error)
type SavedLink struct {
	Link string
	// contains filtered or unexported fields
}

SavedLink saves the content of a URL to a file.

func (*SavedLink) Remove added in v0.1.130

func (s *SavedLink) Remove()

Remove remove any left over temporary file.

func (*SavedLink) Save added in v0.1.130

func (s *SavedLink) Save() (filename string, err error)

Save link to a temporary file, return the filename.

type SavedReaders added in v0.1.130

type SavedReaders struct {
	Readers []io.Reader
	// contains filtered or unexported fields
}

SavedReaders takes a list of readers and persists their content in a temporary file.

func (*SavedReaders) Remove added in v0.1.130

func (r *SavedReaders) Remove()

Remove remove any left over temporary file.

func (*SavedReaders) Save added in v0.1.130

func (r *SavedReaders) Save() (filename string, err error)

Save saves all readers to a temporary file and returns the filename.

type Skip

type Skip struct {
	Reason string
}

Skip marks records to skip.

func (Skip) Error

func (s Skip) Error() string

Error returns the reason for skipping.

type SkipReader added in v0.1.130

type SkipReader struct {
	CommentPrefixes []string
	// contains filtered or unexported fields
}

SkipReader skips empty lines and lines with comments.

func NewSkipReader added in v0.1.130

func NewSkipReader(r *bufio.Reader) *SkipReader

NewSkipReader creates a new SkipReader.

func (SkipReader) ReadString added in v0.1.130

func (r SkipReader) ReadString(delim byte) (s string, err error)

ReadString will return only non-empty lines and lines not starting with a comment prefix.

type WriteCounter added in v0.1.130

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

WriteCounter counts the number of bytes written through it.

func (*WriteCounter) Count added in v0.1.130

func (w *WriteCounter) Count() uint64

Count returns the number of bytes written.

func (*WriteCounter) Write added in v0.1.130

func (w *WriteCounter) Write(p []byte) (int, error)

Write increments the total byte count.

type ZipContentReader added in v0.1.130

type ZipContentReader struct {
	Filename string
	// contains filtered or unexported fields
}

ZipContentReader returns the concatenated content of all files in a zip archive given by its filename. All content is temporarily stored in memory, so this type should only be used with smaller archives.

func (*ZipContentReader) Read added in v0.1.130

func (r *ZipContentReader) Read(p []byte) (int, error)

Read returns the content of all archive members.

type ZipOrPlainLinkReader added in v0.1.130

type ZipOrPlainLinkReader struct {
	Link string
	// contains filtered or unexported fields
}

ZipOrPlainLinkReader is a reader that transparently handles zipped and uncompressed content, given a URL as string.

func (*ZipOrPlainLinkReader) Read added in v0.1.130

func (r *ZipOrPlainLinkReader) Read(p []byte) (int, error)

Read implements the reader interface.

Directories

Path Synopsis
cmd
span-check
span-check runs quality checks on input data
span-check runs quality checks on input data
span-crossref-snapshot
Given as single file with crossref works API message, create a potentially smaller file, which contains only the most recent version of each document.
Given as single file with crossref works API message, create a potentially smaller file, which contains only the most recent version of each document.
span-export
span-export creates various destination formats, mostly for SOLR.
span-export creates various destination formats, mostly for SOLR.
span-freeze
Freeze file containing urls along with the content of all urls.
Freeze file containing urls along with the content of all urls.
span-import
span-reshape is a dumbed down span-import.
span-reshape is a dumbed down span-import.
span-join-assets
span-join-assets combines a directory of json or single column TSV configurations into a single file.
span-join-assets combines a directory of json or single column TSV configurations into a single file.
span-oa-filter
span-oa-filter will set x.oa to true, if the given KBART file validates a record.
span-oa-filter will set x.oa to true, if the given KBART file validates a record.
span-redact
redact intermediate schema
redact intermediate schema
span-tag
span-tag takes an intermediate schema file and a configuration forest of filters for various tags and runs all filters on every record of the input to produce a stream of tagged records.
span-tag takes an intermediate schema file and a configuration forest of filters for various tags and runs all filters on every record of the input to produce a stream of tagged records.
span-update-labels
span-update-labels takes a TSV of an IDs and ISILs and updates an intermediate schema record x.labels field accordingly.
span-update-labels takes a TSV of an IDs and ISILs and updates an intermediate schema record x.labels field accordingly.
Package sets implements basic set types.
Package sets implements basic set types.
encoding
csv
Package csv implements a decoder, that supports CSV decoding.
Package csv implements a decoder, that supports CSV decoding.
formeta
Package formeta implements marshaling for formeta (metafacture internal format).
Package formeta implements marshaling for formeta (metafacture internal format).
tsv
Package tsv implements a decoder for tab separated data.
Package tsv implements a decoder for tab separated data.
Package filter implements flexible ISIL attachments with expression trees[1], serialized as JSON.
Package filter implements flexible ISIL attachments with expression trees[1], serialized as JSON.
formats
doaj
Package doaj maps DOAJ metadata to intermediate schema.
Package doaj maps DOAJ metadata to intermediate schema.
dummy
Package dummy is just a minimal example.
Package dummy is just a minimal example.
elsevier
TODO.
TODO.
jstor
TODO.
TODO.
Package licensing implements support for KBART and ISIL attachments.
Package licensing implements support for KBART and ISIL attachments.
kbart
Package kbart implements support for KBART (Knowledge Bases And Related Tools working group, http://www.uksg.org/kbart/) holding files (http://www.uksg.org/kbart/s5/guidelines/data_format).
Package kbart implements support for KBART (Knowledge Bases And Related Tools working group, http://www.uksg.org/kbart/) holding files (http://www.uksg.org/kbart/s5/guidelines/data_format).
Package parallel implements helpers for fast processing of line oriented inputs.
Package parallel implements helpers for fast processing of line oriented inputs.
Package quality implements quality checks.
Package quality implements quality checks.
Package sift implements various filters, that help with the record labelling (ISIL) process.
Package sift implements various filters, that help with the record labelling (ISIL) process.

Jump to

Keyboard shortcuts

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