use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class NearestTransformTest method makeFeatureVector.
public FeatureVector makeFeatureVector() {
Map<String, Set<String>> stringFeatures = new HashMap<>();
Map<String, Map<String, Double>> floatFeatures = new HashMap<>();
Set list = new HashSet<String>();
list.add("aaa");
list.add("bbb");
stringFeatures.put("strFeature1", list);
Map<String, Double> map = new HashMap<>();
map.put("lat", 37.7);
map.put("long", 40.0);
floatFeatures.put("loc", map);
Map<String, Double> map2 = new HashMap<>();
map2.put("foo", 41.0);
floatFeatures.put("f2", map2);
FeatureVector featureVector = new FeatureVector();
featureVector.setStringFeatures(stringFeatures);
featureVector.setFloatFeatures(floatFeatures);
return featureVector;
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class NearestTransformTest method testTransform.
@Test
public void testTransform() {
Config config = ConfigFactory.parseString(makeConfig());
Transform transform = TransformFactory.createTransform(config, "test_nearest");
FeatureVector featureVector = makeFeatureVector();
transform.doTransform(featureVector);
Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
assertTrue(stringFeatures.size() == 2);
Set<String> out = stringFeatures.get("nearest");
log.info("nearest output");
for (String string : out) {
log.info(string);
}
assertTrue(out.size() == 1);
assertTrue(out.contains("foo~=long"));
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class NgramTransformTest method makeFeatureVector.
public FeatureVector makeFeatureVector() {
Map<String, Set<String>> stringFeatures = new HashMap<>();
Map<String, Map<String, Double>> floatFeatures = new HashMap<>();
Set<String> list = new HashSet<>();
list.add("I like blueberry pie, apple pie; and I also like blue!");
list.add("I'm so excited: I like blue!?!!");
stringFeatures.put("strFeature1", list);
FeatureVector featureVector = new FeatureVector();
featureVector.setStringFeatures(stringFeatures);
featureVector.setFloatFeatures(floatFeatures);
return featureVector;
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class NgramTransformTest method testTransform1gram.
@Test
public void testTransform1gram() {
Config config = ConfigFactory.parseString(makeConfig("\"\"\"[\\s\\p{Punct}]\"\"\"", 1, false));
Transform transform = TransformFactory.createTransform(config, "test_ngram");
FeatureVector featureVector = makeFeatureVector();
transform.doTransform(featureVector);
Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
Map<String, Map<String, Double>> floatFeatures = featureVector.getFloatFeatures();
assertEquals(1, stringFeatures.size());
assertEquals(1, floatFeatures.size());
Map<String, Double> output = floatFeatures.get("bar");
assertEquals(11, output.size());
assertEquals(1.0, output.get("apple"), 0.0);
assertEquals(1.0, output.get("blueberry"), 0.0);
assertEquals(2.0, output.get("blue"), 0.0);
assertEquals(3.0, output.get("like"), 0.0);
assertEquals(1.0, output.get("excited"), 0.0);
assertEquals(1.0, output.get("and"), 0.0);
assertEquals(4.0, output.get("I"), 0.0);
assertEquals(1.0, output.get("also"), 0.0);
assertEquals(1.0, output.get("so"), 0.0);
assertEquals(2.0, output.get("pie"), 0.0);
assertEquals(1.0, output.get("m"), 0.0);
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class NgramTransformTest method testTransformUseMinN.
@Test
public void testTransformUseMinN() {
Config config = ConfigFactory.parseString(makeConfig("\"\"\"[\\s\\p{Punct}]\"\"\"", 2, true));
Transform transform = TransformFactory.createTransform(config, "test_ngram");
FeatureVector featureVector = makeFeatureVector();
transform.doTransform(featureVector);
Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
Map<String, Map<String, Double>> floatFeatures = featureVector.getFloatFeatures();
assertEquals(1, stringFeatures.size());
assertEquals(1, floatFeatures.size());
Map<String, Double> output = floatFeatures.get("bar");
assertEquals(25, output.size());
assertEquals(1.0, output.get("apple"), 0.0);
assertEquals(1.0, output.get("blueberry"), 0.0);
assertEquals(2.0, output.get("blue"), 0.0);
assertEquals(3.0, output.get("like"), 0.0);
assertEquals(1.0, output.get("excited"), 0.0);
assertEquals(1.0, output.get("and"), 0.0);
assertEquals(4.0, output.get("I"), 0.0);
assertEquals(1.0, output.get("also"), 0.0);
assertEquals(1.0, output.get("so"), 0.0);
assertEquals(2.0, output.get("pie"), 0.0);
assertEquals(1.0, output.get("m"), 0.0);
assertEquals(2.0, output.get("I" + NgramTransform.BIGRAM_SEPARATOR + "like"), 0.0);
assertEquals(1.0, output.get("like" + NgramTransform.BIGRAM_SEPARATOR + "blueberry"), 0.0);
assertEquals(1.0, output.get("blueberry" + NgramTransform.BIGRAM_SEPARATOR + "pie"), 0.0);
assertEquals(1.0, output.get("pie" + NgramTransform.BIGRAM_SEPARATOR + "apple"), 0.0);
assertEquals(1.0, output.get("apple" + NgramTransform.BIGRAM_SEPARATOR + "pie"), 0.0);
assertEquals(1.0, output.get("pie" + NgramTransform.BIGRAM_SEPARATOR + "and"), 0.0);
assertEquals(1.0, output.get("and" + NgramTransform.BIGRAM_SEPARATOR + "I"), 0.0);
assertEquals(1.0, output.get("I" + NgramTransform.BIGRAM_SEPARATOR + "also"), 0.0);
assertEquals(1.0, output.get("also" + NgramTransform.BIGRAM_SEPARATOR + "like"), 0.0);
assertEquals(2.0, output.get("like" + NgramTransform.BIGRAM_SEPARATOR + "blue"), 0.0);
assertEquals(1.0, output.get("I" + NgramTransform.BIGRAM_SEPARATOR + "m"), 0.0);
assertEquals(1.0, output.get("m" + NgramTransform.BIGRAM_SEPARATOR + "so"), 0.0);
assertEquals(1.0, output.get("so" + NgramTransform.BIGRAM_SEPARATOR + "excited"), 0.0);
assertEquals(1.0, output.get("excited" + NgramTransform.BIGRAM_SEPARATOR + "I"), 0.0);
}
Aggregations