Skip to content

Commit

Permalink
Merge pull request #62 from MarcinKosinski/master
Browse files Browse the repository at this point in the history
Polish language available as an additional language in serVis
  • Loading branch information
kshirley committed Jul 25, 2016
2 parents 69397bb + 7bbcb19 commit 503b556
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 25 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -33,3 +33,4 @@ LazyData: true
VignetteBuilder: knitr
URL: https://github.com/cpsievert/LDAvis
BugReports: https://github.com/cpsievert/LDAvis/issues
RoxygenNote: 5.0.1
3 changes: 2 additions & 1 deletion NAMESPACE
@@ -1,8 +1,9 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2: do not edit by hand

export(createJSON)
export(jsPCA)
export(renderVis)
export(runShiny)
export(serVis)
export(visOutput)
importFrom(utils,read.csv)
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -2,6 +2,8 @@

A new argument, reorder.topics, was added to createJSON(). For details, see #51

It is possible to use different language than english in the final visualization (polish so far). See [[#60]](https://github.com/cpsievert/LDAvis/issues/60).

CHANGES IN LDAvis VERSION 0.3.2

BUG FIX
Expand Down
1 change: 1 addition & 0 deletions R/imports.R
Expand Up @@ -4,3 +4,4 @@
#' @importFrom proxy dist
#' @importFrom utils packageVersion browseURL
#' @importFrom stats cmdscale
#' @importFrom utils read.csv
23 changes: 22 additions & 1 deletion R/serVis.R
Expand Up @@ -20,11 +20,13 @@
#' interactive login if the GITHUB_PAT environment variable is not set. For more
#' details, see \url{https://github.com/ropensci/gistr#authentication}.
#' @param ... arguments passed onto \code{gistr::gist_create}
#' @param language Which language to use in visualization? So far: \code{english} or \code{polish}.
#'
#' @return An invisible object.
#' @seealso \link{createJSON}
#' @export
#' @author Carson Sievert
#' @importFrom utils read.csv
#' @examples
#'
#' \dontrun{
Expand All @@ -33,14 +35,33 @@
#' }

serVis <- function(json, out.dir = tempfile(), open.browser = interactive(),
as.gist = FALSE, ...) {
as.gist = FALSE, language = "english", ...) {

stopifnot(is.character(language), length(language) == 1, language %in% c('english', 'polish'))

## Copy html/js/css files to out.dir
dir.create(out.dir)
src.dir <- system.file("htmljs", package = "LDAvis")
to.copy <- Sys.glob(file.path(src.dir, "*"))
file.copy(to.copy, out.dir, overwrite = TRUE, recursive = TRUE)

## Substitute words to different language if required
if (language != 'english') {
ldavis.js <- readLines(file.path(out.dir, "ldavis.js")) # changes are made only in this file
lang.dict <- read.csv(system.file("languages/dictionary.txt",
package = "LDAvis")) # read the dictionary
for (i in 1:nrow(lang.dict)){ # substitute sentences row by row
ldavis.js <- gsub(x = ldavis.js, pattern = lang.dict[i, 1],
replacement = lang.dict[i, language], fixed = TRUE)
}
# lambda coordinate to display its value
if (language == 'polish') {
ldavis.js[674] <- gsub(ldavis.js[674], pattern = "80", replacement ="175", fixed = TRUE)
}
# save new language version
write(ldavis.js, file = file.path(out.dir, "ldavis.js"))
}

## Write json to out.dir
cat(json, file = file.path(out.dir, "lda.json"))

Expand Down
2 changes: 1 addition & 1 deletion inst/htmljs/ldavis.js
Expand Up @@ -334,7 +334,7 @@ LDAvis = function(to_select, json_file) {
.attr('class', "circleGuideTitle")
.style("text-anchor", "left")
.style("fontWeight", "bold")
.text("Marginal topic distribtion");
.text("Marginal topic distribution");
d3.select("#leftpanel").append("text")
.attr("x", cx2 + 10)
.attr("y", mdsheight + 2 * newSmall)
Expand Down
17 changes: 17 additions & 0 deletions inst/languages/dictionary.txt
@@ -0,0 +1,17 @@
base, polish
"Marginal topic distribution", "Rozkład brzegowy tematów"
"Intertopic Distance Map (via multidimensional scaling)", "Mapa odległości między tematami (na bazie skalowania wielowymiarowego)"
"Overall term frequency", "Całkowita częstość terminu"
"Estimated term frequency within the selected topic", "Przewidywana częstość terminu w wybranym temacie"
"1. saliency(term w) = frequency(w) * [sum_t p(t | w) * log(p(t | w)/p(t))] for topics t; see Chuang et. al (2012)", "1. widoczność(terminu w) = częstość(w) * [sum_t p(t | w) * log(p(t | w)/p(t))] dla tematu t; Chuang et. al (2012)",
""2. relevance(term w | topic t) = \u03BB * p(w | t) + (1 - \u03BB) * p(w | t)/p(w); see Sievert & Shirley (2014)"", "2. związek(terminu w | temat t) = \u03BB * p(w | t) + (1 - \u03BB) * p(w | t)/p(w); Sievert & Shirley (2014)",
" Most Salient Terms", " Najbardziej Widocznych Terminów "
"Slide to adjust relevance metric:", "Dopasuj miarę związku terminów z tematami"
" Most Relevant Terms for Topic ", " Najbardziej Związaych Terminy z Tematem "
"% of tokens)", "% wyrazów)"
"Conditional topic distribution given term = '", "Warunkowy rozkład tematów przy zadanym terminie = '"
"Previous Topic", "Poprzedni Temat"
"Next Topic", "Następny Temat"
"Clear Topic", "Wyczyść"
"Selected Topic: <span", "Wybrany Temat: <span"
"mdswidth = 530", "mdswidth = 620"
2 changes: 1 addition & 1 deletion man/TwentyNewsgroups.Rd

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

6 changes: 3 additions & 3 deletions man/jsPCA.Rd

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

4 changes: 2 additions & 2 deletions man/renderVis.Rd

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

10 changes: 5 additions & 5 deletions man/runShiny.Rd

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

23 changes: 13 additions & 10 deletions man/serVis.Rd

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

2 changes: 1 addition & 1 deletion man/visOutput.Rd

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

0 comments on commit 503b556

Please sign in to comment.