List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:org.codelibs.fess.es.config.exentity.DataConfig.java
public void setBoostValue(final String value) { if (value != null) { try {/*w w w . ja v a 2s .co m*/ boost = Float.parseFloat(value); } catch (final Exception e) { } } }
From source file:io.anserini.embeddings.IndexW2V.java
public void indexEmbeddings() throws IOException, InterruptedException { LOG.info("Starting indexer..."); long startTime = System.currentTimeMillis(); final WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(); final IndexWriterConfig config = new IndexWriterConfig(analyzer); final IndexWriter writer = new IndexWriter(directory, config); BufferedReader bRdr = new BufferedReader(new FileReader(args.input)); String line = null;/* w w w . j a v a 2 s .c o m*/ bRdr.readLine(); Document document = new Document(); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); int cnt = 0; while ((line = bRdr.readLine()) != null) { String[] termEmbedding = line.trim().split("\t"); document.add(new StringField(LuceneDocumentGenerator.FIELD_ID, termEmbedding[0], Field.Store.NO)); String[] parts = termEmbedding[1].split(" "); for (int i = 0; i < parts.length; ++i) { byteStream.write(ByteBuffer.allocate(4).putFloat(Float.parseFloat(parts[i])).array()); } document.add(new StoredField(FIELD_BODY, byteStream.toByteArray())); byteStream.flush(); byteStream.reset(); writer.addDocument(document); document.clear(); cnt++; if (cnt % 100000 == 0) { LOG.info(cnt + " terms indexed"); } } LOG.info(String.format("Total of %s terms added", cnt)); try { writer.commit(); writer.forceMerge(1); } finally { try { writer.close(); } catch (IOException e) { LOG.error(e); } } LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms"); }
From source file:hivemall.classifier.multiclass.MulticlassSoftConfidenceWeightedUDTF.java
@Override protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException { final CommandLine cl = super.processOptions(argOIs); float phi = 1.f; float c = 1.f; if (cl != null) { String phi_str = cl.getOptionValue("phi"); if (phi_str == null) { String eta_str = cl.getOptionValue("eta"); if (eta_str != null) { double eta = Double.parseDouble(eta_str); if (eta <= 0.5 || eta > 1) { throw new UDFArgumentException( "Confidence hyperparameter eta must be in range (0.5, 1]: " + eta_str); }// ww w. ja va 2s . com phi = (float) StatsUtils.probit(eta, 5d); } } else { phi = Float.parseFloat(phi_str); } String c_str = cl.getOptionValue("c"); if (c_str != null) { c = Float.parseFloat(c_str); if (!(c > 0.f)) { throw new UDFArgumentException("Aggressiveness parameter C must be C > 0: " + c); } } } this.phi = phi; this.c = c; return cl; }
From source file:keel.Algorithms.Genetic_Rule_Learning.PART.C45.java
/** Constructor. * * @param paramFile The parameters file. * * @throws Exception If the algorithm cannot be executed. *//* ww w . j a va 2s . c om*/ public C45(parseParameters paramFile) throws Exception { try { // starts the time long startTime = System.currentTimeMillis(); /* Sets the options of the execution from text file*/ //StreamTokenizer tokenizer = new StreamTokenizer( new BufferedReader( new FileReader( paramFile ) ) ); //initTokenizer( tokenizer) ; //setOptions( tokenizer ); //File Names modelFileName = paramFile.getTrainingInputFile(); trainFileName = paramFile.getValidationInputFile(); testFileName = paramFile.getTestInputFile(); //Options prune = Boolean.valueOf(paramFile.getParameter(1)).booleanValue(); //wether the tree must be pruned or not confidence = Float.parseFloat(paramFile.getParameter(2)); //confidence level for the uniform distribution minItemsets = Integer.parseInt(paramFile.getParameter(3)); //itemset per Leaf if (confidence < 0 || confidence > 1) { confidence = 0.25F; System.err.println("Error: Confidence must be in the interval [0,1]"); System.err.println("Using default value: 0.25"); } if (minItemsets <= 0) { minItemsets = 2; System.err.println("Error: itemsetPerLeaf must be greater than 0"); System.err.println("Using default value: 2"); } /* Sets the options from XML file */ /** para commons.configuration XMLConfiguration config = new XMLConfiguration(paramFile); setOptions( config ); */ /* Initializes the dataset. */ modelDataset = new MyDataset(modelFileName, true); trainDataset = new MyDataset(trainFileName, false); testDataset = new MyDataset(testFileName, false); priorsProbabilities = new double[modelDataset.numClasses()]; priorsProbabilities(); marginCounts = new double[marginResolution + 1]; // generate the tree generateTree(modelDataset); //printTrain(); //printTest(); //printResult(); } catch (Exception e) { System.err.println(e.getMessage()); System.exit(-1); } }
From source file:com.jaeksoft.searchlib.analysis.ClassFactory.java
protected float getFloatProperty(ClassPropertyEnum prop) { String value = getProperty(prop).getValue(); if (value == null) return 1.0F; return Float.parseFloat(value); }
From source file:it.readbeyond.minstrel.media.AudioHandler.java
/** * Executes the request and returns PluginResult. * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return A PluginResult object with a status and message. *///w w w .ja v a2 s.c om public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { CordovaResourceApi resourceApi = webView.getResourceApi(); PluginResult.Status status = PluginResult.Status.OK; String result = ""; if (action.equals("startPlayingAudio")) { String target = args.getString(1); String fileUriStr; try { Uri targetUri = resourceApi.remapUri(Uri.parse(target)); fileUriStr = targetUri.toString(); } catch (IllegalArgumentException e) { fileUriStr = target; } this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr)); } else if (action.equals("seekToAudio")) { this.seekToAudio(args.getString(0), args.getInt(1)); } else if (action.equals("pausePlayingAudio")) { this.pausePlayingAudio(args.getString(0)); } else if (action.equals("stopPlayingAudio")) { this.stopPlayingAudio(args.getString(0)); } else if (action.equals("setVolume")) { try { this.setVolume(args.getString(0), Float.parseFloat(args.getString(1))); } catch (NumberFormatException nfe) { //no-op } } else if (action.equals("getCurrentPositionAudio")) { float f = this.getCurrentPositionAudio(args.getString(0)); callbackContext.sendPluginResult(new PluginResult(status, f)); return true; } else if (action.equals("getDurationAudio")) { float f = this.getDurationAudio(args.getString(0), args.getString(1)); callbackContext.sendPluginResult(new PluginResult(status, f)); return true; } else if (action.equals("create")) { String id = args.getString(0); String src = FileHelper.stripFileProtocol(args.getString(1)); getOrCreatePlayer(id, src); } else if (action.equals("release")) { boolean b = this.release(args.getString(0)); callbackContext.sendPluginResult(new PluginResult(status, b)); return true; } else if (action.equals("messageChannel")) { messageChannel = callbackContext; return true; } else { // Unrecognized action. return false; } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:com.joliciel.csvLearner.features.NormalisationLimitReader.java
private void readCSVFile(InputStream csvInputStream, Map<String, Float> featureToMaxMap) { Scanner scanner = new Scanner(csvInputStream, "UTF-8"); try {//w w w. ja va2 s . c om boolean firstLine = true; while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (!firstLine) { List<String> cells = CSVFormatter.getCSVCells(line); String featureName = cells.get(0); float maxValue = Float.parseFloat(cells.get(1)); featureToMaxMap.put(featureName, maxValue); } firstLine = false; } } finally { scanner.close(); } }
From source file:net.loyin.jfinal.TypeConverter.java
/** * test for all types of mysql/* www . j a v a 2 s. com*/ * * ???: * 1: ?,?,? "", ??? null. * 2: ??? * 3: ? model string,? "" ? null??, * , null, ? "" * * ?: 1:clazz??String.class, ?sblank, * ? null, ? * 2:???? null ?? ModelInjector */ public static final Object convert(Class<?> clazz, String s) throws ParseException { // mysql type: varchar, char, enum, set, text, tinytext, mediumtext, longtext if (clazz == String.class) { return (StringUtils.isEmpty(s) ? null : s); // ???? "", ,?? null. } s = s.trim(); if (StringUtils.isEmpty(s)) { // ?? String?,? null, ?? return null; } // ??,, ?, ??null s ?(????null, ?"") Object result = null; // mysql type: int, integer, tinyint(n) n > 1, smallint, mediumint if (clazz == Integer.class || clazz == int.class) { result = Integer.parseInt(s); } // mysql type: bigint else if (clazz == Long.class || clazz == long.class) { result = Long.parseLong(s); } // ?java.util.Data?, java.sql.Date, java.sql.Time,java.sql.Timestamp java.util.Data, getDate?? else if (clazz == java.util.Date.class) { if (s.length() >= timeStampLen) { // if (x < timeStampLen) datePattern ? // Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff] // result = new java.util.Date(java.sql.Timestamp.valueOf(s).getTime()); // error under jdk 64bit(maybe) result = new SimpleDateFormat(timeStampPattern).parse(s); } else { // result = new java.util.Date(java.sql.Date.valueOf(s).getTime()); // error under jdk 64bit result = new SimpleDateFormat(datePattern).parse(s); } } // mysql type: date, year else if (clazz == java.sql.Date.class) { if (s.length() >= timeStampLen) { // if (x < timeStampLen) datePattern ? // result = new java.sql.Date(java.sql.Timestamp.valueOf(s).getTime()); // error under jdk 64bit(maybe) result = new java.sql.Date(new SimpleDateFormat(timeStampPattern).parse(s).getTime()); } else { // result = new java.sql.Date(java.sql.Date.valueOf(s).getTime()); // error under jdk 64bit result = new java.sql.Date(new SimpleDateFormat(datePattern).parse(s).getTime()); } } // mysql type: time else if (clazz == java.sql.Time.class) { result = java.sql.Time.valueOf(s); } // mysql type: timestamp, datetime else if (clazz == java.sql.Timestamp.class) { result = java.sql.Timestamp.valueOf(s); } // mysql type: real, double else if (clazz == Double.class) { result = Double.parseDouble(s); } // mysql type: float else if (clazz == Float.class) { result = Float.parseFloat(s); } // mysql type: bit, tinyint(1) else if (clazz == Boolean.class) { result = Boolean.parseBoolean(s) || "1".equals(s); } // mysql type: decimal, numeric else if (clazz == java.math.BigDecimal.class) { result = new java.math.BigDecimal(s); } // mysql type: unsigned bigint else if (clazz == java.math.BigInteger.class) { result = new java.math.BigInteger(s); } // mysql type: binary, varbinary, tinyblob, blob, mediumblob, longblob. I have not finished the test. else if (clazz == byte[].class) { result = s.getBytes(); } else { throw new RuntimeException( clazz.getName() + " can not be converted, please use other type of attributes in your model!"); } return result; }
From source file:free.rm.skytube.gui.businessobjects.UpdatesChecker.java
/** * Extracts from json the latest APP's version. * * @param json/*from w w w. j a v a 2s.c o m*/ * @return * @throws Exception */ private float getLatestVersionNumber(JSONObject json) throws Exception { String versionNumberStr = json.getString("tag_name").substring(1); // tag_name = "v2.0" --> so we are going to delete the 'v' character return Float.parseFloat(versionNumberStr); }
From source file:io.druid.benchmark.datagen.BenchmarkColumnValueGenerator.java
private Object convertType(Object input, ValueType type) { if (input == null) { return null; }// w w w. java 2 s .com Object ret; switch (type) { case STRING: ret = input.toString(); break; case LONG: if (input instanceof Number) { ret = ((Number) input).longValue(); } else { ret = Long.parseLong(input.toString()); } break; case FLOAT: if (input instanceof Number) { ret = ((Number) input).floatValue(); } else { ret = Float.parseFloat(input.toString()); } break; default: throw new UnsupportedOperationException("Unknown data type: " + type); } return ret; }