From 1f74ad9801db2dd6148ea79e3c443f9fc13b8774 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Mon, 17 Jun 2019 20:39:13 -0300 Subject: [PATCH] Add method to restore previous saved model --- mallet/NAMESPACE | 1 + mallet/R/mallet.R | 15 +++++++++++++-- mallet/man/mallet.topic.load.Rd | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 mallet/man/mallet.topic.load.Rd diff --git a/mallet/NAMESPACE b/mallet/NAMESPACE index bfa81bd..cada3e1 100644 --- a/mallet/NAMESPACE +++ b/mallet/NAMESPACE @@ -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) diff --git a/mallet/R/mallet.R b/mallet/R/mallet.R index fd12007..c66aeee 100644 --- a/mallet/R/mallet.R +++ b/mallet/R/mallet.R @@ -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)) } diff --git a/mallet/man/mallet.topic.load.Rd b/mallet/man/mallet.topic.load.Rd new file mode 100644 index 0000000..7a4d2b9 --- /dev/null +++ b/mallet/man/mallet.topic.load.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mallet.R +\name{mallet.topic.load} +\alias{mallet.topic.load} +\title{Load a topic from a file} +\usage{ +mallet.topic.load(filename) +} +\arguments{ +\item{filname}{The mallet topic file} +} +\description{ +This function returns the topic model loaded from a file. +} +