We have a simple Web API that can be used to query the UMBC Semantic Similarity service. Given two words or phrases it returns a string representing a number between 0.0 and 1.0. Call it using a a URL like the following
Where XXX and YYY are the urlencoded words or short noun or verb phrases you want to compare. For example, to compare the words car and bike with the URL.
You can also specify part of speech tag to your terms by appending them with _NN (noun), _VB (verb), _JJ (adj) or _RB (adv), as in the following examples.
http://swoogle.umbc.edu/SimService/GetSimilarity?operation=api&phrase1=fire_VB&phrase2=dismiss_VB
http://swoogle.umbc.edu/SimService/GetSimilarity?operation=api&phrase1=fire_NN&phrase2=dismiss_VB
The API supports two additional optional parameters: corpus and type which allow you to choose which corpus (e.g., webbase or gigawords) and which type of semantic similarity to use (e.g., concept or relation), as in the following example.
To compare Semantic Textual Similarity (STS) between two strings "A small violin is being played by a girl" and "a child is performing on a tiny instrument", you can use the following URL (note that the service name is different from the api above)
You can call the service easily from a program. Here's an example showing how to do it in Python.
from requests import get
sss_url = "http://swoogle.umbc.edu/SimService/GetSimilarity"
def sss(s1, s2, type='relation', corpus='webbase'):
try:
response = get(sss_url, params={'operation':'api','phrase1':s1,'phrase2':s2,'type':type,'corpus':corpus})
return float(response.text.strip())
except:
print 'Error in getting similarity for %s: %s' % ((s1,s2), response)
return 0.0
If you use this service in your research, we would appreciate citing it using the following paper, which descibes the approach behind the service.