1. 程式人生 > >Flesch Index To Determine The Readability Of A Text File With Python.

Flesch Index To Determine The Readability Of A Text File With Python.

import os
dire=os.getcwd()
listOfdir=os.listdir(dire)
while True:

    UserFileName=raw_input(“Enter file name:”)
    if (UserFileName in listOfdir)         and (UserFileName.endswith(‘.txt’)):
        InputFile=open(UserFileName,‘r’)
        text=InputFile.read()
        sentence=text.count(“.”) + text.count(‘!’
) +

                  text.count(“;”) + text.count(“:”) +
                  text.count(“?”)
        words=len(text.split())
        syllable=0
        for word in text.split():
            for vowel in [‘a’,‘e’,‘i’,‘o’,‘u’]:
                syllable += word.count(vowel)
            for ending in [‘es’,‘ed’
,‘e’]:

                if word.endswith(ending):
                    syllable -= 1
            if word.endswith(‘le’):
                    syllable += 1
        G=round((0.39*words)/sentence+ (11.8*syllable)/words-15.59)


        if G >= 0 and G <=30:
            print ‘The Readability level is College’
        elif
 G >= 50 and G <=60:

            print ‘The Readability level is High School’
        elif  G >= 90 and G <=100:
            print ‘The Readability level is fourth grade’

        print ‘This text has %d words’ %(words)

    elif UserFileName not in listOfdir:
        print “This text file does not exist in current directory”
    elif not(UserFileName.endswith(‘.txt’)):             print “This is not a text file.”
If you look closely at the above python index script,you will notice some additions that were made that was not in the algorithm.I added them to prevent ERROR in our program.Also,the program was not properly indented.

Explanation of the FLESCH INDEX PYTHON SCRIPT.

os 300x76 - Flesch Index To  Determine The Readability Of A Text File With Python.

The python os module provides methods that help you perform file processing operation such as viewing the list of file in the current directory.
The getcwd() displays the current working directory of where our python program is located.Our text file has to be saved in the same directory of our python program to avoid ERROR in our program.
dire is the location of our currently working directory.
The listdir(dire) displays a list of files in the current working directory of the object dire.
So far,we have succeeded in knowing the name of files in our 
current working directory.
Our next block of code is: 

wile 300x58 - Flesch Index To  Determine The Readability Of A Text File With Python.

 The if statement avoids ERROR in case the input file is not a text file or it does not exist in our current working directory.
Our next block of code executes the algorithm of our FLESCH INDEX PYTHON SCRIPT.

algorithm 300x174 - Flesch Index To  Determine The Readability Of A Text File With Python.

相關推薦

Flesch Index To Determine The Readability Of A Text File With Python.

import osdire=os.getcwd()listOfdir=os.listdir(dire)while True:    UserFileName=raw_input(“Enter file name:”)    if (UserFileName in listOfdir)         and 

How to determine the filesystem of an unmounted device?

轉載自 https://unix.stackexchange.com/questions/53542/how-to-determine-the-filesystem-of-an-unmounted-device There are multiple ways to get this i

[iOS] How to round the corners of a button

如何做出圓角的按鈕?比我想像中的簡單,其實一行指令(buyButton.layer.cornerRadius)就完成了。 實作出來的效果,我是用 cornerRadius = 5 You can manipulate the CALayer of your button to do this pre

Ask HN: Where can I find a text file with a set of representative URLs?

My google-fu is failing me today.I'm looking for something similar to an a list of phrases but for URLs.A phrase list looks something like this: https://ww

"The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

這句話的意思是將datetime2資料型別轉換為datetime資料型別會導致超出範圍的值。宣告已經終止。 在使用EF插入資料是發生列轉換的錯誤,搞了好久,不知道問題出在哪裡! 根據提示的錯誤資訊來看是Datetime資料型別出現錯誤 後來發現 public Nullable<S

Get Smart: from Theory, to Practice, to the Future of A.I.

This piece accompanies a dedicated series from Ben around intelligence, A.I, and data-driven design and development in retail – all of which you can find i

How To Put Arrows at the Bottom of a Div(給一個div元素下邊加個向下箭頭的方法)

You’ll only need HTML and CSS to make this element.(這個方法只需要用到html和css) The HTML is simple. All you need is a div element with a class name. Here’s what th

解決Gradle執行命令時報Could not determine the dependencies of task &#39;:compileReleaseJava&#39;.

內容 oid 兩個 jsb pan mpi 技術分享 android undle Could not determine the dependencies of task ‘:compileReleaseJava‘. > failed to find targe

POJ 2553 The Bottom of a Graph(強連通分量)

margin target 代碼 not push ret dsm ng- http POJ 2553 The Bottom of a Graph 題目鏈接 題意:給定一個有向圖,求出度為0的強連通分量 思路:縮點搞就可以 代碼: #include <

The Bottom of a Graph

ive limit rtai assume ted can hab spa mean                poj——The Bottom of a Graph

return three values that can be the lengths of the sides of a triangle,

static use prev element and hat [] sin sha 這是return numbers, return value 剛簡單, 首先sort ,然後遍歷,看當前值+ 前值> 後值 class CountTriangles { /

How to Get the Length of File in C

code class clas body position pre -c set == How to get length of file in C //=== int fileLen(FILE *fp) { int nRet = -1; int nPosB

【poj2553】The Bottom of a Graph(強連通分量縮點)

targe ring sin spa const ostream 連通 stream pty 題目鏈接:http://poj.org/problem?id=2553 【題意】 給n個點m條邊構成一幅圖,求出所有的sink點並按順序輸出。sink點是指該點能到達的點反過來

安裝Neo4j提示:Unable to determine the path to java.exe

neo4j安裝Neo4j 壓縮版時提示如圖所示的錯誤:出現這種原因是發現系統沒有安裝相應的java環境。從java網站現在java開發軟件: 安裝完jdk,這後在安裝 neo4j 如圖:安裝Neo4j提示:Unable to determine the path to java.exe

#748 – 獲得按下時對應位置點的大小(Getting the Size of a Contact Point during Raw Touch)

ini bounds event view hup main.c .cn hand phoenix 原文:#748 – 獲得按下時對應位置點的大小(Getting the Size of a Contact Point during Raw Touch)

沒有生產者 Failed to check the status of the service org.java.service.HotelService. No provider available for the service

ble 1.0 防火墻 stat 設定 火墻 xml文件 tro 問題 經過反復查找原因終於鎖定了生產者XML文件中的version="1.0" 教訓:如果生產者設定了服務的版本,消費者一定要提供相應的版本號(或空或寫入對應的版本號) 如果有朋友不是這個問題,建議看看防

POJ 2553 The Bottom of a Graph

har tac memset pac ack cpp namespace include string 我的第一道tarjin 要註意兩點,有向圖一定要判斷點是否在棧中 彈棧的時候不能判斷low[x]==low[stack[top]] #include <cstdi

How to Pronounce the Months of the Year

line http itl alt breaking popular linkedin mos nbsp How to Pronounce the Months of the Year Share Tweet Share Tagg

poj 2553 The Bottom of a Graph (Tarjan強聯通)

題意:在v可以到達的所有點也都可以到達v,由此就可以知道求解縮點以後出度為0的點中的節點數字即可 思路:就是縮點後,輸出出度為0的點內的點。 #pragma GCC optimize(2) #include<stdio.h> #include<algorithm

Failed to determine the https port for redirect

() nta use sim over comm ont cert docs warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to determine the