public function analyze()
{
$mapping = <<<GREMLIN
x2 = it.get().value("token");
GREMLIN;
$storage = array('array()' => 'T_ARRAY', '[]' => 'T_OPEN_BRACKET');
$this->atomFunctionIs('\\array')->raw('map{ ' . $mapping . ' }')->raw('groupCount("gf").cap("gf").sideEffect{ s = it.get().values().sum(); }.next()');
$types = (array) $this->rawQuery();
$store = array();
$total = 0;
foreach ($storage as $key => $v) {
$c = empty($types[$v]) ? 0 : $types[$v];
$store[] = array('key' => $key, 'value' => $c);
$total += $c;
}
Analyzer::$datastore->addRowAnalyzer($this->analyzerQuoted, $store);
if ($total == 0) {
return;
}
$types = array_filter($types, function ($x) use($total) {
return $x > 0 && $x / $total < 0.1;
});
$types = '["' . str_replace('\\', '\\\\', implode('", "', array_keys($types))) . '"]';
$this->atomFunctionIs('\\array')->raw('sideEffect{ ' . $mapping . ' }')->raw('filter{ x2 in ' . $types . '}')->back('first');
$this->prepareQuery();
}