forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop using System.ComponentModel.Composition (dotnet#2569)
* Stop using System.ComponentModel.Composition Replace our MEF usage, which is only used by custom mapping transforms, with the ComponentCatalog class. Fix dotnet#1595 Fix dotnet#2422 * Rename new class to CustomMappingFactory.
- Loading branch information
Showing
15 changed files
with
196 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Microsoft.ML.Core/ComponentModel/ExtensionBaseAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.ML | ||
{ | ||
/// <summary> | ||
/// The base attribute type for all attributes used for extensibility purposes. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public abstract class ExtensionBaseAttribute : Attribute | ||
{ | ||
public string ContractName { get; } | ||
|
||
[BestFriend] | ||
private protected ExtensionBaseAttribute(string contractName) | ||
{ | ||
ContractName = contractName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Microsoft.Data.DataView; | ||
|
||
namespace Microsoft.ML.Transforms | ||
{ | ||
/// <summary> | ||
/// Place this attribute onto a type to cause it to be considered a custom mapping factory. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public sealed class CustomMappingFactoryAttributeAttribute : ExtensionBaseAttribute | ||
{ | ||
public CustomMappingFactoryAttributeAttribute(string contractName) | ||
: base(contractName) | ||
{ | ||
} | ||
} | ||
|
||
internal interface ICustomMappingFactory | ||
{ | ||
ITransformer CreateTransformer(IHostEnvironment env, string contractName); | ||
} | ||
|
||
/// <summary> | ||
/// The base type for custom mapping factories. | ||
/// </summary> | ||
/// <typeparam name="TSrc">The type that describes what 'source' columns are consumed from the input <see cref="IDataView"/>.</typeparam> | ||
/// <typeparam name="TDst">The type that describes what new columns are added by this transform.</typeparam> | ||
public abstract class CustomMappingFactory<TSrc, TDst> : ICustomMappingFactory | ||
where TSrc : class, new() | ||
where TDst : class, new() | ||
{ | ||
/// <summary> | ||
/// Returns the mapping delegate that maps from <typeparamref name="TSrc"/> inputs to <typeparamref name="TDst"/> outputs. | ||
/// </summary> | ||
public abstract Action<TSrc, TDst> GetMapping(); | ||
|
||
ITransformer ICustomMappingFactory.CreateTransformer(IHostEnvironment env, string contractName) | ||
{ | ||
Action<TSrc, TDst> mapAction = GetMapping(); | ||
return new CustomMappingTransformer<TSrc, TDst>(env, mapAction, contractName); | ||
} | ||
} | ||
} |
Oops, something went wrong.