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.4.tar.gz (27.8 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.4-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ciga-0.0.4.tar.gz
  • Upload date:
  • Size: 27.8 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.4.tar.gz
Algorithm Hash digest
SHA256 22a017b386528b97b5cbb136930cd3abd421ce626c8b4fb6bbc93189622e1613
MD5 d5984bb1c2379f7f68a368809c1149a1
BLAKE2b-256 bd931680866376c9355691b8ab8eb64d2d388602bbf80c2d0d72d93a099ad377

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ciga-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 32.6 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e32576f9d977eb36a1a31ced16a5b937891fa17751b4264ef4a9fb01de2a1165
MD5 f9e340e22cd21fbcf1033665b238e686
BLAKE2b-256 97cdcfd2452420f5c8538f84f760ac968d3e5eeb21b7e42636c9ba7ae914fe5d

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