Saturday, 15 June 2013

java - Error while executing Google Prediction API Command line Sample -



java - Error while executing Google Prediction API Command line Sample -

i have downloaded sample command line programme prediction api , imported in eclipse mention here .

i have imported sample programme , replaced content of client_secrets.json values of file downloaded api console mentioned in above link .

i have built model using standalone explorer .

but prediction want through java code . below have mentioned code .

package com.google.api.services.samples.prediction.cmdline; import com.google.api.client.auth.oauth2.credential; import com.google.api.client.extensions.java6.auth.oauth2.authorizationcodeinstalledapp; import com.google.api.client.extensions.jetty.auth.oauth2.localserverreceiver; import com.google.api.client.googleapis.auth.oauth2.googleauthorizationcodeflow; import com.google.api.client.googleapis.auth.oauth2.googleclientsecrets; import com.google.api.client.googleapis.javanet.googlenethttptransport; import com.google.api.client.http.httpresponse; import com.google.api.client.http.httpresponseexception; import com.google.api.client.http.httptransport; import com.google.api.client.json.jsonfactory; import com.google.api.client.json.jackson2.jacksonfactory; import com.google.api.client.util.store.datastorefactory; import com.google.api.client.util.store.filedatastorefactory; import com.google.api.services.prediction.prediction; import com.google.api.services.prediction.predictionscopes; import com.google.api.services.prediction.model.input; import com.google.api.services.prediction.model.input.inputinput; import com.google.api.services.prediction.model.output; import com.google.api.services.prediction.model.training; import java.io.ioexception; import java.io.inputstreamreader; import java.util.collections; /** * @author yaniv inbar */ public class predictionsample { /** * sure specify name of application. if application name {@code null} or * blank, application log warning. suggested format "mycompany-productname/1.0". */ private static final string application_name = "senti-model/1.0"; static final string model_id = "senti-model"; //static final string storage_data_location = "enter_bucket/language_id.txt"; /** directory store user credentials. */ private static final java.io.file data_store_dir = new java.io.file(system.getproperty("user.home"), ".store/prediction_sample"); /** * global instance of {@link datastorefactory}. best practice create single * globally shared instance across application. */ private static filedatastorefactory datastorefactory; /** global instance of http transport. */ private static httptransport httptransport; /** global instance of json factory. */ private static final jsonfactory json_factory = jacksonfactory.getdefaultinstance(); /** authorizes installed application access user's protected data. */ private static credential authorize() throws exception { // load client secrets googleclientsecrets clientsecrets = googleclientsecrets.load(json_factory, new inputstreamreader(predictionsample.class.getresourceasstream("/client_secrets.json"))); if (clientsecrets.getdetails().getclientid().startswith("enter") || clientsecrets.getdetails().getclientsecret().startswith("enter ")) { system.out.println( "enter client id , secret https://code.google.com/apis/console/?api=prediction " + "into prediction-cmdline-sample/src/main/resources/client_secrets.json"); system.exit(1); } // set authorization code flow googleauthorizationcodeflow flow = new googleauthorizationcodeflow.builder( httptransport, json_factory, clientsecrets, collections.singleton(predictionscopes.prediction)).setdatastorefactory( datastorefactory).build(); // authorize homecoming new authorizationcodeinstalledapp(flow, new localserverreceiver()).authorize("user"); } private static void run() throws exception { httptransport = googlenethttptransport.newtrustedtransport(); datastorefactory = new filedatastorefactory(data_store_dir); // authorization credential credential = authorize(); prediction prediction = new prediction.builder( httptransport, json_factory, credential).setapplicationname(application_name).build(); //train(prediction); predict(prediction, "is sentence in english?"); predict(prediction, "¿es esta frase en español?"); predict(prediction, "est-ce cette phrase en français?"); } private static void error(string errormessage) { system.err.println(); system.err.println(errormessage); system.exit(1); } private static void predict(prediction prediction, string text) throws ioexception { input input = new input(); inputinput inputinput = new inputinput(); inputinput.setcsvinstance(collections.<object>singletonlist(text)); input.setinput(inputinput); output output = prediction.trainedmodels().predict(model_id, input).execute(); system.out.println("text: " + text); system.out.println("predicted language: " + output.getoutputlabel()); } public static void main(string[] args) { seek { run(); // success! return; } grab (ioexception e) { system.err.println(e.getmessage()); } grab (throwable t) { t.printstacktrace(); } system.exit(1); } }

this error getting while executing code:

jun 24, 2014 2:11:09 pm com.google.api.client.util.store.filedatastorefactory setpermissionstoowneronly warning: unable alter permissions everybody: c:\users\deepesh.shetty\.store\prediction_sample jun 24, 2014 2:11:09 pm com.google.api.client.util.store.filedatastorefactory setpermissionstoowneronly warning: unable alter permissions owner: c:\users\deepesh.shetty\.store\prediction_sample java.lang.nullpointerexception @ com.google.api.client.repackaged.com.google.common.base.preconditions.checknotnull(preconditions.java:191) @ com.google.api.client.util.preconditions.checknotnull(preconditions.java:127) @ com.google.api.client.json.jackson2.jacksonfactory.createjsonparser(jacksonfactory.java:96) @ com.google.api.client.json.jsonobjectparser.parseandclose(jsonobjectparser.java:85) @ com.google.api.client.json.jsonobjectparser.parseandclose(jsonobjectparser.java:81) @ com.google.api.client.auth.oauth2.tokenresponseexception.from(tokenresponseexception.java:88) @ com.google.api.client.auth.oauth2.tokenrequest.executeunparsed(tokenrequest.java:287) @ com.google.api.client.auth.oauth2.tokenrequest.execute(tokenrequest.java:307) @ com.google.api.client.auth.oauth2.credential.executerefreshtoken(credential.java:570) @ com.google.api.client.auth.oauth2.credential.refreshtoken(credential.java:489) @ com.google.api.client.auth.oauth2.credential.intercept(credential.java:217) @ com.google.api.client.http.httprequest.execute(httprequest.java:859) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:410) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.executeunparsed(abstractgoogleclientrequest.java:343) @ com.google.api.client.googleapis.services.abstractgoogleclientrequest.execute(abstractgoogleclientrequest.java:460) @ com.google.api.services.samples.prediction.cmdline.predictionsample.predict(predictionsample.java:157) @ com.google.api.services.samples.prediction.cmdline.predictionsample.run(predictionsample.java:100) @ com.google.api.services.samples.prediction.cmdline.predictionsample.main(predictionsample.java:164)

help me in issue . give thanks .

.../jre/lib/security/java.policy

can seek giving permission below ?

grant{ permission java.security.allpermission; };

java eclipse nullpointerexception google-api google-prediction

No comments:

Post a Comment