text.relatedGroups

Search for groups that are related to the text.
Returns a JSONArray named "related_groups" with result objects.

Request Parameters

collection_idint (required)
Id for the collection where the text is stored.
text_idint (required)
Id for text to find get related contexts to.
group_scopeint (default: all your groups)

The group ids you want the text to be compared against. Can either be a single integer or an array containing many groups e.g. "group_scope":[1,32,54]

waitint (default: 5)
Maximum time you want to wait for a result to be calculated. Maximum wait time is 60 sec. If wait time is zero (0) you will only start the process and disconnect and can check out the result later. An exception will be thrown saying processing request. (See Error Codes)
min_thresholddecimal (default: 0.0)
If you only want results that have higher than 50 % relevance to the source text, provide 0.5 as parameter.
max_thresholddecimal (default: 1.0)
Maximum relevance value you want to have in your result set.
ext_text_idString

Get related groups based on external text id.

limitint (default: 10)

Set max number of results.

Response Parameters

group_idint
The result group id.
relevancedecimal
The relevance value between 0-1.
nameString
Name of the group

Code Examples

JSON

//Request
{
  "method":"text.relatedGroups", 
  "params":{
    "collection_id":607,
    "text_id":1412
  }, 
  "id":0
}

//Response
{ 
 "id":0,
 "result":{
    "related_groups":[
        {
          "group_id":12,
          "name": "Technology",
          "relevance":0.91,
        },
        {
          "group_id":13,
          "name": "Sport",
          "relevance":0.75
        },
        {
          "group_id":64,
          "name": "My personal Interests",
          "relevance":0.23
        }
    ]
}

Java


// You need to have a ready-to-use client to use the other methods
SaploClient client = new SaploClient("YOUR_API_KEY", "YOUR_SECRET_KEY");

// Create a SaploTextManager to work with texts
SaploTextManager textMgr = new SaploTextManager(client);

// Assuming you already have collection the text belongs to and the text ID 
SaploText text = new SaploText();
text.setCollection(collection);
text.setId(textId);

// Find groups that are related to the given text, among your groups
textMgr.relatedGroups(text);

// The related groups can now be retrieved by .getRelatedGroups(); 
// on the text object
// Print the result
for(SaploGroup related : text.getRelatedGroups())
    System.out.println("Related group Id: " + related.getId() 
        + " relevance: " + related.getRelatedRelevance());

PHP


$client = new SaploAPI("YOUR API KEY", "YOUR SECRET KEY");

$params = array(
    "collection_id" => 15,
    "text_id" => 1
);

try {
    $result = $client->text->related_groups($params);
} catch(SaploException $e) {
    echo '(' . $e->getCode() . ') ' . $e->getMessage();
}
  
var_dump($result);

Matlab

params.text_id = 1;
params.collection_id = 2131;
params.wait = 15;

response = saploRequest('text.relatedGroups', params)