api

package module
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 16 Imported by: 7

Documentation

Overview

Package api provides basic api types.

Index

Constants

View Source
const (
	LoginURL   = "/login"
	LogoutURL  = "/logout"
	VersionURL = "/api-version"
)

API routes

View Source
const (
	// Auth definest the ?auth=xxx token
	Auth = "auth"
)

Variables

This section is empty.

Functions

func IsValidJSONResponse

func IsValidJSONResponse(res *http.Response, codes ...int) bool

IsValidJSONResponse returns true if the given response matches one of the given codes and if response is either empty or its Content-Type is `application/json`.

Types

type AdaptiveTokens added in v0.7.0

type AdaptiveTokens struct {
	BookID         int      `json:"bookId"`
	ProjectID      int      `json:"projectId"`
	AdaptiveTokens []string `json:"adaptiveTokens"`
}

AdaptiveTokens holds a list of adaptive tokens.

type AdditionalLexicon added in v0.9.0

type AdditionalLexicon struct {
	Tokens []string `json:"tokens"`
}

AdditionalLexicon represents the additional lexicon tokens for th post data of the postcorrection and the profiler.

type Book

type Book struct {
	Author       string          `json:"author"`
	Title        string          `json:"title"`
	Language     string          `json:"language"`
	Status       map[string]bool `json:"status"`
	ProfilerURL  string          `json:"profilerUrl"`
	Description  string          `json:"description"`
	HistPatterns string          `json:"histPatterns"`
	Year         int             `json:"year"`
	BookID       int             `json:"bookId"`
	ProjectID    int             `json:"projectId"`
	Pages        int             `json:"pages"`
	PageIDs      []int           `json:"pageIds"`
	IsBook       bool            `json:"isBook"`
	Pooled       bool            `json:"pooled"`
}

Book defines the response data for books.

type BookWithPages

type BookWithPages struct {
	Book
	PageContent []Page
}

BookWithPages is a Book with an additional field that holds all the book's pages.

type Books

type Books struct {
	Books []Book `json:"books"`
}

Books defines a list of books.

type Box

type Box struct {
	Left   int `json:"left"`
	Right  int `json:"right"`
	Top    int `json:"top"`
	Bottom int `json:"bottom"`
	Width  int `json:"width"`
	Height int `json:"height"`
}

Box defines the bounding box in an image.

type CharMap added in v0.14.2

type CharMap struct {
	ProjectID int            `json:"projectId"`
	BookID    int            `json:"bookId"`
	CharMap   map[string]int `json:"charMap"`
}

CharMap represents a freqency list of characters.

type Client

type Client struct {
	Host    string
	Session Session // active session
	// contains filtered or unexported fields
}

Client implements the api calls for the pcw backend. Use Login to initalize the client.

func Authenticate

func Authenticate(host, authToken string, skipVerify bool) *Client

Authenticate creates a new Client from a given auth-token.

func Login

func Login(host, email, password string, skipVerify bool) (*Client, error)

Login creates a new Client and authenticates with the given username and password.

func NewClient added in v0.4.7

func NewClient(host string, skipVerify bool) *Client

NewClient creates a new client with the given host (and it default web host).

func (Client) AssignBack added in v0.15.0

func (c Client) AssignBack(pid int) error

AssignBack assigns a package back to its original user. User must own the package.

func (Client) AssignTo added in v0.15.0

func (c Client) AssignTo(pid, uid int) error

AssignTo assigns a package to another user. User must be an admin.

func (Client) DeleteBook added in v0.15.0

func (c Client) DeleteBook(bookID int) error

DeleteBook deletes the book the given book.

func (Client) DeleteLine added in v0.4.7

func (c Client) DeleteLine(bookID, pageID, lineID int) error

DeleteLine deletes the given line, page or .

func (Client) DeletePage added in v0.4.7

func (c Client) DeletePage(bookID, pageID int) error

DeletePage deletes the given page.

func (Client) DeleteUser added in v0.15.0

func (c Client) DeleteUser(id int64) error

DeleteUser deletes the user with the given id.

func (Client) Download added in v0.4.4

func (c Client) Download(pid int) (io.ReadCloser, error)

Download downloads the zipped book's contents.

func (Client) GetAPIVersion

func (c Client) GetAPIVersion() (Version, error)

GetAPIVersion returns the API version of the pocoweb server.

func (Client) GetAdaptiveTokens added in v0.7.0

func (c Client) GetAdaptiveTokens(bookID int) (AdaptiveTokens, error)

GetAdaptiveTokens returns the adaptive tokens for the given book.

func (Client) GetBook

func (c Client) GetBook(bookID int) (*Book, error)

GetBook returns the book with the given id.

func (Client) GetBooks

func (c Client) GetBooks() (*Books, error)

GetBooks returns all books of a user.

func (Client) GetCharMap added in v0.14.2

func (c Client) GetCharMap(bid int, filter string) (CharMap, error)

GetCharMap returns the frequency map of characters for the given book.

func (Client) GetExtendedLexicon added in v0.8.0

func (c Client) GetExtendedLexicon(bookID int) (ExtendedLexicon, error)

GetExtendendLexicon returns the extended lexicon for the given book or project.

func (Client) GetFirstPage added in v0.16.0

func (c Client) GetFirstPage(bookID int) (*Page, error)

GetFirstPage returns the first page of the given book.

func (Client) GetJobStatus added in v0.7.0

func (c Client) GetJobStatus(jobID int) (*JobStatus, error)

GetJobStatus returns the job status for the given job.

func (Client) GetLastPage added in v0.16.0

func (c Client) GetLastPage(bookID int) (*Page, error)

GetLastPage returns the last page of the given book.

func (Client) GetLine

func (c Client) GetLine(bookID, pageID, lineID int) (*Line, error)

GetLine returns the line with the given ids.

func (Client) GetLineImage added in v0.4.1

func (c Client) GetLineImage(line *Line) (image.Image, error)

GetLineImage downloads the line image for the given line. At this point only PNGs are accepted.

func (Client) GetLogin added in v0.15.0

func (c Client) GetLogin() (Session, error)

GetLogin returns the session of the authentificated user.

func (Client) GetOCRModels added in v0.9.0

func (c Client) GetOCRModels(bookID int) (Models, error)

GetOCRModels returns the available ocr models for the given book or project.

func (Client) GetPage

func (c Client) GetPage(bookID, pageID int) (*Page, error)

GetPage returns the page with the given ids.

func (Client) GetPatterns added in v0.7.0

func (c Client) GetPatterns(bookID int, ocr bool) (PatternCounts, error)

GetPatterns returns the ocr or hist error-patterns for the given book.

func (Client) GetPostCorrection added in v0.9.0

func (c Client) GetPostCorrection(bookID int) (*PostCorrection, error)

GetExtendendLexicon returns the post-correction data for the given book.

func (Client) GetProfile added in v0.7.0

func (c Client) GetProfile(bookID int) (gofiler.Profile, error)

GetProfile downloads the profile for the given book.

func (Client) GetSuspicious added in v0.7.0

func (c Client) GetSuspicious(bookID int) (SuggestionCounts, error)

GetSuspicious returns the suspicious words for the given book.

func (Client) GetToken added in v0.16.0

func (c Client) GetToken(bookID, pageID, lineID, tokenID int) (*Token, error)

GetToken returns the token for the given line.

func (Client) GetTokenLen added in v0.16.0

func (c Client) GetTokenLen(bookID, pageID, lineID, offset, len int) (*Token, error)

GetTokenLen returns the token with the given length.

func (Client) GetUser

func (c Client) GetUser(id int64) (User, error)

GetUser returns the user with the given id.

func (Client) GetUsers

func (c Client) GetUsers() (Users, error)

GetUsers returns all users (needs admin rights).

func (Client) Logout added in v0.4.7

func (c Client) Logout() error

Logout logs the user out.

func (Client) OCRPredict added in v0.14.1

func (c Client) OCRPredict(bid, pid, lid int, name string) (Job, error)

OCRPredict runs the OCR prediction with the given model over the given book or project pages and/or lines. If the give line and/or page ids are equal to zero the whole page and/or project are predicted.

func (Client) OCRTrain added in v0.14.1

func (c Client) OCRTrain(bid int, name string) (Job, error)

OCRTrain trains a new model using the given model as base on the given project.

func (Client) PostBook

func (c Client) PostBook(zip io.Reader, book Book) (*Book, error)

PostBook uploads a zipped OCR project and the given metadata. It returns the newly created book.

func (Client) PostExtendedLexicon added in v0.8.0

func (c Client) PostExtendedLexicon(bookID int) (Job, error)

PostExtendendLexicon sends a request to create the extendedn lexicon for the given book or project.

func (Client) PostPostCorrection added in v0.9.0

func (c Client) PostPostCorrection(bookID int) (Job, error)

PostPostCorrection sends a request to start the automatic post correction on the given book with the given extended lexicon tokens.

func (Client) PostProfile

func (c Client) PostProfile(bookID int, tokens ...string) (Job, error)

PostProfile sends a request to profile the book with the given id.

func (Client) PostUser

func (c Client) PostUser(u CreateUserRequest) (User, error)

PostUser creates a new User and returns it.

func (Client) PostZIP

func (c Client) PostZIP(zip io.Reader) (*Book, error)

PostZIP uploads a zipped OCR project and returns the new project.

func (Client) PutBook added in v0.16.0

func (c Client) PutBook(book Book) (*Book, error)

PutBook updates the given book's metadata. It returns the updated book data.

func (Client) PutLine added in v0.16.4

func (c Client) PutLine(bookID, pageID, lineID int, cor string) (*Line, error)

PutLine corrects is used to correct a line.

func (Client) PutToken added in v0.16.4

func (c Client) PutToken(bookID, pageID, lineID, tokenID int, cor string) (*Token, error)

PutToken corrects a token.

func (Client) PutTokenLen added in v0.16.4

func (c Client) PutTokenLen(bookID, pageID, lineID, tokenID, len int, cor string) (*Token, error)

PutTokenLen corrects a token of a spcific length.

func (Client) PutUser

func (c Client) PutUser(u CreateUserRequest) (User, error)

PutUser updates the settings for a user and returns it.

func (Client) QueryPatterns added in v0.7.0

func (c Client) QueryPatterns(bookID int, ocr bool, q string, qs ...string) (Patterns, error)

QueryPatterns returns the suggestions for the given error patterns.

func (Client) QueryProfile added in v0.7.0

func (c Client) QueryProfile(bookID int, q string, qs ...string) (Suggestions, error)

QueryProfile returns the suggestions for the given words.

func (Client) Raw

func (c Client) Raw(path string, out io.Writer) error

Raw sends a get request to the given path and writes the raw response content into the given writer.

func (Client) Search

func (c Client) Search(bookID int, s Search) (*SearchResults, error)

Search searches for tokens or error patterns.

func (Client) Split added in v0.4.6

func (c Client) Split(pid int, random bool, uid int, ids ...int) (SplitPackages, error)

Split splits a project.

func (Client) TakeBack added in v0.15.0

func (c Client) TakeBack(pid int) error

TakeBack takes all packages of the given project back and reassigns them to the project's owner. Only admins can take back projects.

type CreateUserRequest

type CreateUserRequest struct {
	User     User   `json:"user"`
	Password string `json:"password"`
}

CreateUserRequest defines the data to create new users.

type Error added in v0.7.0

type Error struct {
	Code    int    `json:"code"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

Error defines json-formatted error responses.

type ErrorResponse

type ErrorResponse struct {
	Cause      string `json:"cause"`
	Status     string `json:"status"`
	StatusCode int    `json:"statusCode"`
}

ErrorResponse defines the data of error responses

func NewErrorResponse

func NewErrorResponse(code int, cause string) ErrorResponse

NewErrorResponse creates a new ErrorResponse with the given code and cause. The status text is calculated automatically using http.StatusText.

func (ErrorResponse) Error

func (err ErrorResponse) Error() string

type ExtendedLexicon added in v0.8.0

type ExtendedLexicon struct {
	BookID    int            `json:"bookId"`
	ProjectID int            `json:"projectId"`
	Yes       map[string]int `json:"yes"`
	No        map[string]int `json:"no"`
}

type Job added in v0.4.7

type Job struct {
	ID int `json:"id"`
}

Job defines the job struct.

type JobStatus added in v0.8.0

type JobStatus struct {
	JobID      int    `json:"jobId"`
	BookID     int    `json:"bookId"`
	StatusID   int    `json:"statusId"`
	StatusName string `json:"statusName"`
	JobName    string `json:"jobName"`
	Timestamp  int64  `json:"timestamp"`
}

JobStatus defines the job status struct.

func (JobStatus) Time added in v0.8.0

func (js JobStatus) Time() time.Time

Time returns the time object for the job's timestamp.

type Languages added in v0.6.2

type Languages struct {
	Languages []string `json:"languages"`
}

Languages defines the object that contains the profiler's configured languages.

type Line

type Line struct {
	ImgFile              string    `json:"imgFile"`
	Cor                  string    `json:"cor"`
	OCR                  string    `json:"ocr"`
	LineID               int       `json:"lineId"`
	PageID               int       `json:"pageId"`
	ProjectID            int       `json:"projectId"`
	BookID               int       `json:"bookId"`
	Cuts                 []int     `json:"cuts"`
	Confidences          []float64 `json:"confidences"`
	AverageConfidence    float64   `json:"averageConfidence"`
	IsFullyCorrected     bool      `json:"isFullyCorrected"`
	IsPartiallyCorrected bool      `json:"isPartiallyCorrected"`
	Box                  Box       `json:"box"`
	Tokens               []Token   `json:"tokens"`
}

Line defines the line of a page in a book.

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

LoginRequest defines the login data.

func (LoginRequest) String

func (l LoginRequest) String() string

String returns the string representation of a login request. The Password is *not* printed.

type Match

type Match struct {
	Lines []Line `json:"lines"`
	Total int    `json:"total"`
}

Match defines the matches in the results of searches.

type Model added in v0.9.0

type Model struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

Model defines the ocr models.

type Models added in v0.9.0

type Models struct {
	Models []Model `json:"models"`
}

Models defines multiple models.

type Page

type Page struct {
	PageID     int    `json:"pageId"`
	ProjectID  int    `json:"projectId"`
	BookID     int    `json:"bookId"`
	PrevPageID int    `json:"prevPageId"`
	NextPageID int    `json:"nextPageId"`
	OCRFile    string `json:"ocrFile"`
	ImgFile    string `json:"imgFile"`
	Box        Box    `json:"box"`
	Lines      []Line `json:"lines"`
}

Page defines a page in a book.

type PatternCounts added in v0.7.0

type PatternCounts struct {
	Counts    map[string]int `json:"counts"`
	BookID    int            `json:"bookId"`
	ProjectID int            `json:"projectId"`
	OCR       bool           `json:"ocr"`
}

PatternCounts holds the pattern counts for error patterns.

type Patterns added in v0.7.0

type Patterns struct {
	Patterns  map[string][]Suggestion `json:"patterns"`
	BookID    int                     `json:"bookId"`
	ProjectID int                     `json:"projectId"`
	OCR       bool                    `json:"ocr"`
}

Patterns holds patterns.

type PostCorrection added in v0.9.0

type PostCorrection struct {
	BookID    int            `json:"bookId"`
	ProjectID int            `json:"projectId"`
	Always    map[string]int `json:"always"`
	Sometimes map[string]int `json:"sometimes"`
	Never     map[string]int `json:"never"`
}
type Search struct {
	Qs        []string   // query strings
	Skip, Max int        // skip matches and max matches
	Type      SearchType // type of the search
}

Search is used to configure search requests.

type SearchResults

type SearchResults struct {
	Matches        map[string]Match `json:"matches"`
	BookID         int              `json:"bookId"`
	ProjectID      int              `json:"projectId"`
	Total          int              `json:"total"`
	Max            int              `json:"max"`
	Skip           int              `json:"skip"`
	IsErrorPattern bool             `json:"isErrorPattern"`
}

SearchResults defines the results for token searches.

type SearchType added in v0.16.4

type SearchType string

SearchType defines the type of searches

const (
	SearchToken   SearchType = "token"
	SearchPattern SearchType = "pattern"
	SearchAC      SearchType = "ac"
)

Search types.

type Session

type Session struct {
	User    User   `json:"user"`
	Auth    string `json:"auth"`
	Expires int64  `json:"expires"`
}

Session defines an authenticates user sessions. A session is attached to a unique user with and authentication string and an expiration date.

func (Session) Expired added in v0.4.0

func (s Session) Expired() bool

Expired returns true if the session has exprired.

func (Session) String added in v0.4.0

func (s Session) String() string

type SplitPackage added in v0.14.3

type SplitPackage struct {
	PageIDs   []int `json:"pageIds"`
	ProjectID int   `json:"projectId"`
	Owner     int   `json:"owner"`
}

SplitPackage defines the data for one split package.

type SplitPackages added in v0.14.3

type SplitPackages struct {
	BookID   int            `json:"bookId"`
	Packages []SplitPackage `json:"projects"`
}

SplitPackages defines the response data of split requests.

type SplitRequest added in v0.14.3

type SplitRequest struct {
	UserIDs []int `json:"userIds"`
	Random  bool  `json:"random"`
}

SplitRequest defines the post data for split requests.

type Suggestion added in v0.6.2

type Suggestion struct {
	Token        string   `json:"token"`
	Suggestion   string   `json:"suggestion"`
	Modern       string   `json:"modern"`
	Dict         string   `json:"dict"`
	Distance     int      `json:"distance"`
	ID           int      `json:"id"`
	Weight       float64  `json:"weight"`
	Top          bool     `json:"top"`
	OCRPatterns  []string `json:"ocrPatterns"`
	HistPatterns []string `json:"histPatterns"`
}

Suggestion defines one suggestion of the profiler for a token.

type SuggestionCounts added in v0.7.0

type SuggestionCounts struct {
	Counts    map[string]int `json:"counts"`
	BookID    int            `json:"bookId"`
	ProjectID int            `json:"projectId"`
}

SuggestionCounts holds the counts of correction suggestions.

type Suggestions added in v0.6.2

type Suggestions struct {
	Suggestions map[string][]Suggestion `json:"suggestions"`
	BookID      int                     `json:"bookId"`
	ProjectID   int                     `json:"projectId"`
}

Suggestions defines the profiler's suggestions for tokens.

type Token

type Token struct {
	Cor                  string    `json:"cor"`
	OCR                  string    `json:"ocr"`
	TokenID              int       `json:"tokenId"`
	LineID               int       `json:"lineId"`
	PageID               int       `json:"pageId"`
	ProjectID            int       `json:"projectId"`
	BookID               int       `json:"bookId"`
	Offset               int       `json:"offset"`
	Cuts                 []int     `json:"cuts"`
	Confidences          []float64 `json:"confidences"`
	AverageConfidence    float64   `json:"averageConfidence"`
	IsFullyCorrected     bool      `json:"isFullyCorrected"`
	IsPartiallyCorrected bool      `json:"isPartiallyCorrected"`
	IsNormal             bool      `json:"isNormal"`
	IsMatch              bool      `json:"match"`
	Box                  Box       `json:"box"`
}

Token defines a token on a line.

type Tokens

type Tokens struct {
	Tokens []Token `json:"tokens"`
}

Tokens defines the tokens on a line.

type User

type User struct {
	Name      string `json:"name"`
	Email     string `json:"email"`
	Institute string `json:"institute"`
	ID        int64  `json:"id"`
	Admin     bool   `json:"admin"`
}

User defines basic users.

func (User) String added in v0.4.0

func (u User) String() string

type Users

type Users struct {
	Users []User `json:"users"`
}

Users defines the repsonse data for requests to list the system's users.

type Version

type Version struct {
	Version string `json:"version"`
}

Version defines the resonse data of version requests.

Jump to

Keyboard shortcuts

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