Skip to content

Commit

Permalink
add internal 'rm_fn_data' in rerank fn to close #8
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Sep 24, 2024
1 parent dde39e9 commit f20bebe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pkgsimil
Title: Similarity Metrics between R Packages
Version: 0.1.2.099
Version: 0.1.2.100
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")))
Expand Down
15 changes: 7 additions & 8 deletions R/rerank.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' Re-randk an input `data.frame` of packages with several columns of scores.
#'
#' @param rm_fn_data If `TRUE` (default), only generate combined ranks from
#' data excluding function descriptions.
#' @noRd
pkgsimil_rerank <- function (s) {
pkgsimil_rerank <- function (s, rm_fn_data = TRUE) {

cols <- names (s) [-which (names (s) == "package")]
new_cols <- paste0 (cols, "_rank")
Expand All @@ -21,13 +23,10 @@ pkgsimil_rerank <- function (s) {
rank_matrix <- as.matrix (s [, new_cols])
rank_matrix <- 1 / (k + rank_matrix)

# Weight rankings without function definitions higher than those with.
# Relative weighting are `wt_factor ^ 2`.
wt_factor <- 0.5
cols_with <- grep ("with", colnames (rank_matrix))
cols_wo <- grep ("wo", colnames (rank_matrix))
rank_matrix [, cols_with] <- rank_matrix [, cols_with] * wt_factor
rank_matrix [, cols_wo] <- rank_matrix [, cols_wo] / wt_factor
if (rm_fn_data) {
cols_wo <- grep ("wo", colnames (rank_matrix))
rank_matrix <- rank_matrix [, cols_wo]
}

rank_scores <- rowSums (rank_matrix)

Expand Down
10 changes: 9 additions & 1 deletion R/similar-pkgs.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ similar_pkgs_from_text <- function (input,
similarities [is.na (similarities)] <- 0

index <- seq_len (n)
rm_fn_data <- !input_mentions_functions (input)

return (pkgsimil_rerank (similarities) [index])
return (pkgsimil_rerank (similarities, rm_fn_data) [index])
}

input_mentions_functions <- function (input) {

stopifnot (length (input) == 1L)

grepl ("\\sfunction\\s", input, ignore.case = TRUE)
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/pkgsimil",
"issueTracker": "https://github.com/ropensci-review-tools/pkgsimil/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.1.2.099",
"version": "0.1.2.100",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit f20bebe

Please sign in to comment.