⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphnew.php

📁 flashget43的源代码 一个比较常用的下载程序
💻 PHP
📖 第 1 页 / 共 2 页
字号:

			for ($curpc=0;$curpc<=$curpdiff;$curpc++){
				array_pop($patternmatched);
			}
		}

	}

	// Else no match found...
	if ((($whichresult[0]==-1)&&($whichresult[1]==-1)&&($whichresult[2]==-1))||($continuenode==1)) {			
		//If we were most recently on a wildcard (*,_) then we are still matching it.
		if (($onwild==1)&&($word!="")&&($word!="<that>")&&($word!="<topic>")){
			debugger("On wild and in *. keep going with graphwalker.",2);

			addtostar($parton,$word,$inputstarvals,$thatstarvals,$topicstarvals,2);				

			return graphwalker($remains,$parent,1,1,$parton,$inputstarvals,$thatstarvals,$topicstarvals,$patternmatched);
		}
		else {
			//We didn't find anything. We need to come back out
			debugger("Result is blank from query in *. Returning blank",2);	
			return "";
		}

	}

}

/**
* Does a database query for {@link graphwalker()}
*
* Retrieves the ID, ordera, isend of the word to be searched
* $query="select id,ordera,isend from patterns where word='" . addslashes($word) . "' or word is null and parent=$parent";
*
* @todo The array returned is also returned via call-by-reference. Investigate which should be chosen.
*
* @uses debugger()
*
* @global integer                   The number of queries that have been executed
*
* @param string $query              The SQL code to be executed
* @param array &$whichresult        contains ID, ordera and isend from the query. note: call-by-reference
*
* @return array                     contains ID, ordera and isend from the query. note: call-by-reference array exists too.
*/
function dographquery(&$whichresult, $word, $parent){

	$query="select id,ordera,isend from {$GLOBALS['fc_config']['db']['pref']}patterns where (word='" . addslashes($word) . "' or word is null) and parent=$parent";


	global $numselects;
	
	$numselects++;
	debugger("dographquery: $query\n",2);

	$whichresult[]=-1;
	$whichresult[]=-1;
	$whichresult[]=-1;

	$whichresult[]=-1;
	$whichresult[]=-1;
	$whichresult[]=-1;

	$selectcode = mysql_query($query);
	if ($selectcode){
		if(!mysql_numrows($selectcode)){
			return $whichresult;
		}
		else{
			while ($q = mysql_fetch_array($selectcode)){
				if ($q[1]==1){
					$whichresult[0]=$q[0];

					// If it is the last word in its context.
					if ($q[2]==1){
						$whichresult[3]=1;
					}

				}
				elseif ($q[1]==2){
					$whichresult[1]=$q[0];

					// If it is the last word in its context.
					if ($q[2]==1){
						$whichresult[4]=1;
					}

				}
				elseif ($q[1]==3){
					$whichresult[2]=$q[0];

					// If it is the last word in its context.
					if ($q[2]==1){
						$whichresult[5]=1;
					}

				}
				


			}
			return $whichresult;
		}
	}

}



/**
* Retrieve the template from the templates table
*
* Get the template from the templates table. and return it.
* 
* @todo The name {@link gettemplate()} and findtemplate() are too similar.
*
* @param integer $id                  The ID of the template to be returned
*
* @return string                      The contents of <template/> for this category.
*/
function findtemplate($id){

	$query = "select template from {$GLOBALS['fc_config']['db']['pref']}templates where id=$id";
	debugger($query,2);
	$selectcode = mysql_query($query);
	if ($selectcode){
		if(!mysql_numrows($selectcode)){
			return "";
		}
		else{
			while ($q = mysql_fetch_array($selectcode)){
				return $q[0];
			}
		}
	}

	return "";
}


/**
* Deals with creating and adding to the star arrays
*
* If a * or _ is part of the matched pattern, what is covered by that variable is then stored in the 'star arrays'. This function creates and adds words to that array or array element.
*
* @param string $parton          Can be input, that, topic. 
* @param string $word            The word that needs to be stored
* @param array &$inputstarvals   contents of the *'s when they are part of the matching pattern input string
* @param array &$thatstarvals    contents of the *'s when they are part of the matching pattern that string
* @param array &$topicstarvals   contents of the *'s when they are part of the matching pattern topic string
* @param integer $action         what action needs to be done, append to existing or create new.
*
* @return void                   info is returned via call-by-reference variables.
*/
function addtostar($parton,$word,&$inputstarvals,&$thatstarvals,&$topicstarvals,$action){

	if (($word!="<nothing>")&&($word!="<that>")&&($word!="<topic>")){

		if ($parton=="input"){

			// Action 1 is adding a new star
			if ($action==1){
				$inputstarvals[]=$word;
			}
			// Action 2 is appending to existing star
			elseif ($action==2){
				$inputstarvals[sizeof($inputstarvals)-1].= " " . $word;
			}
		
		}
		elseif ($parton=="that"){

			if ($action==1){
				$thatstarvals[]=$word;
			}
			elseif ($action==2){
				$thatstarvals[sizeof($thatstarvals)-1].= " " . $word;
			}

		}
		elseif ($parton=="topic"){

			if ($action==1){
				$topicstarvals[]=$word;
			}
			elseif ($action==2){
				$topicstarvals[sizeof($topicstarvals)-1].= " " . $word;
			}

		}

	}
}


/**
* Fast forward to the processing of the next context
*
* Remainder of the user's input covered by a *. So so add everything up to the next context (<that> & <topic>) to the star.
*
* @todo $newremains is a variable that is created, and filled but not returned. It is perhaps old code that 
*       pre dates {@link addtostar()} that saves the returned value in {@link graphmaster()}. 
* 
*
* @param string $word                     Current processed word
* @param string $ffremains                Words that remain to be processed.
*
* @return string                          words to be saved by {@link addtostar()}
*/
function fastforward($word,$ffremains){

	$starwords=$word;

	$newremains="";

	$ffremains=trim($ffremains);
	$ffar=split(" ",$ffremains);

	$x=0;
	$currentword=$ffar[$x];

	while (($currentword!="<that>")&&($currentword!="<topic>")&&($currentword!="")){

		$starwords = $starwords . " " . $currentword;
		$x++;

		if ($x>=sizeof($ffar)){
			break;
		} else {
			$currentword=$ffar[$x];
		}

	}

	for ($y=$x;$y<sizeof($ffar);$y++){
		$newremains =  $newremains . " " . $ffar[$y];
	}

	$ffremains=trim($newremains);
	
	return $starwords;

}


/**
* Check to see if exact input-that-topic exists in cache
*
* GmCache is a log that contains all unique entries. If the exact same input-that-topic is requested that is found in GmCache, then it's template reference is used instead of traversing the binary AIML tree. Saving response time.
*
* @param string $combined                  the complete input in <input>word word<that>word word<topic>word word format. 
* @param array &$inputstarvals   contents of the *'s when they are part of the matching pattern input string
* @param array &$thatstarvals    contents of the *'s when they are part of the matching pattern that string
* @param array &$topicstarvals   contents of the *'s when they are part of the matching pattern topic string
* @param array &$patternmatched  all the patterns that match input, i.e. multiple sentences are kept seperate.
* @param array &$inputmatched    all the matched input.
*
* @return boolean                true/false Note, info is also transfere through the call-by-reference variables.
*/

function checkcache($combined,&$template,&$inputstarvals,&$thatstarvals,&$topicstarvals,&$patternmatched,&$inputmatched)
{
	$ccquery="select template,inputstarvals,thatstarvals,topicstarvals,patternmatched,inputmatched from {$GLOBALS['fc_config']['db']['pref']}gmcache where combined='" . addslashes($combined) . "' and " . whichbots();	

	$selectcode = mysql_query($ccquery);
	if ($selectcode){
		if(!mysql_numrows($selectcode)){
			return false;
		}
		else{
			while ($q = mysql_fetch_array($selectcode)){

				$template=findtemplate($q[0]);
				$inputstarvals=split(",",$q[1]);
				$thatstarvals=split(",",$q[2]);
				$topicstarvals=split(",",$q[3]);
				$patternmatched=$q[4];
				$inputmatched=$q[5];
				
				return true;
			}
		}
	}

	return false;

}


/**
* Add an entry in the GMcache table
*
* @global integer                  The selected bot.
*
* @param string $combined                  the complete input in <input>word word<that>word word<topic>word word format. 
* @param string $mytemplate                the reply to the input
* @param string $inputstarvals             contents of the input star
* @param string $thatstarvals              contents of the that star
* @param string $topicstarvals             contents of the topic star
* @param string $patternmatched            the AIML category pattern that matches the input
* @param string $inputmatched              the input that matched the category.
*
* @return void
*/
function fillcache($combined,$mytemplate,$inputstarvals,$thatstarvals,$topicstarvals,$patternmatched,$inputmatched)
{
	global $selectbot;	
	
	$ccquery="insert into {$GLOBALS['fc_config']['db']['pref']}gmcache (bot, combined,template,inputstarvals,thatstarvals,topicstarvals,patternmatched,inputmatched) values ($selectbot,'" . addslashes($combined) . "'," . $mytemplate . ",'" . addslashes(arraytostring($inputstarvals)) . "','" . addslashes(arraytostring($thatstarvals)) . "','" . addslashes(arraytostring($topicstarvals)) . "','" . addslashes($patternmatched) . "','" . addslashes($inputmatched) . "')";

	$selectcode = mysql_query($ccquery);
	if ($selectcode){
	}

}


/**
* Turn an array into a string
*
* take each element of the array and put all of them into one big string; one after the other.
*
* @param array $myarray
* 
* @return string                         the contents of the array into a string.
*/
function arraytostring($myarray)
{
	$retstring="";

	for ($x=0;$x<sizeof($myarray);$x++){
		$retstring .= $myarray[$x] . ",";	
	}

	$retstring=substr($retstring,0,strlen($retstring)-1);

	return $retstring;

}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -