<commit_before>require 'tesseract'
class PostsController < ApplicationController
    # GET /posts
    def index
        @post = Post.find(:all, :order => 'posts.created_at DESC')
        respond_to do |format|
            format.html # index.html.erb
        end
    end

    # GET /posts/1
    def show
        @post = Post.find(params[:id])

        respond_to do |format|
            format.html # show.html.erb
        end
    end

    # GET /posts/1/edit
    def edit
        @post = Post.find(params[:id])
    end

    # POST /posts
    def create
        @post = Post.new(params[:post].permit(:nature,:content,:caption,:user,:att_file,:tags_list))
        @post.posted_by_uid=current_user.id
        @post.posted_by=current_user.name
        #@post.user = current_user
        @post.ups=0
        @post.downs=0
	@blacklist=Blacklist.all.pluck('word')
        e = Tesseract::Engine.new {|e|
            e.language  = :eng
            e.blacklist = @blacklist
        }

        @post.save
        respond_to do |format|
            if @post.save
		@path= Rails.root.to_s() + '/public' +@post.att_file.url
                ocr_link=(@path).split('?')
                #Here the adding of tags starts
		x=[]
                y=[]
                z=[]
                begin
                    a=e.text_for(ocr_link[0]).strip
                    x = word_frequencies(a+" "+@post.caption,5)
                    y= @poset.content.split(' ')
                    #z= @post.caption.split(' ')
                rescue
                    puts "------------------------"
                    puts "Couldn't find the frequency"
                    puts "------------------------"
                end
                puts "----------------------"
                puts "tags"  
                puts "----------------------"
                @post.tag_list.add(x+y)
                @post.save
                #Ends here (hopefully)
                format.html { redirect_to root_path }
                format.json { render :json => @post, :status => :created, :location => @post }
            else
                format.html { redirect_to root_path }
                format.json { render :json => @post.errors, :status => :unprocessable_entity }
            end
        end
    end
    def word_frequencies(string, n)
        words = string.split(/\s/)  # O(n)
        max = 0
        min = Float::INFINITY
        frequencies = words.inject(Hash.new(0)) do |hash,word|  # O(k)<commit_msg>commit to merge with bootstrap to allow rebase<commit_after>require 'tesseract'
class PostsController < ApplicationController
    # GET /posts
    def index
        @post = Post.find(:all, :order => 'posts.created_at DESC')
        respond_to do |format|
            format.html # index.html.erb
        end
    end

    # GET /posts/1
    def show
        @post = Post.find(params[:id])

        respond_to do |format|
            format.html # show.html.erb
        end
    end

    # GET /posts/1/edit
    def edit
        @post = Post.find(params[:id])
    end

    # POST /posts
    def create
        @post = Post.new(params[:post].permit(:nature,:content,:caption,:user,:att_file,:tags_list))
        @post.posted_by_uid=current_user.id
        @post.posted_by=current_user.name
        #@post.user = current_user
        @post.ups=0
        @post.downs=0
	@blacklist=Blacklist.all.pluck('word')
        e = Tesseract::Engine.new {|e|
            e.language  = :eng
            e.blacklist = @blacklist
        }

        @post.save
        respond_to do |format|
            if @post.save
		@path= Rails.root.to_s() + '/public' +@post.att_file.url
                ocr_link=(@path).split('?')
                #Here the adding of tags starts
		x=[]
                y=[]
                begin
                    a=e.text_for(ocr_link[0]).strip
                    x = word_frequencies(a+" "+@post.caption,5)
                    y= @poset.content.split(' ')
                    #z= @post.caption.split(' ')
                rescue
                    puts "------------------------"
                    puts "Couldn't find the frequency"
                    puts "------------------------"
                end
                puts "----------------------"
                puts "tags"  
                puts "----------------------"
                @post.tag_list.add(x+y)
                @post.save
                #Ends here (hopefully)
                format.html { redirect_to root_path }
                format.json { render :json => @post, :status => :created, :location => @post }
            else
                format.html { redirect_to root_path }
                format.json { render :json => @post.errors, :status => :unprocessable_entity }
            end
        end
    end
    def word_frequencies(string, n)
        words = string.split(/\s/)  # O(n)
        max = 0
        min = Float::INFINITY
        frequencies = words.inject(Hash.new(0)) do |hash,word|  # O(k)
{'fraction_non_alphanumeric': 0.15088638195004028, 'fraction_numerical': 0.0032232070910556, 'mean_word_length': 1.306084533209475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6521416', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1432, 'n_words': 299}