1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53

media / learning / common / feature_dictionary.h [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_LEARNING_COMMON_FEATURE_DICTIONARY_H_
#define MEDIA_LEARNING_COMMON_FEATURE_DICTIONARY_H_

#include <map>
#include <string>

#include "base/component_export.h"
#include "media/learning/common/labelled_example.h"
#include "media/learning/common/learning_task.h"

namespace media {
namespace learning {

// Dictionary of feature name => value pairs.
//
// This is useful if one simply wants to snapshot some features, and apply them
// to more than one task without recomputing anything.
//
// While it's not required, FeatureLibrary is useful to provide the descriptions
// that a FeatureDictionary will provide, so that the LearningTask and the
// dictionary agree on names.
class COMPONENT_EXPORT(LEARNING_COMMON) FeatureDictionary {
 public:
  // [feature name] => snapshotted value.
  using Dictionary = std::map<std::string, FeatureValue>;

  FeatureDictionary();

  FeatureDictionary(const FeatureDictionary&) = delete;
  FeatureDictionary& operator=(const FeatureDictionary&) = delete;

  ~FeatureDictionary();

  // Add features for |task| to |features| from our dictionary.  Features that
  // aren't present in the dictionary will be ignored.  |features| will be
  // expanded if needed to match |task|.
  void Lookup(const LearningTask& task, FeatureVector* features) const;

  // Add |name| to the dictionary with value |value|.
  void Add(const std::string& name, const FeatureValue& value);

 private:
  Dictionary dictionary_;
};

}  // namespace learning
}  // namespace media

#endif  // MEDIA_LEARNING_COMMON_FEATURE_DICTIONARY_H_