Jave normalize

60 Jave code examples are found related to " normalize". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: Arc2D.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static double normalizeDegrees(double angle) {
    if (angle > 180.0) {
        if (angle <= (180.0 + 360.0)) {
            angle = angle - 360.0;
        } else {
            angle = Math.IEEEremainder(angle, 360.0);
            // IEEEremainder can return -180 here for some input values...
            if (angle == -180.0) {
                angle = 180.0;
            }
        }
    } else if (angle <= -180.0) {
        if (angle > (-180.0 - 360.0)) {
            angle = angle + 360.0;
        } else {
            angle = Math.IEEEremainder(angle, 360.0);
            // IEEEremainder can return -180 here for some input values...
            if (angle == -180.0) {
                angle = 180.0;
            }
        }
    }
    return angle;
}
 
Example 2
Source File: IdlTextParser.java    From smithy with Apache License 2.0 6 votes vote down vote up
private static String normalizeLineEndings(String lexeme) {
    if (!containsCarriageReturn(lexeme)) {
        return lexeme;
    }

    StringBuilder builder = new StringBuilder(lexeme.length());
    for (int i = 0; i < lexeme.length(); i++) {
        char c = lexeme.charAt(i);
        if (c != '\r') {
            builder.append(c);
        } else {
            // Convert "\r\n" to "\n".
            if (i < lexeme.length() - 1 && lexeme.charAt(i + 1) == '\n') {
                i++;
            }
            builder.append('\n');
        }
    }

    return builder.toString();
}
 
Example 3
Source File: DocHelper.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Normalizes a point so that it is biased towards text nodes, and node ends
 * rather than node start.
 *
 * @param <N>
 * @param <E>
 * @param <T>
 * @param point
 * @param doc
 */
public static <N, E extends N, T extends N> Point<N> normalizePoint(Point<N> point,
    ReadableDocument<N, E, T> doc) {
  N previous = null;
  if (!point.isInTextNode()) {
    previous = Point.nodeBefore(doc, point.asElementPoint());
    T nodeAfterAsText = doc.asText(point.getNodeAfter());
    if (nodeAfterAsText != null) {
      point = Point.<N>inText(nodeAfterAsText, 0);
    }
  } else if (point.getTextOffset() == 0) {
    previous = doc.getPreviousSibling(point.getContainer());
  }

  T previousAsText = doc.asText(previous);
  if (previous != null && previousAsText != null) {
    point = Point.inText(previous, doc.getLength(previousAsText));
  }

  return point;
}
 
Example 4
Source File: UpdateSiteLoader.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private URI normalizeSiteUri(URI uri, URI defaultValue) {
    if (uri == null) {
        return defaultValue;
    }
    String uriString = uri.toString();
    if (uriString.endsWith("site.xml")) {
        try {
            return new URI(uriString.substring(0, uriString.length() - 8));
        } catch (URISyntaxException e) {
            throw new RuntimeException("Illegal uri", e);
        }
    }
    if (!uriString.endsWith("/")) {
        try {
            return new URI(uriString + "/");
        } catch (URISyntaxException e) {
            throw new RuntimeException("Illegal uri", e);
        }
    }
    return uri;
}
 
Example 5
Source File: WebGraph.java    From nutch-htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Normalizes and trims extra whitespace from the given url.
 * 
 * @param url The url to normalize.
 * 
 * @return The normalized url.
 */
private String normalizeUrl(String url) {

  if (!normalize) {
    return url;
  }

  String normalized = null;
  if (urlNormalizers != null) {
    try {

      // normalize and trim the url
      normalized = urlNormalizers.normalize(url,
        URLNormalizers.SCOPE_DEFAULT);
      normalized = normalized.trim();
    }
    catch (Exception e) {
      LOG.warn("Skipping " + url + ":" + e);
      normalized = null;
    }
  }
  return normalized;
}
 
Example 6
Source File: BidRequest.java    From bidder with Apache License 2.0 6 votes vote down vote up
/**
 * Convert iso2 country codes to iso3. C1X and bidswitch need this. The database
 * key device.geo.country shadows the json object. So we do a lookup and replace
 * it. But, then, we also need to replace the textnode of the bid request,
 * becaause it is still 2 character. This means that you need to know the 2 and
 * 3 char codes for the countries to do meaningful queries.
 *
 * So, we must overrwite the bid request country field to normalize it.
 */
protected void normalizeCountryCode() {
	Object o = this.database.get("device.geo.country");
	if (o instanceof MissingNode)
		return;

	TextNode country = (TextNode) o;
	TextNode test = null;
	if (country != null) {
		test = cache.get(country.asText());
		if (test == null) {
			String iso3 = isoMap.query(country.asText());
			test = new TextNode(iso3);
		}
		if (test != country) {
			database.put("device.geo.country", test);
			JsonNode device = rootNode.get("device");
			ObjectNode geo = (ObjectNode) device.get("geo");
			geo.set("country", test);

		}
	}
}
 
Example 7
Source File: MatrixTools.java    From Juicebox with MIT License 6 votes vote down vote up
public static int[][] normalizeMatrixUsingColumnSum(int[][] matrix) {
    int[][] newMatrix = new int[matrix.length][matrix[0].length];
    int[] columnSum = new int[matrix[0].length];
    for (int[] row : matrix) {
        for (int i = 0; i < row.length; i++) {
            columnSum[i] += row[i];
        }
    }

    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[i].length; j++) {
            newMatrix[i][j] = matrix[i][j] / columnSum[j];
        }
    }

    return newMatrix;
}
 
Example 8
Source File: DataNormalization.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
/**
 * Normalizes data matrix
 * 
 * @param data matrix to be normalized
 * @return normalized matrix
 */
public double[][] normalize(double[][] data) {

	int rows = data.length;
	int cols = data[0].length;

	if ((minValues == null) && (maxValues == null) && (meanValues == null) && (stdValues == null))
		calculateReference(data);

	double[][] normalizedData = new double[rows][cols];

	for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
			switch (TYPE) {
			case MIN_MAX:
				normalizedData[i][j] = (minNorm)
						+ ((data[i][j] - minValues[j]) / (maxValues[j] - minValues[j])) * (scaleNorm);
				break;
			case ZSCORE:
				normalizedData[i][j] = scaleNorm * (data[i][j] - meanValues[j]) / stdValues[j];
				break;
			}
		}
	}
	return normalizedData;
}
 
Example 9
Source File: Placement.java    From Mindustry with GNU General Public License v3.0 6 votes vote down vote up
/** Normalize two points into one straight line, no diagonals. */
public static Seq<Point2> normalizeLine(int startX, int startY, int endX, int endY){
    Pools.freeAll(points);
    points.clear();
    if(Math.abs(startX - endX) > Math.abs(startY - endY)){
        //go width
        for(int i = 0; i <= Math.abs(startX - endX); i++){
            points.add(Pools.obtain(Point2.class, Point2::new).set(startX + i * Mathf.sign(endX - startX), startY));
        }
    }else{
        //go height
        for(int i = 0; i <= Math.abs(startY - endY); i++){
            points.add(Pools.obtain(Point2.class, Point2::new).set(startX, startY + i * Mathf.sign(endY - startY)));
        }
    }
    return points;
}
 
Example 10
Source File: DeNormalize.java    From joshua with Apache License 2.0 6 votes vote down vote up
/**
 * Scanning from left-to-right, a comma or period preceded by a space will become just the
 * comma/period.
 * 
 * @param line The single-line input string
 * @return The input string modified as described above
 */
public static String joinPunctuationMarks(String line) {
  String result = line;
  result = result.replace(" ,", ",");
  result = result.replace(" ;", ";");
  result = result.replace(" :", ":");
  result = result.replace(" .", ".");
  result = result.replace(" !", "!");
  result = result.replace("¡ ", "¡");
  result = result.replace(" ?", "?");
  result = result.replace("¿ ", "¿");
  result = result.replace(" )", ")");
  result = result.replace(" ]", "]");
  result = result.replace(" }", "}");
  result = result.replace("( ", "(");
  result = result.replace("[ ", "[");
  result = result.replace("{ ", "{");
  return result;
}
 
Example 11
Source File: BaseCalendar.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void normalizeMonth(CalendarDate date) {
    Date bdate = (Date) date;
    int year = bdate.getNormalizedYear();
    long month = bdate.getMonth();
    if (month <= 0) {
        long xm = 1L - month;
        year -= (int)((xm / 12) + 1);
        month = 13 - (xm % 12);
        bdate.setNormalizedYear(year);
        bdate.setMonth((int) month);
    } else if (month > DECEMBER) {
        year += (int)((month - 1) / 12);
        month = ((month - 1)) % 12 + 1;
        bdate.setNormalizedYear(year);
        bdate.setMonth((int) month);
    }
}
 
Example 12
Source File: BasisLibrary.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * XSLT Standard function normalize-space(string).
 */
public static String normalize_spaceF(String value) {
    int i = 0, n = value.length();
    StringBuilder result = threadLocalStringBuilder.get();
result.setLength(0);

    while (i < n && isWhiteSpace(value.charAt(i)))
        i++;

    while (true) {
        while (i < n && !isWhiteSpace(value.charAt(i))) {
            result.append(value.charAt(i++));
        }
        if (i == n)
            break;
        while (i < n && isWhiteSpace(value.charAt(i))) {
            i++;
        }
        if (i < n)
            result.append(' ');
    }
    return result.toString();
}
 
Example 13
Source File: URLPermission.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private List<String> normalizeMethods(String methods) {
    List<String> l = new ArrayList<>();
    StringBuilder b = new StringBuilder();
    for (int i=0; i<methods.length(); i++) {
        char c = methods.charAt(i);
        if (c == ',') {
            String s = b.toString();
            if (s.length() > 0)
                l.add(s);
            b = new StringBuilder();
        } else if (c == ' ' || c == '\t') {
            throw new IllegalArgumentException("white space not allowed");
        } else {
            if (c >= 'a' && c <= 'z') {
                c += 'A' - 'a';
            }
            b.append(c);
        }
    }
    String s = b.toString();
    if (s.length() > 0)
        l.add(s);
    return l;
}
 
Example 14
Source File: Util.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static String normalizeNewlines(String text) {
    StringBuilder sb = new StringBuilder();
    final int textLength = text.length();
    final String NL = DocletConstants.NL;
    int pos = 0;
    for (int i = 0; i < textLength; i++) {
        char ch = text.charAt(i);
        switch (ch) {
            case '\n':
                sb.append(text, pos, i);
                sb.append(NL);
                pos = i + 1;
                break;
            case '\r':
                sb.append(text, pos, i);
                sb.append(NL);
                if (i + 1 < textLength && text.charAt(i + 1) == '\n')
                    i++;
                pos = i + 1;
                break;
        }
    }
    sb.append(text, pos, textLength);
    return sb.toString();
}
 
Example 15
Source File: MutableBigInteger.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure that the MutableBigInteger is in normal form, specifically
 * making sure that there are no leading zeros, and that if the
 * magnitude is zero, then intLen is zero.
 */
final void normalize() {
    if (intLen == 0) {
        offset = 0;
        return;
    }

    int index = offset;
    if (value[index] != 0)
        return;

    int indexBound = index+intLen;
    do {
        index++;
    } while(index < indexBound && value[index] == 0);

    int numZeros = index - offset;
    intLen -= numZeros;
    offset = (intLen == 0 ?  0 : offset+numZeros);
}
 
Example 16
Source File: InfoMessageDaoImpl.java    From olat with Apache License 2.0 6 votes vote down vote up
private String normalizeBusinessPath(String url) {
    if (url == null) {
        return null;
    }
    if (url.startsWith("ROOT")) {
        url = url.substring(4, url.length());
    }
    final List<String> tokens = new ArrayList<String>();
    for (final StringTokenizer tokenizer = new StringTokenizer(url, "[]"); tokenizer.hasMoreTokens();) {
        final String token = tokenizer.nextToken();
        if (!tokens.contains(token)) {
            tokens.add(token);
        }
    }

    final StringBuilder sb = new StringBuilder();
    for (final String token : tokens) {
        sb.append('[').append(token).append(']');
    }
    return sb.toString();
}
 
Example 17
Source File: KryoSerializer.java    From incubator-heron with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private static Map<String, String> normalizeKryoRegister(Map<String, Object> config) {
  // TODO: de-duplicate this logic with the code in nimbus
  Object res = config.get(Config.TOPOLOGY_KRYO_REGISTER);
  if (res == null) {
    return new TreeMap<String, String>();
  }
  Map<String, String> ret = new HashMap<>();
  // Register config is a list. Each value can be either a String or a map
  for (Object o: (List) res) {
    if (o instanceof Map) {
      ret.putAll((Map) o);
    } else {
      ret.put((String) o, null);
    }
  }

  //ensure always same order for registrations with TreeMap
  return new TreeMap<String, String>(ret);
}
 
Example 18
Source File: PDFTextStripper.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Normalize the given list of TextPositions.
 * 
 * @param line list of TextPositions
 * @return a list of strings, one string for every word
 */
private List<WordWithTextPositions> normalize(List<LineItem> line)
{
    List<WordWithTextPositions> normalized = new LinkedList<WordWithTextPositions>();
    StringBuilder lineBuilder = new StringBuilder();
    List<TextPosition> wordPositions = new ArrayList<TextPosition>();

    for (LineItem item : line)
    {
        lineBuilder = normalizeAdd(normalized, lineBuilder, wordPositions, item);
    }

    if (lineBuilder.length() > 0)
    {
        normalized.add(createWord(lineBuilder.toString(), wordPositions));
    }
    return normalized;
}
 
Example 19
Source File: UriHelper.java    From azure-mobile-apps-android-client with Apache License 2.0 6 votes vote down vote up
/**
 * Normalizes the parameters to add it to the Url
 *
 * @param parameters list of the parameters.
 * @return the parameters to add to the url.
 */
public static String normalizeParameters(HashMap<String, String> parameters) {

    String result = "";

    if (parameters != null && parameters.size() > 0) {
        for (Map.Entry<String, String> parameter : parameters.entrySet()) {

            if (result.isEmpty()) {
                result = "?";
            } else {
                result += "&";
            }

            result += parameter.getKey() + "=" + parameter.getValue();
        }
    }

    return result;
}
 
Example 20
Source File: UriHelper.java    From azure-mobile-apps-android-client with Apache License 2.0 6 votes vote down vote up
public static String normalizeAndUrlEncodeParameters(HashMap<String, String> parameters, String encoding) {
    String result = "";

    if (parameters != null && parameters.size() > 0) {
        for (Map.Entry<String, String> parameter : parameters.entrySet()) {

            if (result.isEmpty()) {
                result = "?";
            } else {
                result += "&";
            }

            try {
                result += URLEncoder.encode(parameter.getKey(), encoding) + "=" + URLEncoder.encode(parameter.getValue(), encoding);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }

    return result;
}
 
Example 21
Source File: SQLiteLocalStore.java    From azure-mobile-apps-android-client with Apache License 2.0 6 votes vote down vote up
private String normalizeColumnName(String columnName) {
    String invColumnName = columnName != null ? columnName.trim().toLowerCase(Locale.getDefault()) : null;

    if (invColumnName == null || columnName.length() == 0) {
        throw new IllegalArgumentException("Column name cannot be null or empty.");
    }

    if (invColumnName.length() > 128) {
        throw new IllegalArgumentException("Column name cannot be longer than 128 characters.");
    }

    if (invColumnName.matches("[a-zA-Z_]/w*")) {
        throw new IllegalArgumentException(
                "Column name must start with a letter or underscore, and can contain only alpha-numeric characters and underscores.");
    }

    if (invColumnName.matches("__/w*") && !isSystemProperty(invColumnName)) {
        throw new IllegalArgumentException("Column names prefixed with \"__\" are system reserved.");
    }

    return invColumnName;
}
 
Example 22
Source File: BooleanNormalizer.java    From sql-parser with Eclipse Public License 1.0 6 votes vote down vote up
/** Normalize a top-level boolean expression. */
public ValueNode normalizeExpression(ValueNode boolClause) throws StandardException {
    /* For each expression tree:
     *  o Eliminate NOTs (eliminateNots())
     *  o Ensure that there is an AndNode on top of every
     *      top level expression. (putAndsOnTop())
     *  o Finish the job (changeToCNF())
     */
    if (boolClause != null) {
        boolClause = eliminateNots(boolClause, false);
        assert verifyEliminateNots(boolClause);
        boolClause = putAndsOnTop(boolClause);
        assert verifyPutAndsOnTop(boolClause);
        boolClause = changeToCNF(boolClause, true);
        assert verifyChangeToCNF(boolClause, true);
    }
    return boolClause;
}
 
Example 23
Source File: TextUtils.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
private static String normalizeIndentationFromWhitespace(String str, int tabSize, boolean insertSpaces) {
	int spacesCnt = 0;
	for (int i = 0; i < str.length(); i++) {
		if (str.charAt(i) == '\t') {
			spacesCnt += tabSize;
		} else {
			spacesCnt++;
		}
	}

	StringBuilder result = new StringBuilder();
	if (!insertSpaces) {
		long tabsCnt = Math.round(Math.floor(spacesCnt / tabSize));
		spacesCnt = spacesCnt % tabSize;
		for (int i = 0; i < tabsCnt; i++) {
			result.append('\t');
		}
	}

	for (int i = 0; i < spacesCnt; i++) {
		result.append(' ');
	}

	return result.toString();
}
 
Example 24
Source File: DirectiveUtil.java    From react-templates-plugin with MIT License 6 votes vote down vote up
public static String normalizeAttributeName(String name) {
    if (name == null) return null;
    if (name.startsWith("data-")) {
        name = name.substring(5);
    } else if (name.startsWith("x-")) {
        name = name.substring(2);
    }
    name = name.replace(':', '-');
    name = name.replace('_', '-');
    if (name.endsWith("-start")) {
        name = name.substring(0, name.length() - 6);
    } else if (name.endsWith("-end")) {
        name = name.substring(0, name.length() - 4);
    }
    return name;
}
 
Example 25
Source File: AddressInformation.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
private static String normalizePhysicalUri(String physicalUri) {
    if (StringUtils.isEmpty(physicalUri)) {
        return physicalUri;
    }

    // backend returns non normalized uri with "//" tail
    // e.g, https://cdb-ms-prod-westus2-fd2.documents.azure.com:15248/apps/4f5c042d-76fb-4ce6-bda3-517e6ef3984f/
    // services/cf4b9ab2-019c-45ca-ac88-25a92b66dddf/partitions/2078862a-d698-475b-a308-02598370d1d9/replicas/132077748219659199s//
    // we should trim the tail double "//"

    int i = physicalUri.length() -1;

    while(i >= 0 && physicalUri.charAt(i) == '/') {
        i--;
    }

    return physicalUri.substring(0, i + 1) + '/';
}
 
Example 26
Source File: MDMcomparable.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
private void normalizeDocumentVectors(Matrix termByDocument){
	JatecsLogger.status().println("Normalizing document-vectors");
	int rows=termByDocument.getRowDimension();
	int cols=termByDocument.getColumnDimension();
	for(int c = 0; c < cols; c++){
		double norm=0.0;
		for(int f = 0; f < rows; f++){
			norm+=(termByDocument.get(f, c)*termByDocument.get(f, c));
		}
		norm = Math.sqrt(norm);
		for(int f = 0; f < rows; f++){
			double old = termByDocument.get(f, c);
			termByDocument.set(f, c, old / norm);
		}
	}
	JatecsLogger.status().println("[done].");
}
 
Example 27
Source File: RefactoringInfo.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public String normalizeSourceSelection(ICoreTextSelection selection) {
    String selectedText = "";

    if (selection.getText() != null) {
        selectedText = selection.getText().trim();
    }
    if (selectedText.length() == 0) {
        return "";
    }

    try {
        return normalizeBlockIndentation(selection, selectedText);
    } catch (Throwable e) {
        /* TODO: uncommented empty exception catch all */
    }
    return selectedText;

}
 
Example 28
Source File: TestNormalize.java    From yauaa with Apache License 2.0 6 votes vote down vote up
@Test
public void checkBrandNormalizationExamples() {
    // At least 3 lowercase
    assertEquals("NielsBasjes",      Normalize.brand("NielsBasjes"));
    assertEquals("NielsBasjes",      Normalize.brand("NIelsBasJES"));
    assertEquals("BlackBerry",       Normalize.brand("BlackBerry"));

    // Less than 3 lowercase
    assertEquals("Nielsbasjes",      Normalize.brand("NIelSBasJES"));
    assertEquals("Blackberry",       Normalize.brand("BLACKBERRY"));

    // Multiple words. Short words (1,2,3 letters) go full uppercase
    assertEquals("Niels NBA Basjes", Normalize.brand("NIels NbA BasJES"));
    assertEquals("LG",               Normalize.brand("lG"));
    assertEquals("HTC",              Normalize.brand("hTc"));
    assertEquals("Sony",             Normalize.brand("sOnY"));
    assertEquals("Asus",             Normalize.brand("aSuS"));
}
 
Example 29
Source File: Quat4d.java    From sensorhub with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Normalizes quaternion q and places the result into this quaternion
 * @param q other quaternion
 * @return reference to this quaternion for chaining other operations
 */
public final Quat4d normalize(final Quat4d q)
{
    double norm = (q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);

    if (norm > 0.0)
    {
        norm = 1.0 / Math.sqrt(norm);
        this.x = norm * q.x;
        this.y = norm * q.y;
        this.z = norm * q.z;
        this.w = norm * q.w;
    }
    else
    {
        this.x = 0.0;
        this.y = 0.0;
        this.z = 0.0;
        this.w = 0.0;
    }
    
    return this;
}
 
Example 30
Source File: ResourceParser.java    From agrest with Apache License 2.0 6 votes vote down vote up
/**
 * Strips leading and trailing slash from the path for further resolution against the base
 */
// From @Path javadoc:
//   Paths are relative. For an annotated class the base URI is the application path, see {@link ApplicationPath}.
//   For an annotated method the base URI is the effective URI of the containing class. For the purposes of
//   absolutizing a path against the base URI , a leading '/' in a path is ignored and base URIs are treated as if
//   they ended in '/'.
private static String normalizePathSegment(String path) {

    if (path == null || path.length() == 0 || path.equals("/")) {
        return "";
    }

    if (path.startsWith("/")) {
        path = path.substring(1);
    }

    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }

    return path;
}
 
Example 31
Source File: StringParser.java    From AML-Project with Apache License 2.0 6 votes vote down vote up
/**
 * @param s: the name to normalize
 * @return the normalized name
 */
public static String normalizeProperty(String name)
{
	//First replace codes with their word equivalents 
	String parsed = name.replace("&amp","and");
	parsed = parsed.replace("&apos;","'");
	parsed = parsed.replace("&nbsp;"," ");
	//Remove dashes
	parsed = parsed.replaceAll("-","");
	//Then replace all other non-word characters with white spaces
	//except for apostrophes and brackets
	parsed = parsed.replaceAll(" *[^a-zA-Z0-9'()] *"," ");
	
	//Then remove multiple, leading and trailing spaces
	parsed = parsed.replaceAll(" {2,}"," ");
	parsed = parsed.trim();
	
	//Then normalize the case changes and return the result
	parsed = normalizeCaseChanges(parsed,true);
	return parsed;
}
 
Example 32
Source File: TransportTest.java    From javamail with Apache License 2.0 6 votes vote down vote up
private static String normalizeContent(String input) {
    Pattern trimTailPattern = Pattern.compile("[ \t]+$");
    StringBuilder sb = new StringBuilder();
    for(String line : input.split("\n")) {
        line = trimTailPattern.matcher(line).replaceAll("");
        if (line.startsWith("Message-ID:")) {
            sb.append("Message-ID: testID\n");
            continue;
        }
        if (line.startsWith("\tboundary=")) {
            sb.append("\tboundary=\"tb\"\n");
            continue;
        }
        if (line.startsWith("------=_Part")) {
            sb.append("------=_Part_XYZ--\n");
            continue;
        }
        sb.append(line).append('\n');
    }
    return sb.toString().replaceAll("\r", "");
}
 
Example 33
Source File: PDFTextStripper.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Used within {@link #normalize(List)} to handle a {@link TextPosition}.
 * 
 * @return The StringBuilder that must be used when calling this method.
 */
private StringBuilder normalizeAdd(List<WordWithTextPositions> normalized,
        StringBuilder lineBuilder, List<TextPosition> wordPositions, LineItem item)
{
    if (item.isWordSeparator())
    {
        normalized.add(
                createWord(lineBuilder.toString(), new ArrayList<TextPosition>(wordPositions)));
        lineBuilder = new StringBuilder();
        wordPositions.clear();
    }
    else
    {
        TextPosition text = item.getTextPosition();
        lineBuilder.append(text.getUnicode());
        wordPositions.add(text);
    }
    return lineBuilder;
}
 
Example 34
Source File: RawUploadHandlerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void testNormalizePath(String directory, String file, String expectedPath) throws IOException {
  reset(rawFacet);
  ComponentUpload component = new ComponentUpload();

  component.getFields().put("directory", directory);

  AssetUpload asset = new AssetUpload();
  asset.getFields().put("filename", file);
  asset.setPayload(jarPayload);
  component.getAssetUploads().add(asset);

  when(assetPayload.componentId()).thenReturn(new DetachedEntityId("foo"));
  when(attributesMap.get(Asset.class)).thenReturn(assetPayload);
  when(content.getAttributes()).thenReturn(attributesMap);
  when(rawFacet.put(any(), any())).thenReturn(content);
  underTest.handle(repository, component);

  ArgumentCaptor<String> pathCapture = ArgumentCaptor.forClass(String.class);
  verify(rawFacet).put(pathCapture.capture(), any(PartPayload.class));

  String path = pathCapture.getValue();
  assertNotNull(path);
  assertThat(path, is(expectedPath));
}
 
Example 35
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Normalizes the binding so that it can be used as a type inside a declaration (e.g. variable
 * declaration, method return type, parameter type, ...).
 * For null bindings, java.lang.Object is returned.
 * For void bindings, <code>null</code> is returned.
 * 
 * @param binding binding to normalize
 * @param ast current AST
 * @return the normalized type to be used in declarations, or <code>null</code>
 */
public static ITypeBinding normalizeForDeclarationUse(ITypeBinding binding, AST ast) {
	if (binding.isNullType())
		return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	if (binding.isPrimitive())
		return binding;
	binding= normalizeTypeBinding(binding);
	if (binding == null || !binding.isWildcardType())
		return binding;
	ITypeBinding bound= binding.getBound();
	if (bound == null || !binding.isUpperbound()) {
		ITypeBinding[] typeBounds= binding.getTypeBounds();
		if (typeBounds.length > 0) {
			return typeBounds[0];
		} else {
			return binding.getErasure();
		}
	} else {
		return bound;
	}
}
 
Example 36
Source File: List.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** Makes sure all the items in the list have the same indentation. */
public void normalizeIndentation() {
	float max = 0;
	Element o;
	for (Iterator i = list.iterator(); i.hasNext();) {
		o = (Element) i.next();
		if (o instanceof ListItem) {
			max = Math.max(max, ((ListItem) o).getIndentationLeft());
		}
	}
	for (Iterator i = list.iterator(); i.hasNext();) {
		o = (Element) i.next();
		if (o instanceof ListItem) {
			((ListItem) o).setIndentationLeft(max);
		}
	}
}
 
Example 37
Source File: XMLGregorianCalendarImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
     * <p>Normalize this instance to UTC.</p>
     *
     * <p>2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z</p>
     * <p>Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).</p>
     */
private XMLGregorianCalendar normalizeToTimezone(int timezone) {

    int minutes = timezone;
    XMLGregorianCalendar result = (XMLGregorianCalendar) this.clone();

    // normalizing to UTC time negates the timezone offset before
    // addition.
    minutes = -minutes;
    Duration d = new DurationImpl(minutes >= 0, // isPositive
            0, //years
            0, //months
            0, //days
            0, //hours
            minutes < 0 ? -minutes : minutes, // absolute
            0  //seconds
    );
    result.add(d);

    // set to zulu UTC time.
    result.setTimezone(0);
    return result;
}
 
Example 38
Source File: MXBeanHelper.java    From garmadon with Apache License 2.0 6 votes vote down vote up
public static String normalizeName(String poolName) {
    if (poolName == null) return null;
    if ("Code Cache".equals(poolName)) {
        return MEMORY_POOL_CODE_HEADER;
    }
    if ("Tenured Gen".equals(poolName) || poolName.endsWith("Old Gen") || "GenPauseless Old Gen".equals(poolName)) {
        return MEMORY_POOL_OLD_HEADER;
    }
    if (poolName.endsWith("Perm Gen")) {
        return MEMORY_POOL_PERM_HEADER;
    }
    if ("Metaspace".equals(poolName)) {
        return MEMORY_POOL_METASPACE_HEADER;
    }
    if ("Compressed Class Space".equals(poolName)) {
        return MEMORY_POOL_COMPRESSEDCLASSPACE_HEADER;
    }
    if (poolName.endsWith("Eden Space") || "GenPauseless New Gen".equals(poolName)) {
        return MEMORY_POOL_EDEN_HEADER;
    }
    if (poolName.endsWith("Survivor Space")) {
        return MEMORY_POOL_SURVIVOR_HEADER;
    }
    return poolName;
}
 
Example 39
Source File: ConfigurationNormalizer.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Normalizes the types of the configuration's parameters to the allowed ones. References are ignored. Null values
 * are replaced with the defaults and then normalized.
 *
 * @param configuration the configuration to normalize.
 * @param configDescriptionMap the meta-data of the configuration.
 */
public static void normalizeConfiguration(Configuration configuration,
        Map<String, ConfigDescriptionParameter> configDescriptionMap) {
    for (Entry<String, ConfigDescriptionParameter> entry : configDescriptionMap.entrySet()) {
        ConfigDescriptionParameter parameter = entry.getValue();
        if (parameter != null) {
            String parameterName = entry.getKey();
            final Object value = configuration.get(parameterName);
            if (value instanceof String && ((String) value).contains("${")) {
                continue; // It is a reference
            }
            if (value == null) {
                final Object defaultValue = parameter.getDefault();
                if (defaultValue == null) {
                    configuration.remove(parameterName);
                } else {
                    configuration.put(parameterName, ConfigUtil.normalizeType(defaultValue, parameter));
                }
            } else {
                configuration.put(parameterName, ConfigUtil.normalizeType(value, parameter));
            }
        }
    }
}
 
Example 40
Source File: ShortTextSearcher.java    From short-text-search with Apache License 2.0 6 votes vote down vote up
public String normalize(String text){
    StringBuilder normal = new StringBuilder();
    for(char c : text.toCharArray()){
        if(isEnglish(c)
                || isNumber(c)
                || isChinese(c)){
            normal.append(c);
        }
    }
    if(text.length() != normal.length()){
        if(LOGGER.isDebugEnabled()){
            LOGGER.debug("移除非英语数字和中文字符, 移除之前: {}, 移除之后: {}", text, normal.toString());
        }
    }
    return normal.toString().toLowerCase();
}
 
Example 41
Source File: NormalizerLightTR.java    From sepia-assist-server with MIT License 6 votes vote down vote up
public String normalizeText(String text) {
			
	//special characters - that fail to convert to small case correctly
	text = text.replaceAll("İ", "i");
	text = text.replaceAll("I", "ı");
			
	text = text.replaceAll("(!(?!\\()|¿|¡|,(?!\\d))", "").toLowerCase().trim();
	//text = text.replaceAll("(?<![oO])'", "").trim();		//TODO: use it or not?
	//text = text.replaceAll("((?<!\\d)\\.$)", "").trim();
	text = text.replaceAll("(\\.|\\?)$", "").trim();
	
	//special characters
	//TODO: use it or not?
	text = text.replaceAll("ß","ss").replaceAll("ä","ae").replaceAll("ü","ue").replaceAll("ö","oe");
	text = text.replaceAll("é","e").replaceAll("è","e").replaceAll("ê","e");
	text = text.replaceAll("á","a").replaceAll("í","i").replaceAll("ó","o").replaceAll("ñ","n").replaceAll("ú","u");
	
	//clean up
	text = text.replaceAll("\\s+", " ").trim();
	
	return text;
}
 
Example 42
Source File: JPAEdmKey.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public void normalizeComplexKey(final ComplexType complexType, final List<PropertyRef> propertyRefList) {
  for (Property property : complexType.getProperties()) {
    try {

      SimpleProperty simpleProperty = (SimpleProperty) property;
      Facets facets = (Facets) simpleProperty.getFacets();
      if (facets == null) {
        simpleProperty.setFacets(new Facets().setNullable(false));
      } else {
        facets.setNullable(false);
      }
      PropertyRef propertyRef = new PropertyRef();
      propertyRef.setName(simpleProperty.getName());
      propertyRefList.add(propertyRef);

    } catch (ClassCastException e) {
      ComplexProperty complexProperty = (ComplexProperty) property;
      normalizeComplexKey(complexTypeView.searchEdmComplexType(complexProperty.getType()), propertyRefList);
    }

  }
}
 
Example 43
Source File: NormalizerSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testNormalizeJson() throws Exception {
    final InputStream resource = getClass().getClassLoader().getResourceAsStream("bookstore.json");
    final String request = context().getTypeConverter().convertTo(String.class, resource);

    getMockEndpoint("mock:unknown").setExpectedMessageCount(0);
    getMockEndpoint("mock:csv").setExpectedMessageCount(0);
    getMockEndpoint("mock:xml").setExpectedMessageCount(0);

    getMockEndpoint("mock:json").expectedBodiesReceived(getExpectedBookstore());
    getMockEndpoint("mock:normalized").expectedBodiesReceived(getExpectedBookstore());

    template.sendBodyAndHeader("direct:start", request, Exchange.FILE_NAME, "bookstore.json");

    assertMockEndpointsSatisfied();
}
 
Example 44
Source File: Distribution.java    From Ngram-Graphs with Apache License 2.0 6 votes vote down vote up
/**Normalizes the values of the distribution to the sum of values, resolving to a probability
 *distribution, as the sum of the new distribution will amount to 1.
 */
public void normalizeToSum() {
    double dMax = 0;
    // 1st pass - Find sum
    Iterator iValIter = hDistro.values().iterator();
    while (iValIter.hasNext()) {
        dMax += (Double)iValIter.next();
    }
    
    Iterator<TKeyType> iKeyIter = hDistro.keySet().iterator();
    while (iKeyIter.hasNext()) {
        TKeyType oKey = iKeyIter.next();
        Double dVal = (Double)hDistro.get(oKey);
        dVal /= dMax; // Normalize
        hDistro.put(oKey, dVal);
    }
}
 
Example 45
Source File: NewsFragment.java    From 4pdaClient-plus with Apache License 2.0 6 votes vote down vote up
private String normalizeCommentUrls(String body) {
    if (App.getInstance().getPreferences().getBoolean("loadNewsComment", false)) {
        body = body.replaceAll("(<div class=\"comment-box\" id=\"comments\">[\\s\\S]*?<ul class=\"page-nav box\">[\\s\\S]*?<\\/ul>)", "");
    }

    body = Pattern.compile("<iframe[^><]*?src=\"http://www.youtube.com/embed/([^\"/]*)\".*?(?:</iframe>|/>)", Pattern.CASE_INSENSITIVE)
            .matcher(body)
            .replaceAll("<a class=\"video-thumb-wrapper\" href=\"https?://www.youtube.com/watch?v=$1\"><img class=\"video-thumb\" width=\"480\" height=\"320\" src=\"https://img.youtube.com/vi/$1/0.jpg\"/></a>");
    return body
            // удаляем форму ответа
            .replaceAll("<form[^>]*action=\"/wp-comments-post.php\"[^>]*>[\\s\\S]*</form>",
                    "")
            // заменяем обрезанные ссылки
            .replace("href=\"/", "href=\"https://4pda.ru/")
            .replace("href=\"#commentform\"", "href=\"https://4pdaservice.org/#commentform");
}
 
Example 46
Source File: AbstractURLHandler.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
protected String normalizeToString(URL url) throws IOException {
    if (!"http".equals(url.getProtocol()) && !"https".equals(url.getProtocol())) {
        return url.toExternalForm();
    }

    try {
        URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(),
                url.getRef());

        // it is possible that the original url was already (partial) escaped,
        // so we must unescape all '%' followed by 2 hexadecimals...
        String uriString = uri.normalize().toASCIIString();

        // manually escape the '+' character
        uriString = uriString.replaceAll("\\+", "%2B");

        return ESCAPE_PATTERN.matcher(uriString).replaceAll("%$1");
    } catch (URISyntaxException e) {
        IOException ioe = new MalformedURLException("Couldn't convert '" + url.toString()
                + "' to a valid URI");
        ioe.initCause(e);
        throw ioe;
    }
}
 
Example 47
Source File: DocHelperTest.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Test normalize points between an element and a text node <a>stuff</a>"hi"
 */
public void testNormalizePointElementFollowedByTextNode() {
  MutableDocument<Node, Element, Text> doc = initializeMutableDoc();
  Element p = doc.asElement(doc.getFirstChild(doc.getDocumentElement()));
  assert p != null;

  Element aElement =
      doc.createElement(Point.start(doc, p), "a", Collections.<String, String> emptyMap());
  doc.insertText(Point.start(doc, aElement), "stuff");
  doc.insertText(Point.<Node> end(p), "hi");
  Text hi = doc.asText(doc.getLastChild(p));
  Text stuff = doc.asText(aElement.getFirstChild());

  assertEquals(Point.inText(hi, 0), DocHelper.normalizePoint(Point.<Node> inText(hi, 0), doc));
  assertEquals(Point.inText(hi, 0), DocHelper.normalizePoint(Point.<Node>inElement(p, hi), doc));
  // In the future, we might want to move the caret out from inline elements.
  assertEquals(Point.inText(stuff, stuff.getLength()), DocHelper.normalizePoint(Point
      .<Node> inText(stuff, stuff.getLength()), doc));
}
 
Example 48
Source File: Arc2D.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static double normalizeDegrees(double angle) {
    if (angle > 180.0) {
        if (angle <= (180.0 + 360.0)) {
            angle = angle - 360.0;
        } else {
            angle = Math.IEEEremainder(angle, 360.0);
            // IEEEremainder can return -180 here for some input values...
            if (angle == -180.0) {
                angle = 180.0;
            }
        }
    } else if (angle <= -180.0) {
        if (angle > (-180.0 - 360.0)) {
            angle = angle + 360.0;
        } else {
            angle = Math.IEEEremainder(angle, 360.0);
            // IEEEremainder can return -180 here for some input values...
            if (angle == -180.0) {
                angle = 180.0;
            }
        }
    }
    return angle;
}
 
Example 49
Source File: ComparableVersion.java    From The-5zig-Mod with GNU General Public License v3.0 6 votes vote down vote up
void normalize()
{
    for ( int i = size() - 1; i >= 0; i-- )
    {
        Item lastItem = get( i );

        if ( lastItem.isNull() )
        {
            // remove null trailing items: 0, "", empty list
            remove( i );
        }
        else if ( !( lastItem instanceof ListItem ) )
        {
            break;
        }
    }
}
 
Example 50
Source File: BeatDetector.java    From lwbd with MIT License 6 votes vote down vote up
/**
 * Normalizes all values in this hash map to [0, 1]. Does not normalize
 * keys.
 * @param map the map to normalize. This map is not modified.
 * @return The normalized map.
 */
public static LinkedHashMap<Long, Float> normalizeValues(final LinkedHashMap<Long, Float> map) {
    // normalize values to range [0, 1]
    LinkedHashMap<Long, Float> newMap = new LinkedHashMap<Long, Float>();

    // find max value
    float max = 0;
    for (Float f : map.values())
        if (f > max)
            max = f;

    // divide all values by max value
    float value;
    for (Long l : map.keySet()) {
        value = map.get(l);
        value /= max;
        newMap.put(l, value);
    }

    return newMap;
}
 
Example 51
Source File: EditorAssert.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * 'Normalises' an xml string to avoid fickleness in testing. Currently
 * we only perform a few normalisation steps:
 *
 * Self-close all empty elements, e.g., <p></p> -> <p/>
 * Replace " with '
 *
 * More can be added, e.g., to normalise whitespace, if + when needed.
 *
 * @param xml
 * @return normalised xml string
 */
private static String normalizeXml(String xml) {
  if (xml == null) {
    return null;
  }
  int index = 0;
  int last = 0;
  StringBuilder out = new StringBuilder();
  while ((index = xml.indexOf("></", index)) != -1) {
    if (xml.charAt(index - 1) == '/') {
      index += 3;
      // Already self-closing.
      continue;
    }
    int open = xml.lastIndexOf('<', index);
    if (open != -1 && xml.charAt(open + 1) != '/') {
      out.append(xml.subSequence(last, index)).append("/>");
      index = last = xml.indexOf('>', index + 1) + 1;
    } else {
      index += 3;
    }
  }
  out.append(xml.subSequence(last, xml.length()));
  return out.toString().replaceAll("\"", "'");
}
 
Example 52
Source File: AnnotationRegistry.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * @param key,
 *          a probably short-format annotation key
 * @return a normalized annotation key
 */
@JsIgnore
public static ReadableStringSet normalizeKeys(ReadableStringSet keySet) {

  StringSet normalizedKeySet = CollectionUtils.createStringSet();

  keySet.each(new Proc() {

    @Override
    public void apply(String key) {
      normalizedKeySet.add(normalizeKey(key));
    }

  });

  return normalizedKeySet;
}
 
Example 53
Source File: ReductionOpValidation.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testNormalizeMomentsOp() {
    INDArray data = Nd4j.linspace(1, 100, 100, DataType.DOUBLE).reshape(10, 10);
    INDArray ssSum = data.sum(0);
    INDArray ssSqSum = data.mul(data).sum(0);

    INDArray meanExp = data.mean(0);
    INDArray varExp = data.var(false, 0);

    INDArray mean = Nd4j.createUninitialized(DataType.DOUBLE, meanExp.shape());
    INDArray var = Nd4j.createUninitialized(DataType.DOUBLE, varExp.shape());

    OpTestCase op = new OpTestCase(new NormalizeMoments(Nd4j.scalar(DataType.DOUBLE, 10), ssSum, ssSqSum, mean, var));
    op.expectedOutput(0, meanExp);
    op.expectedOutput(1, varExp);

    String err = OpValidation.validate(op);
    assertNull(err);
}
 
Example 54
Source File: Link.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * @return best guess link annotation value from an arbitrary string. feeding
 *         the return value back through this method should always return the
 *         input.
 * @throws InvalidLinkException
 */
@SuppressWarnings("deprecation")
public static String normalizeLink(String rawLinkValue) throws InvalidLinkException {
  Preconditions.checkNotNull(rawLinkValue);
  rawLinkValue = rawLinkValue.trim();
  String[] parts = splitUri(rawLinkValue);
  String scheme = parts != null ? parts[0] : null;

  // Normal web url
  if (rawLinkValue.matches(QUERY_REGEX) || 
      (scheme != null && WEB_SCHEMES.contains(scheme))) {
    return rawLinkValue;
  }

  // default 
  return "http://"+rawLinkValue;

}
 
Example 55
Source File: MediaType.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * Normalizes the specified token.
 * 
 * @param token
 *            Token to normalize.
 * @return The normalized token.
 * @throws IllegalArgumentException
 *             if <code>token</code> is not legal.
 */
private static String normalizeToken(String token) {
    int length;
    char c;

    // Makes sure we're not dealing with a "*" token.
    token = token.trim();
    if ("".equals(token) || "*".equals(token))
        return "*";

    // Makes sure the token is RFC compliant.
    length = token.length();
    for (int i = 0; i < length; i++) {
        c = token.charAt(i);
        if (c <= 32 || c >= 127 || _TSPECIALS.indexOf(c) != -1)
            throw new IllegalArgumentException("Illegal token: " + token);
    }

    return token;
}
 
Example 56
Source File: CrawlableDatasetFile.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Return the given path with backslashes ("\") converted to slashes ("/).
 * Slashes are the normalized CrawlableDatset path seperator.
 * This method can be used on absolute or relative paths.
 * <p/>
 *
 * @param path the path to be normalized.
 * @return the normalized path.
 * @throws NullPointerException if path is null.
 */
private String normalizePath(String path) {
  // Replace any occurance of a backslash ("\") with a slash ("/").
  // NOTE: Both String and Pattern escape backslash, so need four backslashes to find one.
  // NOTE: No longer replace multiple backslashes with one slash, which allows for UNC pathnames (Windows LAN
  // addresses).
  // Was path.replaceAll( "\\\\+", "/");
  return path.replaceAll("\\\\", "/");

  // String newPath = path.replaceAll( "\\\\", "/" );
  // Note: No longer remove trailing slashes as new File() removes slashes for us.
  // // Remove trailing slashes.
  // while ( newPath.endsWith( "/" ) && ! newPath.equals( "/" ) )
  // newPath = newPath.substring( 0, newPath.length() - 1 );
  //
  // return newPath;
}
 
Example 57
Source File: Thesis.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String normalizeKeywords(String keywords) {
    StringBuilder builder = new StringBuilder();

    if (keywords == null) {
        return null;
    } else {
        for (String part : keywords.split(",")) {
            String trimmed = part.trim();

            if (trimmed.length() != 0) {
                if (builder.length() != 0) {
                    builder.append(", ");
                }

                builder.append(trimmed);
            }
        }
    }

    return builder.toString();
}
 
Example 58
Source File: JavaASTExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Hacky way to compare snippets.
 *
 * @param snippet
 * @return
 */
private String normalizeCode(final char[] snippet) {
	final List<String> tokens = (new JavaTokenizer())
			.tokenListFromCode(snippet);

	final StringBuffer bf = new StringBuffer();
	for (final String token : tokens) {
		if (token.equals(ITokenizer.SENTENCE_START)
				|| token.equals(ITokenizer.SENTENCE_END)) {
			continue;
		} else {
			bf.append(token);
		}
		bf.append(" ");
	}
	return bf.toString();

}
 
Example 59
Source File: NormalizeLinDekNeighbors.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static TObjectDoubleHashMap<String> add(TObjectDoubleHashMap<String> vector, 
		TObjectDoubleHashMap<String> oldVector, int count) {
	TObjectDoubleHashMap<String> res = new TObjectDoubleHashMap<String>();
	if (oldVector == null) {
		oldVector = new TObjectDoubleHashMap<String>();
	}
	String[] vKeys = new String[vector.size()];
	vector.keys(vKeys);
	for (int i = 0; i < vKeys.length; i++) {
		double value = vector.get(vKeys[i]) / (double)count;
		if (oldVector.contains(vKeys[i])) {
			res.put(vKeys[i], value + oldVector.get(vKeys[i]));
			oldVector.remove(vKeys[i]);
		} else {
			res.put(vKeys[i], value);
		}
	}			
	String[] oldKeys = new String[oldVector.size()];
	oldVector.keys(oldKeys);
	for (int i = 0; i < oldKeys.length; i++) {
		res.put(oldKeys[i], oldVector.get(oldKeys[i]));
	}
	return res;
}
 
Example 60
Source File: ProduceLargerFrameDistribution.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static void normalizeMap(THashMap<String, THashMap<String, Double>> map) {
	Set<String> keys = map.keySet();
	for (String key: keys) {
		THashMap<String, Double> val = map.get(key);
		double total = 0.0;
		Set<String> keys1 = val.keySet();
		for (String key1: keys1) {
			total += val.get(key1);
		}
		for (String key1: keys1) {
			double v = val.get(key1) / total;
			val.put(key1, v);
		}
		map.put(key, val);
	}
}