/// <summary> /// Gets kernel instance for specified kernel name. If kernel not recognized it returns default: <see cref="kernelTFcIDF"/> /// </summary> /// <param name="kernelName">Name of the kernel.</param> /// <returns></returns> public static ISimilarityKernel GetKernel(String kernelName) { if (registry.ContainsKey(kernelName)) { ISimilarityKernel output = registry[kernelName].getInstance() as ISimilarityKernel; return(output); } switch (kernelName) { default: return(new kernelCSSRM()); break; } }
/// <summary> /// Registers the specified kernel type /// </summary> /// <param name="kernelType">Type of the kernel.</param> /// <exception cref="System.ArgumentException"> /// Kernel Type must have parameterless constructor! - kernelType /// or /// Kernel Type must implement ITermWeightKernel interface! - kernelType /// </exception> public static void RegisterKernel(Type kernelType) { if (!kernelType.hasParameterlessConstructor()) { throw new ArgumentException("Kernel Type must have parameterless constructor!", nameof(kernelType)); } ISimilarityKernel output = kernelType.getInstance() as ISimilarityKernel; if (output == null) { throw new ArgumentException("Kernel Type must implement ITermWeightKernel interface!", nameof(kernelType)); } if (!registry.ContainsKey(output.kernelName)) { registry.Add(output.kernelName, kernelType); } }