List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:darks.learning.word2vec.Word2Vec.java
/** * Incremental training sentence. //w ww. j av a 2 s.c o m * * @param source Target source * @return Whether success */ public boolean trainIncrement(String source) { log.debug("Training word2vec " + source + " by increment way."); StringTokenizer token = new StringTokenizer(source, " \t"); trainingVocabCount = token.countTokens(); List<WordNode> sentence = sampleSentence(token); if (sentence.isEmpty()) { return false; } executeNeuronNetwork(sentence); return true; }
From source file:hydrograph.ui.dataviewer.adapters.DataViewerAdapter.java
private String getType(String databaseName) throws IOException { StringBuffer typeString = new StringBuffer(); String debugFileName = debugDataViewer.getDebugFileName(); String debugFileLocation = debugDataViewer.getDebugFileLocation(); if (ViewDataSchemaHelper.INSTANCE.getFieldsFromSchema( debugFileLocation + debugFileName + AdapterConstants.SCHEMA_FILE_EXTENTION) == null) { return ""; }/*from ww w . j a v a 2 s .c om*/ Map<String, String> fieldAndTypes = new HashMap<String, String>(); for (Field field : ViewDataSchemaHelper.INSTANCE .getFieldsFromSchema(debugFileLocation + debugFileName + AdapterConstants.SCHEMA_FILE_EXTENTION) .getField()) { fieldAndTypes.put(StringUtils.lowerCase(field.getName()), field.getType().value()); } try (BufferedReader bufferedReader = new BufferedReader( new FileReader(new File(databaseName + tableName + AdapterConstants.CSV)))) { String firstLine = bufferedReader.readLine(); StringTokenizer stringTokenizer = new StringTokenizer(firstLine, ","); int countTokens = stringTokenizer.countTokens(); for (int i = 0; i < countTokens; i++) { String columnName = stringTokenizer.nextToken(); String typeName = fieldAndTypes.get(StringUtils.lowerCase(columnName)); typeString.append(StringUtils.substring(typeName, StringUtils.lastIndexOf(typeName, ".") + 1)); if (i != countTokens - 1) { typeString.append(","); } } } catch (IOException ioException) { logger.error("Failed to read view data file column headers", ioException); throw ioException; } return typeString.toString(); }
From source file:com.octo.captcha.j2ee.servlet.ImageCaptchaFilter.java
/** * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) * @TODO : verify that URL begins with a "\" (or add it and trace * a warning) ?//from ww w.j a v a2 s . com */ public void init(final FilterConfig theFilterConfig) throws ServletException { // get associated servlet context this.servletContext = theFilterConfig.getServletContext(); // get rendering URL from web.xml this.captchaRenderingURL = FilterConfigUtils.getStringInitParameter(theFilterConfig, CAPTCHA_RENDERING_URL_PARAMETER, true); // get verification URLs from web.xml (CSV list of URLs) String captchaVerificationURLs = FilterConfigUtils.getStringInitParameter(theFilterConfig, CAPTCHA_VERIFICATION_URLS_PARAMETER, true); // get forward error URLs from web.xml (CSV list of URLs) String captchaForwardErrorURLs = FilterConfigUtils.getStringInitParameter(theFilterConfig, CAPTCHA_ERROR_URLS_PARAMETER, true); // initialize the verificationForwards hashtable StringTokenizer verificationURLs = new StringTokenizer(captchaVerificationURLs, CSV_DELIMITER, false); StringTokenizer forwardErrorURLs = new StringTokenizer(captchaForwardErrorURLs, CSV_DELIMITER, false); if (verificationURLs.countTokens() != forwardErrorURLs.countTokens()) { // The URL lists are not consistant (there should be a forward and // a success for each verification URL) throw new ServletException(CAPTCHA_VERIFICATION_URLS_PARAMETER + " and " + CAPTCHA_ERROR_URLS_PARAMETER + " values are not consistant in web.xml : there should be" + " exactly one forward error for each verification URL !"); } while (verificationURLs.hasMoreTokens()) { // Create a ForwardInfo for each verification URL and store it in // the verificationForward hashtable this.verificationForwards.put(verificationURLs.nextToken(), forwardErrorURLs.nextToken()); } // get captcha ID parameter name from web.xml this.captchaIDParameterName = FilterConfigUtils.getStringInitParameter(theFilterConfig, CAPTCHA_ID_PARAMETER_NAME_PARAMETER, true); // get challenge response parameter name from web.xml this.captchaChallengeResponseParameterName = FilterConfigUtils.getStringInitParameter(theFilterConfig, CAPTCHA_RESPONSE_PARAMETER_NAME_PARAMETER, true); // get from web.xml the indicator signaling if the CaptchaFilter // should be registered to an MBean Server this.captchaRegisterToMBeanServer = FilterConfigUtils.getBooleanInitParameter(theFilterConfig, CAPTCHA_REGISTER_TO_MBEAN_SERVER_PARAMETER, false); // Extract the ImageCaptchaService initialization parameters // from web.xml Properties captchaServiceInitParameters = new Properties(); { // get max number of simultaneous captchas from web.xml String captchaInternalStoreSize = FilterConfigUtils.getStringInitParameter(theFilterConfig, MAX_NUMBER_OF_SIMULTANEOUS_CAPTCHAS_PROP, true); captchaServiceInitParameters.setProperty(ImageCaptchaService.MAX_NUMBER_OF_SIMULTANEOUS_CAPTCHAS_PROP, captchaInternalStoreSize); // get minimum guaranted storage delay in seconds from web.xml String captchaTimeToLive = FilterConfigUtils.getStringInitParameter(theFilterConfig, MIN_GUARANTED_STORAGE_DELAY_IN_SECONDS_PROP, true); captchaServiceInitParameters.setProperty( ImageCaptchaService.MIN_GUARANTED_STORAGE_DELAY_IN_SECONDS_PROP, captchaTimeToLive); // get from web.xml the ImageCaptchaEngine implementation class name String engineClass = FilterConfigUtils.getStringInitParameter(theFilterConfig, CAPTCHA_ENGINE_CLASS_PARAMETER, true); captchaServiceInitParameters.setProperty(ImageCaptchaService.ENGINE_CLASS_INIT_PARAMETER_PROP, engineClass); } // create the ImageCaptchaService this.captchaService = new ImageCaptchaService(captchaServiceInitParameters); // get captcha ID max length from web.xml and set the // ImageCaptchaService captcha ID max length value with it Integer captchaIDMaxMLengthAsInteger = FilterConfigUtils.getIntegerInitParameter(theFilterConfig, CAPTCHA_ID_MAX_LENGTH_PARAMETER, true, 0, Integer.MAX_VALUE); this.captchaService.setCaptchaIDMaxLength(captchaIDMaxMLengthAsInteger.intValue()); // register the ImageCaptchaService to an MBean server if specified if (this.captchaRegisterToMBeanServer) { registerToMBeanServer(); } }
From source file:darks.learning.word2vec.Word2Vec.java
private void startTrainer(Corpus corpus) { try {/*from ww w . j a v a 2s . c o m*/ log.debug("Start to train with " + wordHandler); long lastTrainCount = 0; String line = null; while ((line = corpus.readCorpusLine()) != null) { line = line.trim(); if ("".equals(line)) { continue; } StringTokenizer token = new StringTokenizer(line, " \t"); trainingVocabCount = token.countTokens(); List<WordNode> sentence = sampleSentence(token); if (sentence.isEmpty()) { continue; } lastTrainCount = updateLearnRate(lastTrainCount); executeNeuronNetwork(sentence); } log.debug("Words in train file: " + actualVocabCount + "/" + totalVocabCount); log.info("Succeed to train word2vec model."); } catch (Exception e) { log.error(e.getMessage(), e); } finally { corpus.closeReader(); } }
From source file:net.sf.webphotos.sync.FTP.SyncObject.java
/** * Recebe uma linha com comando de FTP (DELETE, DOWNLOAD ou UPLOAD), * processa o tipo "acao albumID foto" e a carrega em cima do ArrayList * listaArquivos, que contm dados de//from w ww . j a v a 2 s . c o m * {@link net.sf.webphotos.util.Arquivo Arquivo}. * * @param linha Linha de comando FTP. */ @Override public void loadSyncCacheLine(String linha) { StringTokenizer tok = new StringTokenizer(linha); int acao = -1; int albumID = -1; int fotoID = -1; Util.out.println("carrega: " + linha); if (tok.countTokens() == 3) { acao = Integer.parseInt(tok.nextToken()); albumID = Integer.parseInt(tok.nextToken()); fotoID = Integer.parseInt(tok.nextToken()); } else { // houve um erro... Util.out.println("erro: " + linha); return; } // obtem uma lista do lbum (todos os arquivos) File f = new File(getAlbunsRoot(), Integer.toString(albumID)); String[] ls = f.list(); switch (acao) { // Apagar case CacheFTP.DELETE: // Receber case CacheFTP.DOWNLOAD: if (fotoID == 0) { // O lbum inteiro listaArquivos.add(new Arquivo(linha, acao, albumID, 0, "* todos")); } else { // Uma foto listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_a" + fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_b" + fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_c" + fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_d" + fotoID + ".jpg")); if (isEnviarAltaResolucao() == true) { listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, fotoID + ".zip")); } listaArquivos.add(new Arquivo(linha, acao, albumID, 0, albumID + ".xml")); listaArquivos.add(new Arquivo(linha, acao, albumID, 0, albumID + ".js")); } break; // Enviar case CacheFTP.UPLOAD: if (fotoID == 0) { // O lbum inteiro Album.getAlbum().loadAlbum(albumID); for (PhotoDTO atual : Album.getAlbum().getFotos()) { fotoID = atual.getFotoID(); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_a" + fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_b" + fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_c" + fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, "_d" + fotoID + ".jpg")); if (isEnviarAltaResolucao() == true) { listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, fotoID + ".jpg")); listaArquivos.add(new Arquivo(linha, acao, albumID, fotoID, fotoID + ".zip")); } } listaArquivos.add(new Arquivo(linha, acao, albumID, 0, albumID + ".xml")); listaArquivos.add(new Arquivo(linha, acao, albumID, 0, albumID + ".js")); } else { // Uma foto Util.out.println("Upload alta: " + isEnviarAltaResolucao()); for (String fileName : ls) { if ((fileName.startsWith("_") && fileName.toLowerCase().endsWith(fotoID + ".jpg")) || (isEnviarAltaResolucao() && fileName.toLowerCase().endsWith(fotoID + ".zip")) || (isEnviarAltaResolucao() && fileName.toLowerCase().endsWith(fotoID + ".jpg"))) { Arquivo a = new Arquivo(linha, acao, albumID, fotoID, fileName); listaArquivos.add(a); } } // fim for } break; } }
From source file:lineage2.gameserver.instancemanager.HellboundManager.java
/** * Method getHellboundSpawn./* ww w.j a va2 s .c om*/ */ private void getHellboundSpawn() { _list = new ArrayList<>(); _spawnList = new ArrayList<>(); try { File file = new File(Config.DATAPACK_ROOT + "/data/xml/other/hellbound_spawnlist.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); Document doc1 = factory.newDocumentBuilder().parse(file); int counter = 0; for (Node n1 = doc1.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if ("list".equalsIgnoreCase(n1.getNodeName())) { for (Node d1 = n1.getFirstChild(); d1 != null; d1 = d1.getNextSibling()) { if ("data".equalsIgnoreCase(d1.getNodeName())) { counter++; int npcId = Integer.parseInt(d1.getAttributes().getNamedItem("npc_id").getNodeValue()); Location spawnLoc = null; if (d1.getAttributes().getNamedItem("loc") != null) { spawnLoc = Location.parseLoc(d1.getAttributes().getNamedItem("loc").getNodeValue()); } int count = 1; if (d1.getAttributes().getNamedItem("count") != null) { count = Integer.parseInt(d1.getAttributes().getNamedItem("count").getNodeValue()); } int respawn = 60; if (d1.getAttributes().getNamedItem("respawn") != null) { respawn = Integer .parseInt(d1.getAttributes().getNamedItem("respawn").getNodeValue()); } int respawnRnd = 0; if (d1.getAttributes().getNamedItem("respawn_rnd") != null) { respawnRnd = Integer .parseInt(d1.getAttributes().getNamedItem("respawn_rnd").getNodeValue()); } Node att = d1.getAttributes().getNamedItem("stage"); StringTokenizer st = new StringTokenizer(att.getNodeValue(), ";"); int tokenCount = st.countTokens(); int[] stages = new int[tokenCount]; for (int i = 0; i < tokenCount; i++) { Integer value = Integer.decode(st.nextToken().trim()); stages[i] = value; } Territory territory = null; for (Node s1 = d1.getFirstChild(); s1 != null; s1 = s1.getNextSibling()) { if ("territory".equalsIgnoreCase(s1.getNodeName())) { Polygon poly = new Polygon(); for (Node s2 = s1.getFirstChild(); s2 != null; s2 = s2.getNextSibling()) { if ("add".equalsIgnoreCase(s2.getNodeName())) { int x = Integer .parseInt(s2.getAttributes().getNamedItem("x").getNodeValue()); int y = Integer .parseInt(s2.getAttributes().getNamedItem("y").getNodeValue()); int minZ = Integer.parseInt( s2.getAttributes().getNamedItem("zmin").getNodeValue()); int maxZ = Integer.parseInt( s2.getAttributes().getNamedItem("zmax").getNodeValue()); poly.add(x, y).setZmin(minZ).setZmax(maxZ); } } territory = new Territory().add(poly); if (!poly.validate()) { _log.error("HellboundManager: Invalid spawn territory : " + poly + "!"); continue; } } } if ((spawnLoc == null) && (territory == null)) { _log.error("HellboundManager: no spawn data for npc id : " + npcId + "!"); continue; } HellboundSpawn hbs = new HellboundSpawn(npcId, spawnLoc, count, territory, respawn, respawnRnd, stages); _list.add(hbs); } } } } _log.info("HellboundManager: Loaded " + counter + " spawn entries."); } catch (Exception e) { _log.warn("HellboundManager: Spawn table could not be initialized."); e.printStackTrace(); } }
From source file:com.newatlanta.appengine.nio.file.GaePath.java
@Override public Path getName(int index) { StringTokenizer st = new StringTokenizer(path, PATH_DELIMS); int numEntries = st.countTokens(); if ((index < 0) || (index >= numEntries)) { throw new IllegalArgumentException(); }//from ww w .j a v a2 s. com for (int i = 0; i < numEntries; i++) { st.nextToken(); } return new GaePath(fileSystem, st.nextToken()); }
From source file:jotp.java
public boolean action(Event evt, Object arg) { String tmpstr, tmpstr2, seed, passphrase; int seq, hashalg; otp otpwd;//from ww w.ja v a 2s .com if (evt.target instanceof Button) { if (arg.equals(md5label)) { hashalg = otp.MD5; } else { hashalg = otp.MD4; } /* Split up challenge */ tmpstr = chaltf.getText(); StringTokenizer st = new StringTokenizer(tmpstr); if (st.countTokens() != 2) { otptf.setText("bogus challenge"); return true; } tmpstr2 = st.nextToken(); try { seq = (Integer.parseInt(tmpstr2)); } catch (NumberFormatException e) { otptf.setText("bogus sequence number '" + tmpstr2 + "'"); return true; } seed = st.nextToken(); passphrase = pwtf.getText(); /* passphrase = "eat me";*/ System.out.println("passphrase = " + passphrase); otptf.setText("Okay, thinking..."); otpwd = new otp(seq, seed, passphrase, hashalg); otpwd.calc(); otptf.setText(otpwd.toString()); } return true; }
From source file:com.board.games.handler.ipb.IPBPokerLoginServiceImpl.java
@Override public LoginResponseAction handle(LoginRequestAction req) { // At this point, we should get the user name and password // from the request and verify them, but for this example // we'll just assign a dynamic player ID and grant the login // Must be the very first call initialize();// w ww . j a v a2 s . c om boolean userHasAcceptedAgeclause = true; // force to true // boolean useFacebookAuthentication = false; //log.debug("Data login " + req.getData()); /* boolean isBot = false; String loginName = req.getUser(); int idxb = loginName.indexOf("_"); if (idxb != -1) { // let bots through // String idStr = loginName.substring(idxb+1); // if (loginName.toUpperCase().startsWith("BOT")) { isBot = true; // } }*/ int count = 0; int idx = 0; int ref = 0; StringBuffer sb = new StringBuffer(); log.debug("request data length " + req.getData().length); log.debug("Dump request : " + req.toString()); for (byte b : req.getData()) { idx++; // log.debug((char)b); char val = (char) b; // if (idx >7 ) sb.append(val); } //log.debug("count " + count); // TO DBG: activate trace of detail array below log.debug("sb " + sb.toString()); String logindataRequest = sb.toString(); log.debug("datarequest " + logindataRequest); StringTokenizer st = new StringTokenizer(logindataRequest, ";"); String socialNetworkId = ""; String socialAvatar = ""; boolean isBot = false; log.debug("Token size " + st.countTokens()); if (st.countTokens() > 3) { /* if (!isBot) { */ String ageClause = st.nextToken().trim(); log.debug("ageClause " + ageClause); // if (ageClause.toUpperCase().equals("AGEVERIFICATIONDONE")) { // userHasAcceptedAgeclause = true; // } log.debug("User has accepted clause = " + (userHasAcceptedAgeclause ? "yes" : "no")); int snFlag = new Integer(st.nextToken()); log.debug("authId " + (snFlag == 5 || snFlag == 6 || snFlag == 0 ? "use sn" : "no sn")); socialNetworkId = (String) st.nextToken(); log.debug("socialNetworkId " + socialNetworkId); socialAvatar = new String(st.nextToken()); log.debug("socialAvatar " + socialAvatar); if (snFlag == 0) { isBot = true; authTypeId = 0; } else if (snFlag == 5) { // overwrite default authTypeId authTypeId = 5; //force email with fb log.debug("authTypeId " + authTypeId); } else if (snFlag == 6) { // overwrite default authTypeId authTypeId = 6; //force email with google plus log.debug("authTypeId " + authTypeId); } else { authTypeId = 1; } } else { socialNetworkId = "999999"; socialAvatar = ""; userHasAcceptedAgeclause = true; authTypeId = 1; log.debug("authTypeId " + authTypeId); } //} LoginResponseAction response = null; try { log.debug("Performing authentication on " + req.getUser()); String userIdStr = null; if (authTypeId == 0) { log.debug("*** Bots authentication ***"); /* String loginName = req.getUser(); int idxb = loginName.indexOf("_"); if (idxb != -1) { // let bots through String idStr = loginName.substring(idxb+1); }*/ userIdStr = authenticateBot(req.getUser(), socialNetworkId, socialAvatar, getServerCfg(), userHasAcceptedAgeclause, authTypeId, needAgeAgreement); } else if (authTypeId == 5 || authTypeId == 6) { log.debug("*** Social Network authentication ***"); userIdStr = authenticateSocialNetwork(req.getUser(), socialNetworkId, socialAvatar, getServerCfg(), userHasAcceptedAgeclause, authTypeId, needAgeAgreement); } else { log.debug("*** Forum authentication ***"); userIdStr = authenticate(req.getUser(), req.getPassword(), getServerCfg(), userHasAcceptedAgeclause, authTypeId); } if (!userIdStr.equals("")) { response = new LoginResponseAction(Integer.parseInt(userIdStr) > 0 ? true : false, (req.getUser().toUpperCase().startsWith("GUESTXDEMO") ? req.getUser() + "_" + userIdStr : req.getUser()), Integer.parseInt(userIdStr)); // pid.incrementAndGet() response.setErrorCode(Integer.parseInt(userIdStr)); String errMsg = "Login failed "; switch (Integer.parseInt(userIdStr)) { case -3: errMsg += " User does not exist, please sign up same account type on forum first"; break; case -5: errMsg += " User must check age requirement to play due to 18+ clause"; break; case -2: errMsg += " User has not met required posts"; break; case -1: errMsg += " User password is invalid"; break; default: break; } response.setErrorMessage(errMsg); log.debug(Integer.parseInt(userIdStr) > 0 ? "Authentication successful" : "Authentication failed with errorCode as " + userIdStr); return response; } } catch (SQLException sqle) { log.error("Error authenticate", sqle); response = new LoginResponseAction(false, -1); response.setErrorMessage(getSystemErrorMessage(sqle)); response.setErrorCode(getSystemErrorCode(sqle)); log.error(sqle); } catch (Exception e) { log.error("Error system", e); } response = new LoginResponseAction(false, -1); response.setErrorMessage(getNotFoundErrorMessage()); response.setErrorCode(getNotFoundErrorCode()); return response; }
From source file:net.sourceforge.dvb.projectx.xinput.ftp.XInputFileImpl.java
/** * @throws java.io.IOException// w ww. ja v a 2s . co m */ public String[] getUserFTPCommand() { StringTokenizer st = new StringTokenizer(Common.getSettings().getProperty(Keys.KEY_FtpServer_Commands), "|"); String[] tokens = new String[st.countTokens()]; for (int i = 0; st.hasMoreTokens(); i++) tokens[i] = st.nextElement().toString().trim(); return tokens; }