Skip to main content

Computing schematicity of autobiographical narratives

Project description

Measuring narrative schematicity

codecov

Methods from the paper "Computational Tools for Quantifying Schemas in Autobiographical Narratives".

Installation

[Under construction until this project is on PyPI]

Depends on networkx (for network models), SpaCy (for tokenization), and wordfreq for automated topic identification. Additionally, one of SpaCy's models must be downloaded (see their instructions on how to do this).

Usage

Loading and saving models

A text file of word vectors can be read using the read_vectors() function:

vec_mod = narsche.read_vectors('/path/to/vectors.txt')

This produces a vector model. Initializing a network model requires first loading a networkx.Graph object:

import networkx as nx

graph = nx.load('/path/to/graph')
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=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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

narsche-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

narsche-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file narsche-0.1.0.tar.gz.

File metadata

  • Download URL: narsche-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for narsche-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d011c7cedfeea63e66898112c5551b2a3ee573bf594984bb9b19c17334b8807
MD5 eb25a27d5e0c4962353f1ece52816817
BLAKE2b-256 bc79211bcb1e393e82ab5c99ad4b99325bd798ef4ff42a99b31489e45243d4cf

See more details on using hashes here.

File details

Details for the file narsche-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: narsche-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for narsche-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8015ac3230b1d7a6133778243ca8df739939ddeec88b3924d418827a804e0b1
MD5 5e545e76854dbd50643402d31caa4334
BLAKE2b-256 be1df579891ac9fb31da6915ef6f2f152c8f37fdfd492b8f88a2a83cece18b8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page