Skip to content

Commit

Permalink
Merge pull request #16 from victorlaerte/master
Browse files Browse the repository at this point in the history
Add method to restore previous saved model
  • Loading branch information
MansMeg authored Aug 6, 2019
2 parents 9b86ce7 + 1f74ad9 commit dad6e38
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions mallet/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(mallet.subset.topic.words)
export(mallet.top.words)
export(mallet.topic.hclust)
export(mallet.topic.labels)
export(mallet.topic.load)
export(mallet.topic.words)
export(mallet.word.freqs)
export(save.mallet.state)
Expand Down
15 changes: 13 additions & 2 deletions mallet/R/mallet.R
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,24 @@ mallet.topic.hclust <- function(doc.topics, topic.words, balance = 0.3) {
stats::hclust(balance * stats::dist(topic.words) + (1.0 - balance) * stats::dist(topic.docs))
}


#' @title
#' Load a topic from a file
#'
#' @description
#' This function returns the topic model loaded from a file.
#'
#' @param filename
#' The mallet topic file
#'
#' @export
mallet.topic.load <- function(filename) {
rJava::J("cc/mallet/topics/RTopicModel")$read(rJava::.jnew("java/io/File", filename))
}

save.mallet.instances <- function(instances, filename) {
instances$save(rJava::.jnew("java/io/File", filename))
}


load.mallet.instances <- function(filename) {
rJava::J("cc.mallet.types.InstanceList")$load(rJava::.jnew("java/io/File", filename))
}
15 changes: 15 additions & 0 deletions mallet/man/mallet.topic.load.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dad6e38

Please sign in to comment.