Skip to main content

Create and analyze argument graphs and serialize them via Protobuf

Project description

Arguebuf Python

Arguebuf is a format for serializing argument graphs and specified using Protobuf. The complete specification and documentation is available at the Buf Schema Registry. While Protobuf automatically generates native code for all major programming languages (including Python), we created a custom implementation that provides some additional benefits, including:

  • The ability to import existing formats like AIF, SADFace, and a few others.
  • Export of Arguebuf graphs to AIF, NetworkX, and Graphviz.
  • Integration with the popular NLP library spaCy.
  • Various helper methods to programmatically manipulate/create argument graphs.
  • More pythonic interfaces than the regular code generated by protoc.

You can easily install the library from PyPI using pip. The documentation is hosted on ReadTheDocs

Command Line Interface (CLI)

We also offer some tools to simplify dealing with structured argument graphs. Among others, it is possible to convert graphs between different formats, translate them, and render images using graphviz. To use it, install the cli extras when installing the package. When using pip, this can be accomplished with

pip install arguebuf[cli]

Afterwards, you can execute it by calling arguebuf, for example:

arguebuf --help

Alternatively, you can use the Docker image available at ghcr.io/recap-utr/arguebuf-python. To use it, mount a folder to the container and pass the options as the command.

docker run --rm -it -v $(pwd)/data:/data ghcr.io/recap-utr/arguebuf-python:latest --help

If you use the nix package manager, you can run it as follows:

nix run github:recap-utr/arguebuf-python -- --help

Theoretical Foundations

An argument graph is way to represent structured argumentation. What sets it apart from unstructured argumentation (e.g., in newspaper articles) is that only the essential/argumentative parts of a text art part of this representation. These units of argumentation are also called ADUs (argumentative discourse units). The length of ADUs can differ dramatically (depending on various factors like the context), meaning they might contain only a few words, a sentence, or even a whole paragraph. The structure of an argument is then represented through relations between these units. For this purpose, they can be further subdivided into claims and premises: A claim is a statement that is supported or attacked by one or multiple premises. At the same time, a claim may also function as a premise for another claim, making it possible to construct even complex argument graphs. One of the claims is called major claim and represents the overall claim of the whole argument. In many cases (but not all), this major claim is located right at the top of the graph Here is a rather simple example.

Exemplary argument graph

Claims, premises and the major claim are represented as atom nodes while relations between them are represented by scheme nodes. The set of nodes $V = A \cup S$ is composed of the set of atom nodes $A$ and the set of scheme nodes $S$. The supporting or attacking relations are encoded in a set of edges $E \subseteq V \times V \setminus A \times A$. Edges can be drawn between any type of nodes except for two atom nodes. For instance, it is possible to connect two scheme nodes to support or attack the inference between two ADUs. Based on this, we define an argument graph $G$ as the triple $G = ( V , E , M )$.

User Guide

When importing this library, we recommend using an abbreviation such as ag (for argument graph).

import arguebuf as ag

In the following, we will introduce the most important features of arguebuf. For more details including examples, check out our API documentation.

Importing an Existing Graph

We support multiple established formats to represent argument graphs: AIF, OVA, SADFace, ArgDown, BRAT, and Kialo. Given an input file, the library can automatically determine the correct format and convert it to a representation in the arguebuf format. One can either pass a string pointing to the file or a pathlib.Path object.

graph = ag.load.file("graph.json")

It is also possible to load multiple graphs within a folder. Here, you need to pass the folder along with a glob pattern for selecting the argument graphs. This also enables to recursively load all argument graphs from a common parent directory.

graphs = ag.load.folder("./data", "**/*.json")

Since atom nodes contain textual information that may need to be analyzed using NLP techniques, we support passing a custom nlp function to these loader methods. This also makes it really easy to integrate the popular spacy library with arguebuf as all texts of atom nodes are automatically converted to a spacy Doc.

import spacy
nlp = spacy.load("en_core_web_lg")
graph = ag.load.file("graph.json", nlp=nlp)

Programmatically Create a New Graph

Instead of importing an existing graph, you can also create a new one using an object-oriented API using our library. To illustrate this, we generate a graph with two premises that are connected to a major claim. Please note: In case edges with nodes not yet contained in the graph are added, the respective nodes are added automatically.

graph = ag.Graph()

premise1 = ag.AtomNode("Text of premise 1")
premise2 = ag.AtomNode("Text of premise 2")
claim = ag.AtomNode("Text of claim")

scheme1 = ag.SchemeNode(ag.Support.DEFAULT)
scheme2 = ag.SchemeNode(ag.Attack.DEFAULT)

graph.add_edge(ag.Edge(premise1, scheme1))
graph.add_edge(ag.Edge(scheme1, claim))
graph.add_edge(ag.Edge(premise2, scheme2))
graph.add_edge(ag.Edge(scheme2, claim))

graph.major_claim = claim
gv_graph = ag.dump.graphviz(graph)
ag.render.graphviz(gv_graph, "./assets/programmatic.png")

With this code, we get the following output

Output of programmatic graph creation

Exporting Argument Graphs

We support different output formats and integration with other libraries to ease the use of argument graphs. Have a look at the following code snippet to get an overview of the possibilities

# Export to graphviz DOT format
dot = ag.dump.graphviz(graph)

# Export an image of this dot source to a file
ag.render.graphviz(dot, "./graph.pdf")

# Convert to NetworkX graph
nx = ag.dump.networkx(graph)

# Save the graph as Arguebuf
ag.dump.file(graph, "./graph.json")

# Save the graph as AIF
ag.dump.file(graph, "./graph.json", ag.GraphFormat.AIF)

Development

To pull the testing data, make sure to install DVC and run dvc pull in the root directory of the repository.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

arguebuf-2.7.2.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

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

arguebuf-2.7.2-py3-none-any.whl (64.1 kB view details)

Uploaded Python 3

File details

Details for the file arguebuf-2.7.2.tar.gz.

File metadata

  • Download URL: arguebuf-2.7.2.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for arguebuf-2.7.2.tar.gz
Algorithm Hash digest
SHA256 34b5d254ea1ce68223bc238ffa7e14481b895d92bfb715ad6e4a352f4343cb14
MD5 73a05e435ed9358e1413a4493193cc70
BLAKE2b-256 877c9b928f715378c3c36e913a9e0917bee5b74bcc3aca29b5bac58994b36c45

See more details on using hashes here.

Provenance

The following attestation bundles were made for arguebuf-2.7.2.tar.gz:

Publisher: ci.yml on recap-utr/arguebuf-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arguebuf-2.7.2-py3-none-any.whl.

File metadata

  • Download URL: arguebuf-2.7.2-py3-none-any.whl
  • Upload date:
  • Size: 64.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for arguebuf-2.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b67ccf61f0247ad355d5563c8be334ce9043179e6a69a14b13e19a60e998d878
MD5 fedaa88aeee041f897fab1fae2986685
BLAKE2b-256 b4f91ae0632f0a1fd98310aa6dd1bc0c911509bea9ca73c0a699cfd87cc2e126

See more details on using hashes here.

Provenance

The following attestation bundles were made for arguebuf-2.7.2-py3-none-any.whl:

Publisher: ci.yml on recap-utr/arguebuf-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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