diff --git a/processing/wikiproc/R/get_data.R b/processing/wikiproc/R/get_data.R index 1050189120a85492d34b8dda19d6ff414db55b6f..24ffb1df148ead2457fc83576bbce3ad1852f677 100644 --- a/processing/wikiproc/R/get_data.R +++ b/processing/wikiproc/R/get_data.R @@ -37,7 +37,11 @@ get_data <- function(use.cache = TRUE, write.cache = FALSE, data.dir = "data") { cat("Downloading list from wikipedia... ") +<<<<<<< HEAD:processing/wikiproc/R/get_data.R page <- xml2::read_html("https://en.wikipedia.org/wiki/List_of_physicists") +======= + page <- read_html("https://en.wikipedia.org/wiki/List_of_physicists") +>>>>>>> master:processing/wikiproc/R/get_data.R cat("Done.\n") @@ -46,8 +50,13 @@ get_data <- function(use.cache = TRUE, write.cache = FALSE, data.dir = "data") { cat("Processing data:\n") physicists <- page %>% +<<<<<<< HEAD:processing/wikiproc/R/get_data.R rvest::html_nodes(".mw-parser-output li a") %>% rvest::html_attr("href") +======= + html_nodes(".mw-parser-output li a") %>% + html_attr("href") +>>>>>>> master:processing/wikiproc/R/get_data.R # Clean the list diff --git a/processing/wikiproc/R/nlp_annotate.R b/processing/wikiproc/R/nlp_annotate.R index 98a3f320ed35aa5d0ed205b84dd51037755735d1..9a94958c7fd7e1019a3e7f6cd7a5649b60c1cb73 100644 --- a/processing/wikiproc/R/nlp_annotate.R +++ b/processing/wikiproc/R/nlp_annotate.R @@ -34,6 +34,7 @@ init_nlp <- function(type, value) { #' @return Annotation object for use with cleanNLP methods #' @export create_annotations <- function(text, article.id, article.rev.id, use.cache = TRUE, write.cache = FALSE, data.dir = "data") { +<<<<<<< HEAD # Generate filename, for some reason there paste0 will pad the article id with leading whitespaces # To prevent this we stip 'em again @@ -42,6 +43,16 @@ create_annotations <- function(text, article.id, article.rev.id, use.cache = TRU # Check if there is a cached version of the annotations for this article in this specific revision +======= + + # Generate filename, for some reason there paste0 will pad the article id with leading whitespaces + # To prevent this we stip 'em again + + filename <- gsub(" ", "", paste(data.dir, "annotations", paste0(article.id, "-", article.rev.id, ".RDS"), sep = .Platform$file.sep), fixed = TRUE) + + # Check if there is a cached version of the annotations for this article in this specific revision + +>>>>>>> master if(use.cache & file.exists(filename)) { res <- tryCatch({ data <- readRDS(filename) @@ -51,11 +62,19 @@ create_annotations <- function(text, article.id, article.rev.id, use.cache = TRU }) return(res) } +<<<<<<< HEAD annotation <- cleanNLP::cnlp_annotate(text, as_strings = TRUE) # Write cache if desired +======= + + annotation <- cleanNLP::cnlp_annotate(text, as_strings = TRUE) + + # Write cache if desired + +>>>>>>> master if(write.cache) { if (!dir.exists("data")) { dir.create("data") @@ -65,6 +84,7 @@ create_annotations <- function(text, article.id, article.rev.id, use.cache = TRU } saveRDS(annotation, filename) } +<<<<<<< HEAD # Return data # On a side note: Should we do this? The tidyverse style guide discourages explicit returns. @@ -72,3 +92,12 @@ create_annotations <- function(text, article.id, article.rev.id, use.cache = TRU return(annotation) } +======= + + # Return data + # On a side note: Should we do this? The tidyverse style guide discourages explicit returns. + # But then again, it suggests snake case for variables... + + return(annotation) +} +>>>>>>> master diff --git a/processing/wikiproc/tests/testthat/article-4-cleansed.txt b/processing/wikiproc/tests/testthat/article-4-cleansed.txt index 339f780a2ebaa0fd57d2a878abcf24d4a01c689f..499e8b869b6cbad18d7c08093396be04a9743916 100644 --- a/processing/wikiproc/tests/testthat/article-4-cleansed.txt +++ b/processing/wikiproc/tests/testthat/article-4-cleansed.txt @@ -13,4 +13,7 @@ According to a 2008 article, "Academician Abdullayev was called the Father of Ph Academician Abdullayev was recognized as the top expert on the chemical element selenium, and thus entrusted authoring the article on selenium in the third (final) edition of the top scientific reference publication - the Great Soviet Encyclopedia. Original quote in Russian: "Модель Ñ Ð¸Ñпользованием Ñтруктуры Ñ p−n-переходом Ð´Ð»Ñ Ð¾Ð±ÑŠÑÑÐ½ÐµÐ½Ð¸Ñ Ð²Ñ‹Ð¿Ñ€ÑÐ¼Ð»ÐµÐ½Ð¸Ñ Ð² Ñеленовых выпрÑмителÑÑ… предлагалаÑÑŒ Д.Ð. ÐаÑледовым и Г.Б. Ðбдуллаевым. ÐеÑÐ¼Ð¾Ñ‚Ñ€Ñ Ð½Ð° многочиÑленные иÑÑледованиÑ, Ñ‚ÐµÐ¾Ñ€Ð¸Ñ Ñ„ÑƒÐ½ÐºÑ†Ð¸Ð¾Ð½Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð¿Ð¾Ð»ÑƒÐ¿Ñ€Ð¾Ð²Ð¾Ð´Ð½Ð¸ÐºÐ¾Ð²Ñ‹Ñ… выпрÑмителей на оÑнове закиÑи меди и Ñелена в течение многих лет не была Ñоздана." Original quote in Russian: "ÐÐ°Ñ‡Ð¸Ð½Ð°Ñ Ñ 1960-года, и примерно до 1987 года в Баку Ñ Ð±Ñ‹Ð» много раз. Затем приезжал Ñюда в 2003 году, принÑÑ‚ÑŒ учаÑтие в праздновании 85 лет Ñо Ð´Ð½Ñ Ñ€Ð¾Ð¶Ð´ÐµÐ½Ð¸Ñ Ð¼Ð¾ÐµÐ³Ð¾ друга, покойного президента ÐзербайджанÑкой академии наук ГаÑана Багировича Ðбдуллаева. Тогда же Ñ Ð¿Ð¾Ð±Ñ‹Ð²Ð°Ð» в ИнÑтитуте физики Ðкадемии наук Ðзербайджана. ОбрадовалÑÑ, что он ÑохранилÑÑ.... Ðо дело в том, что и в ÑоветÑкое Ð²Ñ€ÐµÐ¼Ñ Ð°Ð·ÐµÑ€Ð±Ð°Ð¹Ð´Ð¶Ð°Ð½Ñ†Ð°Ð¼ было нелегко иметь доÑтаточно прочные позиции, не то, чтобы в мировой, но и в ÑоветÑкой науке. Г. Ðбдуллаев был очень талантливым физиком. Он понимал, что физика полупроводников - ÑˆÐ¸Ñ€Ð¾ÐºÐ°Ñ Ð¾Ð±Ð»Ð°ÑÑ‚ÑŒ. Ð”Ð»Ñ Ñ€Ð°Ð·Ð²Ð¸Ñ‚Ð¸Ñ Ð¿Ñ€Ð¾Ð¼Ñ‹ÑˆÐ»ÐµÐ½Ð½Ð¾Ñти нужно развивать многое. Ðо в целом ИнÑтитут должен иметь Ñвое лицо. И он его Ñоздал - Ñто ÑлоиÑтые полупроводники на оÑнове Ñелена, которые нашли маÑÑу применений в опцеÑлектронике, в оптике. И Ñто очень хорошо. Люди на Ñтом роÑли и развивалиÑÑŒ. ПоÑвилÑÑ Ñ†ÐµÐ»Ñ‹Ð¹ Ñ€Ñд отраÑлевых организаций. Я не могу Ñказать как обÑтоÑÑ‚ дела Ñ Ñ„Ð¸Ð·Ð¸ÐºÐ¾Ð¹ в Ðзербайджане ÑегоднÑ, но думаю, что они далеки от благополучиÑ." Original quote from the Great Soviet Encyclopedia in Russian: "Большой вклад в Ñоздание Полупроводниковой Ñлектроники внеÑли ÑоветÑкие учёные — физики и инженеры (Ð. Ф. Иоффе, Ð. П. Сажин, Я. И. Френкель, Б. Ðœ. Вул, Ð’. Ðœ. Тучкевич, Г. Б. Ðбдулаев, Ж. И. Ðлферов, К. Ð. Валиев, Ю. П. Докучаев, Л. Ð’. Келдыш, С. Г. Калашников, Ð’. Г. КолеÑников, Ð. Ð’. КраÑилов, Ð’. Е, Лашкарёв, Я. Ð. Федотов и многие др.)." Ð. И. Шокин. ÐŸÐ¾Ð»ÑƒÐ¿Ñ€Ð¾Ð²Ð¾Ð´Ð½Ð¸ÐºÐ¾Ð²Ð°Ñ Ñлектроника. Ð‘Ð¾Ð»ÑŒÑˆÐ°Ñ ÑоветÑÐºÐ°Ñ ÑнциклопедиÑ. — Ðœ.: СоветÑÐºÐ°Ñ ÑÐ½Ñ†Ð¸ÐºÐ»Ð¾Ð¿ÐµÐ´Ð¸Ñ 1969—1978. +<<<<<<< HEAD +======= +>>>>>>> master diff --git a/processing/wikiproc/tests/testthat/test-clean_html.R b/processing/wikiproc/tests/testthat/test-clean_html.R index 764103572428c4013637196589a452e65d75c33b..084e9b3cb77c0b9eade4a114de4f985652e1572d 100644 --- a/processing/wikiproc/tests/testthat/test-clean_html.R +++ b/processing/wikiproc/tests/testthat/test-clean_html.R @@ -4,8 +4,13 @@ test_that("html cleansing works", { filename_raw <- "article-4-raw.html" filename_cleansed <- "article-4-cleansed.txt" html <- readChar(filename_raw, file.info(filename_raw)$size) +<<<<<<< HEAD expected <- gsub("\\s", "", readChar(filename_cleansed, file.info(filename_cleansed)$size)) actual <- gsub("\\s", "", clean_html(html)) +======= + expected <- readChar(filename_cleansed, file.info(filename_cleansed)$size) + actual <- clean_html(html) +>>>>>>> master expect_equal(expected, actual) })