internal static bool GetIntents(IntPtr enginePtr, string input, out CIntentClassifierResult[] results) { IntPtr resultPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); try { SNIPS_RESULT r = snips_nlu_engine_run_get_intents(enginePtr, input, ref resultPtr); if (r == SNIPS_RESULT.SNIPS_RESULT_OK) { CIntentlassifierResultArray result = (CIntentlassifierResultArray)Marshal.PtrToStructure(resultPtr, typeof(CIntentlassifierResultArray)); results = MarshalPtrToArray <CIntentClassifierResult>(result.intent_classifer_result_array_ptr, result.size); return(true); } else { results = null; return(false); } } catch (Exception) { results = null; return(false); } finally { resultPtr.FreeHGlobalIfNotZero(); } }
public static bool CreateEngineFromZipFile(string zipFilePath, out IntPtr enginePtr, out string error) { error = ""; if (!File.Exists(zipFilePath)) { error = "File not found."; enginePtr = IntPtr.Zero; return(false); } enginePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));; try { var f = new FileInfo(zipFilePath); SNIPS_RESULT r = snips_nlu_engine_create_from_zip(f.FullName, zipFilePath.Length, ref enginePtr); return(r == SNIPS_RESULT.SNIPS_RESULT_OK); } catch (Exception) { enginePtr.FreeHGlobalIfNotZero(); return(false); } finally { snips_nlu_engine_get_last_error(ref error); } }
internal static bool GetSlotsIntoJson(IntPtr enginePtr, string input, string intent, out string json, out string error) { error = ""; json = ""; try { SNIPS_RESULT r = snips_nlu_engine_run_get_slots_into_json(enginePtr, input, intent, ref json); if (r == SNIPS_RESULT.SNIPS_RESULT_OK) { return(true); } else { return(false); } } catch (Exception e) { error = e.Message; return(false); } finally { snips_nlu_engine_get_last_error(ref error); } }
internal static bool GetSlots(IntPtr enginePtr, string input, string intent, out CSlot[] results, out string error) { error = ""; IntPtr resultPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); try { SNIPS_RESULT r = snips_nlu_engine_run_get_slots(enginePtr, input, intent, ref resultPtr); if (r == SNIPS_RESULT.SNIPS_RESULT_OK) { CSlotArray result = (CSlotArray)Marshal.PtrToStructure(resultPtr, typeof(CSlotArray)); results = MarshalPtrToArray <CSlot>(result.slots_array_ptr, result.size); return(true); } else { results = null; return(false); } } catch (Exception e) { results = null; error = e.Message; return(false); } finally { snips_nlu_engine_get_last_error(ref error); resultPtr.FreeHGlobalIfNotZero(); } }
/// <summary> /// Used to retrieve the last error that happened in this thread. A function encountered an /// error if its return type is of type SNIPS_RESULT and it returned SNIPS_RESULT_KO. /// </summary> /// <returns></returns> internal static NluEngineError GetLast() { try { IntPtr errPrt = IntPtr.Zero; SNIPS_RESULT r = SnipsNLUEngine.NativeMethods.snips_nlu_engine_get_last_error(ref errPrt); if (r != SNIPS_RESULT.SNIPS_RESULT_OK) { return(new NluEngineError("Cannot retrieve last error.")); } return(new NluEngineError(Marshal.PtrToStringAnsi(errPrt))); } catch (Exception ex) { return(new NluEngineError("Cannot retrieve last error.", ex)); } }
public static bool CreateEngineFromDir(string rootDir, out IntPtr enginePtr, out string error) { enginePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));; try { SNIPS_RESULT r = snips_nlu_engine_create_from_dir(rootDir, ref enginePtr); error = ""; return(r == SNIPS_RESULT.SNIPS_RESULT_OK); } catch (Exception e) { enginePtr.FreeHGlobalIfNotZero(); error = e.Message; return(false); } finally { } }
public static bool GetModelVersion(out string version) { IntPtr versionPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); try { SNIPS_RESULT r = snips_nlu_engine_get_model_version(ref versionPtr); version = r == SNIPS_RESULT.SNIPS_RESULT_OK ? Marshal.PtrToStringAnsi(versionPtr) : string.Empty; return(r == SNIPS_RESULT.SNIPS_RESULT_OK); } catch (Exception) { version = string.Empty; return(false); } finally { versionPtr.FreeHGlobalIfNotZero(); } }