You are on page 1of 4

Visualizing literary narratives with a graph-centered

approach
Meg Ermer Germán H. Alférez
School of Computing School of Computing
Southern Adventist University Southern Adventist University
Collegedale, Tennessee Collegedale, Tennessee
mermer@southern.edu harveya@southern.edu

Abstract—The art of storytelling is multifaceted and nonlinear, contribution, and Section VI discusses the implications of our
involving multiple characters, themes, and symbols while often contribution and explores opportunities for further research.
jumping between the present and past. While media forms such
as novels can encapsulate these complexities, it is often difficult II. S TATE OF THE A RT
to visualize a narrative in an easy-to-understand format. Our
contribution is a graph-based system to let users organize and VOSviewer [1] is a software tool for building and visualiz-
visualize those narratives. Events and characters are represented ing bibliometric networks with information about researchers,
as nodes and their relationships are represented as edges. Neo4J journals, and individual publications. VOSviewer’s text mining
is used as a database management system to store the graph functionality also allows co-occurrent networks of key terms to
and to run queries on it, and Streamlit and Pyvis are used to
represent the database in the user interface. be extracted and visualized from different pieces of scientific
Index Terms—data visualization, data science, graph, database, literature. While this software can be adapted to visualize
node, edge, literature, narrative nearly any concept in terms of nodes and edges, it is not
designed with narrative summaries in mind. Thus, there is no
I. I NTRODUCTION way to easily display different types of relationships and the
Striking similarities exist between the fields of literature software is not oriented towards time-centered data.
and data science. Both require strong competencies in reading Bandara et al. [2] designed a timeline-based approach to nar-
comprehension and writing fluency, as well as the ability to rative storylines with Yarn visualization. This proposal allows
summarize and draw conclusions from an abundance of infor- multiple characters’ timelines to be visualized simultaneously
mation. Within data science, the data visualization discipline without coexisting in the same timeline. Yarn allows the user to
enables data analysts to quickly see trends and summarize efficiently generate all possible timelines within a narrative and
findings through bar graphs, scatter plots, histograms, and to view storyline layouts that depict non-linear point-of-view
many other graphical representations. However, in literature, narratives. However, this visualization does not display non-
there are no tools to visually represent the plot for readers, character-centered elements, such as relationships with places
leaving literary scholars with almost no way to draw their own or objects of importance. Moreover, each node on the timeline
conclusions except with their own interpretation of information is action-oriented, which results in the inability to fully see
directly from the text. While some tools exist to help visualize relationships between different characters, only the resulting
certain aspects of narratives, they are either very advanced actions of those relationships.
tools that must be adapted to fit the narrative storyline [1], StoryPrint [3] is an interactive visualization for script-based
or they rely almost exclusively on the timeline approach with storylines. StoryPrint utilizes a radial-centered approach, with
no way to represent relationships between different characters rings representing characters, scene delineation, and setting.
and events [2]. This ring method allows the viewer to contextualize the
Thus, our contribution is a web application that allows the frequency of a character’s dialogue and the length of a scene
reader to add different characters, relationships, and events in proportion to the total length of the story. It also facili-
from a narrative into a graph database. The reader can then tates comparative analysis by allowing the viewer to easily
interact with the user-interface to run queries on this data, recognize patterns with characters’ emotions, interactions, and
returning the corresponding nodes and edges in an easy-to- frequency of dialogue. StoryPrint also displays character emo-
read manner. This enables the user to visualize the general tion through color overlays that represent a scale of negative
trajectory of a narrative as whole rather than having to draw experience to positive experience.
conclusions straight from the raw text. While each of these tools and proposals contributes valuable
This paper is organized as follows: Section II presents the features to narrative visualization, they all lack the ability to
state of the art. Section III provides the theoretical framework types of relationships between data. In literature, the relation-
for this tool, and then Section IV describes methodology ships among people, places, and elements are as important as
used in its creation. Finally, Section V presents the resulting the people, places, and elements themselves.
III. T HEORETICAL F RAMEWORK
There are several preexisting concepts and technologies
that contributed to the creation of this web application, as Directed Graph Database
visualized in Fig. 1.
A. Directed Graph
A directed graph has a nonempty set of nodes and a set
of edges that is a subset of the square of the set of nodes
composes composes
[4]. Nodes can be thought of as circles that represent different
entities, and edges can be thought of as the lines that connect
those entities to other entities.
B. Database
Graph Database
A database management system is a collection of connected
data, usually called a database, and a set of programs to
access that data [5]. Databases are widely used by universities,
enterprises, banks, airlines, and many other corporations to
store information and records about finances, accounting,
students, and transactions. data represented in queried through
C. Graph Database
A graph database is a database that emphasizes the relations
between data as much as the data itself [6]. Storage can PyVis Streamlit
be visually represented like that of a directed graph, with
the data being the nodes and the relationships between the
data being edges. This allows the database to better describe
the complexity of connections within a dataset. Neo4j [11]
is the leading native graph database that utilizes Cypher as displayed in displayed in
its query language. Cypher is similar to SQL in relational
databases, but vastly more efficient with easier-to-understand
syntax [7]. Cypher eliminates the need for multiple joins and
view creations that many SQL queries require.
Web Application
D. Streamlit
Streamlit [8] is an open-source Python-based library de-
signed for building data science web apps. Its syntax and
structure allows users to create clean applications with minimal
lines of code. Streamlit is unique in that the front-end is taken Fig. 1. The concept map of technologies and theories that compose the
resulting web application.
care of within the backend, and its data caching speeds-up
computation pipelines.
E. Pyvis IV. M ETHODOLOGY
Pyvis [9] is a Python library project that allows users to To create a web application to visualize literary narrative
build and visualize network graphs. Graphs built with Pyvis data, a proper database management system (DBMS) must
are interactable, allowing hovering and dragging of the nodes be chosen, and then the proper libraries must be selected to
and edges. Pyvis is built around the JavaScript library VisJS. represent the data in the front end. This section outlines the
components of creating this application.
F. Web Application
A web application, otherwise known as a web app, is an A. Choosing a Database Management System
application hosted on a web server and delivered over through A DBMS was needed to store the data that the reader inputs.
the internet through a browser [10]. Unlike other applications, Because the data was to be represented in a graph form, a
web applications do not need to be downloaded because they graph database was chosen. This prevented long and needless
are accessible through a network. There are three parts to SQL queries to be created in order to string together rela-
a web application: a web server, an application server, and tionships between data stored in a relational database. Neo4J
a database. The web servers are responsible for managing [11] the most popular DBMS today, was selected because it
client requests. The application servers complete the task. provided Cypher, a reliable and easy-to-use querying language.
The database stores necessary information needed for the Neo4J’s desktop application also supplied a convenient way to
transaction. check and see that the queries were being properly fulfilled.
B. Choosing Front-end Libraries
The web application utilizes two Python libraries to display
the user interface. Initially, a React frontend with MaterialUI
components was considered, but time and convenience ended
up being the key factor in settling on Python-based libraries
instead of incorporating JavaScript. Because Streamlit [8] is
designed specifically for data science, it is used to allow the
reader to input the data from the narrative and submit it to
the DBMS utilizing the various input methods built in to the
library. Representing the graph database was another aspect
of the frontend. At first, the NetworkX library was considered
for the task, but ultimately Pyvis [9] was chosen due to its
cleaner and more interactive visualizations.
Fig. 3. The resulting graph displays a network of people, places, and things
V. R ESULTS from the story.

The resulting tool is a web application that allows readers


to enter characters, places, and things from a narrative into a orange nodes indicate places, blue nodes indicate people, and
database that is then visualized as an interactive graph. The green nodes indicate things. The edges between the nodes
primary actions that the user can make on the database are relate the elements to each other, and the type of relationship
creating an entity and describing the relationships it has with is displayed when the user hovers the cursor over the edge.
other preexisting entities. The physics of the Pyvis library also allow the user to drag
The data used to demonstrate the functionality of the tool and move the nodes around.
is taken from C.S. Lewis’s The Chronicles of Narnia series,
with all nodes being derived from different people, places, and B. Creating a node
objects throughout the seven books. One of the most important features of this web application
is to create a node, as they represent the people, places, and
A. User Interface
things throughout the story.
In order to create a node, a general, callable create node
method is used whose parameters include the type of node
being created, the name of the node, and a dictionary of
relationships that the node has, as seen in line 184 of Fig.
4. In line 184, a Neo4j session is then started with proper
authentications. Then, a series of conditionals checks to see
what type of node is being created, calling the appropriate
helper methods as needed.

Fig. 2. The input types for the storing of data.


Fig. 4. The callable create node method
Upon opening the application, the user is presented with
several input types in which to enter data about the node After the type-specific helper method is called with the
being created, as shown in Fig. 3. The user selects the type name of the node as a parameter, such as shown in
of element it is, with the choices being ”Character,” ”Place,” create character in Fig. 5, a Cypher query is run to submit
and ”Thing,” and then names the element. The user can also the data into the database. The command MERGE creates a
add an optional description with more information. Next, the new character with a specific name if it does not already exist,
user selects any existing nodes that the element is related to as seen in line 69. Once the node is created in the respective
from a drop-down menu, and then is prompted to specify the helper method, the create node method is returned to and the
type of relationship. Upon submitting the data, the graph is length of the relationships dictionary is checked. If the length
updated with the new node and edges. As seen in Fig. 6, is 0, indicating that the node is unrelated to any other existing
VI. C ONCLUSIONS AND F UTURE W ORK
This paper describes a web application that allows the
a reader to input various characters, places, and elements
from literary narratives. The current prototype has no way
to track the changes in relationships over time. A feature
that allows the user to see how relationships between entities
evolve throughout a literary narrative would be useful in
Fig. 5. The helper method create character that creates a node of type demonstrating plot and character development.
”Character.” Additionally, it is expected to implement a natural language
processor such as the Bidirectional Encoder Representations
nodes, lines 195 and 196 are skipped, and the session is closed. from Transformers (BERT) model would allow the application
If the relationship dictionary contains something, the general to ”read” the narrative and then graph the elements rather
create relationship method is called for each relationship in than have the reader input the information. This could prove
the dictionary. useful to students and members of the literary field who
want to quickly generate a graph representing the relationships
C. Creating a relationship between entities in a piece of literature.
To create a relationship between two nodes, a general R EFERENCES
create relationship method with parameters specifying the two
[1] Text mining and visualization using Vosviewer. VOSviewer. (n.d.).
nodes and the relationship type is utilized, as seen in Fig. 6. Retrieved April 6, 2023, from https://www.vosviewer.com/text-mining-
After starting a new session with proper authentication, the and-visualization-using-vosviewer
helper method create and return relationship is called with [2] Padia, K., Bandara, K. H., & Healey, C. G. (2019). A
system for generating storyline visualizations using Hierarchical
the aforementioned parameters. In this helper method, pictured Task Network Planning. Computers &Graphics, 78, 64–75.
in Fig. 7, the two nodes are created, if they do not already exist, https://doi.org/10.1016/j.cag.2018.11.004
with the MERGE keyword. Then, a unidirectional relationship [3] Watson, K., Sohn, S. S., Schriber, S., Gross, M., Muniz, C.
M., & Kapadia, M. (2019). StoryPrint. Proceedings of the
with the specified relation type is created between the two 24th International Conference on Intelligent User Interfaces.
nodes. The query is attempted, and if it fails, the error is https://doi.org/10.1145/3301275.3302302
excepted and raised. [4] Levasseur, K. (2012). Applied Discrete Structures. Lulu Com.
[5] Silberschatz, A., Korth, H. F., amp; Sudarshan, S. (2020). Database
system concepts. McGraw-Hill Education.
[6] What is a graph database? complete overview. Graphable. (2023, January
31). Retrieved April 6, 2023, from https://www.graphable.ai/blog/what-
is-a-graph-database/
[7] What is cypher? A quick Neo4j Cypher Intro (with examples).
Graphable. (2023, January 31). Retrieved April 6, 2023, from
https://www.graphable.ai/blog/neo4j-cypher-tutorial/
[8] Streamlit • the fastest way to build and share data apps. streamlit. (n.d.).
Retrieved April 6, 2023, from https://streamlit.io/
Fig. 6. The callable create relationship method [9] Interactive network visualizations¶. Interactive network visualizations
- pyvis 0.1.3.1 documentation. (n.d.). Retrieved April 6, 2023, from
https://pyvis.readthedocs.io/en/latest/
[10] Fitzgerald, A. (2021, January 11). What is a web app? A be-
ginner’s guide. HubSpot Blog. Retrieved April 6, 2023, from
https://blog.hubspot.com/website/what-is-web-app
[11] The leader in Graph databases. Neo4j Graph Data Platform. (2022,
November 17). Retrieved April 6, 2023, from https://neo4j.com/

Fig. 7. The helper method create and return relationship method queries
into the database to create a connection between the two nodes.

The resulting web application is useful to members of


the linguistics discipline because it allows them to track
and visualize relationships between different entities within a
piece of literature through graph theory. The resulting network
highlights the most pivotal and interconnected pieces of data
and the ways in which they connect to other elements within
the story.

You might also like