Political Analysis

political.predict(data, [params])
Gauge the political leanings of a phrase or document.

Current Version: 2

Arguments

data – String | List – required – text to be analyzed
[api_key] – String – optional – your indico API key
[cloud] – String – optional – your private cloud subdomain
[v or version] – Integer – optional (defaults to 2) – specify model version, versions 1 and 2 are available
[top_n] – Integer – optional (defaults to 3) – only return this many of the most likely topics
[threshold] – Float – optional (defaults to .0) – only return topics with likelihood greater than this number

Output

This function will return a dictionary with 4 key-value pairs. These key-value pairs represent the likelihood that each of 4 political leanings are expressed in the analyzed text. The keys in the dictionary are strings containing the political leanings and the values are the probabilities that the analyzed text is expressing each political view.

Values less than 0.05 indicate that it is very unlikely the text is expressing that particular political leaning.

  # single output
  {
      'libertarian': 0.27192999211817354,
      'green': 0.06525078204908323,
      'liberal': 0.11033990553871972,
      'conservative': 0.5524793202940235
  }

  # batch output
  [
      {
          'libertarian': 0.27192999211817354,
          'green': 0.06525078204908323,
          'liberal': 0.11033990553871972,
          'conservative': 0.5524793202940235
      },
      {
          'libertarian': 0.02334343866477883,
          'green': 0.03302544570586526,
          'liberal': 0.9254000702504355,
          'conservative': 0.01823104537892042
      }
  ]

Example

  import io.indico.Indico;
  import io.indico.api.IndicoResult;
  import io.indico.api.text.PoliticalClass;
  import io.indico.api.BatchIndicoResult;
  import java.util.HashMap;

  Map params = new HashMap();
  params.put("threshold", 0.25)

  // single example
  Indico indico = new Indico("YOUR_API_KEY");
  IndicoResult single = indico.political.predict(
      "I have a constitutional right to bear arms!", params
  );
  Map result = single.getPolitical();
  System.out.println(result);

  // batch example
  String[] example = {
      "I have a constitutional right to bear arms!",
      "I wish more candidates cared about the environment."
  };
  BatchIndicoResult multiple = indico.political.predict(example, params);
  List> results = multiple.getPolitical();
  System.out.println(results);