List of usage examples for org.apache.commons.lang3 StringUtils stripAccents
public static String stripAccents(final String input)
Removes diacritics (~= accents) from a string.
From source file:com.cz4031.SAXHandler.java
@Override public void endElement(String uri, String localName, String qName) throws SAXException { String tempValue = stringBuilder.toString(); String tempAccent = StringUtils.stripAccents(tempValue); String value = StringUtils.trimToEmpty(tempAccent); stringBuilder.setLength(0);// ww w . ja v a 2 s . com if (publication != null) { if (qName.equalsIgnoreCase("author")) { String authorName = value.toLowerCase(); AuthorList instance = AuthorList.getInstance(); HashMap<Author, Set<Integer>> authorList = instance.getAuthorList(); Author author = new Author(); author.setName(authorName); if (authorList.containsKey(author)) { Set<Integer> publicationList = authorList.get(author); publicationList.add(publication.getPubId()); } else { author.setId(++authorID); Set<Integer> publicationList = new HashSet<>(); publicationList.add(publication.getPubId()); authorList.put(author, publicationList); } } else if (qName.equalsIgnoreCase("article") || qName.equalsIgnoreCase("book") || qName.equalsIgnoreCase("incollection") || qName.equalsIgnoreCase("inproceedings")) { CSVWriter csvWriter = CSVWriter.getInstance(); csvWriter.writeToPublication(publication); publication = null; } else if (qName.equalsIgnoreCase("title")) { publication.setTitle(value); } else if (qName.equalsIgnoreCase("year")) { int year = Integer.parseInt(value); publication.setYear(year); } else if (qName.equalsIgnoreCase("journal")) { publication.setJournal(value); } else if (qName.equalsIgnoreCase("volume")) { publication.setVolume(value); } else if (qName.equalsIgnoreCase("number")) { publication.setNumber(value); } else if (qName.equalsIgnoreCase("publisher")) { publication.setPublisher(value); } else if (qName.equalsIgnoreCase("isbn")) { publication.setIsbn(value); } else if (qName.equalsIgnoreCase("booktitle")) { publication.setBooktitle(value); } else if (qName.equalsIgnoreCase("editor")) { publication.setEditor(value); } else if (qName.equalsIgnoreCase("pages")) { String pageStr = value; parsePages(pageStr); } } }
From source file:com.blackducksoftware.tools.idcopier.service.ProjectService.java
/** * Gets projects from internal map/*from w ww.j a v a 2 s . co m*/ * * @param server * @param proxy * @return * @throws Exception */ public List<ProjectInfo> getProjectsByServer(ProtexServerProxy proxy, IDCServer server) throws Exception { this.proxy = proxy; List<ProjectInfo> projects = projectMap.get(server.getServerName()); if (projects == null) { projects = getProjectsByUser(proxy, server.getUserName()); for (ProjectInfo pinfo : projects) { String projectName = pinfo.getName(); String strippedName = StringUtils.stripAccents(projectName); pinfo.setName(strippedName); } projectMap.put(server.getServerName(), projects); } else { return projects; } Collections.sort(projects, new ProjectComparator()); return projects; }
From source file:investiagenofx2.view.InvestiaGenOFXController.java
private void getTransactionsFromWeb() { try {// w w w. j av a 2 s . c o m if (!htmlPage.getUrl().toString().contains("/TransactionReports/Select")) { if (InvestiaGenOFX.debug) { htmlPage = InvestiaGenOFX.getWebClient() .getPage(InvestiaGenOFX.debugFullPath + "-Transactions.htm"); } else { htmlPage = InvestiaGenOFX.getWebClient() .getPage(txt_investiaURL.getText() + "/TransactionReports/Select" + "?wcag=true"); waitForGeneratedTransactions(); } } @SuppressWarnings(("unchecked")) List<HtmlHeading4> h4from = (List<HtmlHeading4>) htmlPage .getByXPath("//h4[contains(text(),'Priode: de ')]"); String from = h4from.get(0).asText(); int index = from.indexOf("Priode: de "); LocalDate selFromDate = LocalDate.parse(from.substring(index + 12, index + 12 + 10)); if (dtp_lastDate.getValue().isBefore(selFromDate)) { @SuppressWarnings(("unchecked")) List<HtmlForm> forms = (List<HtmlForm>) htmlPage.getByXPath("//form"); HtmlForm form = forms.get(1); HtmlTextInput selPerFrom = form.getInputByName("selPerFrom"); selPerFrom.setValueAttribute(dtp_lastDate.getValue().toString()); HtmlAnchor generate = (HtmlAnchor) form.getByXPath("//a[contains(@class, 'btn-investia-blue')]") .get(0); if (InvestiaGenOFX.debug) { htmlPage = InvestiaGenOFX.getWebClient() .getPage(InvestiaGenOFX.debugFullPath + "-Transactions.htm"); } else { htmlPage = generate.click(); waitForGeneratedTransactions(); } } HtmlTable htmlTable = (HtmlTable) htmlPage.getElementById("tblTransactionReports"); if (htmlTable == null) { return; } for (int i = 0; i < htmlTable.getRowCount(); i++) { LocalDate transacDate = LocalDate.parse(htmlTable.getCellAt(i, 0).getTextContent(), DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.CANADA_FRENCH)); if (transacDate.isBefore(dtp_lastDate.getValue())) { break; } String transacType = htmlTable.getCellAt(i, 2).getTextContent(); String[] token = transacType.split("[\\-/(]"); switch (token[0].replace(" ", "")) { case "Dividendes": transacType = "Distribution"; break; case "Achat": case "changeentrant": case "Prlvementautomatique": case "Transfertentrantdecourtier": case "Transfertexterneentrant": case "Transfertinterneentrant": transacType = "Purchase"; break; case "changesortant": case "Rachat": case "Transfertexternesortant": case "Transf.int.sort.": case "Transf.Int.sortant": case "Transfertinternesortant": transacType = "Switch Out"; break; case "Dpt": transacType = "Credit"; break; case "Retrait": case "Retenue": transacType = "Debit"; break; case "Crditenespces": case "Entred'espces": case "Fraisd'administration": case "Sortied'espces": case "Transfertd'espcesentrant": case "Transfertd'espcessortant": continue; default: try { throw new MyOwnException("Type de transaction non prise en charge: " + transacType.trim()); } catch (MyOwnException ex) { Logger.getLogger(OFXUtilites.class.getName()).log(Level.SEVERE, null, ex); continue; } } String transacAccount = accountOwnerName.split(" ")[0] + "\\" + htmlTable.getCellAt(i, 1).getTextContent(); String symbol = htmlTable.getCellAt(i, 3).getTextContent(); String unit = htmlTable.getCellAt(i, 5).getTextContent().replaceAll("[^0-9,]", "").replace(",", "."); String fitid = ""; String price = "0.00"; String amount; if ("Credit".equals(transacType) || "Debit".equals(transacType)) { amount = htmlTable.getCellAt(i, 9).getTextContent().replaceAll("[^0-9,]", "").replace(",", "."); fitid = StringUtils.stripAccents(htmlTable.getCellAt(i, 2).getTextContent()); } else { amount = htmlTable.getCellAt(i, 10).getTextContent().replaceAll("[^0-9,]", "").replace(",", "."); price = Float.toString(Float.parseFloat(amount) / Float.parseFloat(unit)); } if (PropertiesInit.getLinkAccountsTransac().indexOf(transacAccount) < 0) { linkAccountTransac(transacAccount); } int idxAccount = linkAccountToLocalAccountIndex[PropertiesInit.getLinkAccountsTransac() .indexOf(transacAccount)]; accounts.get(idxAccount) .add(new Transaction(transacDate, transacType, amount, fitid, symbol, unit, price, "")); } } catch (Exception ex) { Logger.getLogger(InvestiaGenOFXController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:nl.inl.blacklab.filter.DesensitizeFilter.java
@Override final public boolean incrementToken() throws IOException { if (input.incrementToken()) { String t = new String(termAtt.buffer(), 0, termAtt.length()); if (removeAccents) t = StringUtils.stripAccents(t); if (lowerCase) t = t.toLowerCase();// w ww.ja v a 2s . c o m termAtt.copyBuffer(t.toCharArray(), 0, t.length()); return true; } return false; }
From source file:nl.inl.blacklab.filter.RemoveAllAccentsFilter.java
@Override final public boolean incrementToken() throws IOException { if (input.incrementToken()) { String t = new String(termAtt.buffer(), 0, termAtt.length()); t = StringUtils.stripAccents(t); termAtt.copyBuffer(t.toCharArray(), 0, t.length()); return true; }//from ww w . j av a2 s .co m return false; }
From source file:nl.inl.blacklab.search.HitsImpl.java
/** * Count occurrences of context words around hit. * * @param propName the property to use for the collocations, or null if default * @param ctx query execution context, containing the sensitivity settings * * @return the frequency of each occurring token */// ww w . j av a 2 s. c o m @Override public synchronized TermFrequencyList getCollocations(String propName, QueryExecutionContext ctx) { if (propName == null) propName = searcher.getIndexStructure().getMainContentsField().getMainProperty().getName(); if (ctx == null) ctx = searcher.getDefaultExecutionContext(settings().concordanceField()); ctx = ctx.withProperty(propName); findContext(Arrays.asList(ctx.luceneField(false))); MutableIntIntMap coll = IntIntMaps.mutable.empty(); for (int j = 0; j < hits.size(); j++) { int[] context = contexts[j]; // Count words int contextHitStart = context[CONTEXTS_HIT_START_INDEX]; int contextRightStart = context[CONTEXTS_RIGHT_START_INDEX]; int contextLength = context[CONTEXTS_LENGTH_INDEX]; int indexInContent = CONTEXTS_NUMBER_OF_BOOKKEEPING_INTS; for (int i = 0; i < contextLength; i++, indexInContent++) { if (i >= contextHitStart && i < contextRightStart) continue; // don't count words in hit itself, just around [option..?] int w = context[indexInContent]; int n; if (!coll.contains(w)) n = 1; else n = coll.get(w) + 1; coll.put(w, n); } } // Get the actual words from the sort positions boolean caseSensitive = searcher.isDefaultSearchCaseSensitive(); boolean diacSensitive = searcher.isDefaultSearchDiacriticsSensitive(); TermFrequencyList collocations = new TermFrequencyList(coll.size()); Terms terms = searcher.getTerms(contextFieldsPropName.get(0)); Map<String, Integer> wordFreq = new HashMap<>(); for (IntIntPair e : coll.keyValuesView()) { int key = e.getOne(); int value = e.getTwo(); String word = terms.get(key); if (!diacSensitive) { word = StringUtils.stripAccents(word); } if (!caseSensitive) { word = word.toLowerCase(); } // Note that multiple ids may map to the same word (because of sensitivity settings) // Here, those groups are merged. Integer n = wordFreq.get(word); if (n == null) { n = 0; } n += value; wordFreq.put(word, n); } // Transfer from map to list for (Map.Entry<String, Integer> e : wordFreq.entrySet()) { collocations.add(new TermFrequency(e.getKey(), e.getValue())); } return collocations; }
From source file:nl.inl.util.TestStringUtil.java
@Test public void testRemoveAccents() { Assert.assertEquals("He, jij!", StringUtils.stripAccents("H, jij!")); }
From source file:nl.xs4all.home.freekdb.b52reader.general.Utilities.java
/** * Normalize a string by stripping all accents and converting it to lowercase. * * @param text the text to normalized.//from w w w.j av a 2s . c om * @return the normalized version of text. */ public static String normalize(final String text) { return text != null ? StringUtils.stripAccents(text).toLowerCase() : null; }
From source file:org.blocks4j.commons.environment.LocalHostname.java
private static String fallbackStrategy() { try {//ww w . ja v a 2 s . c om return StringUtils.stripAccents(InetAddress.getLocalHost().getHostName()); } catch (Exception e) { return null; } }
From source file:org.blocks4j.commons.environment.LocalHostname.java
private static String runtimeStrategy() { BufferedReader in = null;/*from w w w.ja v a 2 s.com*/ try { Process proc = Runtime.getRuntime().exec("hostname"); proc.waitFor(); in = new BufferedReader(new InputStreamReader(proc.getInputStream())); return StringUtils.stripAccents(in.readLine()); } catch (Exception e) { return null; } finally { if (in != null) { try { in.close(); } catch (Exception ignored) { } } } }