Git Product home page Git Product logo

wse-research / linguaf Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 4.0 112 KB

python package for calculating famous measures in computational linguistics

License: MIT License

Python 99.81% Makefile 0.19%
python computational-linguistics language language-features flesh-reading-ease lexical-density lexical-complexity dependency-distance type-token-ratio lexical-diversity quantitative-text-analysis

linguaf's Introduction

LinguaF

Version Downloads Repo size

LinguaF provides an easy access for researchers and developers to methods of quantitative language analysis, such as: readability, complexity, diversity, and other descriptive statistics.

Usage

documents = [
    "Pain and suffering are always inevitable for a large intelligence and a deep heart. The really great men must, I think, have great sadness on earth.",
    "To go wrong in one's own way is better than to go right in someone else's.",
    "The darker the night, the brighter the stars, The deeper the grief, the closer is God!"
]

Descriptive Statistics

The following descriptive statistics are supported (descriptive_statistics.py module):

  • Number of characters char_count
  • Number of letters letter_count
  • Number of punctuation characters punctuation_count
  • Number of digits digit_count
  • Number of syllables syllable_count
  • Number of sentences sentence_count
  • Number of n-syllable words number_of_n_syllable_words
  • Average syllables per word avg_syllable_per_word
  • Average word length avg_word_length
  • Average sentence length avg_sentence_length
  • Average words per sentence avg_words_per_sentence

Additional methods:

  • Get lexical items (nouns, adjectives, verbs, adverbs) get_lexical_items
  • Get n-grams get_ngrams
  • Get sentences get_sentences
  • Get words get_words
  • Tokenize tokenize
  • Remove punctuation remove_punctuation
  • Remove digits remove_digits

Example:

from linguaf import descriptive_statistics as ds


ds.words_per_sentence(documents)
# Output: 15

Syntactical Complexity

The following syntactical complexity metrics are supported (syntactical_complexity.py module):

  • Mean Dependency Distance (MDD) mean_dependency_distance

Example:

from linguaf import syntactical_complexity as sc


sc.mean_dependency_distance(documents)
# Output: 2.307306255835668

Lexical Diversity

The following lexical diversity metrics are supported (lexical_diversity.py module):

  • Lexical Density (LD) lexical_density
  • Type Token Ratio (TTR) type_token_ratio
  • Herdan's Constant or Log Type Token Ratio (LogTTR) log_type_token_ratio
  • Summer's Index summer_index
  • Root Type Token Ratio (RootTTR) root_type_token_ratio

Example:

from linguaf import lexical_diversity as ld


ld.log_type_token_ratio(documents)
# Output: 94.03574963462502

Readability

The following readability metrics are supported (readability.py module):

  • Flesch Reading Ease (FRE) flesch_reading_ease
  • Flesch-Kincaid Grade (FKG) flesch_kincaid_grade
  • Automated Readability Index (ARI) automated_readability_index
  • Simple Automated Readability Index (sARI) automated_readability_index_simple
  • Coleman's Readability Score coleman_readability
  • Easy Listening Score easy_listening

Example:

from linguaf import readability as r


r.flesch_kincaid_grade(documents)
# Output: 4.813333333333336

Install

Via PIP

pip install linguaf

Latest version from GitHub

git clone https://github.com/Perevalov/LinguaF.git
cd LinguaF
pip install .

Language Support

At the moment, library supports English and Russian languages for all the methods.

Citation

TBD

linguaf's People

Contributors

anbo-de avatar heinpa avatar javiersorucol avatar perevalov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

linguaf's Issues

Problems using the library

Hi! I've installing the library by using pip, but I'm getting an error when trying to use the example in the readme, I'm trying to run:

from linguaf import descriptive_statistics as ds

documents = [
    "Pain and suffering are always inevitable for a large intelligence and a deep heart. The really great men must, I think, have great sadness on earth.",
    "To go wrong in one's own way is better than to go right in someone else's.",
    "The darker the night, the brighter the stars, The deeper the grief, the closer is God!"
]

print(ds.words_per_sentence(documents))

and I get:

Traceback (most recent call last):
  File "x.py", line 1, in <module>
    from linguaf import descriptive_statistics as ds
  File "C:\Users\javi\anaconda3\lib\site-packages\linguaf\descriptive_statistics.py", line 26, in <module>
    STOPWORDS[language] = __load_json(
  File "C:\Users\javi\anaconda3\lib\site-packages\linguaf\__init__.py", line 10, in __load_json
    data = json.load(f)
  File "C:\Users\javi\anaconda3\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\javi\anaconda3\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 98: character maps to <undefined>

I've tried to install the package from github too and got the same result, can you give me a hand?

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.