Skip to content

Instantly share code, notes, and snippets.

@tondrej
Last active April 16, 2018 08:38
Show Gist options
  • Save tondrej/91a9b9d336c411943a9483543e7ce49f to your computer and use it in GitHub Desktop.
Save tondrej/91a9b9d336c411943a9483543e7ce49f to your computer and use it in GitHub Desktop.
FastText C-style bindings for .NET
public static class FastTextWrapper
{
[return: MarshalAs(UnmanagedType.Bool)]
[UnmanagedFunctionPointer(callingConvention: CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public delegate bool FastTextNNCallback(StringBuilder word, Single score, IntPtr data);
[DllImport(dllName: "fasttext.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool fasttext_new(out IntPtr ft);
[DllImport(dllName: "fasttext.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool fasttext_release(IntPtr ft);
[DllImport(dllName: "fasttext.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool fasttext_nn2(IntPtr ft, IntPtr mx, string[] positive, string[] negative, int count, FastTextNNCallback callback, IntPtr data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment