Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addressing NOTES, more robust tests and retry
- Loading branch information
1 parent
7371b00
commit a8ca6e4
Showing
8 changed files
with
145 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
test_that( | ||
"categorize_overlap() categorizes entity overlaps based on character vectors", | ||
{ | ||
|
||
doc <- "Crude oil prices on the rise." | ||
|
||
x <- get_dbpedia_uris( | ||
x = doc, | ||
max_len = 5600L, | ||
confidence = 0.35, | ||
api = "https://api.dbpedia-spotlight.org/en/annotate", | ||
language = "en", | ||
types = character(), | ||
support = 20, | ||
types_src = c("DBpedia", "Wikidata"), | ||
verbose = TRUE | ||
) |> | ||
detect_overlap(start_col = "start", verbose = TRUE) | ||
|
||
y <- categorize_overlap(x, | ||
start_col = "start", | ||
end_col = "end", | ||
experimental = TRUE, | ||
verbose = TRUE) | ||
|
||
# expect four rows | ||
expect_equal(nrow(y), 4L) | ||
|
||
# expect specific entity texts | ||
expect_contains(y[["text"]], c("Crude oil", "Crude oil prices", "oil", "oil prices")) | ||
|
||
# expect specific values in specific row | ||
example_row <- y[text == "Crude oil prices"] | ||
|
||
# concatenated uris | ||
expect_equal(example_row[["dbpedia_uri"]], | ||
"http://dbpedia.org/resource/Petroleum|http://dbpedia.org/resource/Price_of_oil") | ||
|
||
expect_equal( | ||
unname( | ||
unlist( | ||
example_row[, ovl_longest:ovl_undetermined] | ||
) | ||
), | ||
c(FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE) | ||
) | ||
} | ||
) | ||
|
||
test_that( | ||
"categorize_overlap() categorizes entity overlaps based on CWB corpora", | ||
{ | ||
|
||
withr::local_package("polmineR") | ||
|
||
use("RcppCWB") | ||
|
||
reuters_anno <- corpus("REUTERS") |> | ||
polmineR::subset(id == "353") |> | ||
get_dbpedia_uris( | ||
max_len = 5600L, | ||
confidence = 0.35, | ||
api = "https://api.dbpedia-spotlight.org/en/annotate", | ||
language = "en", | ||
types = character(), | ||
support = 20, | ||
verbose = TRUE | ||
) |> | ||
detect_overlap(start_col = "cpos_left", end_col = "cpos_right", verbose = TRUE) | ||
|
||
y <- categorize_overlap(reuters_anno, | ||
start_col = "cpos_left", | ||
end_col = "cpos_right", | ||
experimental = TRUE, | ||
corpus = "REUTERS", | ||
verbose = TRUE) | ||
|
||
ymin <- y[!is.na(ovl_id)] | ||
|
||
# expect four rows | ||
expect_equal(nrow(ymin), 4L) | ||
|
||
# expect specific entity texts | ||
expect_contains(ymin[["text"]], c("Crude oil", "Crude oil prices fell", "oil prices fell", "oil")) | ||
|
||
# expect specific values in specific row | ||
example_row <- ymin[text == "Crude oil prices fell"] | ||
|
||
# concatenated uris | ||
expect_equal(example_row[["dbpedia_uri"]], | ||
"http://dbpedia.org/resource/West_Texas_Intermediate|http://dbpedia.org/resource/1980s_oil_glut") | ||
|
||
expect_equal( | ||
unname( | ||
unlist( | ||
example_row[, ovl_longest:ovl_undetermined] | ||
) | ||
), | ||
c(FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE) | ||
) | ||
} | ||
) |
Oops, something went wrong.