/********************************************************************* * * Func Name : GetForeignCharCount * * Description: * * Parameters : sWord: the word * * Returns : the index value * Author : Kevin Zhang * History : * 1.create 2002-4-4 * 2.Modify 2002-5-21 *********************************************************************/ int GetForeignCharCount(char *sWord) { unsigned int nForeignCount,nCount; nForeignCount=GetCharCount(TRANS_ENGLISH,sWord);//English char counnts nCount=GetCharCount(TRANS_JAPANESE,sWord);//Japan char counnts if(nForeignCount<=nCount) nForeignCount=nCount; nCount=GetCharCount(TRANS_RUSSIAN,sWord);//Russian char counnts if(nForeignCount<=nCount) nForeignCount=nCount; return nForeignCount; }
bool CSegment::IsYearTime(char *sNum) { //Judge whether the sNum is a num genearating year unsigned int nLen=strlen(sNum); char sTemp[3]; strncpy(sTemp,sNum,2); sTemp[2]=0; if(IsAllSingleByte((unsigned char *)sNum)&&(nLen>=3||nLen==2&&sNum[0]>'4'))//1992年, 90年 return true; if(IsAllNum((unsigned char *)sNum)&&(nLen>=6||nLen==4&&CC_Find("56789",sTemp))) return true; if(GetCharCount("零○一二三四五六七八九壹贰叁肆伍陆柒捌玖",sNum)==(int)nLen/2&&nLen>=3) return true; if(nLen==8&&GetCharCount("千仟零○",sNum)==2)//二仟零二年 return true; return false; }
/********************************************************************* * * Func Name : GetForeignCharCount * * Description: Return the foreign type * * Parameters : sWord: the word * * Returns : the index value * Author : Kevin Zhang * History : * 1.create 2002-4-4 * 2.Modify 2002-5-21 *********************************************************************/ int GetForeignType(char *sWord) { unsigned int nForeignCount,nCount,nType=TT_ENGLISH; nForeignCount=GetCharCount(TRANS_ENGLISH,sWord);//English char counnts nCount=GetCharCount(TRANS_RUSSIAN,sWord);//Russian char counnts if(nForeignCount<nCount) { nForeignCount=nCount; nType=TT_RUSSIAN; } nCount=GetCharCount(TRANS_JAPANESE,sWord);//Japan char counnts if(nForeignCount<nCount) { nForeignCount=nCount; nType=TT_JAPANESE; } return nType; }
/* draw the line */ void scTextline::Draw( APPDrwCtx appMat, const scFlowDir& flowDir, const scMuPoint& transpt ) { if ( !fPara->Marked( scREBREAK | scRETABULATE ) ) { if ( GetCharCount() || Marked( scLASTLINE ) ) { scDrawLine ld( *this, flowDir, appMat, transpt ); ld.Draw(); } Unmark( scREPAINT ); } }
size_t CCharRefArray::InsertChar( const CChar *pChar, size_t i ) { ADDTOCALLSTACK("CCharRefArray::InsertChar"); size_t currentIndex = FindChar(pChar); if ( currentIndex != m_uidCharArray.BadIndex() ) { if ( currentIndex == i ) // already there return i; DetachChar(currentIndex); // remove from list } if ( !IsValidIndex(i) ) // prevent from being inserted too high i = GetCharCount(); m_uidCharArray.InsertAt(i, pChar->GetUID() ); return i; }
bool CSegGraph::GenerateWordNet(char *sSentence,CDictionary &dictCore,bool bOriginalFreq) { //Gernerate the word net from the sLine, that's list all the possible word unsigned int i=0,j,nLen=strlen(sSentence); char sWord[WORD_MAXLENGTH]="",sTempWord[WORD_MAXLENGTH]="",sWordMatch[WORD_MAXLENGTH]; int nWordIndex=0,nHandleTemp,k,nPOS; int nMatchFreq[20],nMatchHandle[20],nTotalFreq,nMatchCount; double dValue=0; m_nAtomCount=0; m_segGraph.SetEmpty();//Set segmentation graph empty AtomSegment(sSentence); //Atomic Segmentation for(i=0;i<m_nAtomCount;i++)//Init the cost array { if(m_nAtomPOS[i]==CT_CHINESE)//The atom is a Chinese Char { if(!bOriginalFreq)//Not original frequency m_segGraph.SetElement(i,i+1,log(MAX_FREQUENCE),0);//init the link with the maximum value else m_segGraph.SetElement(i,i+1,0,0,m_sAtom[i]);//init the link with the maximum value } else//Other atom { strcpy(sWord,m_sAtom[i]);//init the word dValue=MAX_FREQUENCE; switch(m_nAtomPOS[i]) { case CT_INDEX: case CT_NUM: nPOS=-27904;//'m'*256 strcpy(sWord,"未##数"); dValue=0; break; case CT_DELIMITER: nPOS=30464;//'w'*256; break; case CT_LETTER: nPOS=-'n'*256-'x';// dValue=0; strcpy(sWord,"未##串"); break; case CT_SINGLE://12021-2129-3121 if(GetCharCount("+-1234567890",m_sAtom[i])==(int)strlen(m_sAtom[i])) { nPOS=-27904;//'m'*256 strcpy(sWord,"未##数"); } else { nPOS=-'n'*256-'x';// strcpy(sWord,"未##串"); } dValue=0; break; default: nPOS=m_nAtomPOS[i];//'?'*256; break; } if(!bOriginalFreq)//Not original frequency m_segGraph.SetElement(i,i+1,0,nPOS);//init the link with minimum else m_segGraph.SetElement(i,i+1,dValue,nPOS,sWord);//init the link with minimum } } i=0; while(i<m_nAtomCount)//All the word { strcpy(sWord,m_sAtom[i]);//Get the current atom j=i+1; if(strcmp(sWord,"月")==0&&strcmp(m_sAtom[i+1],"份")==0)//Don't split 月份 j+=1; while(j<=m_nAtomCount&&dictCore.GetMaxMatch(sWord,sWordMatch,&nHandleTemp)) {//Add a condition to control the end of string //retrieve the dictionary with the word if(strcmp(sWordMatch,sWord)==0)//find the current word { nTotalFreq=0; dictCore.GetHandle(sWord,&nMatchCount,nMatchHandle,nMatchFreq); for(k=0;k<nMatchCount;k++)//Add the frequency { nTotalFreq+=nMatchFreq[k]; } //Adding a rule to exclude some words to be formed. if(strlen(sWord)==4&&i>=1&&(IsAllNum((unsigned char *)m_sAtom[i-1])||IsAllChineseNum(m_sAtom[i-1]))&&(strncmp(sWord,"年",2)==0||strncmp(sWord,"月",2)==0)) {//1年内、1999年末 if(CC_Find("末内中底前间初",sWord+2)) break; } if(nMatchCount==1)//The possible word has only one POS, store it { if(!bOriginalFreq)//Not original frequency m_segGraph.SetElement(i,j,-log(nTotalFreq+1)+log(MAX_FREQUENCE),nMatchHandle[0]); else m_segGraph.SetElement(i,j,nTotalFreq,nMatchHandle[0],sWord); } else { if(!bOriginalFreq)//Not original frequency m_segGraph.SetElement(i,j,-log(nTotalFreq+1)+log(MAX_FREQUENCE),0); else m_segGraph.SetElement(i,j,nTotalFreq,0,sWord); } } strcat(sWord,m_sAtom[j++]); } i+=1;//Start from i++; } return true; }
/* * lnd_name:lljz_net_disk_name */ void CreateFolderReq(RequestPacket* req, void* args, ResponsePacket* resp) { Document req_doc; /* Document resp_doc; Document::AllocatorType& resp_allocator=resp_doc.GetAllocator(); StringBuffer resp_buffer; Writer<StringBuffer> resp_writer(resp_buffer); Value resp_json(kObjectType); Value resp_error_msg(kStringType); */ TBSYS_LOG(DEBUG,"-------data:%s",req->data_); req_doc.Parse(req->data_); if (!CheckAuth(req,resp)) return; if (!req_doc.HasMember("folder_name") || !req_doc["folder_name"].IsString() || !req_doc["folder_name"].GetStringLength()) { SetErrorMsg(35001,"folder_name is invalid",resp); return; } const char* folder_name=req_doc["folder_name"].GetString(); char value[200]; char file_name[200]; int file_n=0; int num=GetCharCount(folder_name, '/')+1; int i=0; // /a/b//c//d for (i=0;i<num;i++) { GetStrValue(folder_name, '/', i+1, value); if (value[0]=='\0') continue; sprintf(file_name,"%s",value); file_n++; } if (0==file_n) { SetErrorMsg(35003,"path of new folder is invalid",resp); return; } RedisClient* file_rc=g_file_redis->GetRedisClient(); char cmd[512]; redisReply* reply; int cmd_ret; //是否存在根目录,父目录,新目录 char father_name[200]; sprintf(father_name,"folder_%s",req_doc["account"].GetString()); sprintf(cmd,"HGET %s %c_%s", father_name,0x02,"create_time"); cmd_ret=Rhget(file_rc,cmd,reply); if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误 g_file_redis->ReleaseRedisClient(file_rc,cmd_ret); SetErrorMsg(35002,"redis database server is busy",resp); return; } else if (FAILED_ACTIVE==cmd_ret) {//没有父目录 //记录异常日志 g_file_redis->ReleaseRedisClient(file_rc,cmd_ret); SetErrorMsg(35003,"path of root folder does not exist",resp); return; } int counter=0; for (i=0;i<num;i++) { GetStrValue(folder_name, '/', i+1, value); if (value[0]=='\0') continue; counter++; if (counter>=file_n) break; sprintf(cmd,"HGET %s %s", father_name,value); cmd_ret=Rhget(file_rc,cmd,reply,false); if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误 g_file_redis->ReleaseRedisClient(file_rc,cmd_ret); SetErrorMsg(35002,"redis database server is busy",resp); return; } else if (FAILED_ACTIVE==cmd_ret) {//没有父目录 //记录异常日志 g_file_redis->ReleaseRedisClient(file_rc,cmd_ret); freeReplyObject(reply); SetErrorMsg(35003,"path of parent folder does not exist",resp); return; } // if (0==reply->len) { //记录异常日志 g_file_redis->ReleaseRedisClient(file_rc,cmd_ret); freeReplyObject(reply); SetErrorMsg(35003,"path of parent folder does not exist",resp); return; } sprintf(father_name,"%s",reply->str); freeReplyObject(reply); } //增加新文件夹,lnd_name不能冲突 //取得file_id sprintf(cmd,"SPOP file_id_sets_%s", req_doc["account"].GetString()); cmd_ret=Rspop(file_rc,cmd,reply,false); if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误 g_file_redis->ReleaseRedisClient(file_rc,cmd_ret); SetErrorMsg(35002,"get file_id fail,redis database server is busy",resp); return; } else if (FAILED_ACTIVE==cmd_ret) { //记录异常日志 g_file_redis->ReleaseRedisClient(file_rc,cmd_ret); freeReplyObject(reply); SetErrorMsg(35006,"get file_id fail,file_id is used out",resp); return; } //在父目录增加记录 char lnd_name[512]; sprintf(lnd_name,"%d%c%s%c%s", 0,0x01, req_doc["account"].GetString(),0x01,reply->str); freeReplyObject(reply); sprintf(cmd,"HSETNX %s %s %s",father_name,file_name, lnd_name); cmd_ret=Rhsetnx(file_rc,cmd,reply); if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误 g_file_redis->ReleaseRedisClient(file_rc,false); SetErrorMsg(35002,"redis database server is busy",resp); return; } else if (FAILED_ACTIVE==cmd_ret) { //记录异常日志 g_file_redis->ReleaseRedisClient(file_rc,true); SetErrorMsg(35006,"create folder fail,folder has existed",resp); return; } //为新文件夹增加hash表 sprintf(cmd,"HSETNX %s %c_create_time %lld", lnd_name,0x02, tbsys::CTimeUtil::getTime()); cmd_ret=Rhsetnx(file_rc,cmd,reply); if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误 g_file_redis->ReleaseRedisClient(file_rc,false); SetErrorMsg(35002,"create folder fail,redis database server is busy",resp); return; } else if (FAILED_ACTIVE==cmd_ret) { //记录异常日志 g_file_redis->ReleaseRedisClient(file_rc,true); SetErrorMsg(35006,"file_id has used,redis database server status error",resp); return; } g_file_redis->ReleaseRedisClient(file_rc,true); SetErrorMsg(0,"",resp); }
// update the lines instance variables, determining if there have // been any changes in the line void scTextline::Set( short lineCount, eBreakType breakType, scLINERefData& lineData ) { BOOL changed; scXRect exrect = lineData.fInkExtents; scAssert( lineData.fInkExtents.Valid() ); TypeSpec ts = lineData.GetMaxLeadSpec(); scCachedStyle& cs = scCachedStyle::GetCachedStyle( ts ); if ( fOrigin == lineData.fOrg && fLength == lineData.fComputedLen && GetCharCount() == lineData.GetCharCount() && fLineCount == lineCount && fLspAdjustment == lineData.fLetterSpace && fInkExtents == lineData.fInkExtents && Marked( scLASTLINE ) && ( breakType == eEndStreamBreak ) && fMaxLead == lineData.fEndLead.GetLead() && fMaxLeadSpec == lineData.GetMaxLeadSpec() ) { changed = false; } else changed = true; if ( !changed ) { if ( fColumn->GetFlowdir().IsVertical() ) { changed = ( fCursorY1 == lineData.fOrg.x + cs.GetCursorX1() ) && ( fCursorY2 == lineData.fOrg.x + cs.GetCursorX2() ); } else { changed = ( fCursorY1 == lineData.fOrg.y + cs.GetCursorY1() ) && ( fCursorY2 == lineData.fOrg.y + cs.GetCursorY2() ); } } SetOffsets( lineData.GetStartCharOffset(), lineData.GetEndCharOffset() ); if ( changed ) { fOrigin = lineData.fOrg; fVJOffset = 0; fLength = lineData.fComputedLen; fLineCount = lineCount; if ( breakType == eEndStreamBreak ) Mark( scLASTLINE ); else Unmark( scLASTLINE ); fLspAdjustment = lineData.fLetterSpace; fInkExtents = lineData.fInkExtents; fMaxLead = lineData.fEndLead.GetLead(); fMaxLeadSpec = lineData.GetMaxLeadSpec(); // fMaxLeadSpec if ( fColumn->GetFlowdir().IsVertical() ) { fCursorY1 = lineData.fOrg.x + cs.GetCursorX1(); fCursorY2 = lineData.fOrg.x + cs.GetCursorX2(); lineData.fInkExtents.x1 = fCursorY1; lineData.fInkExtents.x2 = fCursorY2; if ( !lineData.GetStartCharOffset() && scCachedStyle::GetParaStyle().GetNumbered() ) lineData.fInkExtents.y1 -= scCachedStyle::GetParaStyle().GetBulletIndent(); } else { fCursorY1 = lineData.fOrg.y + cs.GetCursorY1(); fCursorY2 = lineData.fOrg.y + cs.GetCursorY2(); lineData.fInkExtents.y1 = fCursorY1; lineData.fInkExtents.y2 = fCursorY2; if ( !lineData.GetStartCharOffset() && scCachedStyle::GetParaStyle().GetNumbered() ) lineData.fInkExtents.x1 -= scCachedStyle::GetParaStyle().GetBulletIndent(); } fInkExtents.Union( lineData.fInkExtents ); } if ( fColumn->GetFlowdir().IsVertical() && lineData.fColShapeType & eVertFlex ) SetFlexLineAdjustment( lineData.fRagSetting ); else if ( lineData.fColShapeType & eHorzFlex ) SetFlexLineAdjustment( lineData.fRagSetting ); else SetFlexLineAdjustment( eNoRag ); lineData.fLastLineLen = lineData.fComputedLen; if ( changed ) fColumn->Mark( scREPAINT ); scAssertValid( false ); }