List of usage examples for java.lang Float floatValue
@HotSpotIntrinsicCandidate public float floatValue()
From source file:hivemall.topicmodel.OnlineLDAModel.java
private void preprocessMiniBatch(@Nonnull final String[][] miniBatch) { initMiniBatch(miniBatch, _miniBatchDocs); this._miniBatchSize = _miniBatchDocs.size(); // accumulate the number of words for each documents double valueSum = 0.d; for (int d = 0; d < _miniBatchSize; d++) { for (Float n : _miniBatchDocs.get(d).values()) { valueSum += n.floatValue(); }/*from w w w .j a va 2s . c o m*/ } this._valueSum = valueSum; this._docRatio = (float) ((double) _D / _miniBatchSize); }
From source file:org.las.tools.LanguageIdentifier.LanguageIdentifier.java
/** * Identify language of a content.//from w ww . j a v a2 s .c o m * * @param content is the content to analyze. * @return The 2 letter * <a href="http://www.w3.org/WAI/ER/IG/ert/iso639.htm">ISO 639 * language code</a> (en, fi, sv, ...) of the language that best * matches the specified content. */ public String identify(StringBuilder content) { // Identify is Latin or not if (!isLatinCharacter(content.toString())) { return "not-latin"; } StringBuilder text = content; if ((analyzeLength > 0) && (content.length() > analyzeLength)) { text = new StringBuilder().append(content); text.setLength(analyzeLength); } suspect.analyze(text); Iterator<NGramEntry> iter = suspect.getSorted().iterator(); float topscore = Float.MIN_VALUE; String lang = ""; HashMap<NGramProfile, Float> scores = new HashMap<NGramProfile, Float>(); NGramEntry searched = null; while (iter.hasNext()) { searched = iter.next(); NGramEntry[] ngrams = ngramsIdx.get(searched.getSeq()); if (ngrams != null) { for (int j = 0; j < ngrams.length; j++) { NGramProfile profile = ngrams[j].getProfile(); Float pScore = scores.get(profile); if (pScore == null) { pScore = new Float(0); } float plScore = pScore.floatValue(); plScore += ngrams[j].getFrequency() + searched.getFrequency(); scores.put(profile, new Float(plScore)); if (plScore > topscore) { topscore = plScore; lang = profile.getName(); } } } } return lang; }
From source file:it.uniroma2.sag.kelp.data.representation.vector.SparseVector.java
@Override public void setDataFromText(String representationDescription) throws IOException { String[] feats = representationDescription.trim().split(FEATURE_SEPARATOR); if (feats[0].equals("")) { return;/*from www . j a v a2 s. co m*/ } String dimTmp = null; String valueTmp = null; float value; for (String feature : feats) { int separatorIndex = feature.lastIndexOf(NAME_VALUE_SEPARATOR); if (separatorIndex <= 0) { throw new IOException( "Parsing error in SparseVector.init function: formatting error in the feat-value pair " + feature); } dimTmp = feature.substring(0, separatorIndex); valueTmp = feature.substring(separatorIndex + 1); Float val = Float.parseFloat(valueTmp); if (val.isNaN()) { logger.warn("NaN value in representation: " + representationDescription); } value = val.floatValue(); this.setFeatureValue(dimTmp, value); } }
From source file:org.opencms.search.solr.CmsSolrDocument.java
/** * @see org.opencms.search.I_CmsSearchDocument#getScore() *///from w ww .j a v a 2 s.co m public float getScore() { Float score = (Float) getSolrDocument().getFirstValue(CmsSearchField.FIELD_SCORE); if (score != null) { m_score = score.floatValue(); return m_score; } return 0F; }
From source file:jcalccalculator.TaskClient.java
public boolean cmdOperation(Request rq) throws ComputeEngineException { Response rs = new Response(); Operation op = (Operation) rq.getData().get(0); if (op.getType().compareTo("x+y") == 0) { Float[] numeros = new Float[op.getInputData().size()]; for (int i = 0; i < numeros.length; i++) { numeros[i] = (Float) op.getInputData().get(i).value; }//from ww w .j a v a2 s .c o m float[] datos = ArrayUtils.toPrimitive(numeros); Double res = new Double(fengine.sumar(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("x-y") == 0) { Float[] numeros = new Float[op.getInputData().size()]; for (int i = 0; i < numeros.length; i++) { numeros[i] = (Float) op.getInputData().get(i).value; } float[] datos = ArrayUtils.toPrimitive(numeros); Double res = new Double(fengine.restar(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("media") == 0) { Float[] numeros = (Float[]) op.getInputData().get(0).value; float[] datos = ArrayUtils.toPrimitive(numeros); Double res = new Double(fengine.media(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("varianza") == 0) { Float[] numeros = (Float[]) op.getInputData().get(0).value; float[] datos = ArrayUtils.toPrimitive(numeros); Double res = new Double(fengine.varianza(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("desviacion") == 0) { Float[] numeros = (Float[]) op.getInputData().get(0).value; float[] datos = ArrayUtils.toPrimitive(numeros); Double res = null; try { res = new Double(fengine.desviacion(datos)); } catch (ComputeEngineException ex) { Logger.getLogger(TaskClient.class.getName()).log(Level.SEVERE, null, ex); } op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("moda") == 0) { Float[] numeros = (Float[]) op.getInputData().get(0).value; float[] datos = ArrayUtils.toPrimitive(numeros); Double res = null; res = new Double(fengine.moda(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("mediana") == 0) { Float[] numeros = (Float[]) op.getInputData().get(0).value; float[] datos = ArrayUtils.toPrimitive(numeros); Double res = null; res = new Double(fengine.mediana(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("mediaGeometrica") == 0) { Float[] numeros = (Float[]) op.getInputData().get(0).value; float[] datos = ArrayUtils.toPrimitive(numeros); try { Double res = fengine.mediaGeometrica(datos); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); } catch (ComputeEngineException ex) { protocol.common.Error err = new protocol.common.Error(); err.type = ex.getMessage(); err.msg = "Raz cuadrada negativa"; op.setResult(err); rs.setSubtype("_JCALC_OPERATION_ERROR_"); } rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("aproximacionE") == 0) { Float n = (Float) op.getInputData().get(0).value; double rss = fengine.aproximacionE(n.floatValue()); Double res = new Double(rss); // Double res = new Double(fengine.x2(n.floatValue())); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("x*y") == 0) { Float[] numeros = new Float[op.getInputData().size()]; for (int i = 0; i < numeros.length; i++) { numeros[i] = (Float) op.getInputData().get(i).value; } float[] datos = ArrayUtils.toPrimitive(numeros); Double res = new Double(fengine.multiplicar(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("x/y") == 0) { Float[] numeros = new Float[op.getInputData().size()]; for (int i = 0; i < numeros.length; i++) { numeros[i] = (Float) op.getInputData().get(i).value; } float[] datos = ArrayUtils.toPrimitive(numeros); try { Double res = new Double(fengine.dividir(datos)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); } catch (ComputeEngineException ex) { protocol.common.Error err = new protocol.common.Error(); err.type = ex.getMessage(); err.msg = "Divisor 0"; op.setResult(err); rs.setSubtype("_JCALC_OPERATION_ERROR_"); } rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("x2") == 0) { Float n = (Float) op.getInputData().get(0).value; double rss = fengine.x2(n.floatValue()); Double res = new Double(rss); // Double res = new Double(fengine.x2(n.floatValue())); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("cambioSigno") == 0) { Float n = (Float) op.getInputData().get(0).value; double rss = fengine.cambioSigno(n.floatValue()); Double res = new Double(rss); // Double res = new Double(fengine.x2(n.floatValue())); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("raiz2") == 0) { Float n = (Float) op.getInputData().get(0).value; double rss = 0; try { rss = fengine.raiz2(n.floatValue()); Double res = new Double(rss); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); } catch (ComputeEngineException ex) { protocol.common.Error err = new protocol.common.Error(); err.type = ex.getMessage(); err.msg = "Raz cuadrada negativa"; op.setResult(err); rs.setSubtype("_JCALC_OPERATION_ERROR_"); } rs.addData(op); return ccp.sendResponse(rs); } else if (op.getType().compareTo("segundoGrado") == 0) { Float[] numeros = new Float[op.getInputData().size()]; for (int i = 0; i < numeros.length; i++) { numeros[i] = (Float) op.getInputData().get(i).value; } float[] datos = ArrayUtils.toPrimitive(numeros); float[] resta = new float[2]; float[] suma = new float[2]; resta[0] = datos[0]; resta[1] = datos[2]; suma[0] = datos[1]; suma[1] = datos[2]; try { Double[] res = new Double[2]; res[0] = new Double(fengine.dividir(suma)); res[1] = new Double(fengine.dividir(resta)); op.setResult(res); rs.setSubtype("_JCALC_OPERATION_OK_"); rs.addData(op); } catch (ComputeEngineException ex) { if (ex.getMessage() == "DIVIDE_BY_ZERO") { protocol.common.Error err = new protocol.common.Error(); err.type = ex.getMessage(); err.msg = "Divisor 0"; op.setResult(err); rs.setSubtype("_JCALC_OPERATION_ERROR_"); } if (ex.getMessage() == "SQUAREROOT_NEGATIVE") { protocol.common.Error err = new protocol.common.Error(); err.type = ex.getMessage(); err.msg = "Raz cuadrada negativa"; op.setResult(err); rs.setSubtype("_JCALC_OPERATION_ERROR_"); } rs.addData(op); return ccp.sendResponse(rs); } return ccp.sendResponse(rs); } return true; }
From source file:org.apache.nutch.analysis.lang.LanguageIdentifier.java
/** * Identify language of a content.//w w w.j av a 2 s . co m * * @param content is the content to analyze. * @return The 2 letter * <a href="http://www.w3.org/WAI/ER/IG/ert/iso639.htm">ISO 639 * language code</a> (en, fi, sv, ...) of the language that best * matches the specified content. */ public String identify(StringBuilder content) { StringBuilder text = content; if ((analyzeLength > 0) && (content.length() > analyzeLength)) { text = new StringBuilder().append(content); text.setLength(analyzeLength); } suspect.analyze(text); Iterator<NGramEntry> iter = suspect.getSorted().iterator(); float topscore = Float.MIN_VALUE; String lang = ""; HashMap<NGramProfile, Float> scores = new HashMap<NGramProfile, Float>(); NGramEntry searched = null; while (iter.hasNext()) { searched = iter.next(); NGramEntry[] ngrams = ngramsIdx.get(searched.getSeq()); if (ngrams != null) { for (int j = 0; j < ngrams.length; j++) { NGramProfile profile = ngrams[j].getProfile(); Float pScore = scores.get(profile); if (pScore == null) { pScore = new Float(0); } float plScore = pScore.floatValue(); plScore += ngrams[j].getFrequency() + searched.getFrequency(); scores.put(profile, new Float(plScore)); if (plScore > topscore) { topscore = plScore; lang = profile.getName(); if (lang.equals("zh")) { return lang; } } } } } return lang; }
From source file:net.pflaeging.PortableSigner.SignCommandLine.java
/** Creates a new instance of CommandLine */ public SignCommandLine(String args[]) { langcodes = ""; java.util.Enumeration<String> langCodes = ResourceBundle .getBundle("net/pflaeging/PortableSigner/SignatureblockLanguages").getKeys(); while (langCodes.hasMoreElements()) { langcodes = langcodes + langCodes.nextElement() + "|"; }//from ww w . j a v a 2 s . c om langcodes = langcodes.substring(0, langcodes.length() - 1); // System.out.println("Langcodes: " + langcodes); CommandLine cmd; Options options = new Options(); options.addOption("t", true, rbi18n.getString("CLI-InputFile")); options.addOption("o", true, rbi18n.getString("CLI-OutputFile")); options.addOption("s", true, rbi18n.getString("CLI-SignatureFile")); options.addOption("p", true, rbi18n.getString("CLI-Password")); options.addOption("n", false, rbi18n.getString("CLI-WithoutGUI")); options.addOption("f", false, rbi18n.getString("CLI-Finalize")); options.addOption("h", false, rbi18n.getString("CLI-Help")); options.addOption("b", true, rbi18n.getString("CLI-SigBlock") + langcodes); options.addOption("i", true, rbi18n.getString("CLI-SigImage")); options.addOption("c", true, rbi18n.getString("CLI-SigComment")); options.addOption("r", true, rbi18n.getString("CLI-SigReason")); options.addOption("l", true, rbi18n.getString("CLI-SigLocation")); options.addOption("e", true, rbi18n.getString("CLI-EmbedSignature")); options.addOption("pwdfile", true, rbi18n.getString("CLI-PasswdFile")); options.addOption("ownerpwd", true, rbi18n.getString("CLI-OwnerPasswd")); options.addOption("ownerpwdfile", true, rbi18n.getString("CLI-OwnerPasswdFile")); options.addOption("z", false, rbi18n.getString("CLI-LastPage")); CommandLineParser parser = new PosixParser(); HelpFormatter usage = new HelpFormatter(); try { cmd = parser.parse(options, args); input = cmd.getOptionValue("t", ""); output = cmd.getOptionValue("o", ""); signature = cmd.getOptionValue("s", ""); password = cmd.getOptionValue("p", ""); nogui = cmd.hasOption("n"); help = cmd.hasOption("h"); finalize = !cmd.hasOption("f"); sigblock = cmd.getOptionValue("b", ""); sigimage = cmd.getOptionValue("i", ""); comment = cmd.getOptionValue("c", ""); reason = cmd.getOptionValue("r", ""); location = cmd.getOptionValue("l", ""); embedParams = cmd.getOptionValue("e", ""); pwdFile = cmd.getOptionValue("pwdfile", ""); ownerPwdString = cmd.getOptionValue("ownerpwd", ""); ownerPwdFile = cmd.getOptionValue("ownerpwdfile", ""); lastPage = !cmd.hasOption("z"); if (cmd.getArgs().length != 0) { throw new ParseException(rbi18n.getString("CLI-UnknownArguments")); } } catch (ParseException e) { System.err.println(rbi18n.getString("CLI-WrongArguments")); usage.printHelp("PortableSigner", options); System.exit(3); } if (nogui) { if (input.equals("") || output.equals("") || signature.equals("")) { System.err.println(rbi18n.getString("CLI-MissingArguments")); usage.printHelp("PortableSigner", options); System.exit(2); } if (!help) { if (password.equals("")) { // password missing if (!pwdFile.equals("")) { // read the password from the given file try { FileInputStream pwdfis = new FileInputStream(pwdFile); byte[] pwd = new byte[1024]; password = ""; try { do { int r = pwdfis.read(pwd); if (r < 0) { break; } password += new String(pwd); password = password.trim(); } while (pwdfis.available() > 0); pwdfis.close(); } catch (IOException ex) { } } catch (FileNotFoundException fnfex) { } } else { // no password file given, read from standard input System.out.print(rbi18n.getString("CLI-MissingPassword")); Console con = System.console(); if (con == null) { byte[] pwd = new byte[1024]; password = ""; try { do { int r = System.in.read(pwd); if (r < 0) { break; } password += new String(pwd); password = password.trim(); } while (System.in.available() > 0); } catch (IOException ex) { } } else { // Console not null. Use it to read the password without echo char[] pwd = con.readPassword(); if (pwd != null) { password = new String(pwd); } } } } if (ownerPwdString.equals("") && ownerPwdFile.equals("")) { // no owner password or owner password file given, read from standard input System.out.print(rbi18n.getString("CLI-MissingOwnerPassword") + " "); Console con = System.console(); if (con == null) { byte[] pwd = new byte[1024]; String tmppassword = ""; try { do { int r = System.in.read(pwd); if (r < 0) { break; } tmppassword += new String(pwd, 0, r); tmppassword = tmppassword.trim(); } while (System.in.available() > 0); } catch (java.io.IOException ex) { // TODO: perhaps notify the user } ownerPwd = tmppassword.getBytes(); } else { // Console not null. Use it to read the password without echo char[] pwd = con.readPassword(); if (pwd != null) { ownerPwd = new byte[pwd.length]; for (int i = 0; i < pwd.length; i++) { ownerPwd[i] = (byte) pwd[i]; } } } } else if (!ownerPwdString.equals("")) { ownerPwd = ownerPwdString.getBytes(); } else if (!ownerPwdFile.equals("")) { try { FileInputStream pwdfis = new FileInputStream(ownerPwdFile); ownerPwd = new byte[0]; byte[] tmp = new byte[1024]; byte[] full; try { do { int r = pwdfis.read(tmp); if (r < 0) { break; } // trim the length: tmp = Arrays.copyOfRange(tmp, 0, r); //System.arraycopy(tmp, 0, tmp, 0, r); full = new byte[ownerPwd.length + tmp.length]; System.arraycopy(ownerPwd, 0, full, 0, ownerPwd.length); System.arraycopy(tmp, 0, full, ownerPwd.length, tmp.length); ownerPwd = full; } while (pwdfis.available() > 0); pwdfis.close(); } catch (IOException ex) { } } catch (FileNotFoundException fnfex) { } } } } if (!embedParams.equals("")) { String[] parameter = null; parameter = embedParams.split(","); try { Float vPosF = new Float(parameter[0]), lMarginF = new Float(parameter[1]), rMarginF = new Float(parameter[2]); vPos = vPosF.floatValue(); lMargin = lMarginF.floatValue(); rMargin = rMarginF.floatValue(); noSigPage = true; } catch (NumberFormatException nfe) { System.err.println(rbi18n.getString("CLI-embedParameter-Error")); usage.printHelp("PortableSigner", options); System.exit(5); } } if (!(langcodes.contains(sigblock) || sigblock.equals(""))) { System.err.println(rbi18n.getString("CLI-Only-german-english") + langcodes); usage.printHelp("PortableSigner", options); System.exit(4); } if (help) { usage.printHelp("PortableSigner", options); System.exit(1); } // System.err.println("CMDline: input: " + input); // System.err.println("CMDline: output: " + output); // System.err.println("CMDline: signature: " + signature); // System.err.println("CMDline: password: " + password); // System.err.println("CMDline: sigblock: " + sigblock); // System.err.println("CMDline: sigimage: " + sigimage); // System.err.println("CMDline: comment: " + comment); // System.err.println("CMDline: reason: " + reason); // System.err.println("CMDline: location: " + location); // System.err.println("CMDline: pwdFile: " + pwdFile); // System.err.println("CMDline: ownerPwdFile: " + ownerPwdFile); // System.err.println("CMDline: ownerPwdString: " + ownerPwdString); // System.err.println("CMDline: ownerPwd: " + ownerPwd.toString()); }
From source file:org.nuxeo.ecm.platform.categorization.categorizer.tfidf.TfIdfCategorizer.java
protected float tfidfNorm(String topicName) { Float norm = cachedTopicTfIdfNorm.get(topicName); if (norm == null) { norm = normOf(tfidf(topicName)); cachedTopicTfIdfNorm.put(topicName, norm); }//from ww w .j av a 2 s .c om return norm.floatValue(); }
From source file:org.etudes.mneme.impl.GradesServiceGradebook23Impl.java
/** * Convert the points / score value into a double, without picking up float to double conversion junk * /*from w w w . java2 s . c o m*/ * @param score * The value to convert. * @return The converted value. */ protected double toDoubleScore(Float score) { if (score == null) return 0.0d; // we want only .xx precision, and we don't want any double junk from the float to double conversion float times100 = score.floatValue() * 100f; Double rv = (double) times100; rv = rv / 100d; return rv; }
From source file:org.acmsl.commons.utils.ConversionUtils.java
/** * Converts given String to float.//w w w . j av a 2s. com * @param value the value to convert. * @return the converted value. */ public float toFloat(@Nullable final String value) { float result = 0.0f; @Nullable final Float t_Result = toFloatIfNotNull(value); if (t_Result != null) { result = t_Result.floatValue(); } return result; }