vladukua / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

Defect in Prediction API - need to add access method for mixture and numeric data type #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In the code for 
com.google.api.client.sample.prediction.PredictionSample 

there is a method for Predict (Shown below).  In the API we need a way to set 
the inout type to be mixture and numeric 

Currently you can only do this: 
nputData.input.text.add(text); 

 private static void predict(HttpTransport transport, String text) 
      throws IOException { 
    HttpRequest request = transport.buildPostRequest(); 
    request.url = 
PredictionUrl.forPrediction(ClientLoginCredentials.OBJECT_PATH); 
    JsonCContent content = new JsonCContent(); 
    InputData inputData = new InputData(); 
    inputData.input.text.add(text); 
    content.data = inputData; 
    request.content = content; 
    OutputData outputData = 
request.execute().parseAs(OutputData.class); 
    System.out.println("Text: " + text); 
    System.out.println("Predicted language: " + 
outputData.output.outputLabel); 
  } 

Original issue reported on code.google.com by njun...@gmail.com on 21 Sep 2010 at 9:30

GoogleCodeExporter commented 9 years ago
Thanks for reporting the problem.  Can you try changing the type for Input.text 
as follows and see if it fixes the problem:

  public List<Object> text = new ArrayList<Object>();

Original comment by yan...@google.com on 22 Sep 2010 at 1:46

GoogleCodeExporter commented 9 years ago
 public List<Object> text = new ArrayList<Object>();   Does not work

I get the following : 
{"error":{"errors":[{"domain":"global","reason":"invalid","message":"'data' 
field must contain a JSON object."}],"code":400,"message":"'data' field must 
contain a JSON object."}}

This is what I did:
  List<Object> mix = new ArrayList<Object>();
  mix.add(text);
  content.data = mix;

Note : my problem is not with inputData.input.text.add(text) not working. The 
call is  working. I am not sure how to set the input to be of "mixture" type

Original comment by njun...@gmail.com on 22 Sep 2010 at 2:13

GoogleCodeExporter commented 9 years ago
Just change the "text" field name to "mixture".  It matches the name of the 
JSON key.

Original comment by yan...@google.com on 22 Sep 2010 at 2:33

GoogleCodeExporter commented 9 years ago
I did not get it.

the text field is a class level variable defined in the Java API. I dont have 
an option to set this as mixture anywhere.

In the call - inputData.input.text.add(...) . text is a class level varible . 
Where Do I set it to be mixture.  

Code snippet:
InputData inputData = new InputData(); 
inputData.input.text.add(text); 
content.data = inputData; 
request.content = content; 

Original comment by njun...@gmail.com on 22 Sep 2010 at 4:15

GoogleCodeExporter commented 9 years ago
So , I did what you suggested.

Changed the Input class to be Input  class to be

public class Input {
  @Key
  public List<String> mixture = new ArrayList<String>();
}

and my predict call to be

inputData.input.mixture.add(text);

It did not work.

I get this error.
java.lang.IllegalArgumentException: data key not found
    at com.google.api.client.googleapis.json.JsonCParser.parserForResponse(JsonCParser.java:80)
    at com.google.api.client.googleapis.json.JsonCParser.parse(JsonCParser.java:49)
    at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:280)
    at com.google.api.client.sample.prediction.PredictionSample.predict(PredictionSample.java:120)
    at com.google.api.client.sample.prediction.PredictionSample.main(PredictionSample.java:51)

Original comment by njun...@gmail.com on 1 Oct 2010 at 6:37