List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:reviews.indexing.HTMLDocument.java
public static Document Document(File f, SWN swn) throws IOException, InterruptedException { // make a new, empty document Document doc = new Document(); // Add the url as a field named "path". Use a field that is // indexed (i.e. searchable), but don't tokenize the field into words. doc.add(new Field("path", f.getPath().replace(dirSep, '/'), Field.Store.YES, Field.Index.NOT_ANALYZED)); // Add the last modified date of the file a field named "modified". // Use a field that is indexed (i.e. searchable), but don't tokenize // the field into words. doc.add(new Field("modified", DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE), Field.Store.YES, Field.Index.NOT_ANALYZED)); // Add the uid as a field, so that index can be incrementally // maintained. // This field is not stored with document, it is indexed, but it is not // tokenized prior to indexing. doc.add(new Field("uid", uid(f), Field.Store.NO, Field.Index.NOT_ANALYZED)); FileInputStream fis = new FileInputStream(f); HTMLParser parser = new HTMLParser(fis); Reader reader = parser.getReader(); // getting text content String contents = ""; int c;// w w w . j a va 2 s.com while ((c = reader.read()) != -1) { char buf[] = Character.toChars(c); contents += String.valueOf(buf); } // clean the review content ReviewContentCleaner rcc = new ReviewContentCleaner(contents); HashMap<String, ArrayList<FeatureMapData>> featureMap = new HashMap<String, ArrayList<FeatureMapData>>(); // creates a StanfordCoreNLP object, with POS tagging, parsing Properties props = new Properties(); props.put("annotators", "tokenize, ssplit, pos"); props.put("pos.model", "left3words-wsj-0-18.tagger"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); // Here you can adjust the score bonus and the score modifier for review pros and cons. // Default, score bonus is +2.0 for pros, -2.0 for cons and 0.0 for summary. // Default, score modifier is 1.0 for all. // process review pros featureMap = processReviewSegment(pipeline, swn, featureMap, rcc.getPros(), 2.0, 1.0); // process review cons featureMap = processReviewSegment(pipeline, swn, featureMap, rcc.getCons(), -2.0, 1.0); // process review summary featureMap = processReviewSegment(pipeline, swn, featureMap, rcc.getSummary(), 0.0, 1.0); String features = ""; for (String s : featureMap.keySet()) { features += s + " "; } System.out.println(features); doc.add(new Field("features", features, Field.Store.YES, Field.Index.ANALYZED)); JSONObject serializedFeatureMap = new JSONObject(); try { serializedFeatureMap.put("featureMap", featureMap); doc.add(new Field("feature-contents", serializedFeatureMap.toString(), Field.Store.YES, Field.Index.NO)); } catch (JSONException e) { e.printStackTrace(); } // doc.add(new Field("contents", parser.getReader())); // Add the summary as a field that is stored and returned with // hit documents for display doc.add(new Field("summary", parser.getSummary(), Field.Store.YES, Field.Index.NO)); // Add the title as a field that it can be searched and that is stored. doc.add(new Field("title", parser.getTitle(), Field.Store.YES, Field.Index.ANALYZED)); // return the document return doc; }
From source file:org.eclipse.rdf4j.rio.nquads.NQuadsParser.java
protected int parseContext(int c) throws IOException, RDFParseException { StringBuilder sb = new StringBuilder(100); // subject is either an uriref (<foo://bar>) or a nodeID (_:node1) if (c == '<') { // subject is an uriref c = parseUriRef(c, sb);/*from w w w . j a v a 2 s. c om*/ context = createURI(sb.toString()); } else if (c == '_') { // subject is a bNode c = parseNodeID(c, sb); context = createNode(sb.toString()); } else if (c == -1) { throwEOFException(); } else { reportFatalError("Expected '<' or '_', found: " + new String(Character.toChars(c))); } return c; }
From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java
/** * Numbering scheme using UTF Fullwidth Latin Small Letter (lower case) characters `?-`. * /*from ww w . j a v a2s .c om*/ * ---- * ? item 1 * item 2 * item 3 * ... * item 26 * ---- * * @return the line */ public static TA_Numbering alphaFullwidthLatinSmallLetter() { return new TA_Numbering() { @Override public String getNumber(int number) { Validate.validState(0 < number && number < 27, "numbering supported 0<number<27 - number was: " + number); return new String(Character.toChars(number + 65344)); } @Override public int getMinNumber() { return 1; } @Override public int getMaxNumber() { return 26; } @Override public String getDescription() { return "numbering scheme using UTF Fullwidth Latin Small Letter (lower case) characters '?-'"; } }; }
From source file:org.openrdf.rio.nquads.NQuadsParser.java
protected int parseContext(int c) throws IOException, RDFParseException { StringBuilder sb = new StringBuilder(100); // subject is either an uriref (<foo://bar>) or a nodeID (_:node1) if (c == '<') { // subject is an uriref c = parseUriRef(c, sb);/*from w ww . j a v a2 s . com*/ context = createURI(sb.toString()); } else if (c == '_') { // subject is a bNode c = parseNodeID(c, sb); context = createBNode(sb.toString()); } else if (c == -1) { throwEOFException(); } else { reportFatalError("Expected '<' or '_', found: " + new String(Character.toChars(c))); } return c; }
From source file:org.deviceconnect.message.http.impl.factory.AbstractHttpMessageFactory.java
/** * HTTP???dConnect???.//w ww.j a v a2 s.c o m * @param dmessage dConnect * @param message HTTP */ protected void parseHttpBody(final DConnectMessage dmessage, final M message) { mLogger.entering(getClass().getName(), "newDConnectMessage", new Object[] { dmessage, message }); HttpEntity entity = getHttpEntity(message); if (entity != null) { MimeStreamParser parser = new MimeStreamParser(new MimeEntityConfig()); MultipartContentHandler handler = new MultipartContentHandler(dmessage); parser.setContentHandler(handler); StringBuilder headerBuffer = new StringBuilder(); for (Header header : message.getAllHeaders()) { headerBuffer.append(header.getName()); headerBuffer.append(": "); headerBuffer.append(header.getValue()); headerBuffer.append(Character.toChars(HTTP.CR)); headerBuffer.append(Character.toChars(HTTP.LF)); mLogger.fine("header: " + header.getName() + ":" + header.getValue()); } headerBuffer.append(Character.toChars(HTTP.CR)); headerBuffer.append(Character.toChars(HTTP.LF)); try { parser.parse(new SequenceInputStream( new ByteArrayInputStream(headerBuffer.toString().getBytes("US-ASCII")), entity.getContent())); } catch (IllegalStateException e) { mLogger.log(Level.FINE, e.toString(), e); mLogger.warning(e.toString()); } catch (MimeException e) { mLogger.log(Level.FINE, e.toString(), e); mLogger.warning(e.toString()); } catch (IOException e) { mLogger.log(Level.FINE, e.toString(), e); mLogger.warning(e.toString()); } } mLogger.exiting(getClass().getName(), "newDConnectMessage"); }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Full Stop characters. * @param number to convert// ww w. j a v a2s .c o m * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 20) */ public final static String toFullStop(int number) { if (number < 1 || number > 20) { throw new NotImplementedException( "Arabic literals - UTF Full Stop - supported 0<number<21 - number was: " + number); } return new String(Character.toChars(number + 9351)); }
From source file:org.kitodo.dataaccess.format.xml.Namespaces.java
/** * Returns a sequence of letters from a positive whole number. * * @param value/*from w w w . j av a2 s. c o m*/ * number to convert * @return a, b, c, , x, y, z, aa, ab, ac, */ private static String asLetters(long value) { int codePoint = (int) ('a' + (--value % 26)); long higher = value / 26; String letter = new String(Character.toChars(codePoint)); return higher == 0 ? letter : asLetters(higher).concat(letter); }
From source file:org.wso2.carbon.appmgt.hostobjects.HostObjectUtils.java
/** * Returns the text (key {@code text}) and color (key {@code color}) of the default thumbnail based on the specified app name. * @param appName app name//from w ww . ja v a2 s. c o m * @return default thumbnail data * @exception IllegalArgumentException if {@code appName} is {@code null} or empty */ public static Map<String, String> getDefaultThumbnail(String appName) { if (appName == null) { throw new IllegalArgumentException("Invalid argument. App name cannot be null."); } if (appName.isEmpty()) { throw new IllegalArgumentException("Invalid argument. App name cannot be empty."); } String defaultThumbnailText; if (appName.length() == 1) { // only one character in the app name defaultThumbnailText = appName; } else { // there are more than one character in the app name String[] wordsInAppName = StringUtils.split(appName); int firstCodePoint, secondCodePoint; if (wordsInAppName.length == 1) { // one word firstCodePoint = Character.toTitleCase(wordsInAppName[0].codePointAt(0)); secondCodePoint = wordsInAppName[0].codePointAt(Character.charCount(firstCodePoint)); } else { // two or more words firstCodePoint = Character.toTitleCase(wordsInAppName[0].codePointAt(0)); secondCodePoint = wordsInAppName[1].codePointAt(0); } defaultThumbnailText = (new StringBuffer()).append(Character.toChars(firstCodePoint)) .append(Character.toChars(secondCodePoint)).toString(); } String defaultThumbnailColor = DEFAULT_THUMBNAIL_COLORS[Math.abs(appName.hashCode()) % DEFAULT_THUMBNAIL_COLORS.length]; Map<String, String> defaultThumbnail = new HashMap<String, String>(2); defaultThumbnail.put("text", defaultThumbnailText); defaultThumbnail.put("color", defaultThumbnailColor); return defaultThumbnail; }
From source file:org.ajax4jsf.request.MultipartRequest.java
private String decodeFileName(String name) { String fileName = null;//from w ww.java2s . co m try { if (getRequest().getParameter("_richfaces_send_http_error") != null) { fileName = new String(name.getBytes(encoding), "UTF-8"); } else { StringBuffer buffer = new StringBuffer(); String[] codes = name.split(";"); if (codes != null) { for (String code : codes) { if (code.startsWith("&")) { String sCode = code.replaceAll("[&#]*", ""); Integer iCode = Integer.parseInt(sCode); buffer.append(Character.toChars(iCode)); } else { buffer.append(code); } } fileName = buffer.toString(); } } } catch (Exception e) { fileName = name; } return fileName; }
From source file:net.metanotion.json.StreamingParser.java
private String lexExp(final Reader in) throws IOException { in.mark(MAX_BUFFER);//from w w w. ja va 2 s. c o m int c = in.read(); if (Character.toLowerCase(c) == 'e') { c = in.read(); if (c == '+') { return "e+" + lexDigits(in); } else if (c == '-') { return "e-" + lexDigits(in); } else if (Character.isDigit(c)) { return (new String(Character.toChars(c))) + lexDigits(in); } else if (c == -1) { throw new ParserException("Unexpected end of stream"); } else { throw new ParserException( "Expected exponent, instead found: '" + (new String(Character.toChars(c))) + QUOTE); } } else { in.reset(); return ""; } }