Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MODULE] - Maximum sentence complexity #378

Open
LeonardPuettmannKern opened this issue Oct 17, 2023 · 0 comments
Open

[MODULE] - Maximum sentence complexity #378

LeonardPuettmannKern opened this issue Oct 17, 2023 · 0 comments
Assignees
Labels
cognition enhancement New feature or request

Comments

@LeonardPuettmannKern
Copy link
Contributor

LeonardPuettmannKern commented Oct 17, 2023

Please describe the module you would like to add to bricks
Similar to the sentence complexity brick, however, this brick returns the highest sentence complexity that can be found.

Do you already have an implementation?

import textstat

ATTRIBUTE: str = "text" # only text attributes
TARGET_LANGUAGE: str = "en" # iso codes

def chunked_sentence_complexity(record):
    complexities = [textstat.flesch_reading_ease(sent.text) for sent in record[ATTRIBUTE].sents] 
    return get_mapping_complexity(min(complexities))

def get_mapping_complexity(score):
    if score < 30:
        return "very difficult"
    if score < 50:
        return "difficult"
    if score < 60:
        return "fairly difficult"
    if score < 70:
        return "standard"
    if score < 80:
        return "fairly easy"
    if score < 90:
        return "easy"        
    return "very easy"

if TARGET_LANGUAGE is not None:
    textstat.set_lang(TARGET_LANGUAGE)

Additional context
Ironically, the most complex sentence be retrieved by using the min() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cognition enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant