User Profile

Collapse

Profile Sidebar

Collapse
thistle
thistle
Last Activity: Dec 11 '15, 08:15 PM
Joined: Mar 11 '15
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • computing uni-gram and bigram probability using python

    I have 2 files. I have to calculate the monogram (uni-gram) and at the next step calculate bi-gram probability of the first file in terms of the words repetition of the second file. (the files are text files). for this, first I have to write a function that calculates the number of total words and unique words of the file, because the monogram is calculated by the division of unique word to the total word for each word. and at last write it to a...
    See more | Go to post
    Last edited by bvdet; May 18 '15, 05:33 PM. Reason: Please use code tags when posting code [code]....[/code]

  • thistle
    started a topic normalize spaces in a txt file

    normalize spaces in a txt file

    I want to write a function that takes a file and (corrects) deletes extra spaces after or before punctuations "() [] {} "" . , : ;! ? $" or add spaces where necessary.
    example:
    word .word should changes to word. word
    word( word )word should changes to word (word) word

    my code doesn't corrects the spaces!

    Code:
    import re
    
    def c (file):
        with open ('c.txt')as f1:
    ...
    See more | Go to post
    Last edited by Rabbit; Mar 14 '15, 07:55 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

  • thistle
    replied to how to count spaces in a file in python?
    Code:
    def C (file, char):
        f = open ('file1.txt', 'r')
        s = f.read()
        i = 0
        for ch in s:
            if ch == char:
                i += 1
        return i
    See more | Go to post
    Last edited by bvdet; Mar 12 '15, 11:17 PM. Reason: Please use code tags when posting code [code]....[/code]

    Leave a comment:


  • thistle
    replied to how to count spaces in a file in python?
    thanks. but I want a function and it should take a file not a string. How should I write a function?
    See more | Go to post

    Leave a comment:


  • thistle
    started a topic how to count spaces in a file in python?

    how to count spaces in a file in python?

    I want to write a function that takes a file and a character and returns the number of character, the character is space for example.I wrote the code below but it doesn't work.
    Code:
    def c (file, char):
        f = open ('file1.txt', 'r')
        s = f.read()
        i = 0
        for char in s:
            i += 1
    See more | Go to post
    Last edited by bvdet; Mar 12 '15, 05:43 PM. Reason: Please use code tags when posting code [code]....[/code]

  • thistle
    replied to merging files, each file in a new line
    I started python recently. sorry for so much questions. open (fn)reads a file but I have a folder which contains 10 files. what should I write instead of fn so that it reads the folder. I know I have to split the folder first with os.listdir (folder) but then what?
    See more | Go to post

    Leave a comment:


  • thistle
    replied to merging files, each file in a new line
    I want each file (which has some lines) to be written in just one line. so I need to omit newlines between them. and the to write the next file as the next line I need to add '\n'. so I cant eliminate for loop. If I eliminate it of course it merges them but there are a lot of lines. each file should be = one line
    See more | Go to post

    Leave a comment:


  • thistle
    replied to merging files, each file in a new line
    I added 2 lines to the code. it was working some hours ago, but now it doesn't work. I don't know the problem!!!!!!!! !!!can anybody help?
    Code:
    import os,shutil
    path = 'فناوري'
    f=open("wwww.txt","a", encoding = 'utf-8')
    for r,d,fi in os.walk(path):
    	for files in fi:
    		if files.endswith(".txt"):
    			 g=open(os.path.join(r,files), encoding
    ...
    See more | Go to post
    Last edited by bvdet; Mar 11 '15, 05:47 PM. Reason: PLEASE use code tags when posting code [code]....[/code]

    Leave a comment:


  • thistle
    started a topic merging files, each file in a new line

    merging files, each file in a new line

    I have this code to merge files. the files language is persian. it merges them but I want each file to be written in a new line. for example if I have 9 files, the output should be 9 lines. each line is one file. the problem is that I don't know where to put replace('\n', " ") to omit newlines of a file and where to add '\n' to go to the next file.

    Code:
    import os,shutil
    path = 'فناوري'
    ...
    See more | Go to post
    Last edited by bvdet; Mar 11 '15, 02:17 PM. Reason: Please use code tags when posting code [code]....[/code]
No activity results to display
Show More
Working...