use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class PropertiesStringLookupTest method testInterpolator.
@Test
public void testInterpolator() {
final StringSubstitutor stringSubstitutor = StringSubstitutor.createInterpolator();
assertEquals("Hello World!", stringSubstitutor.replace("${properties:" + KEY_PATH + "}"));
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class PropertiesStringLookupTest method testInterpolatorNestedColon.
@Test
public void testInterpolatorNestedColon() {
final StringSubstitutor stringSubstitutor = StringSubstitutor.createInterpolator();
// Need to handle "C:" in the sys prop user.dir.
final String replaced = stringSubstitutor.replace("$${properties:${sys:user.dir}/" + KEY_PATH + "}");
assertEquals("${properties:" + System.getProperty("user.dir") + "/src/test/resources/document.properties::mykey}", replaced);
assertEquals("Hello World!", stringSubstitutor.replace(replaced));
}
use of org.apache.commons.text.StringSubstitutor in project commons-text by apache.
the class PropertiesStringLookupTest method testInterpolatorWithParameterizedKey2.
@Test
public void testInterpolatorWithParameterizedKey2() {
final Map<String, String> map = new HashMap<>();
map.put("KeyIsHere", KEY);
final StringSubstitutor stringSubstitutor = new StringSubstitutor(StringLookupFactory.INSTANCE.interpolatorStringLookup(map));
final String replaced = stringSubstitutor.replace("$${properties:${sys:user.dir}/" + PropertiesStringLookup.toPropertyKey(DOC_PATH, "${KeyIsHere}}"));
assertEquals("${properties:" + System.getProperty("user.dir") + "/" + PropertiesStringLookup.toPropertyKey(DOC_PATH, "mykey}"), replaced);
assertEquals("Hello World!", stringSubstitutor.replace(replaced));
}
use of org.apache.commons.text.StringSubstitutor in project anserini by castorini.
the class JDIQ2018EffectivenessDocsTest method main.
@Test
public void main() throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
URL yaml = JDIQ2018EffectivenessDocsTest.class.getResource("/jdiq2018/models.yaml");
Model data = mapper.readValue(new File(yaml.toURI()), Model.class);
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("results", data.generateEffectiveness());
StringSubstitutor sub = new StringSubstitutor(valuesMap);
URL template = GenerateRegressionDocsTest.class.getResource("/jdiq2018/doc.template");
Scanner scanner = new Scanner(new File(template.toURI()), "UTF-8");
String text = scanner.useDelimiter("\\A").next();
scanner.close();
String resolvedString = sub.replace(text);
FileUtils.writeStringToFile(new File("docs/experiments-jdiq2018.md"), resolvedString, "UTF-8");
}
use of org.apache.commons.text.StringSubstitutor in project anserini by castorini.
the class GenerateRegressionDocsTest method main.
@Test
public void main() throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
URL templatesRoot = GenerateRegressionDocsTest.class.getResource("/docgen/templates/");
for (final File fileEntry : new File(templatesRoot.toURI()).listFiles()) {
String fileName = fileEntry.getName();
// This is the name of the test, which can be different from the name of the collection,
// e.g., multiple topics run on the same collection.
String testName = fileEntry.getName().replaceAll(".template", "");
URL yaml = GenerateRegressionDocsTest.class.getResource(String.format("/regression/%s.yaml", testName));
DataModel data = mapper.readValue(new File(yaml.toURI()), DataModel.class);
String corpus = data.getCorpus();
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("yaml", String.format("../src/main/resources/regression/%s.yaml", testName));
valuesMap.put("template", String.format("../src/main/resources/docgen/templates/%s.template", testName));
valuesMap.put("test_name", testName);
valuesMap.put("corpus", corpus);
valuesMap.put("index_cmds", data.generateIndexingCommand(corpus));
valuesMap.put("ranking_cmds", data.generateRankingCommand(corpus));
valuesMap.put("eval_cmds", data.generateEvalCommand(corpus));
valuesMap.put("effectiveness", data.generateEffectiveness(corpus));
StringSubstitutor sub = new StringSubstitutor(valuesMap);
URL template = GenerateRegressionDocsTest.class.getResource(String.format("/docgen/templates/%s.template", testName));
Scanner scanner = new Scanner(new File(template.toURI()), "UTF-8");
String text = scanner.useDelimiter("\\A").next();
scanner.close();
String resolvedString = sub.replace(text);
FileUtils.writeStringToFile(new File(String.format("docs/regressions-%s.md", testName)), resolvedString, "UTF-8");
}
}
Aggregations