-
Notifications
You must be signed in to change notification settings - Fork 0
fix(curation): Use matches_hash for statement hash due to string issues #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,8 @@ | |
| } | ||
| if (filter_by_curation) { | ||
| for (i in seq_along(res)) { | ||
| stmt_hash <- res[[i]]$data$stmt_hash | ||
| stmt_json <- fromJSON(res[[i]]$data$stmt_json) | ||
| stmt_hash <- stmt_json$matches_hash | ||
| incorrect_count <- .get_incorrect_curation_count(stmt_hash, api_key) | ||
| res[[i]]$data$evidence_count <- res[[i]]$data$evidence_count - incorrect_count | ||
| # Todo: Also subtract source_counts accordingly if requested | ||
|
|
@@ -301,7 +302,8 @@ | |
| query(res, x)$data$source_counts | ||
| }, ""), | ||
| stmt_hash = vapply(keys(res), function(x) { | ||
| as.character(query(res, x)$data$stmt_hash) | ||
| stmt_json <- fromJSON(query(res, x)$data$stmt_json) | ||
| stmt_json$matches_hash | ||
| }, ""), | ||
|
Comment on lines
304
to
307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and validation for JSON parsing in vapply. Similar to the issue in Apply this diff to add defensive error handling: stmt_hash = vapply(keys(res), function(x) {
- stmt_json <- fromJSON(query(res, x)$data$stmt_json)
- stmt_json$matches_hash
+ tryCatch({
+ stmt_json <- fromJSON(query(res, x)$data$stmt_json)
+ if (is.null(stmt_json$matches_hash)) {
+ return(NA_character_)
+ }
+ stmt_json$matches_hash
+ }, error = function(e) {
+ warning(paste("Failed to parse stmt_json for key", x, ":", e$message))
+ return(NA_character_)
+ })
}, ""),🤖 Prompt for AI Agents |
||
| stringsAsFactors = FALSE | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for JSON parsing and field validation.
The
fromJSONcall lacks error handling and there's no validation thatmatches_hashexists in the parsed JSON. If the INDRA API returns malformed JSON or if the structure changes, this will cause runtime failures.Apply this diff to add defensive error handling:
for (i in seq_along(res)) { - stmt_json <- fromJSON(res[[i]]$data$stmt_json) - stmt_hash <- stmt_json$matches_hash + stmt_json <- tryCatch( + fromJSON(res[[i]]$data$stmt_json), + error = function(e) { + warning(paste("Failed to parse stmt_json for statement", i, ":", e$message)) + return(NULL) + } + ) + if (is.null(stmt_json) || is.null(stmt_json$matches_hash)) { + warning(paste("Missing matches_hash for statement", i)) + next + } + stmt_hash <- stmt_json$matches_hash incorrect_count <- .get_incorrect_curation_count(stmt_hash, api_key)📝 Committable suggestion
🤖 Prompt for AI Agents