Skip to content

Commit

Permalink
renaming captcha_available_models()
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrecenti committed Feb 22, 2023
1 parent 514609b commit 2d927f4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 38 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ S3method(decrypt,default)
S3method(length,captcha)
S3method(plot,captcha)
S3method(print,captcha)
export(available_models)
export(captcha_accuracy)
export(captcha_annotate)
export(captcha_available_models)
export(captcha_dataset)
export(captcha_fit_model)
export(captcha_generate)
Expand Down
106 changes: 69 additions & 37 deletions R/load.R
Original file line number Diff line number Diff line change
@@ -1,48 +1,80 @@
#' Available models for prediction
#'
#' Available models for prediction using [decrypt()]().
#'
#' Currently, available captchas are:
#'
#' \itemize{
#' \item \href{https://pje.trf5.jus.br/pje/ConsultaPublica/listView.seam}{trf5}: Tribunal Regional Federal 5
#' \item \href{https://www4.tjmg.jus.br/juridico/sf/proc_resultado.jsp?comrCodigo=24&numero=1&listaProcessos=50718889720218130024&btn_pesquisar=Pesquisar}{tjmg}: Tribunal de Justiça de Minas Gerais
#' \item \href{https://pje-consulta.trt3.jus.br/pje-consulta-api/api/processos/2104879}{trt}: Tribunal Regional do Trabalho 3
#' \item \href{http://esaj.tjba.jus.br/cpopg/open.do}{esaj}: Tribunal de Justiça da Bahia
#' \item \href{https://www.jucesponline.sp.gov.br/ResultadoBusca.aspx}{jucesp}: Junta Comercial de São Paulo
#' \item \href{https://srv01.tjpe.jus.br/consultaprocessualunificada/}{tjpe}: Tribunal de Justiça de Pernambuco
#' \item \href{https://www.tjrs.jus.br/site_php/consulta/verificador.php}{tjrs}: Tribunal de Justiça do Rio Grande do Sul
#' \item \href{https://www.cadesp.fazenda.sp.gov.br/(S(vyfz1cfybbxj3sgpf4eqhxd3}{cadesp}: Centro de Apoio ao Desenvolvimento da Saúde Pública
#' \item \href{https://sei.economia.gov.br/sei/modulos/pesquisa/md_pesq_processo_pesquisar.php?acao_externa=protocolo_pesquisar&acao_origem_externa=protocolo_pesquisar&id_orgao_acesso_externo=0}{sei}: Sistema Eletrônico de Informações - ME
#' \item \href{https://servicos.receita.fazenda.gov.br/servicos/cnpjreva/Cnpjreva_Solicitacao_CS.asp}{rfb}: Receita Federal
#' Load or list available models for prediction
#'
#' The `captcha_available_models()` function lists the models available for
#' prediction in the `{captcha}` package or another repository referenced
#' in the `repo` parameter.
#' The models are loaded from the [captcha repository
#' release page](https://github.com/decryptr/captcha/releases/tag/captcha_model)
#' using the [piggyback::pb_list()] function.
#' The `captcha_load_model()` function downloads a model using
#' [piggyback::pb_download()] and returns a `luz_module_fitted` object.
#'
#' @param repo repo in the form `"<user>/<captcha>"`.
#' Defaults to `"decryptr/captcha"`
#' @param tag tag name of the release to load the file.
#'
#' @name models
#'
#' @return `captcha_available_models()` returns a character vector with the
#' names of the available models. `captcha_load_model()` returns an object
#' of class `luz_module_fitted`.
#'
#' @details
#'
#' Currently, available models are:
#'
#
#' * [trf5](https://pje.trf5.jus.br/pje/ConsultaPublica/listView.seam):
#' Tribunal Regional Federal 5
#' * [tjmg](https://www4.tjmg.jus.br/juridico/sf/proc_resultado.jsp?comrCodigo=24&numero=1&listaProcessos=50718889720218130024&btn_pesquisar=Pesquisar):
#' Tribunal de Justiça de Minas Gerais
#' * [trt](https://pje-consulta.trt3.jus.br/pje-consulta-api/api/processos/2104879):
#' Tribunal Regional do Trabalho 3
#' * [esaj](http://esaj.tjba.jus.br/cpopg/open.do):
#' Tribunal de Justiça da Bahia
#' * [jucesp](https://www.jucesponline.sp.gov.br/ResultadoBusca.aspx):
#' Junta Comercial de São Paulo
#' * [tjpe](https://srv01.tjpe.jus.br/consultaprocessualunificada/):
#' Tribunal de Justiça de Pernambuco
#' * [tjrs](https://www.tjrs.jus.br/site_php/consulta/verificador.php):
#' Tribunal de Justiça do Rio Grande do Sul
#' * [sei](https://sei.economia.gov.br/sei/modulos/pesquisa/md_pesq_processo_pesquisar.php?acao_externa=protocolo_pesquisar&acao_origem_externa=protocolo_pesquisar&id_orgao_acesso_externo=0):
#' Sistema Eletrônico de Informações - ME
#' * [rfb](https://servicos.receita.fazenda.gov.br/servicos/cnpjreva/Cnpjreva_Solicitacao_CS.asp):
#' Receita Federal do Brasil
#'
#' This list may be updated when new models are added to the release.
#'
#' @examples
#' # run only with internet connection
#' if (interactive()) {
#'
#' captcha_models_available()
#'
#' # loads rfb model
#' model <- captcha_load_model("rfb")
#' # model estimated accuracy on validation dataset
#' utils::tail(model$records$metrics$valid, 1)[[1]][["captcha acc"]]
#'
#' }
#'
#'
#' @export
available_models <- function() {

c(
"trf5",
"tjmg",
"trt",
"esaj",
"jucesp",
"tjpe",
"tjrs",
"cadesp",
"sei",
"rfb"
)

captcha_available_models <- function(repo = "decryptr/captcha",
tag = "captcha_model") {
model_list <- piggyback::pb_list(repo = repo, tag = tag)[["file_name"]]
gsub("\\.pt$", "", model_list)
}

#' Load captcha model
#'

#' @param captcha file name or captcha name
#' @param repo repo in the form `"<user>/<captcha>"`. Default `"decryptr/captcha"`
#' @param tag tag name of the release to load the file.
#'
#' @rdname models
#'
#' @export
captcha_load_model <- function(captcha, repo = "decryptr/captcha", tag = "captcha_model") {
captcha_load_model <- function(captcha,
repo = "decryptr/captcha",
tag = "captcha_model") {

if (file.exists(captcha)) {
path <- captcha
Expand Down

0 comments on commit 2d927f4

Please sign in to comment.