Not able to do pairwise comparison in two documents(Minhashing and locality sensitive hashing)

Hi R fraternity,
I am trying to compare two text docs in R but not able to get the results. I am using Minhashing and locality sensitive hashing.

Reprex of the code is-

library(textreuse)
library(shiny)
library(RecordLinkage)
library(tidyverse)
library(dplyr)
library(shinydashboard)
library(tesseract)
library(magick)
library(stringdist)





ui<- fluidPage(
  fluidRow(
    column(4,
           fileInput("image1", "Upload Image 1")),
    column(4,
           fileInput("image2", "Upload Image 2")),
    column(8,
           actionButton("submit", "Submit"), 
           actionButton("compare", "Analyze"))
  ),
  fluidRow(column(12,
                  box(width = 12,
                      uiOutput("text"),
                      title = "Text Output 1"
                  )
  )),
  fluidRow(column(12,
                  box(width = 12,
                      uiOutput("text1"),
                      title = "Text Output 2"
                  )
  )),
  fluidRow(column(12,
                  box(width = 12,
                      verbatimTextOutput("analysis"),
                      title = "Analysis"
                  )
  )))

server<- function(input, output, session)
{
  
  
  text1<- reactive({
    t1<- c(image_ocr(image_read(input$image1, path = input$image1$datapath)))
    t<- as.character(t1)
    return(t1)
  })
  
  text2<- reactive({
    t2<-c(image_ocr(image_read(input$image2, path = input$image2$datapath)))
    t2<-as.character(t2)
    return(t2)
  })
  
  observeEvent(input$submit, {
    req(input$image1)
    output$text<- renderUI({
      text1()
    })
  })
  
  observeEvent(input$submit, {
    req(input$image2)
    output$text1<- renderUI({
      text2()
    })
  })
  
  a<- reactive({
    t<-c(text1(),text2())
    minhash <- minhash_generator(200, seed = 235)
    ats <- TextReuseCorpus(text = t,
                           tokenizer = tokenize_ngrams, n = 7,
                           minhash_func = minhash)
    
    buckets <- lsh(ats, bands = 50, progress = FALSE)
    candidates <- lsh_candidates(buckets)
    scores <- lsh_compare(candidates, ats, jaccard_similarity, progress = FALSE)
    return(scores)
  })
  
  observeEvent(input$compare,{
    output$analysis<- renderPrint({
      req(a())
    }) 
  })
}

shinyApp(ui,server)

o\p I am getting-

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.