示例#1
0
        public WordAlignmentMatrix GetBestAlignment(IReadOnlyList <string> sourceSegment,
                                                    IReadOnlyList <string> targetSegment)
        {
            CheckDisposed();

            IntPtr nativeSourceSegment = Thot.ConvertStringsToNativeUtf8(sourceSegment);
            IntPtr nativeTargetSegment = Thot.ConvertStringsToNativeUtf8(targetSegment);
            IntPtr nativeMatrix        = Thot.AllocNativeMatrix(sourceSegment.Count, targetSegment.Count);

            uint iLen = (uint)sourceSegment.Count;
            uint jLen = (uint)targetSegment.Count;

            try
            {
                Thot.swAlignModel_getBestAlignment(Handle, nativeSourceSegment, nativeTargetSegment, nativeMatrix,
                                                   ref iLen, ref jLen);
                return(Thot.ConvertNativeMatrixToWordAlignmentMatrix(nativeMatrix, iLen, jLen));
            }
            finally
            {
                Thot.FreeNativeMatrix(nativeMatrix, iLen);
                Marshal.FreeHGlobal(nativeTargetSegment);
                Marshal.FreeHGlobal(nativeSourceSegment);
            }
        }