fastcat is a little Python library for quickly looking up broader/narrower relations in Wikipedia categories locally. The idea is that fastcat can be useful in situations where you need to rapidly lookup category relations, but don't want to hammer on the Wikipedia API. fastcat relies on Redis, and a SKOS file that DBpedia make available based on the Wikipedia MySQL dumps.
The original author of fastcat is Ed Summers, and here Takuya Kitazawa directly modifies the code on this forked repository. The main difference with the original version is that, Japanese is supported in addition to English, and you can install fastcat via pip
. Note that the modified version of fastcat only supports Python 3, while the original code was written in Python 2.
You first need to setup Redis server on your machine as follows.
On Mac:
$ brew install redis
On Linux:
$ apt-get install redis-server
Eventually, installing fastcat itself is straightforward:
$ pip install git+https://github.com/takuti/fastcat.git
First and foremost, you should not forget to launch a local Redis server as:
$ redis-server
Next, the first time you import fastcat you'll need to populate your Redis database
with the category data from DBpedia. To do that instantiate a FastCatLoader
object
and call the load
method. After that you can use it to do lookups.
>>> from fastcat import FastCatLoader, FastCat
>>> f = FastCat()
>>> # English
>>> FastCatLoader(lang='en').load()
...
>>> f.narrower('Functional programming')
['Lambda calculus', 'Functional data structures', 'Dependently typed programming', 'Higher-order functions', 'Implementation of functional programming languages', 'Recursion schemes', 'Combinatory logic', 'Functional languages']
>>> f.broader('Computer programming')
['Computing', 'Software engineering']
>>> # Japanese
>>> FastCatLoader(lang='ja').load()
...
>>> f.narrower( 関数型プログラミング')
['高階関数', '関数型言語']
>>> f.broader('プログラミング')
['コンピュータ', '計算機科学', 'ソフトウェア工学']