Analysis Module (PsychiatryNLPKit.analysis)

Seven categories of linguistic analysis functions, each returning a dictionary keyed by section name with numeric metric values.

All functions accept pre-computed features from TextData properties and are designed to be called individually or orchestrated via BatchAnalyzer.

Batch Analysis

PsychiatryNLPKit.analysis.AnalysisResult([...])

Container for batch analysis output.

PsychiatryNLPKit.analysis.BatchAnalyzer(...)

Run selected analyses on a TextData object in batch.

Syntax Metrics

POS tag ratios, clause structure, syntax tree depth, and sentence complexity.

PsychiatryNLPKit.analysis.sentence_length(...)

Average sentence length (in tokens) per section.

PsychiatryNLPKit.analysis.syntax_depth(...)

Average syntax tree height per section.

PsychiatryNLPKit.analysis.unique_pos_tags(...)

Average number of unique POS tags per sentence per section.

PsychiatryNLPKit.analysis.adverb_ratio(pos_tags)

Adverb-to-total-word ratio per section.

PsychiatryNLPKit.analysis.coordinating_conjunction_ratio(...)

Coordinating conjunction-to-total-word ratio per section.

PsychiatryNLPKit.analysis.adjective_ratio(...)

Adjective-to-total-word ratio per section.

PsychiatryNLPKit.analysis.pronoun_ratio(pos_tags)

Pronoun-to-total-word ratio per section.

PsychiatryNLPKit.analysis.determiner_ratio(...)

Determiner-to-total-word ratio per section.

PsychiatryNLPKit.analysis.modal_auxiliary_verb_ratio(...)

Modal auxiliary verb-to-total-word ratio per section.

PsychiatryNLPKit.analysis.stop_words_ratio(...)

Stop word-to-total-word ratio per section.

PsychiatryNLPKit.analysis.clause_count(...)

Average number of clauses per sentence per section.

PsychiatryNLPKit.analysis.noun_group_count(...)

Average number of noun phrases (NP) per sentence per section.

PsychiatryNLPKit.analysis.adjective_sentence_length(...)

Average length of adjective phrases (ADJP) per section.

Similarity Metrics

Semantic coherence measured as cosine similarity between adjacent embeddings.

PsychiatryNLPKit.analysis.word_level_cosine_similarity(...)

Cosine similarity between adjacent word embeddings per section.

PsychiatryNLPKit.analysis.sentence_level_cosine_similarity(...)

Cosine similarity between adjacent sentence embeddings per section.

Perplexity Metrics

Language model perplexity at paragraph and sentence levels (generative + masked LM).

PsychiatryNLPKit.analysis.paragraph_level_perplexity(...)

Generative perplexity for full paragraphs.

PsychiatryNLPKit.analysis.sentence_level_perplexity(...)

Generative perplexity averaged across sentences per section.

PsychiatryNLPKit.analysis.paragraph_level_pseudo_perplexity(...)

Pseudo-perplexity for full paragraphs using a masked language model.

PsychiatryNLPKit.analysis.sentence_level_pseudo_perplexity(...)

Pseudo-perplexity averaged across sentences per section using a masked LM.

Density Metrics

Semantic space dimensionality via PCA explained variance and intrinsic dimension estimation.

PsychiatryNLPKit.analysis.pca_density_metrics(...)

PCA-based density metrics per section.

PsychiatryNLPKit.analysis.intrinsic_dimensionality_density(...)

Estimate intrinsic dimensionality using MLE (Levina & Bickel, 2004).

Lexicon Metrics

Disfluency markers and filler word frequency analysis.

PsychiatryNLPKit.analysis.filler_words_count(...)

Count the number and ratio of filler words in the text data.

Optional Analyses

These require additional dependencies (networkx for graph, pillow for image).

PsychiatryNLPKit.analysis.structural_graph(...)

Constructs a structural graph from lemmatized content words per section and immediately computes all network metrics.

PsychiatryNLPKit.analysis.image_text_similarity(...)

Compute token-patch similarity between an image and text sections.