Code Monkey home page Code Monkey logo

ptr's Introduction

Parse Tree Readability

ptr.py is a python program that measures the readability of a text by inspecting its parse tree, that is, how complicated the sentences are regardless of the words (or word lengths) within them.

Parse Tree Readability.ipynb is a Jupyter notebook that walks through the ptr code. It contains the same functions, etc., presented in a conversational and exploratory way.

There are no other files needed. Libraries such as nltk and spaCy themselves contain corpora, so we can use those (at least to begin with).

Example: Finding the reading level of a text file within the console

>>> from ptr import *
>>> file = open('moby-dick.txt')
>>> text = file.read()
>>> file.close()
>>> corpus = tag_sentences(text)
>>> text_stats = TextStats(corpus).basic_counts()
>>> tag_stats = TagStats(corpus).get_stats()
>>> tree_stats = TreeStats(corpus).get_stats()
>>> readability = ptr(text_stats, tag_stats, tree_stats)
>>> print(readability)
16.74
>>>

Using Parse Tree Readability.ipynb

The Jupyter notebook Parse Tree Readability.ipynb is the best introduction to the theory and usage of this library. Open it (on the command line, with jupyter notebook "Parse Tree Readability.ipynb") and begin exploring.

Installation

Installation is simple. Download (or clone) this repository to your working directory. Then import ptr inside your python file.

Installing the required libraries can be done with pip or conda, your preference, on the command line, ex.:

$ pip install spacy

You may need to download the spaCy english language parser; an error such as Warning: no model found for 'en' will alert you of this. This can be done on the command line as well:

$ python -m spacy download en

License

Licensed under the MIT License. See LICENSE.

ptr's People

Watchers

Aaron Jacobson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.