Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public void AddSegmentPair(IReadOnlyList <string> sourceSegment, IReadOnlyList <string> targetSegment,
                                   WordAlignmentMatrix hintMatrix = null)
        {
            CheckDisposed();

            IntPtr nativeSourceSegment = Thot.ConvertStringsToNativeUtf8(sourceSegment);
            IntPtr nativeTargetSegment = Thot.ConvertStringsToNativeUtf8(targetSegment);
            IntPtr nativeMatrix = IntPtr.Zero;
            uint   iLen = 0, jLen = 0;

            if (hintMatrix != null)
            {
                nativeMatrix = Thot.ConvertWordAlignmentMatrixToNativeMatrix(hintMatrix);
                iLen         = (uint)hintMatrix.RowCount;
                jLen         = (uint)hintMatrix.ColumnCount;
            }

            try
            {
                Thot.swAlignModel_addSentencePair(Handle, nativeSourceSegment, nativeTargetSegment, nativeMatrix, iLen,
                                                  jLen);
            }
            finally
            {
                Thot.FreeNativeMatrix(nativeMatrix, iLen);
                Marshal.FreeHGlobal(nativeTargetSegment);
                Marshal.FreeHGlobal(nativeSourceSegment);
            }
        }