Skip to main content

A library for finding the link between two wikipedia pages.

Project description

Wiki Wormhole

Description

This python library leverages graphs and artificial intelligence to find the path from a start wikipedia page to a destination wikipedia page.

Installation

Install wikiwormhole through pip package manager.

pip install wikiwormhole

Then run the setup script to accomplish the following:

  • Generate config.yaml script for the pageviews api (How many pageviews does a wikipedia page have).
  • Download pre-trained Word2Vec model using Gensim.
  • Download corpus of stop words (insignificant words) to help embed titles using natural language toolkit (NLTK).
python <venv-name>/bin/setup_wormhole.py <config-path> <download-path>

Here config path is where the new config-yaml will be created. The download path is where the Word2Vec model weights and NLTK corpus will be downloaded on your system.

The final step in installation is providing a personal website and email in the config.yaml file. Once filled you'll be able to use the pageviews API.

Algorithm

The algorithm is split into two parts: popular and similar traversal.

Popular Traversal is an algorithm that attempts to find a more popular page connected to the original page. In the small-world phenomenon it's observed its much easier to connect two separate "hubs" rather than two obscure nodes. The purpose of this algorithm is to find those popular hubs.

Similar Traversal is an algorithm that attempts to find the path of pages from the starting page to the destination page. The algorithm assumes that titles with similar words will be closer to each other in the graph than the contrary. This similarity calculation is powered by the infamous word embedder Word2Vec. The word embedder calculates the words position in a latent space and the similarity is then calculated for two separate words using a cosine similarity metric (emphasis on directional alignment rather than distance).

Sample Usage

.. code-block:: python from wikiwormhole.traverse.popular import PopularTraverse from wikiwormhole.traverse.similar import SimilarTraverse from wikiwormhole.title2vec import Title2Vec from tqdm import tqdm

data_dir = './data'
config_path = './config.yaml'

start_title = 'Apple'
end_title= 'Cadillac'

pop_rounds = 5

pop_start = PopularTraverse(start_title, config_path)
pop_end = PopularTraverse(end_title, config_path)

for _ in tqdm(range(pop_rounds)):
    pop_start.traverse()
    pop_end.traverse()

path_start = pop_start.most_popular_pathway()
path_end = pop_end.most_popular_pathway()
print("START: ", path_start)
print("END: ", path_end)

t2v = Title2Vec(data_dir)
sim_start, sim_end = path_start[-1], path_end[-1]
sim_trav = SimilarTraverse(sim_start, sim_end, t2v)

while not sim_trav.target_reached():
    sim_trav.traverse()

path_cnx = sim_trav.path_to_target()
print("RESULT: ", path_start[:-1] + path_cnx + path_end[:-1][::-1])

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

wikiwormhole-0.0.2.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

wikiwormhole-0.0.2-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wikiwormhole-0.0.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for wikiwormhole-0.0.2.tar.gz
Algorithm Hash digest
SHA256 161150aef9a79a727a102815abc6364e3cc153c23d037ebbafc6319725dcee89
MD5 92e5105be4c883a1cf611459c46bdabb
BLAKE2b-256 fb276fab4c296298953f569760ed927602fcdf91fc72c7d7d389c05033b318fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wikiwormhole-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for wikiwormhole-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5acab9d5632fe6514aa091dc161c3b1d839c5e6290dc90729bd9daa6870a4eb1
MD5 be798c94749d61a01a89f1727603c5f6
BLAKE2b-256 4b0cc3cba4df385886733a57512bf94fb8c7438233bcc07fdf8c7026ade27459

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page