📄 whfhost.js
字号:
if (a_strQuery.length > a_strTerm.length )
return false ;
var bPrefix = true ;
var i ;
for (i=0; i< a_strQuery.length;i++)
{
if (a_strQuery.charAt(i) != a_strTerm.charAt(i))
{
bPrefix = false ;
break ;
}
}
return bPrefix ;
}
this.getAttr = function( a_strTagName )
{
var nArgsNum = this.getAttr.arguments.length;
if ( nArgsNum < 2 || nArgsNum % 2 != 0 )
return "";
with( this.curData )
{
for ( var i = 0; i < aNodes.length; i++ )
{
if ( utf8Compare(aNodes[i].strTagName,a_strTagName) != 0 )
continue;
for ( var j = 1; j + 1 < nArgsNum - 1; j += 2 )
{
if ( utf8Compare(aNodes[i].aAttrs[this.getAttr.arguments[j]], this.getAttr.arguments[j + 1]) != 0 )
break;
}
if ( j + 1 < nArgsNum - 1 )
continue;
if ( aNodes[i].aAttrs[this.getAttr.arguments[j]] )
return aNodes[i].aAttrs[this.getAttr.arguments[j]];
else
continue;
}
return "";
}
}
this.checkAttr = function( a_strTagName )
{
var nArgsNum = this.checkAttr.arguments.length;
if ( nArgsNum < 1 || nArgsNum % 2 == 0 )
return false;
with( this.curData )
{
for ( var i = 0; i < aNodes.length; i++ )
{
if ( utf8Compare(aNodes[i].strTagName, a_strTagName) != 0 )
continue;
for ( var j = 1; j < nArgsNum - 1; j += 2 )
{
if ( utf8Compare(aNodes[i].aAttrs[this.checkAttr.arguments[j]], this.checkAttr.arguments[j + 1]) != 0 )
break;
}
if ( j < nArgsNum - 1 )
continue;
return true;
}
return false;
}
}
}
function putDataXML( xmlDoc, sdocPath )
{
if(g_bServerResult==true)
{
g_bServerResult=false;
// received the search result
var cRoot=xmlDoc.lastChild;
var cResult=new HuginQueryResult();
var nIndex=1;
if(cRoot)
{
var cNode=cRoot.firstChild;
while(cNode)
{
if(cNode.nodeName=="topic")
{
var cTopic=new Object();
cTopic.nIndex=nIndex;
cTopic.strTitle=cNode.getAttribute("name");
cTopic.strUrl=cNode.getAttribute("url");
cTopic.strSummary=cNode.getAttribute("summary");
cTopic.nRank=cNode.getAttribute("rank");
cResult.aTopics[cResult.aTopics.length]=cTopic;
};
cNode=cNode.nextSibling;
nIndex=nIndex+1;
};
};
displayTopics(cResult)
}else
{
theXmlReader.receiveDom( xmlDoc );
theXmlReader.bSucc = true;
theXmlReader.funcCallback();
};
}
function mergeTopicRec(a_strParentRec , a_strNewRec)
{
var arrOldRecords = a_strParentRec.split("|");
var arrNewRecords = a_strNewRec.split("|");
var mergedRec = "" ;
var i = 0 ;
var j = 0 ;
var arrFinalRec = new Array();
while ( i< arrOldRecords.length && j < arrNewRecords.length)
{
var oldTopicRecord = getTopicDetails(arrOldRecords[i]);
if (oldTopicRecord == null)
{
i++;
continue ;
}
var newTopicRecord = getTopicDetails(arrNewRecords[j]);
if (newTopicRecord == null)
{
j++;
continue ;
}
if (oldTopicRecord.nTopicId < newTopicRecord.nTopicId)
{
arrFinalRec[arrFinalRec.length] = arrOldRecords[i] ;
i++ ;
}
else if (oldTopicRecord.nTopicId > newTopicRecord.nTopicId)
{
arrFinalRec[arrFinalRec.length] = arrNewRecords[j] ;
j++ ;
}
else
{
var temp = arrOldRecords[i].split(":");
var uEmphasis = (oldTopicRecord.uEmphasis > newTopicRecord.uEmphasis)?oldTopicRecord.uEmphasis:newTopicRecord.uEmphasis;
var strRec = oldTopicRecord.nTopicId + "," + uEmphasis + ":" + temp [1] ; //since this will not be called in case of phrase search, we can ignore positions of other rec
arrFinalRec[arrFinalRec.length] = strRec ;
j++ ;
i++ ;
}
}
while (i< arrOldRecords.length)
{
arrFinalRec[arrFinalRec.length] = arrOldRecords[i] ;
i++ ;
}
while (j < arrNewRecords.length)
{
arrFinalRec[arrFinalRec.length] = arrNewRecords[j] ;
j++ ;
}
if (arrFinalRec.length == 0)
return a_strParentRec ;
mergedRec = arrFinalRec[0];
for ( i = 1 ; i < arrFinalRec.length ; i++)
mergedRec += "|" + arrFinalRec[i] ;
return mergedRec ;
}
function getTopicDetails( a_strRecord )
{
var index = a_strRecord.indexOf(",");
if (index == -1)
return null ;
var nTopicId = a_strRecord.substring(0 , index);
var strTopicDetails = a_strRecord.substring(index+1,a_strRecord.length);
var aShapes = strTopicDetails.split( ":" );
if ( aShapes.length == 0 )
return null;
var record = new Object();
record.nTopicId = nTopicId ;
record.uEmphasis = parseInt( aShapes[0] );
return record ;
}
function onLoadXMLError()
{
//For Debug & Test------
if ( window.gbTesting )
return;
//----------------------
theXmlReader.bSucc = false;
theXmlReader.funcCallback();
}
////////////////////////////////
function splitPathName( a_strPath ) //this utility function only fit this project.
{
var rslt = new Object();
rslt.strDir = "";
rslt.strFile = "";
rslt.strExt = "";
var rg1 = /^(.*[\\\/])?([^\\\/]+)(\.[^\\\/\.]*)$/;
var rg2 = /^(.*[\\\/])?([^\\\/.]+)$/;
var v = a_strPath.match( rg1 );
if ( v != null )
{
rslt.strDir = v[1];
rslt.strFile = v[2];
rslt.strExt = v[3];
}
else
{
v = a_strPath.match( rg2 );
rslt.strDir = v[1];
rslt.strFile = v[2];
rslt.strExt = "";
}
return rslt;
}
function getAbsPath( a_strBasePath, a_strRelPath )
{
var sf = splitPathName( a_strBasePath );
return sf.strDir + a_strRelPath;
}
// HuginContext.js------------------------------
function HuginContext()
{
this.aTasks = new Array();
this.bExecuting = false;
this.bCallBack = false;
this.bCallBackReady = false;
this.nLastTime = 0;
this.bError = false;
this.bCancel = false;
this.strMsg = null;
this.reset = function()
{
this.aTasks.length = 0;
this.bExecuting = false;
this.bCallBack = false;
this.bCallBackReady = false;
this.nLastTime = 0;
this.bError = false;
this.bCancel = false;
this.strMsg = null;
}
this.push = function()
{
var i = 0;
var ttasks = new Array();
while( i < context.push.arguments.length )
{
var nLen = ttasks.length;
ttasks[nLen] = new Object();
ttasks[nLen].func = context.push.arguments[i];
ttasks[nLen].owner = context.push.arguments[i + 1];
i += 2;
var bSuspend = false;
if ( i < context.push.arguments.length &&
context.push.arguments[i].constructor.toString().search( /^\nfunction Boolean/ ) == 0 )
{
var bSuspend = context.push.arguments[i];
++i;
}
ttasks[nLen].bSuspend = bSuspend;
}
for ( i = ttasks.length - 1; i >= 0; --i )
context.aTasks[context.aTasks.length] = ttasks[i];
}
this.pop = function()
{
if ( context.aTasks.length == 0 )
return null;
var task = context.aTasks[context.aTasks.length - 1];
context.aTasks.length--;
return task;
}
this.initTime = function()
{
context.nLastTime = ( new Date() ).getTime();
}
this.needBreathe = function()
{
var nCurTime = ( new Date() ).getTime();
return nCurTime - context.nLastTime >= 100;
}
this.resume = function()
{
if ( context.bExecuting )
{
if ( context.bCallBack )
context.bCallBackReady = true;
return;
}
context.bExecuting = true;
context.initTime();
while ( true )
{
if ( context.bCancel )
{
context.bExecuting = false;
g_CurState = ECS_CANCELED;
updateResultView();
return true;
}
var task = context.pop();
if ( task == null )
{ //All tasks were finished.
context.bExecuting = false;
return true;
}
context.bCallBack = task.bSuspend;
task.func( context, task.owner, context.resume ); //If it is not a suspend task, the 3rd argument will be ignored.
if ( context.bError )
{ //Failed. Stop executing.
context.bExecuting = false;
g_CurState = ECS_FATALERROR;
updateResultView();
return;
}
if ( context.bCallBack && !context.bCallBackReady )
{ //Callback function not finished. Give the resume right to it.
context.bExecuting = false;
return;
}
context.bCallBack = false;
context.bCallBackReady = false;
if ( context.needBreathe() )
{ //Give GUI a chance to process messages.
context.bExecuting = false;
updateResultView();
if(gbAIR)
context.resume();
else setTimeout( "context.resume();", 1 );
return;
}
}
}
this.stop = function()
{
context.bCancel = true;
}
}
// Base64.js------------------------------------
var XX = 127; //mark for not used
var s_strBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var s_aAsciiToBase64 = new Array
(
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, // 00~0F
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, // 10~1F
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, 62, XX, XX, XX, 63, // 20~2F '+'=62, '/'=63
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, XX, XX, XX, XX, XX, XX, // 30~3F '0'=52 to '9'=61
XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 40~4F 'A'=0 to 'O'=14
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, XX, XX, XX, XX, XX, // 50~5F 'P'=15 to 'Z'=25
XX, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 60~6F 'a'=26 to 'o'=40
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, XX, XX, XX, XX, XX // 70~7F 'p'=41 to 'z'=51
);
var s_aOdinToAscii = new Array
( // the first the char is '\0', so that s_aOdinToAscii[0] means end of string
'\0', '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '|', ':', ',', '\0', '\0'
);
var s_aBase64DecodeMap = new Array();
function _decordBase64ToStr( a_nA, a_nB )
{
var uBuf = ( s_aAsciiToBase64[a_nA] << 6 ) + s_aAsciiToBase64[a_nB];
var strRslt = "";
var uCur = 0;
for ( var i = 0; i <= 8; i += 4 )
{
uCur = uBuf >> ( 8 - i ) & 0x000F;
if ( uCur == 0 )
return strRslt;
strRslt += s_aOdinToAscii[uCur];
}
return strRslt;
}
// Decode a base64 formatted string into an odin formatted one (only contains charactors occur in s_strBase64
// [in]a_strBase64: Base64 formatted string;
// RESULT: Odin formatted string;
function decodeBase64ToOdin( a_strBase64 )
{
var nLen = a_strBase64.length;
var strRslt = "";
var str = 0;
for ( var i = 0; i + 1 < nLen; i += 2 )
{
str = s_aBase64DecodeMap[( a_strBase64.charCodeAt( i ) << 8 ) + a_strBase64.charCodeAt( i + 1 )]
if ( !str ) return strRslt;
strRslt += str;
}
if ( i < nLen )
{
str = s_aBase64DecodeMap[( a_strBase64.charCodeAt( i ) << 8 ) + s_strBase64.charCodeAt( 0 )]
if ( !str ) return strRslt;
strRslt += str;
}
return strRslt;
}
function initBase64DecodeMap()
{
var i, j;
for ( i = 0; i < 64; i++ )
for ( j = 0; j < 64; j++ )
s_aBase64DecodeMap[( s_strBase64.charCodeAt( i ) << 8 ) + s_strBase64.charCodeAt( j )] = _decordBase64ToStr( s_strBase64.charCodeAt( i ), s_strBase64.charCodeAt( j ) );
for ( i = 0; i < 64; i++ )
s_aBase64DecodeMap[s_strBase64.charCodeAt( i ) << 8] = _decordBase64ToStr( s_strBase64.charCodeAt( i ), s_strBase64.charCodeAt( 0 ) );
}
initBase64DecodeMap();
// HuginPackageReader.js------------------------
function HuginStemRecordTopicShape()
{
this.aPositions = null;
}
function HuginStemRecordTopic()
{
this.uEmphasis = null;
this.aShapes = null;
}
function HuginStemRecord()
{
this.aTopics = null;
}
function HuginPackageReaderResult()
{
this.strNefStem = null;
this.strRecord = null;
this.bStopWord = null ;
}
function HuginPackageReader()
{
this.strPackagePath = null; //in
this.strSynonymPath = null ; //in
this.recordResult = null; //out
this.strQueryWord = null; //in
this.bPhraseSearch = false ;
this.bSucc = true;
this.prepareQuery = function()
{
this.recordResult = null; //out
this.bSucc = true;
this.strQueryWord = null;
this.bPhraseSearch = false ;
}
this.loadFromFile = function( a_Context, a_this, a_funcCallback )
{
theXmlReader.loadFromFile( a_funcCallback, false );
}
this.pickSynonyms = function( a_strStem )
{
return theXmlReader.getSynonyms(a_strStem).split( "," );
}
this.setSynonymForHighlighting = function( a_Context, a_this )
{
if ( !theXmlReader.bSucc )
{
return;
}
var strSyn = "";
var arySynonyms = a_this.pickSynonyms( a_this.strQueryWord );
for ( var i = 0; i < arySynonyms.length; ++i )
{
strSyn += " " + arySynonyms[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -