List of usage examples for org.apache.commons.lang StringUtils replace
public static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String.
From source file:info.magnolia.cms.module.ModuleUtil.java
public static void bootstrap(String[] resourceNames) throws IOException, RegisterException { HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.CONFIG); // sort by length --> import parent node first List list = new ArrayList(Arrays.asList(resourceNames)); Collections.sort(list, new Comparator() { public int compare(Object name1, Object name2) { return ((String) name1).length() - ((String) name2).length(); }//from www .ja va 2 s. c o m }); for (Iterator iter = list.iterator(); iter.hasNext();) { String resourceName = (String) iter.next(); // windows again resourceName = StringUtils.replace(resourceName, "\\", "/"); String name = StringUtils.removeEnd(StringUtils.substringAfterLast(resourceName, "/"), ".xml"); String repository = StringUtils.substringBefore(name, "."); String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(name, "."), "."); //$NON-NLS-1$ String nodeName = StringUtils.substringAfterLast(name, "."); String fullPath; if (StringUtils.isEmpty(pathName)) { pathName = "/"; fullPath = "/" + nodeName; } else { pathName = "/" + StringUtils.replace(pathName, ".", "/"); fullPath = pathName + "/" + nodeName; } // if the path already exists --> delete it try { if (hm.isExist(fullPath)) { hm.delete(fullPath); if (log.isDebugEnabled()) log.debug("already existing node [{}] deleted", fullPath); } // if the parent path not exists just create it if (!pathName.equals("/")) { ContentUtil.createPath(hm, pathName, ItemType.CONTENT); } } catch (Exception e) { throw new RegisterException("can't register bootstrap file: [" + name + "]", e); } InputStream stream = ModuleUtil.class.getResourceAsStream(resourceName); DataTransporter.executeImport(pathName, repository, stream, name, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, true, true); } }
From source file:de.tudarmstadt.ukp.dkpro.tc.weka.task.CrossValidationTask.java
@Override public void execute(TaskContext aContext) throws Exception { File arffFile = new File( aContext.getStorageLocation(INPUT_KEY, AccessMode.READONLY).getPath() + "/" + TRAINING_DATA_KEY); Instances data = WekaUtils.getInstances(arffFile, multiLabel); Instances randData = new Instances(data); FOLDS = getFolds(randData);//from w w w. j ava 2s .co m // this will make the Crossvalidation outcome unpredictable randData.randomize(new Random(new Date().getTime())); randData.stratify(FOLDS); Classifier cl; String[] mlArgs; for (int n = 0; n < FOLDS; n++) { aContext.message("Performing " + FOLDS + "-fold cross-validation (" + n + ", with " + Arrays.asList(classificationArguments) + ")"); // Train-Test-split Instances train = randData.trainCV(FOLDS, n); Instances test = randData.testCV(FOLDS, n); if (multiLabel) { mlArgs = Arrays.copyOfRange(classificationArguments, 1, classificationArguments.length); cl = AbstractClassifier.forName(classificationArguments[0], new String[] {}); ((MultilabelClassifier) cl).setOptions(mlArgs); } else { cl = AbstractClassifier.forName(classificationArguments[0], Arrays.copyOfRange(classificationArguments, 1, classificationArguments.length)); } Instances filteredTrainData; Instances filteredTestData; if (train.attribute(Constants.ID_FEATURE_NAME) != null) { int instanceIdOffset = // TaskUtils.getInstanceIdAttributeOffset(trainData); train.attribute(Constants.ID_FEATURE_NAME).index() + 1; Remove remove = new Remove(); remove.setAttributeIndices(Integer.toString(instanceIdOffset)); remove.setInvertSelection(false); remove.setInputFormat(train); filteredTrainData = Filter.useFilter(train, remove); filteredTestData = Filter.useFilter(test, remove); } else { filteredTrainData = new Instances(train); filteredTestData = new Instances(test); } // train the classifier on the train set split cl.buildClassifier(filteredTrainData); // file to hold Crossvalidation results File evalOutput = new File(aContext.getStorageLocation(OUTPUT_KEY, AccessMode.READWRITE).getPath() + "/" + StringUtils.replace(EVALUATION_DATA_KEY, "#", String.valueOf(n))); // evaluation if (multiLabel) { Result r = Evaluation.evaluateModel((MultilabelClassifier) cl, filteredTrainData, filteredTestData, threshold); Result.writeResultToFile(r, evalOutput.getAbsolutePath()); // add predictions for test set double[] t = WekaUtils.getMekaThreshold(threshold, r, filteredTrainData); for (int j = 0; j < filteredTestData.numInstances(); j++) { Instance predicted = filteredTestData.instance(j); // multi-label classification results double[] labelPredictions = cl.distributionForInstance(predicted); for (int i = 0; i < labelPredictions.length; i++) { predicted.setValue(i, labelPredictions[i] >= t[i] ? 1. : 0.); } test.add(predicted); } int numLabels = filteredTestData.classIndex(); // add attributes to store gold standard classification Add filter = new Add(); for (int i = 0; i < numLabels; i++) { filter.setAttributeIndex(new Integer(numLabels + i + 1).toString()); filter.setNominalLabels("0,1"); filter.setAttributeName(test.attribute(i).name() + "_classification"); filter.setInputFormat(test); test = Filter.useFilter(test, filter); } // fill values of gold standard classification with original values from test set for (int i = 0; i < test.size(); i++) { for (int j = 0; j < numLabels; j++) { test.instance(i).setValue(j + numLabels, test.instance(i).value(j)); } } } else { weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(filteredTrainData); eval.evaluateModel(cl, filteredTestData); weka.core.SerializationHelper.write(evalOutput.getAbsolutePath(), eval); Add filter = new Add(); filter.setAttributeIndex(new Integer(test.classIndex() + 1).toString()); filter.setAttributeName("goldlabel"); filter.setInputFormat(test); test = Filter.useFilter(test, filter); // fill values of gold standard classification with original values from test set for (int i = 0; i < test.size(); i++) { test.instance(i).setValue(test.classIndex() - 1, filteredTestData.instance(i).classValue()); } for (int i = 0; i < filteredTestData.numInstances(); i++) { double prediction = cl.classifyInstance(filteredTestData.instance(i)); Instance instance = test.instance(i); instance.setClassValue(prediction); } } // Write out the predictions DataSink.write(aContext.getStorageLocation(OUTPUT_KEY, AccessMode.READWRITE).getAbsolutePath() + "/" + StringUtils.replace(PREDICTIONS_KEY, "#", String.valueOf(n)), test); } }
From source file:info.magnolia.cms.util.ConfigUtil.java
/** * Replace tokens in a string.//from w w w . j a v a 2 s . co m * @param config * @return * @throws IOException */ public static String replaceTokens(String config) throws IOException { for (Iterator iter = SystemProperty.getProperties().keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); config = StringUtils.replace(config, "${" + key + "}", SystemProperty.getProperty(key, "")); } return config; }
From source file:info.magnolia.init.DefaultMagnoliaInitPaths.java
/** * Figures out the root path where the webapp is deployed. *//*from ww w . ja va2s.co m*/ protected String determineRootPath(ServletContext context) { final String retroCompatMethodCall = magnoliaServletContextListener.initRootPath(context); if (retroCompatMethodCall != null) { DeprecationUtil.isDeprecated( "You should update your code and override determineRootPath(ServletContext) instead of initRootPath(ServletContext)"); return retroCompatMethodCall; } String realPath = StringUtils.replace(context.getRealPath(StringUtils.EMPTY), "\\", "/"); realPath = StringUtils.removeEnd(realPath, "/"); if (realPath == null) { // don't use new java.io.File("x").getParentFile().getAbsolutePath() to find out real directory, could throw // a NPE for unexpanded war throw new RuntimeException( "Magnolia is not configured properly and therefore unable to start: real path can't be obtained [ctx real path:" + context.getRealPath(StringUtils.EMPTY) + "]. Please refer to the Magnolia documentation for installation instructions specific to your environment."); } return realPath; }
From source file:de.extra.client.core.config.impl.ExtraProfileConfiguration.java
/** * // Noch ein Workaround Plugin -> PlugIn konvertieren * // w ww .ja v a2s . c om * @param fieldName * @return */ private String convertPluginName(final String fieldName) { final String plugInConverted = StringUtils.replace(fieldName, "Plugin", "PlugIn"); return plugInConverted; }
From source file:edu.ku.brc.specify.toycode.mexconabio.FMPCreateTable.java
/** * @param nameArg//from w w w. j av a 2 s . com * @return */ public static String fixName(final String nameArg) { String name = nameArg.toLowerCase(); StringBuilder nm = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (c != ':' && c <= 'z') { nm.append(c); } } return StringUtils.replace(nm.toString().trim(), " ", "_"); }
From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java
public static String cleanModelDescriptor(String s) { String clean = Translate.decode(s).replace("{", "").replace("}", ""); clean = StringUtils.replace(clean, "script", ""); clean = StringUtils.replace(clean, "%", ""); clean = StringUtils.replace(clean, "\"", ""); clean = StringUtils.replace(clean, "$", ""); clean = StringUtils.replace(clean, "\\", ""); if (clean.length() == 0) { clean = "empty"; }//from ww w . ja va 2 s.c o m return clean; }
From source file:com.taobao.datax.common.util.StrUtils.java
License:asdf
public static String replaceString(String param) { Matcher matcher = VARIABLE_PATTERN.matcher(param); String param1 = param;//from w w w .jav a 2 s .co m List<String> re = new ArrayList<String>(); int i = 0; while (matcher.find()) { param1 = StringUtils.replace(param1, matcher.group(), System.getProperty(matcher.group(2), matcher.group())); if (param1.equals(param)) { i++; param1 = StringUtils.replace(param1, matcher.group(), "@replace" + i); re.add(matcher.group()); } log.debug(param1); param = param1; matcher = VARIABLE_PATTERN.matcher(param1); } for (; i > 0; i--) { param1 = StringUtils.replace(param1, "@replace" + i, re.get(i - 1)); } log.debug(param1); return param1; }
From source file:com.hangum.tadpole.rdb.core.dialog.msg.TDBClipboardDialog.java
/** * ?? ./*from w w w.j a va 2 s.c o m*/ */ private void initData() { String strSep = txtSeperate.getText(); if (strSep.equals("\\t")) { strSep = " "; } String strMsg = StringUtils.replace(strResultData, PublicTadpoleDefine.DELIMITER_DBL, strSep) + PublicTadpoleDefine.LINE_SEPARATOR; // if (strSep.equals(",")) { strMsg = StringUtils.replace(strMsg, ",''", ",") + PublicTadpoleDefine.LINE_SEPARATOR; } textMessage.setText(strMsg); textMessage.setFocus(); textMessage.setSelection(0, strMsg.length()); }
From source file:com.thoughtworks.gauge.autocomplete.StepCompletionProvider.java
private void replaceStepParamWithStaticArg(InsertionContext context1, PsiElement stepParam, String replacementText) { String stepV = StringUtils.replace(StringUtils.replace(stepParam.getText(), "<", "\""), ">", "\""); context1.getDocument().replaceString(stepParam.getTextOffset(), stepParam.getTextOffset() + replacementText.length(), stepV); }