Skip to content

Commit

Permalink
decode() failed if nested s-attribute does not occur - fixed #284
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Blätte authored and Andreas Blätte committed Feb 29, 2024
1 parent 14b4a26 commit a32708c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ values. Warning issued now.
available for s_attribute defined by `mw`.
* `decode()` to `AnnotatedPlainTextDocument` failed if a document contains only
one token. Fixed #285.
* `decode()` failed if nested s-attribute does not occur. Fixed #284.

# polmineR v0.8.9

Expand Down
12 changes: 10 additions & 2 deletions R/decode.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,16 @@ setMethod("decode", "slice", function(.Object, to = c("data.table", "Annotation"
registry = .Object@registry_dir,
region_matrix = .Object@cpos
)
strucs <- RcppCWB::ranges_to_cpos(struc_matrix)
if (length(strucs) == 0L) next
strucs <- suppressWarnings(RcppCWB::ranges_to_cpos(struc_matrix))
if (length(strucs) == 0L){
if (decode){
y[, (s_attributes[i]) := rep(NA_character_, times = nrow(y))]
} else {
y[, (s_attributes[i]) := rep(NA_integer_, times = nrow(y))]
}

next
}

regions <- RcppCWB::get_region_matrix(
corpus = .Object@corpus,
Expand Down

0 comments on commit a32708c

Please sign in to comment.