Documentation
¶
Overview ¶
Package api provides basic api types.
Index ¶
- Constants
- func IsValidJSONResponse(res *http.Response, codes ...int) bool
- type AdaptiveTokens
- type AdditionalLexicon
- type Book
- type BookWithPages
- type Books
- type Box
- type CharMap
- type Client
- func (c Client) AssignBack(pid int) error
- func (c Client) AssignTo(pid, uid int) error
- func (c Client) DeleteBook(bookID int) error
- func (c Client) DeleteLine(bookID, pageID, lineID int) error
- func (c Client) DeletePage(bookID, pageID int) error
- func (c Client) DeleteUser(id int64) error
- func (c Client) Download(pid int) (io.ReadCloser, error)
- func (c Client) GetAPIVersion() (Version, error)
- func (c Client) GetAdaptiveTokens(bookID int) (AdaptiveTokens, error)
- func (c Client) GetBook(bookID int) (*Book, error)
- func (c Client) GetBooks() (*Books, error)
- func (c Client) GetCharMap(bid int, filter string) (CharMap, error)
- func (c Client) GetExtendedLexicon(bookID int) (ExtendedLexicon, error)
- func (c Client) GetFirstPage(bookID int) (*Page, error)
- func (c Client) GetJobStatus(jobID int) (*JobStatus, error)
- func (c Client) GetLastPage(bookID int) (*Page, error)
- func (c Client) GetLine(bookID, pageID, lineID int) (*Line, error)
- func (c Client) GetLineImage(line *Line) (image.Image, error)
- func (c Client) GetLogin() (Session, error)
- func (c Client) GetOCRModels(bookID int) (Models, error)
- func (c Client) GetPage(bookID, pageID int) (*Page, error)
- func (c Client) GetPatterns(bookID int, ocr bool) (PatternCounts, error)
- func (c Client) GetPostCorrection(bookID int) (*PostCorrection, error)
- func (c Client) GetProfile(bookID int) (gofiler.Profile, error)
- func (c Client) GetSuspicious(bookID int) (SuggestionCounts, error)
- func (c Client) GetToken(bookID, pageID, lineID, tokenID int) (*Token, error)
- func (c Client) GetTokenLen(bookID, pageID, lineID, offset, len int) (*Token, error)
- func (c Client) GetUser(id int64) (User, error)
- func (c Client) GetUsers() (Users, error)
- func (c Client) Logout() error
- func (c Client) OCRPredict(bid, pid, lid int, name string) (Job, error)
- func (c Client) OCRTrain(bid int, name string) (Job, error)
- func (c Client) PostBook(zip io.Reader, book Book) (*Book, error)
- func (c Client) PostExtendedLexicon(bookID int) (Job, error)
- func (c Client) PostPostCorrection(bookID int) (Job, error)
- func (c Client) PostProfile(bookID int, tokens ...string) (Job, error)
- func (c Client) PostUser(u CreateUserRequest) (User, error)
- func (c Client) PostZIP(zip io.Reader) (*Book, error)
- func (c Client) PutBook(book Book) (*Book, error)
- func (c Client) PutLine(bookID, pageID, lineID int, cor string) (*Line, error)
- func (c Client) PutToken(bookID, pageID, lineID, tokenID int, cor string) (*Token, error)
- func (c Client) PutTokenLen(bookID, pageID, lineID, tokenID, len int, cor string) (*Token, error)
- func (c Client) PutUser(u CreateUserRequest) (User, error)
- func (c Client) QueryPatterns(bookID int, ocr bool, q string, qs ...string) (Patterns, error)
- func (c Client) QueryProfile(bookID int, q string, qs ...string) (Suggestions, error)
- func (c Client) Raw(path string, out io.Writer) error
- func (c Client) Search(bookID int, s Search) (*SearchResults, error)
- func (c Client) Split(pid int, random bool, uid int, ids ...int) (SplitPackages, error)
- func (c Client) TakeBack(pid int) error
- type CreateUserRequest
- type Error
- type ErrorResponse
- type ExtendedLexicon
- type Job
- type JobStatus
- type Languages
- type Line
- type LoginRequest
- type Match
- type Model
- type Models
- type Page
- type PatternCounts
- type Patterns
- type PostCorrection
- type Search
- type SearchResults
- type SearchType
- type Session
- type SplitPackage
- type SplitPackages
- type SplitRequest
- type Suggestion
- type SuggestionCounts
- type Suggestions
- type Token
- type Tokens
- type User
- type Users
- type Version
Constants ¶
const ( LoginURL = "/login" LogoutURL = "/logout" VersionURL = "/api-version" )
API routes
const (
// Auth definest the ?auth=xxx token
Auth = "auth"
)
Variables ¶
This section is empty.
Functions ¶
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 ¶
BookWithPages is a Book with an additional field that holds all the book's pages.
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 ¶
Authenticate creates a new Client from a given auth-token.
func NewClient ¶ added in v0.4.7
NewClient creates a new client with the given host (and it default web host).
func (Client) AssignBack ¶ added in v0.15.0
AssignBack assigns a package back to its original user. User must own the package.
func (Client) AssignTo ¶ added in v0.15.0
AssignTo assigns a package to another user. User must be an admin.
func (Client) DeleteBook ¶ added in v0.15.0
DeleteBook deletes the book the given book.
func (Client) DeleteLine ¶ added in v0.4.7
DeleteLine deletes the given line, page or .
func (Client) DeletePage ¶ added in v0.4.7
DeletePage deletes the given page.
func (Client) DeleteUser ¶ added in v0.15.0
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 ¶
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) GetCharMap ¶ added in v0.14.2
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
GetFirstPage returns the first page of the given book.
func (Client) GetJobStatus ¶ added in v0.7.0
GetJobStatus returns the job status for the given job.
func (Client) GetLastPage ¶ added in v0.16.0
GetLastPage returns the last page of the given book.
func (Client) GetLineImage ¶ added in v0.4.1
GetLineImage downloads the line image for the given line. At this point only PNGs are accepted.
func (Client) GetOCRModels ¶ added in v0.9.0
GetOCRModels returns the available ocr models for the given book or project.
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
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) GetTokenLen ¶ added in v0.16.0
GetTokenLen returns the token with the given length.
func (Client) OCRPredict ¶ added in v0.14.1
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
OCRTrain trains a new model using the given model as base on the given project.
func (Client) PostBook ¶
PostBook uploads a zipped OCR project and the given metadata. It returns the newly created book.
func (Client) PostExtendedLexicon ¶ added in v0.8.0
PostExtendendLexicon sends a request to create the extendedn lexicon for the given book or project.
func (Client) PostPostCorrection ¶ added in v0.9.0
PostPostCorrection sends a request to start the automatic post correction on the given book with the given extended lexicon tokens.
func (Client) PostProfile ¶
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) PutBook ¶ added in v0.16.0
PutBook updates the given book's metadata. It returns the updated book data.
func (Client) PutTokenLen ¶ added in v0.16.4
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
QueryPatterns returns the suggestions for the given error patterns.
func (Client) QueryProfile ¶ added in v0.7.0
QueryProfile returns the suggestions for the given words.
func (Client) Raw ¶
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.
type CreateUserRequest ¶
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 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.
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 ¶
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 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 Search ¶ added in v0.16.0
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.
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
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.