Skip to content

Commit

Permalink
Improves #17. New fields, yet unknown content.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekch committed Mar 30, 2015
1 parent adf50fe commit e8c5409
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
46 changes: 38 additions & 8 deletions R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#' \item judgmentDate.
#' }
#' Additionally for classes \code{saos_judgments} and \code{saos_judgments_dump}
#' there are more elements:
#' there are more elements. NOTE - some fields are specific to single court type,
#' thus are not always present, it is indicated in parentheses.
#' \itemize{
#' \item courtType,
#' \item source,
Expand All @@ -29,11 +30,15 @@
#' \item legalBases,
#' \item referencedRegulations,
#' \item referencedCourtCases,
#' \item personnelType,
#' \item judgmentResult,
#' \item receiptDate,
#' \item meansOfAppeal,
#' \item lowerCourtJudgments,
#' \item judgmentForm (\code{saos_judgments}) or form (\code{saos_judgments_dump}),
#' \item chambers.
#' (only SUPREME COURT),
#' \item personnelType (only SUPREME COURT),
#' \item chambers (only SUPREME COURT).
#' }
#'
#' For class \code{saos_judgments} and \code{saos_search} there is also
#' element "href".
#'
Expand Down Expand Up @@ -132,7 +137,9 @@ extract.saos_judgments <- function(x, element) {
"summary", "textContent", "legalBases",
"referencedRegulations", "keywords",
"referencedCourtCases", "division",
"personnelType", "judgmentForm", "chambers"))
"personnelType", "judgmentForm", "chambers",
"judgmentResult", "receiptDate",
"meansOfAppeal", "lowerCourtJudgments"))
ids <- sapply(x, `[[`, "id")
if (length(ids) == 0) ids <- integer()
if (element == "id") return(data.frame(id = ids))
Expand All @@ -158,7 +165,11 @@ extract.saos_judgments <- function(x, element) {
division = extract_division(x),
personnelType = extract_personnel(x),
judgmentForm = extract_form(x, "judgmentForm"),
chambers = extract_chambers(x))
chambers = extract_chambers(x),
judgmentResult = extract_result(x),
receiptDate = extract_receiptdate(x),
meansOfAppeal = extract_means(x),
lowerCourtJudgments = extract_lowercourt(x))

# convert IDs to true values
info$id <- ids[info$id]
Expand All @@ -180,7 +191,9 @@ extract.saos_judgments_dump <- function(x, element) {
"summary", "textContent", "legalBases",
"referencedRegulations", "keywords",
"personnelType", "form", "chambers",
"referencedCourtCases", "division"))
"referencedCourtCases", "division",
"judgmentResult", "receiptDate",
"meansOfAppeal", "lowerCourtJudgments"))
ids <- sapply(x, `[[`, "id")
if (length(ids) == 0) ids <- integer()
if (element == "id") return(data.frame(id = ids))
Expand All @@ -205,7 +218,11 @@ extract.saos_judgments_dump <- function(x, element) {
division = extract_division(x),
personnelType = extract_personnel(x),
form = extract_form(x, "form"),
chambers = extract_chambers(x))
chambers = extract_chambers(x),
judgmentResult = extract_result(x),
receiptDate = extract_receiptdate(x),
meansOfAppeal = extract_means(x),
lowerCourtJudgments = extract_lowercourt(x))

# convert IDs to true values
info$id <- ids[info$id]
Expand Down Expand Up @@ -347,8 +364,21 @@ extract_chambers <- function(x) {
result
}

extract_result <- function(x) {
extractor_single(x, "judgmentResult")
}

extract_receiptdate <- function(x) {
extractor_single(x, "receiptDate")
}

extract_means <- function(x) {
extractor_single(x, "meansOfAppeal")
}

extract_lowercourt <- function(x) {
extractor_list(x, "lowerCourtJudgments")
}

# extractors
extractor_single <- function(judgments, field_name) {
Expand Down
13 changes: 9 additions & 4 deletions man/extract.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Available elements for all methods are:
\item judgmentDate.
}
Additionally for classes \code{saos_judgments} and \code{saos_judgments_dump}
there are more elements:
there are more elements. NOTE - some fields are specific to single court type,
thus are not always present, it is indicated in parentheses.
\itemize{
\item courtType,
\item source,
Expand All @@ -52,11 +53,15 @@ Available elements for all methods are:
\item legalBases,
\item referencedRegulations,
\item referencedCourtCases,
\item personnelType,
\item judgmentResult,
\item receiptDate,
\item meansOfAppeal,
\item lowerCourtJudgments,
\item judgmentForm (\code{saos_judgments}) or form (\code{saos_judgments_dump}),
\item chambers.
(only SUPREME COURT),
\item personnelType (only SUPREME COURT),
\item chambers (only SUPREME COURT).
}

For class \code{saos_judgments} and \code{saos_search} there is also
element "href".

Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ test_that("extracting from empty lists returns empty data frame", {
referencedCourtCases = data.frame(referencedCourtCases = character()),
personnelType = data.frame(personnelType = character()),
chambers = data.frame(chambers.id = integer()),
judgmentResult = data.frame(judgmentResult = character()),
receiptDate = data.frame(receiptDate = character()),
meansOfAppeal = data.frame(meansOfAppeal = character()),
lowerCourtJudgments = data.frame(lowerCourtJudgments = character()),
href = data.frame(href = character()))
templates <- lapply(templates, function(temp) data.frame(id = integer(), temp))

Expand All @@ -45,7 +49,7 @@ test_that("extracting from empty lists returns empty data frame", {

# elements for saos_judgments and saos_dump_judgments
for (method in methods[2:3]) {
for (element in names(templates[9:18])) {
for (element in names(templates[9:22])) {
expect_empty_equal(method, element, templates[[element]])
}
}
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-get_judgments.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ test_that("get returns proper object", {
})

test_that("no new fields appear", {
expect_identical(names(table(sapply(g, names))),
expect_true( all(sapply(g, names) %in%
c("courtCases", "courtReporters", "courtType", "decision",
"division", "href", "id", "judges", "judgmentDate",
"judgmentType", "keywords", "legalBases",
"judgmentResult", "judgmentType", "keywords", "legalBases",
"lowerCourtJudgments", "meansOfAppeal", "receiptDate",
"referencedCourtCases", "referencedRegulations", "source",
"summary", "textContent"))
"summary", "textContent", "chambers", "personnelType",
"judgmentForm")))
})

test_that("c and [ methods works properly", {
Expand Down

0 comments on commit e8c5409

Please sign in to comment.