Skip to main content

Delab Trees

A library to analyze conversation trees.

Installation

pip install delab_trees

Get started

Example data for Reddit and Twitter are available here https://github.com/juliandehne/delab-trees/raw/main/delab_trees/data/dataset_[reddit|twitter]_no_text.pkl.

The data is structure only. Ids, text, links, or other information that would break confidentiality of the academic

access have been omitted.

The trees are loaded from tables like this:

| | tree_id | post_id | parent_id | author_id | text | created_at |

|---:|----------:|----------:|------------:|:------------|:------------|:--------------------|

| 0 | 1 | 1 | nan | james | I am James | 2017-01-01 01:00:00 |

| 1 | 1 | 2 | 1 | mark | I am Mark | 2017-01-01 02:00:00 |

| 2 | 1 | 3 | 2 | steven | I am Steven | 2017-01-01 03:00:00 |

| 3 | 1 | 4 | 1 | john | I am John | 2017-01-01 04:00:00 |

| 4 | 2 | 1 | nan | james | I am James | 2017-01-01 01:00:00 |

| 5 | 2 | 2 | 1 | mark | I am Mark | 2017-01-01 02:00:00 |

| 6 | 2 | 3 | 2 | steven | I am Steven | 2017-01-01 03:00:00 |

| 7 | 2 | 4 | 3 | john | I am John | 2017-01-01 04:00:00 |

This dataset contains two conversational trees with four posts each.

Currently, you need to import conversational tables as a pandas dataframe like this:

import pandas as pd

from delab_trees import TreeManager



d = {'tree_id': [1] * 4,

     'post_id': [1, 2, 3, 4],

     'parent_id': [None, 1, 2, 1],

     'author_id': ["james", "mark", "steven", "john"],

     'text': ["I am James", "I am Mark", " I am Steven", "I am John"],

     "created_at": [pd.Timestamp('2017-01-01T01'),

                    pd.Timestamp('2017-01-01T02'),

                    pd.Timestamp('2017-01-01T03'),

                    pd.Timestamp('2017-01-01T04')]}

df = pd.DataFrame(data=d)

manager = TreeManager(df) 

# creates one tree

test_tree = manager.random()

Note that the tree structure is based on the parent_id matching another rows post_id.

You can now analyze the reply trees basic metrics:

from delab_trees.main import get_test_tree

from delab_trees.delab_tree import DelabTree



test_tree : DelabTree = get_test_tree()

assert test_tree.total_number_of_posts() == 4

assert test_tree.average_branching_factor() > 0

A summary of basic metrics can be attained by calling

from delab_trees.test_data_manager import get_test_tree

from delab_trees.delab_tree import DelabTree



test_tree : DelabTree = get_test_tree()

print(test_tree.get_author_metrics())



# >>> removed [] and changed {} (merging subsequent posts of the same author)

# >>>{'james': <delab_trees.delab_author_metric.AuthorMetric object at 0x7fa9c5496110>, 'steven': <delab_trees.delab_author_metric.AuthorMetric object at 0x7fa9c5497dc0>, 'john': <delab_trees.delab_author_metric.AuthorMetric object at 0x7fa9c5497a00>, 'mark': <delab_trees.delab_author_metric.AuthorMetric object at 0x7fa9c5497bb0>}

More complex metrics that use the full dataset for training can be gotten by the manager:

import pandas as pd

from delab_trees import TreeManager



d = {'tree_id': [1] * 4,

     'post_id': [1, 2, 3, 4],

     'parent_id': [None, 1, 2, 1],

     'author_id': ["james", "mark", "steven", "john"],

     'text': ["I am James", "I am Mark", " I am Steven", "I am John"],

     "created_at": [pd.Timestamp('2017-01-01T01'),

                    pd.Timestamp('2017-01-01T02'),

                    pd.Timestamp('2017-01-01T03'),

                    pd.Timestamp('2017-01-01T04')]}

df = pd.DataFrame(data=d)

manager = TreeManager(df) # creates one tree

rb_vision_dictionary : dict["tree_id", dict["author_id", "vision_metric"]] = manager.get_rb_vision()

The following two complex metrics are implemented:

from delab_trees.test_data_manager import get_test_manager



manager = get_test_manager()

rb_vision_dictionary = manager.get_rb_vision() # predict an author having seen a post

pb_vision_dictionary = manager.get_pb_vision() # predict an author to write the next post

How to cite

    @article{dehne_dtrees_23,

    author    = {Dehne, Julian},

    title     = {Delab-Trees: measuring deliberation in online conversations},        

    url = {https://github.com/juliandehne/delab-trees}     

    year      = {2023},

}

Metadata

Release files for delab-trees 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for delab-trees 0.4.2
File Size Uploaded
delab_trees-0.4.2.tar.gz 24.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for delab-trees 0.4.2
File Interpreter ABI Platform
delab_trees-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 48.2 MB

Release files / delab_trees-0.4.2.tar.gz

Download URL delab_trees-0.4.2.tar.gz
Size 24.0 MB
Tags Source
SHA-256 checksum
How to use checksums
08acdad46589ebe53a4d9a11dbb0f8006a63b33be86944533b68325691c2185f
BLAKE2b-256 checksum
How to use checksums
fde53afa157182f3031cee0df1fda67da66e7b70c1f00c5bd91cd6182b1d7284
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.18

Release files / delab_trees-0.4.2-py3-none-any.whl

Download URL delab_trees-0.4.2-py3-none-any.whl
Size 24.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
fcb264b8ca0129dc7a783cd091516e005ae90e92fa52417e613587259eff54b4
BLAKE2b-256 checksum
How to use checksums
95f9cb783a52212bef97cd9f64888f5ac42b0c354935571b9274cc82a1809501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.7

1 release file

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page