public static String searchAndReplace(String text, String from, String to) { from = escapeString(from, new char[]{'.', '[', ']', '\\'}, '\\'); // special chars in regex Pattern p = Pattern.compile(from); Matcher m = p.matcher(text); return m.replaceAll(to); }
public static String toCSVString(String[] fields) { StringBuilder b = new StringBuilder(); for (String fld : fields) { if (b.length() > 0) { b.append(','); } String field = escapeString(fld, new char[]{'\"'}, '\"'); // escape quotes with double quotes b.append('\"').append(field).append('\"'); } return b.toString(); }
public String toStringNoScore(Index<String> index) { if (cached == null) { cached = '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(child), charsToEscape, '\\'); } return cached; }
public String toLexicalEntry(Index<String> wordIndex, Index<String> tagIndex) { String wordStr = wordString(wordIndex); String tagStr = tagString(tagIndex); return '\"' + StringUtils.escapeString(tagStr, charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(wordStr, charsToEscape, '\\') + '\"'; }
@Override public String toString() { return "\"" + StringUtils.escapeString(head.toString(), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(arg.toString(), charsToEscape, '\\') + "\" " + (leftHeaded ? LEFT : RIGHT) + " " + distance; }
public String toString(Index<String> index) { return '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(child), charsToEscape, '\\') + "\" " + score; }
public String toStringNoScore(Index<String> index) { if (cached == null) { cached = '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(leftChild), charsToEscape, '\\') + "\" \"" + StringUtils.escapeString(index.get(rightChild), charsToEscape, '\\'); } return cached; }
public String toString(Index<String> index) { return '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(leftChild), charsToEscape, '\\') + "\" \"" + StringUtils.escapeString(index.get(rightChild), charsToEscape, '\\') + "\" " + score; }
public String toString(Index<String> wordIndex, Index<String> tagIndex) { return "\"" + StringUtils.escapeString(head.toString(wordIndex, tagIndex), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(arg.toString(wordIndex, tagIndex), charsToEscape, '\\') + "\" " + (leftHeaded ? LEFT : RIGHT) + " " + distance; }
/** Return rank of 1 gram in google ngeams if it is less than 20k. Otherwise -1. */ public static int get1GramRank(String str) { String query = null; try{ connect(); str = str.trim(); if(str.contains("'")){ str = StringUtils.escapeString(str, new char[]{'\''},'\''); } int ngram = str.split("\\s+").length; if(ngram > 1) return -1; String table = "googlengrams_1_ranked20k"; if(!existsTable(table)) return -1; String phrase = escapeString(str); query = "select rank from " + table + " where phrase='" + phrase+"';"; Statement stmt = connection.createStatement(); ResultSet result = stmt.executeQuery(query); if(result.next()){ return result.getInt("rank"); }else return -1; }catch(SQLException e){ log.info("Error getting count for " + str+ ". The query was " + query); e.printStackTrace(); throw new RuntimeException(e); } }
str = str.trim(); if(str.contains("'")){ str = StringUtils.escapeString(str, new char[]{'\''},'\'');
public static String searchAndReplace(String text, String from, String to) { from = escapeString(from, new char[]{'.', '[', ']', '\\'}, '\\'); // special chars in regex Pattern p = Pattern.compile(from); Matcher m = p.matcher(text); return m.replaceAll(to); }
public static String toCSVString(String[] fields) { StringBuilder b = new StringBuilder(); for (String fld : fields) { if (b.length() > 0) { b.append(','); } String field = escapeString(fld, new char[]{'\"'}, '\"'); // escape quotes with double quotes b.append('\"').append(field).append('\"'); } return b.toString(); }
public String toStringNoScore(Index<String> index) { if (cached == null) { cached = '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(leftChild), charsToEscape, '\\') + "\" \"" + StringUtils.escapeString(index.get(rightChild), charsToEscape, '\\'); } return cached; }
public String toLexicalEntry() { String wordStr = wordString(); String tagStr = tagString(); return '\"' + StringUtils.escapeString(tagStr, charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(wordStr, charsToEscape, '\\') + '\"'; }
public String toLexicalEntry(Index<String> wordIndex, Index<String> tagIndex) { String wordStr = wordString(wordIndex); String tagStr = tagString(tagIndex); return '\"' + StringUtils.escapeString(tagStr, charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(wordStr, charsToEscape, '\\') + '\"'; }
public String toStringNoScore(Index<String> index) { if (cached == null) { cached = '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(child), charsToEscape, '\\'); } return cached; }
public String toStringNoScore(Index<String> index) { if (cached == null) { cached = '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(leftChild), charsToEscape, '\\') + "\" \"" + StringUtils.escapeString(index.get(rightChild), charsToEscape, '\\'); } return cached; }
public String toStringNoScore(Index<String> index) { if (cached == null) { cached = '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(child), charsToEscape, '\\'); } return cached; }
public String toString(Index<String> index) { return '\"' + StringUtils.escapeString(index.get(parent), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(index.get(child), charsToEscape, '\\') + "\" " + score; }