📄 common.pas
字号:
(*
* COMMON.PAS - Commonly used constants, types and functions** Copyright (C) 2006 by Yidong Chen <ydchen@xmu.edu.cn>Institute of Artificial Intelligence, Xiamen University* Begin : 09/18/2006* Last Change : 09/18/2006** This program is free software; you can redistribute it and/or* modify it under the terms of the GNU Lesser General Public* License as published by the Free Software Foundation; either* version 2.1 of the License, or (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU Lesser General Public* License along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*)
UNIT COMMON;
INTERFACE
CONST
SOS='<s>';
EOS='</s>';
SEPARATOR='|||';
SMOOTH_PROB=0.0000001;
TYPE
TPTranslation=^TTranslation;
TTranslation=RECORD
strWord: STRING;
rProbCE: Real;
rLexCE: Real;
rProbEC: Real;
rLexEC: Real;
rELen: Real;
rLMScore: Real;
END;
TResultType=(rteNone, rteNeon, rtePurePb, rtePbNeonWord, rteMulti);
TActionType=(ateNone,
ateSingle, ateSingleLog,
ateNistInNistOut, ateNistIn863Out,
ate863File,
ateSimpleFile,
ateIWSLTFile,
ateIWSLTASRFile,
ateNistInPP,
ate863FilePP,
ateSimpleFilePP,
ateIWSLTFilePP,
ateIWSLTASRFilePP);
TSegType=(steNone, steMandel, steICT);
TPhraseType=(pteNone, pteWithBlank, pteNoBlank);
FUNCTION PostProcess(strInput: STRING): STRING;
FUNCTION ExtractFileBase(strFileName: STRING): STRING;
FUNCTION CanFileBeCreated(strFileName: STRING): Boolean;
FUNCTION ConvertToCDir(strDirName: STRING): STRING;
FUNCTION ReadTrunc(VAR strInput: STRING): STRING;
FUNCTION ReadTruncBack(VAR strInput: STRING): STRING;
FUNCTION ReadTruncEx(VAR strInput: STRING; cTemp: Char): STRING;
IMPLEMENTATION
USES SysUtils;
FUNCTION PostProcess(strInput: STRING): STRING;
CONST
wstrSrc: WideString='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
wstrTgt: WideString='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
FUNCTION Idx(wcInput: WideChar): Integer;
VAR iLooper: Integer;
BEGIN
Result:=0;
FOR iLooper:=1 TO Length(wstrSrc) DO
IF wstrSrc[iLooper]=wcInput THEN BEGIN Result:=iLooper; Exit; END;
END;
VAR wstrTemp: WideString; iLooper, iTemp: Integer;
BEGIN
wstrTemp:=strInput;
FOR iLooper:=1 TO Length(wstrTemp) DO
BEGIN
iTemp:=Idx(wstrTemp[iLooper]);
IF iTemp>0 THEN wstrTemp[iLooper]:=wstrTgt[iTemp];
END;
Result:=wstrTemp;
END;
FUNCTION ExtractFileBase(strFileName: STRING): STRING;
VAR strBaseFile: STRING; iLooper, iLen: Integer;
BEGIN
strBaseFile:=ExtractFileName(Trim(strFileName));
iLen:=Length(strBaseFile);
iLooper:=iLen;
WHILE iLooper>=1 DO
BEGIN
IF strBaseFile[iLooper]='.' THEN Break;
Dec(iLooper);
END;
IF iLooper=1 THEN Result:=''
ELSE IF iLooper<1 THEN Result:=strFileName
ELSE Result:=Copy(strBaseFile,1,iLooper-1);
END;
FUNCTION CanFileBeCreated(strFileName: STRING): Boolean;
VAR strPathName, strBaseFile: STRING;
BEGIN
strFileName:=Trim(strFileName);
strPathName:=ExtractFilePath(strFileName);
strBaseFile:=ExtractFileBase(strFileName);
IF strBaseFile='' THEN BEGIN Result:=False; Exit; END;
IF strPathName='' THEN BEGIN Result:=NOT DirectoryExists(ExtractFileName(strFileName)); Exit; END;
IF strPathName<>'' THEN Result:=DirectoryExists(strPathName) AND NOT DirectoryExists(strFileName)
ELSE Result:=False;
END;
FUNCTION ConvertToCDir(strDirName: STRING): STRING;
VAR iLooper, iLen: Integer;
BEGIN
Result:='';
iLen:=Length(strDirName);
FOR iLooper:=1 TO iLen DO
IF (strDirName[iLooper]='\') AND
((iLooper=1) OR (iLooper>1) AND (strDirName[iLooper-1]<>'\')) AND
((iLooper=iLen) OR (iLooper<iLen) AND (strDirName[iLooper+1]<>'\')) THEN
Result:=Result+'\\'
ELSE Result:=Result+strDirName[iLooper];
END;
FUNCTION ReadTrunc(VAR strInput: STRING): STRING;
VAR iLooper, jLooper, iLength: Integer; strFuncResult: STRING;
BEGIN
iLength:=Length(strInput);
strFuncResult:='';
//Kill the preceding blank
jLooper:=1;
WHILE jLooper<=iLength DO
BEGIN
IF NOT (strInput[jLooper] IN [' ', #10, #13, #9]) THEN Break;
Inc(jLooper);
END;
//Get the Trunc
iLooper:=jLooper;
WHILE iLooper<=iLength DO
BEGIN
IF (strInput[iLooper] IN [' ', #10, #13, #9]) THEN Break
ELSE strFuncResult:=strFuncResult+strInput[iLooper];
Inc(iLooper);
END;
//Kill the following blank
jLooper:=iLooper;
WHILE jLooper<=iLength DO
BEGIN
IF NOT (strInput[jLooper] IN [' ', #10, #13, #9]) THEN Break;
Inc(jLooper);
END;
iLooper:=jLooper;
IF iLooper=iLength+1 THEN strInput:=''
ELSE IF iLooper>1 THEN Delete(strInput,1,iLooper-1);
Result:=strFuncResult;
END;
FUNCTION ReadTruncBack(VAR strInput: STRING): STRING;
VAR iLooper, jLooper, iLength: Integer; strFuncResult: STRING;
BEGIN
iLength:=Length(strInput);
strFuncResult:='';
//Kill the preceding blank (backwards)
jLooper:=iLength;
WHILE jLooper>=1 DO
BEGIN
IF NOT (strInput[jLooper] IN [' ', #10, #13, #9]) THEN Break;
Dec(jLooper);
END;
//Get the Trunc
iLooper:=jLooper;
WHILE iLooper>=1 DO
BEGIN
IF (strInput[iLooper] IN [' ', #10, #13, #9]) THEN Break
ELSE strFuncResult:=strInput[iLooper]+strFuncResult;
Dec(iLooper);
END;
//Kill the following blank (backwards)
jLooper:=iLooper;
WHILE jLooper>=1 DO
BEGIN
IF NOT (strInput[jLooper] IN [' ', #10, #13, #9]) THEN Break;
Dec(jLooper);
END;
iLooper:=jLooper;
IF iLooper=0 THEN strInput:=''
ELSE IF iLooper<iLength THEN Delete(strInput,iLooper+1, iLength-iLooper+1);
Result:=strFuncResult;
END;
FUNCTION ReadTruncEx(VAR strInput: STRING; cTemp: Char): STRING;
VAR iLooper, jLooper, iLength: Integer; strFuncResult: STRING;
BEGIN
iLength:=Length(strInput);
strFuncResult:='';;
//Kill the preceding blank
jLooper:=1;
WHILE jLooper<=iLength DO
BEGIN
IF NOT (strInput[jLooper] IN [' ', #10, #13, #9]) THEN Break;
Inc(jLooper);
END;
//Get the Trunc
iLooper:=jLooper;
WHILE iLooper<=iLength DO
BEGIN
IF strInput[iLooper]=cTemp THEN Break
ELSE strFuncResult:=strFuncResult+strInput[iLooper];
Inc(iLooper);
END;
//Kill the following blank
jLooper:=iLooper+1;
WHILE jLooper<=iLength DO
BEGIN
IF NOT (strInput[jLooper] IN [' ', #10, #13, #9]) THEN Break;
Inc(jLooper);
END;
iLooper:=jLooper;
IF iLooper=iLength+1 THEN strInput:=''
ELSE IF iLooper>1 THEN Delete(strInput,1,iLooper-1);
Result:=strFuncResult;
END;
END.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -