Skip to main content

Character interaction temporal graph analysis

Project description

license package publish

CIGA: Character Interaction Graph Analyzer

CharNet is a Python package designed for performing graph analysis on dynamic social networks based on narratives. It is a reimplementation of CharNet using igraph.

Simple example


import ciga as cg
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({
        'Season': [1, 1, 1, 1],
        'Episode': [1, 1, 1, 1],
        'Scene': [1, 1, 2, 2],
        'Line': [1, 2, 1, 2],
        'Speaker': ['Sheldon', 'Leonard', 'Penny', 'Sheldon'],
        'Listener': ['Leonard', 'Sheldon', 'Sheldon', 'Penny'],
        'Words': ['Hello', 'Hi there', 'How are you?', 'Fine, thank you']
    })

def weight_func(interaction):
    return 1

position = ('Season', 'Episode', 'Scene', 'Line')
interactions = cg.prepare_data(data=df,
                               position=position,
                               source='Speaker', 
                               target='Listener', 
                               interaction='Words')
sub_interactions = cg.segment(interactions, start=(1, 1, 1, 1), end=(2, 1, 1, 1))
weights = cg.calculate_weights(sub_interactions, weight_func)
agg_weights = cg.agg_weights(data=weights, 
                             position=position[:-1], 
                             agg_func=lambda x: sum(x))

tg = cg.TGraph(data=agg_weights, 
               position=position[:-1], 
               directed=False)

graph = tg.get_graph((1, 1, 1))
fig, ax = plt.subplots()
cg.iplot(graph, target=ax)
plt.show()

res = cg.tgraph_degree(tg, weighted=True, w_normalized=False, normalized=True)

res.to_csv('results.csv')

Install


Install the latest version of CharNet:

$ pip install ciga

Install with all optional dependencies:

$ pip install ciga[all]

To Do

  • Add non-directed graph support
  • Add closeness centrality
  • Add Eigenvector centrality
  • Add Leiden community detection
  • Add temporal visualization
  • Add centrality visualizer (with visualization)

License

Released under the GNU General Public License v3.0.

Copyright (c) 2024 Media Comprehension Lab

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

ciga-0.0.3.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

ciga-0.0.3-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file ciga-0.0.3.tar.gz.

File metadata

  • Download URL: ciga-0.0.3.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for ciga-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5c6af96f45ffd68f036c8322eaf88d7fa563008c49b1d9090197deed52aac013
MD5 314f889189d7fed73336cd92d6a9b38c
BLAKE2b-256 5001112767ea284044a92d04f6f6bc23f25664ed1abdf3db9710c64e44c422e1

See more details on using hashes here.

File details

Details for the file ciga-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: ciga-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for ciga-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 109e7c7cefe7018f746991e199ac35b54e22ca7b4ca61b39ef856d9c26441a86
MD5 013bb5764d6481a55994e9c011ec8053
BLAKE2b-256 b6b4ab91f09cbe07169afbd38e0ff4b09482cfdeaf55bc8f808eef24e113e0d2

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