|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | +using Microsoft.Spark.Interop; |
| 7 | +using Microsoft.Spark.Interop.Ipc; |
| 8 | + |
| 9 | +namespace Microsoft.Spark.ML.Feature.Param |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// A <see cref="Param"/> with self-contained documentation and optionally default value. |
| 13 | + /// |
| 14 | + /// A <see cref="Param"/> references an individual parameter that includes documentation, the |
| 15 | + /// name of the parameter and optionally a default value. Params can either be set using the |
| 16 | + /// generic <see cref="Param"/> methods or by using explicit methods. For example |
| 17 | + /// <see cref="Bucketizer"/> has <c>SetHandleInvalid</c> or you can call |
| 18 | + /// <c>GetParam("handleInvalid")</c>and then <see cref="Bucketizer"/>. Set using the |
| 19 | + /// <see cref="Param"/> and the value you want to use. |
| 20 | + /// </summary> |
| 21 | + public class Param : IJvmObjectReferenceProvider |
| 22 | + { |
| 23 | + private static readonly string s_ParamClassName = |
| 24 | + "org.apache.spark.ml.param.Param"; |
| 25 | + |
| 26 | + private readonly JvmObjectReference _jvmObject; |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Creates a new instance of a <see cref="Param"/> which will be attached to the parent |
| 30 | + /// specified. The most likely use case for a <see cref="Param"/> is being read from a |
| 31 | + /// parent object such as <see cref="Bucketizer"/> rather than independently |
| 32 | + /// <param name="parent">The parent object to assign the <see cref="Param"/> to</param> |
| 33 | + /// <param name="name">The name of this <see cref="Param"/></param> |
| 34 | + /// <param name="doc">The documentation for this <see cref="Param"/></param> |
| 35 | + /// </summary> |
| 36 | + public Param(Identifiable parent, string name, string doc) |
| 37 | + : this(SparkEnvironment.JvmBridge.CallConstructor( |
| 38 | + s_ParamClassName, parent.Uid(), name, doc)) |
| 39 | + { |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Creates a new instance of a <see cref="Param"/> which will be attached to the parent |
| 44 | + /// with the UID specified. The most likely use case for a <see cref="Param"/> is being |
| 45 | + /// read from a parent object such as <see cref="Bucketizer"/> rather than independently |
| 46 | + /// <param name="parent"> |
| 47 | + /// The UID of the parent object to assign the <see cref="Param"/> to |
| 48 | + /// </param> |
| 49 | + /// <param name="name">The name of this <see cref="Param"/></param> |
| 50 | + /// <param name="doc">The documentation for this <see cref="Param"/></param> |
| 51 | + /// </summary> |
| 52 | + public Param(string parent, string name, string doc) |
| 53 | + : this(SparkEnvironment.JvmBridge.CallConstructor(s_ParamClassName, parent, name, doc)) |
| 54 | + { |
| 55 | + } |
| 56 | + |
| 57 | + internal Param(JvmObjectReference jvmObject) |
| 58 | + { |
| 59 | + _jvmObject = jvmObject; |
| 60 | + } |
| 61 | + |
| 62 | + JvmObjectReference IJvmObjectReferenceProvider.Reference => _jvmObject; |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// The description of what the <see cref="Param"/> does and how it works including any |
| 66 | + /// defaults and the current value |
| 67 | + /// </summary> |
| 68 | + /// <returns>A description of how the <see cref="Param"/> works</returns> |
| 69 | + public string Doc => (string)_jvmObject.Invoke("doc"); |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// The name of the <see cref="Param"/> |
| 73 | + /// </summary> |
| 74 | + /// <returns>The name of the <see cref="Param"/></returns> |
| 75 | + public string Name => (string)_jvmObject.Invoke("name"); |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// The object that contains the <see cref="Param"/> |
| 79 | + /// </summary> |
| 80 | + /// <returns>The UID of the parent oject that this <see cref="Param"/> belongs to</returns> |
| 81 | + public string Parent => (string)_jvmObject.Invoke("parent"); |
| 82 | + } |
| 83 | +} |
0 commit comments