Measuring narrative schematicity
Methods from the paper "Computational Tools for Quantifying Schemas in Autobiographical Narratives".
Installation
pip install narsche
narsche depends on networkx (for network models), SpaCy (for tokenization), and wordfreq for automated topic identification. Additionally, one of SpaCy's models must be downloaded for SpaCy-based tokenization:
python -m spacy download en_core_web_sm
Usage
Loading and saving models
A text file of word vectors can be read using the read_vectors() function:
words, vectors = narsche.read_vectors('/path/to/vectors.txt')
vec_mod = narsche.VectorModel(words, vectors)
This produces a vector model. The text file must be formatted such that the first token (space-delimited) on a line is the word for which the remaining tokens are the vector components. This is how, for example, the GloVe embeddings are formatted.
A network model can be created by first downloading the ConceptNet assertions here. They can be read as a networkx.Graph object and used to create a network model:
graph = narsche.read_conceptnet('conceptnet-assertions-5.7.0.csv.gz', gz=True)
net_mod = narsche.NetworkModel(graph)
Models can be saved using the save() method and loaded using the load() class method:
net_mod.save('network.mod')
net_mod = narsche.NetworkModel.load('network.mod')
vec_mod.save('vector.mod')
vec_mod = narsche.VectorModel.load('vector.mod')
These are just wrappers around pickle.[load/dump]. Any extension can be used.
Tokenizing narratives
Before schematicity can be computed, narratives must be tokenized, i.e., converted to a list of tokens. For this, there is a Tokenizer() class that relies on SpaCy:
txt = 'I sat on the sofa in my living room with a lamp' # Example text
tokenizer = narsche.Tokenizer('en_core_web_sm') # Initialize tokenizer
words = tokenizer.tokenize(txt) # Tokenize words
words = vec_mod.keep_known(words) # Use only those words that are in the model
Computing schematicity
Given a model and a set of tokens (and possibly a topic word), schematicity can be computed using the schematicity() function:
topic = narsche.identify_topic(words) # Identify the topic
# Compute schematicity
narsche.schematicity(
words=words,
model=vec_mod,
method='on-topic-ppn', # or topic-relatedness, pairwise-relatedness, or component-size
topic=topic)
See the documentation of the schematicity() function for kewords required by other methods.
Metadata
Release files for narsche 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| narsche-0.3.3.tar.gz | 12.6 kB | Without provenance | Details for narsche-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| narsche-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for narsche-0.3.3-py3-none-any.whl |
Total release size: 22.9 kB
Release files / narsche-0.3.3.tar.gz
| Download URL | narsche-0.3.3.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7b89c15750a44829626134df6a6b379b76f716176a935efce72f627725d0e83
|
|
BLAKE2b-256 checksum How to use checksums |
9aa9675fcabde6fe702f3e7d65b17a26d1f86e458373a2c82a740f3b47650fbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / narsche-0.3.3-py3-none-any.whl
| Download URL | narsche-0.3.3-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c9ca042168ccc2fe3a86f3af1d8f514baff0061faf846ef0c5de47156d8c356
|
|
BLAKE2b-256 checksum How to use checksums |
5612d30d3e8ff0629ac9bb7fc54a2f2651895467bb421e252d6746e818fbe4db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for narsche 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.