Skip to main content

pywikigraph

pywikigraph helps you determine the relationship between any two wikipedia articles, bold or italic terms. It tells you how closely they are connected to other (degree of separation) and also the exact shortest paths between them. You have the option to specify whether you want to use a directed graph or an undirected graph.

To learn more about this project and/or its use cases, please take a look at this blog.

How to install the package:

pip install pywikigraph

How to get the data:

This package requires two data files to work. These files take about 1.68 GB on disk and about 8.1 GB in memory. They will be lazily downloaded from s3 to your machine and loaded into memory on your first call to get shortest paths.

The two files are linked below:

Note that if you do not specify a data path, the data files will be downloaded to ~/.pywikigraph.

How to use the package:

>>> from pywikigraph import WikiGraph
>>> wg = WikiGraph()

Note that by default, the data will be downloaded from s3 and loaded to memory from ~/.pywikigraph folder on your machine, but you can override this path via the data_root parameter at initialization. The instantiation will always be instant as the data download and load-to-memory are done lazily. This means that your first ever call to get shortest paths will take several minutes to download the files and load them into memory. Also, since the files are relatively large (1.68 GB on disk and 8.1 GB in memory), your first call to a newly instantiated WikiGraph object will always take some time to load the files from disk to memory (about 70 seconds on a MacBook Pro with 2.6Ghz CPU and 16 GB RAM). All subsequent calls should be extremely fast though.

To find the degree of separation and the shortest paths between two inputs - Backpropagation and Data Science:

>>> paths = wg.get_shortest_paths_info('Backpropagation', 'Data Science')
>>> paths
(2, 1, [['backpropagation', 'machine learning', 'data science']])
  • First element of tuple indicates degree of separation
  • Second element of tuple indicates number of shortest paths
  • Third element of tuple is a list of exact paths

Again, be prepared for your first ever call to take several minutes to download the data files and load them into memory. If the files are already downloaded, the first call would still take upwards of a minute on most machines to load them into memory. All subsequent calls will be lightning fast though.

If you only care about the number of paths, then you can pass argument no_paths and the resulting tuple will just have a None for the paths element.

>>> paths_info = wg.get_shortest_paths_info('Backpropagation', 'Data Science', no_paths=True)
>>> paths_info
(2, 1, None)

If you don't care about directionality of the connections, then you can use set directed argument to False:

>>> paths_info = wg.get_shortest_paths_info('Backpropagation', 'Data Science', directed=False)
>>> paths_info
(2,
 5,
 [['backpropagation', 'deep learning', 'data science'],
  ['backpropagation', 'dimensionality reduction', 'data science'],
  ['backpropagation', 'glossary of artificial intelligence', 'data science'],
  ['backpropagation', 'machine learning', 'data science'],
  ['backpropagation', 'tensorflow', 'data science']])

Release files for pywikigraph 0.0.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 pywikigraph 0.0.2
File Size Uploaded
pywikigraph-0.0.2.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pywikigraph 0.0.2
File Interpreter ABI Platform
pywikigraph-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.0 kB

Release files / pywikigraph-0.0.2.tar.gz

Download URL pywikigraph-0.0.2.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7ab86e2d8fae34efc088c72b20546f8c458b020078e05b22fa05bd084f623328
BLAKE2b-256 checksum
How to use checksums
7caa4a6605d0f7b535f6ff83d37e65f1ee3da95c1d2bad744a5418aa23d5b627
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

Release files / pywikigraph-0.0.2-py3-none-any.whl

Download URL pywikigraph-0.0.2-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e0852f42240e884af02acd8bd851703d45b95153ca00ba37965c15b0176bb18
BLAKE2b-256 checksum
How to use checksums
99714568d9649e443607452c8a87283bbee7aa8aad0ea45dc12a4a3001faedc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

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