You are here

Sample Source Code: ParallelDots Semantic Analysis Followers

The parallelDots Semantic Analysis helps users cluster similar articles by understanding the relatedness between different content and streamlines research by eliminating redundant text contents.

This API can help bloggers, publishing and media houses to write more engaging stories by retrieving similar articles from past quickly, and news aggregators to combine similar news from different sources to reduce clutter in the feeds of their readers.

This code sample is for use with the ParallelDots Semantic Analysis API

from paralleldots.config import get_api_key
import requests
import json

def get_similarity( sentence1, sentence2 ): apikey = get_api_key() if not apikey == None: if type( sentence1 ) != str or type( sentence2 ) != str: return "Input must be a string." elif sentence1 == "" or sentence2 == "": return "Input string cannot be empty." url = "http://apis.paralleldots.com/semanticsimilarity" r = requests.get( url, params={ "apikey": apikey, "sentence1": sentence1, "sentence2": sentence2 } ) if r.status_code != 200: return "Oops something went wrong ! You can raise an issue at https://github.com/ParallelDots/ParallelDots-Python-API/issues." r = json.loads( r.text ) r["usage"] = "By accessing ParallelDots API or using information generated by ParallelDots API, you are agreeing to be bound by the ParallelDots API Terms of Use: http://www.paralleldots.com/terms-and-conditions" return r else: return "API key does not exist"