/* Copyright (c) by respective owners including Yahoo!, Microsoft, and individual contributors. All rights reserved. Released under a BSD (revised) license as described in the file LICENSE. */ #pragma once #include "vw_clr.h" #include "vw_interface.h" #include "vw_labelcomparator.h" #include "vw_label.h" namespace VW { using namespace System::Collections::Generic; using namespace VW::Labels; ref class VowpalWabbitExample; ref class VowpalWabbit; [System::Diagnostics::DebuggerDisplay("{m_weight_index}:{m_x}")] public ref struct VowpalWabbitFeature { private: feature_value m_x; uint64_t m_weight_index; VowpalWabbitExample^ m_example; VowpalWabbit^ m_vw; public: VowpalWabbitFeature(VowpalWabbitExample^ example, feature_value x, uint64_t weight_index); VowpalWabbitFeature(VowpalWabbit^ vw, feature_value x, uint64_t weight_index); property feature_value X { float get(); } property uint64_t FeatureIndex { uint64_t get(); } property uint64_t WeightIndex { uint64_t get(); } property float Weight { float get(); } property float AuditWeight { float get(); } virtual bool Equals(Object^ o) override; virtual int GetHashCode() override; }; template struct Holder { T value; }; [System::Diagnostics::DebuggerDisplay("{Index} = '{(char)Index}'")] public ref struct VowpalWabbitNamespace : public IEnumerable { private: ref class FeatureEnumerator : public IEnumerator { private: VowpalWabbitExample^ m_example; features* m_features; Holder* m_iterator; Holder* m_end; internal: FeatureEnumerator(VowpalWabbitExample^ example, features* features); ~FeatureEnumerator(); property System::Object^ IEnumeratorCurrent { virtual System::Object^ get() sealed = System::Collections::IEnumerator::Current::get; } public: virtual bool MoveNext(); virtual void Reset(); property VowpalWabbitFeature^ Current { virtual VowpalWabbitFeature^ get(); } }; namespace_index m_ns; features* m_features; VowpalWabbitExample^ m_example; property System::Collections::IEnumerator^ EnumerableGetEnumerator { virtual System::Collections::IEnumerator^ get() sealed = System::Collections::IEnumerable::GetEnumerator; } public: VowpalWabbitNamespace(VowpalWabbitExample^ m_example, namespace_index ns, features* features); ~VowpalWabbitNamespace(); property namespace_index Index { namespace_index get(); } virtual IEnumerator^ GetEnumerator(); }; /// /// A CLR representation of a vowpal wabbit example. /// /// /// Underlying memory is allocated by native code, but examples are not part of the ring. /// [System::Diagnostics::DebuggerDisplay("{m_example}: '{m_string}'")] public ref class VowpalWabbitExample : public IEnumerable { private: /// /// Reference to an optional underlying example. /// /// If this instance owns this is null. initonly VowpalWabbitExample^ m_innerExample; ref class NamespaceEnumerator : public IEnumerator { private: VowpalWabbitExample^ m_example; namespace_index* m_current; internal: NamespaceEnumerator(VowpalWabbitExample^ example); ~NamespaceEnumerator(); property System::Object^ IEnumeratorCurrent { virtual System::Object^ get() sealed = System::Collections::IEnumerator::Current::get; } public: virtual bool MoveNext(); virtual void Reset(); property VowpalWabbitNamespace^ Current { virtual VowpalWabbitNamespace^ get(); } }; protected: /// /// Returns native example data structure to owning instance. /// !VowpalWabbitExample(); internal: /// /// Initializes a new instance of . /// /// The parent instance. Examples cannot be shared between vw instances. /// The already allocated example structure VowpalWabbitExample(IVowpalWabbitExamplePool^ owner, example* example); /// /// The native example data structure. /// example* m_example; /// /// The owner of this example. /// IVowpalWabbitExamplePool^ m_owner; /// /// The optional string version of the example. /// String^ m_string; public: /// /// Initializes a new instance of . /// /// The parent instance. Examples cannot be shared between instances. /// The inner example this instance wraps. VowpalWabbitExample(IVowpalWabbitExamplePool^ owner, VowpalWabbitExample^ example); /// /// Returns native example data structure to owning pool. /// ~VowpalWabbitExample(); /// /// Extracts the prediction from this example using the given prediction factory. /// /// The prediction stored in this example. generic T GetPrediction(VowpalWabbit^ vw, IVowpalWabbitPredictionFactory^ factory); /// /// An optional inner example this example wraps. /// property VowpalWabbitExample^ InnerExample { VowpalWabbitExample^ get(); } /// /// The owner of this example. /// property IVowpalWabbitExamplePool^ Owner { IVowpalWabbitExamplePool^ get(); } /// /// The corresponding VowpalWabbitString for this example. /// property String^ VowpalWabbitString { String^ get(); void set(String^ value); } /// /// True if this is a new line example, otherwise false. /// /// A example without features is considered a new line example. property bool IsNewLine { bool get(); } String^ Diff(VowpalWabbit^ vw, VowpalWabbitExample^ other, IVowpalWabbitLabelComparator^ labelComparator); void MakeEmpty(VowpalWabbit^ vw); property System::Collections::IEnumerator^ EnumerableGetEnumerator { virtual System::Collections::IEnumerator^ get() sealed = System::Collections::IEnumerable::GetEnumerator; } virtual IEnumerator^ GetEnumerator(); property size_t NumberOfFeatures { size_t get(); } property ILabel^ Label { ILabel^ get(); void set(ILabel^ label); } }; }