Link Grammar Dictionary Visualization In Python

In this article, we will implement the visualization code for link grammar dictionary case using available python libraries

Rohan Rathore
3 min readNov 23, 2020

Introduction

Link grammar is a theory of syntax that builds a relationship between a pair of words. The relationship between words is indicated with various link types. For example, in a subject-verb-object language like English, the verb would look left to form a subject link, and right to form an object link. Nouns would look right to complete the subject link or left to complete the object link.

For example, in categorial grammar, the noun phrase “the bad boy” may be written as:

whereas the corresponding disjuncts in link grammar representation would be:

the: D+;
bad: A+;
boy: D- & A-;

The + and — directional indicators correspond to the forward and backward-slashes of the categorical grammar. Finally, the single-letter names A and D can be understood as labels or “easy-to-read” mnemonic names for the rather more verbose types NP/N, etc.

A practical challenge is encountered when we have a link grammar dictionary (collection of link grammar data representation for multiple phrases) that we want to visualize. It enables Computational Linguists, Natural Language Processing scientists, and others to gain conceptual visibility of the dictionary data. More details of graphs visualization for Unsupervised Language Learning including link grammar dictionary can be found here.

Problem Statement Case

We will attempt to visualize the link grammar dictionary case given here using the available Python libraries. This dictionary consists of 5-word clusters (phrases). There is a successful javascript-based implementation for this dictionary case. More details can be found here under ‘View Link Grammar’. Therefore, we will attempt to reach the same using available Python libraries.

Snapshot of link grammar dictionary case

Solution

Our solution will be based on ontology-based visualization where we first transform the link grammar dictionary into ontology data. Then followed by visualizing this generated ontology in a web app.

The Python library used for generating ontology is rdflib.

Name: rdflib
Version: 5.0.0
Summary: RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
Home-page: https://github.com/RDFLib/rdflib
Author: Daniel 'eikeon' Krech
Author-email: eikeon@eikeon.com
License: BSD-3-Clause
Location: /Users/Rohan/opt/anaconda3/lib/python3.7/site-packages
Requires: six, isodate, pyparsing
Required-by: SPARQLWrapper, rdflib-jsonld, ontospy

The python library used for visualizing the ontology is ontospy.

Name: ontospy
Version: 1.9.8.3
Summary: Query, inspect and visualize knowledge models encoded as RDF/OWL ontologies.
Home-page: https://github.com/lambdamusic/ontospy
Author: Michele Pasin
Author-email: michele.pasin@gmail.com
License: MIT
Location: /Users/Rohan/opt/anaconda3/lib/python3.7/site-packages
Requires: rdflib, html5lib, rdflib-jsonld, SPARQLWrapper, click, keepalive, pyfiglet, requests, colorama, pyparsing
Required-by:

The full implementation can be found on GitHub here.

Snapshot of graph visualization of link grammar dictionary case using python libraries

Future work

After the inspection of the visualization results, there are several challenges yet to overcome to reach the desired features when comparing it with javascript based implementation including but not limited to common links across different clusters, desired bubble colors, filters, node radius control, etc.

One potential possible direction would be to augment the ontospy library for the link grammar dictionary visualization use case. Another possible direction would be to develop a new Python library.

References

  1. https://en.wikipedia.org/wiki/Link_grammar
  2. https://blog.singularitynet.io/graphs-part-2-how-graphs-are-used-in-unsupervised-language-learnings-6a853fc25a29
  3. http://langlearn.singularitynet.io/graph.html
  4. https://github.com/aigents/aigents-java-nlp/blob/master/src/test/java/org/aigents/nlp/lg/poc-english_5C_2018-06-06_0004.4.0.dict.txt

--

--

Rohan Rathore

MS Student, Mathematics and Mechanics Faculty, Novosibirsk State University, Russia