Skip to content

frankier/babelnet-lookup

 
 

Repository files navigation

A simple BabelNet web service for user and non-Java programs.

Obtaining BABEL2WN_MAP

I am not distributing BABEL2WN_MAP, since it is not clear whether I have permission to do so. You will need a BabelNet 4.0.1 dump and the Java code for the BabelNet 4.0.1 API. Download the latter, unzip it in the parent directory of wherever you have cloned this repository. Change ../BabelNet-API-4.0.1/config/babelnet.var.properties so that it points to your BabelNet dump. You can now run::

$ ./gen.sh -wnm > babelwnmap.tsv

You will then need to manually edit this file to delete some extra junk from the beginning.

Build

Install BabelNet API

  1. Change directory into BabelNet-API-4.0.1
  2. Compile: ant -f build.xml
  3. Install into local Maven repository:

mvn install:install-file -Dfile=babelnet-api-4.0.1.jar -DgroupId=it.uniroma1.lcl -DartifactId=babelnet -Dversion=4.0.1 -Dpackaging=jar -DgeneratePom=true

mvn install:install-file -Dfile=lib/babelscape-data-commons-1.0.jar -DgroupId=com.babelscape -DartifactId=commons -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true

  1. Make sure that the babelnet.dir property in config/babelnet.var.properties point to the directory where BabelNet data lives.

Build babelnet-lookup

  1. Change directory into babelnet-lookup
  2. Run mvn clean package
  3. You're ready!

Usage

Start

Run run.sh to start the server. By default it will listen to port 9000.

The script assumes that BabelNet jar and libraries are in a directory named BabelNet-API-4.0.1 in the same directory as babelnet-lookup. If your installation is different, you need to change it accordingly.

Stop

Press Ctrl+C to terminate the server.

Query using a web browser (or curl)

Query using Python

Text:

import urllib
url = "http://%s:%d/text/%s/%s/%s" %(host, port, lang, query, pos)
f = urllib.urlopen(url)
if f.getcode() == 200:
    synsets = f.read().strip().split("\n")

WordNet:

import urllib
url = "http://%s:%d/wordnet/%s" %(host, port, offset)
f = urllib.urlopen(url)
if f.getcode() == 200:
    synsets = f.read().strip().split("\n")

Wikipedia

url = "http://%s:%d/wikipedia/%s/n" %(host, port, offset)
f = urllib.urlopen(url)
if f.getcode() == 200:
	synsets = f.read().strip().split("\n")

Related synsets

url = "http://%s:%d/synset/%s/related" %(host, port, offset)
f = urllib.urlopen(url)
if f.getcode() == 200:
    lines = f.read().strip().split("\n")
    lines = [line.split('\t') for line in lines]
    related_synsets = [{'relation': fields[0], 'synset': fields[1]}
                for fields in lines] 

Senses

url = "http://%s:%d/synset/%s/senses/en" %(host, port, offset)
f = urllib.urlopen(url)
if f.getcode() == 200:
    lines = f.read().strip().split("\n")
    lines = [line.split('\t') for line in lines]
    senses = [{'lemma': fields[0], 'pos': fields[1], 'language': fields[2], 'source': fields[3]}
                for fields in lines] 

DBpedia URI

url = "http://%s:%d/synset/%s/dbpedia_uri/en" %(host, port, offset)
f = urllib.urlopen(url)
if f.getcode() == 200:
    uris = f.read().strip().split("\n")

Notice: urllib doesn't support with ... as ... construction.

About

A basic web service for BabelNet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 97.6%
  • Shell 2.4%