Corpus Annotation Graph Builder ( CAG ): An Architectural Framework to Create and Annotate a Multi-source Graph (2023)

Abstract: Graphs are a natural representation of complex data as their structure allows users to discover (often implicit) relations among the nodes intuitively. Applications build graphs in an ad-hoc fashion, usually tailored to specific use cases, limiting their reusability. To account for this, we present the Corpus Annotation Graph (CAG) architectural framework based on a create-and-annotate pattern that enables users to build uniformly structured graphs from diverse data sources and extend them with automatically extracted annotations (e.g., named entities, topics). The resulting graphs can be used for further analyses across multiple downstream tasks (e.g., node classification). Code and resources are publicly available on GitHub, and downloadable via PyPi with the command pip install cag.

## introduction in many areas of knowledge, facts are spread across a multitude of documents in various forms and modalities (e.g., texts, images, sound recordings, videos, and program code). it is of great interest to exploit explicit links between these documents and -even more so -to detect hidden (or implicit) connections -for knowledge extraction through searching, classifying, comparing, and analyzing. the most explicit and efficient data structure for working with such interlinked document collections (corpora) is that of a graph whose nodes represent documents, entities, and annotations with edges representing relations between them. graph databases can naturally manage these for efficient knowledge querying and storage. in particular, property graph databases like neo4j foot_3 and arangodb foot_4 consider nodes as objects with at-tributes and are, therefore, appropriate for holding documents and metadata or more general objects of interest (ooi). oois can vary in scale and can be linked via containment relationships: e.g., a book series contains books, a book contains chapters, a chapter contains text, pictures, etc. one central idea behind our framework is that graphs are not only the object of analysis but also containers for analysis results. more precisely, to unveil hidden connections, we suggest deriving a second type of nodes, which we call annotation nodes associated with the ooi nodes. they represent features extracted from the oois by methods like named entity recognition, topic discovery, sentiment analysis, image captioning, etc. implicit links of oois can then be established via shared annotation nodes (e.g., common topics) that can be used for further analysis. in this way, with every analysis passed, the graph can get richer and possibly more connected. we call the resulting graph a corpus annotation graph. in this demo paper, we present an architectural framework that facilitates the application of the create-and-annotate pattern for creating such a graph: the corpus annotation graph builder (cag). cag is built on top of arangodb and its python drivers. the create-and-annotate pattern consists of two phases (see figure 1 ) that can be repeated multiple times: (1) ooi data can be collected from different sources (e.g., publication databases, online encyclopedias, news feeds, web portals, electronic libraries, repositories, media platforms) and pre-processed to build the core nodes. the component responsible for this phase is the graph-creator. (2) annotations are extracted from the nodes, and corresponding annotation nodes are created and attached to the graph. the component dealing with this phase is the graph-annotator. at any time, new ooi nodes or new annotations can be added, introducing new information to enrich the graph with subsequent runs further. the cag architectural framework aims to offer researchers a flexible but unified way of organizing and maintaining their interlinked document collections in a reproducible way. in the following sections, we go over related work (section 2), then we present the architecture of cag by describing the building blocks of our framework (section 3). last but not least, section 4 exemplifies two applications, one as the backbone technology for searching scientific work and another one describing a knowledge graph construction using cag. ## related work existing research and tools related to graph data structures cover various topics, from database management systems for creating and maintaining graphs, over a formal framework for graph annotations, to task-oriented (e.g., information retrieval, node classification) approaches. as we mentioned in the introduction (section 1), as the foundation of the architectural framework (cag), we use a pattern of creating and annotating graphs. currently, there exist powerful graph databases, such as neo4j and arangodb.they offer a mature engine to build and persist property graphs. we base our architectural framework on arangodb because it allows saving attributes not only in the nodes but also in the edges of a graph. it is a valuable option for incorporating more information if needed. throughout the years, graphs are highly used to solve several downstream tasks, such as developing extended similarity metrics for documents embedded in graphs @xcite , named entity recognition @xcite , measuring the semantic distance between texts @xcite , using a graph-based ranking algorithm @xcite , frame semantic parsing @xcite among many others ( @xcite , @xcite , etc.). all these works demonstrate the importance of graphs and their multipurpose usage, making it essential to develop an architectural framework to create and annotate graphs so they can be (re)used later on for similar or different downstream tasks. regarding graph annotations, lately, @xcite introduced quickgraph, a rapid annotation tool that allows users, via its web interface, to upload corpora and add annotations to it by selecting the annotation type from a predefined list (e.g., named entities). as mentioned above, cag is not a tool but rather a more general programming framework that employs an architectural pattern for the goal of code centralization and reproducibility, giving users the flexibility to select their datasources and annotation types. cag has predefined nodes (e.g., textnode) and edges to encourage the unification of information from different sources, and it allows the addition of any annotation type to its predefined annotations. formerly, @xcite defined 'linguistic annotation' as a descriptive or analytical notation applied to raw language data of any form (e.g., textual, voice). the added notations may include annotations of all sorts (from phonetic features to discourse structures) @xcite , which provides a formal framework for constructing, maintaining, and searching linguistic annotations while remaining consistent with many alternative data structures and formats. they focus on linguistic annotations regardless of the raw data from which they exploit the commonalities between them. our work here adapts the same concept for annotations. our annotation framework extends an existing graph with new node types holding a notation derived from any raw data. @xcite present the annotation graph toolkit, a formal framework to support the development of annotation tools of time series data based on @xcite framework; these tools allow users to annotate a data point manually. the main difference is that cag is an architectural framework, not a toolkit. it allows the incorporation not only of time series data but any data. most importantly, our framework supports automated bulk annotations instead of manual ones. ## the framework in this section, we describe the technical framework of the corpus annotation graph builder (cag). as mentioned in section 1, we create an architectural framework that employs the create-and-annotate pattern, which requires two main building blocks in cag: graph-creator and graph-annotator. as shown in figure 2 , these two blocks are built on top of several other blocks. from the bottom up, cag uses arangodb as a graph database to store graphs, which is accessed via the python library, function name description main component cag.framework.component.py constructor establishes the connection to the database using the config class, creates the graph ontology if it does not exist, or updates it. get_document gets a node or an edge based on a key or set of attributes. upsert_node updates or creates a new node instance. it uses the get_document function to fetch existing nodes. get_edge_attributes gets the edge attributes based on edge type and from and to nodes. upsert_edge update or create a new edge instance. config cag.utils.config.py constructor establishes the connection to the database using the database attributes: database url, username, password, and port. it retries in case of connection failure. configuration re-establishes a new connection and rewrites a previous one. pyarango foot_5 . after that comes the main component block, which creates and updates the graph ontology by manipulating the graph elements. it uses the config block to establish the connection to the database. ## conclusion and future work we presented cag, a publicly available architectural framework aiming to employ unified and reproducible patterns in graph creation and extension via annotations. cag allows users to concentrate on graph ontologies and pipelines while the framework takes the burden of handling repetitive and cumbersome tasks. we further aim to extend our framework to have an analysis component incorporating dynamic data analysis through time and space, exploiting the 'create-and-annotate' graph results.