# \donttest{
if(require(udpipe)){
library(udpipe)
data(airbnb_chunks, package = "crfsuite")
udmodel <- udpipe_download_model("dutch-lassysmall")
udmodel <- udpipe_load_model(udmodel$file_model)
airbnb_tokens <- unique(airbnb_chunks[, c("doc_id", "text")])
airbnb_tokens <- udpipe_annotate(udmodel,
x = airbnb_tokens$text,
doc_id = airbnb_tokens$doc_id)
airbnb_tokens <- as.data.frame(airbnb_tokens)
x <- merge(airbnb_chunks, airbnb_tokens)
x <- crf_cbind_attributes(x, terms = c("upos", "lemma"), by = "doc_id")
model <- crf(y = x$chunk_entity,
x = x[, grep("upos|lemma", colnames(x))],
group = x$doc_id,
method = "lbfgs", options = list(max_iterations = 5))
scores <- predict(model,
newdata = x[, grep("upos|lemma", colnames(x))],
group = x$doc_id, type = "marginal")
head(scores)
scores <- predict(model,
newdata = x[, grep("upos|lemma", colnames(x))],
group = x$doc_id, type = "sequence")
head(scores)
## cleanup for CRAN
file.remove(model$file_model)
file.remove("modeldetails.txt")
file.remove(udmodel$file)
} # End of main if statement running only if the required packages are installed
# }
Run the code above in your browser using DataLab