Skip to main content

Find connection between any two wikipedia topics

Project description

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']])

Project details


Download files

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

Source Distribution

pywikigraph-0.0.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

pywikigraph-0.0.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file pywikigraph-0.0.2.tar.gz.

File metadata

  • Download URL: pywikigraph-0.0.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pywikigraph-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7ab86e2d8fae34efc088c72b20546f8c458b020078e05b22fa05bd084f623328
MD5 1edf80087abad2e80290526bf7b004c9
BLAKE2b-256 7caa4a6605d0f7b535f6ff83d37e65f1ee3da95c1d2bad744a5418aa23d5b627

See more details on using hashes here.

File details

Details for the file pywikigraph-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pywikigraph-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pywikigraph-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e0852f42240e884af02acd8bd851703d45b95153ca00ba37965c15b0176bb18
MD5 12c07f75d7953dbda029bc9bbbffedaf
BLAKE2b-256 99714568d9649e443607452c8a87283bbee7aa8aad0ea45dc12a4a3001faedc9

See more details on using hashes here.

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