Example #1
0
function findTripleOrder($triples, $firsts = array(), $or = 0, $pref = array())
{
    global $timer;
    /**
     * @author Helena F Deus <*****@*****.**>
     * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
     * @package S3DB http://www.s3db.org
     */
    #Find triple order is based on the premisse that the more contsnts the system has, the more likely it is to trim down the query. So this simple function scores the number of constants in each triple and re-sorts them as each triple is being solved and providing constants for the remaining triples
    #break the triples
    if (count($triples) > 1) {
        for ($i = 0; $i < count($triples); $i++) {
            $triple = trim($triples[$i]);
            $solver = explode(' ', $triple);
            list($s, $p, $o) = $solver;
            $puzzle = array(!ereg('^\\?', $s), !ereg('^\\?', $p), !ereg('^\\?', $o));
            #If all are constant, then it is not an S3QL query
            if (array_sum($puzzle) == 3) {
                #$triples[$i]='';
                #$s="";$p="";$o="";#delete also s, p, o to use next
                $score[$i] = 0;
                $s = "";
                $p = "";
                $o = "";
            } else {
                $score[$i] = array_sum($puzzle);
            }
            ##Queries on items of collections that do not have results make it unnecessary to query the attributes of those. Score higher those that query collections
            #Find if the obj is collection
            $ob = "";
            $pr = "";
            ereg("<(.*)>", $o, $ob);
            $obj = isS3DBCore($ob[1], false);
            #Find if predicate is type
            $Pterm = hasNotation($p, 'rdf', $pref);
            if ($Pterm == 'type' && ereg('I|C|S|R|P', $obj['letter'])) {
                $score[$i] = $score[$i] + 1;
                ##Queries get 1 point for being faster
            }
            ##triples that are a subclass of something are faster, get 1 extra point
            if ($p == 'http://www.w3.org/2000/01/rdf-schema#subClassOf' && ereg('C|P', $obj['letter'])) {
                $score[$i] = $score[$i] + 1;
            }
            #Some predicates, such as label comment, etc, appear in any entity, therefore they are non specific and do not help in building a query  - lose 1 point
            $pr = "";
            ereg("<(.*)>", $p, $pr);
            if (in_array($pr[1], $GLOBALS['not_uid_specific']) && $score[$i] == 1) {
                #the constant part is not specific and there is only this one constant
                $score[$i] = $score[$i] - 1;
            }
        }
        ##This will basically assign the triple to a subgroup of queries to be performed simulataneously, according to its order
        array_multisort($score, SORT_NUMERIC, SORT_DESC, $triples);
        ##Because I don't want to lose the index relationship between the ttriples and the order
        ##Now separate the triples into groups
        $groups = array();
        foreach ($score as $i => $s) {
            $j = max($score) - $s;
            if (!is_array($groups[$j])) {
                $groups[$j] = array();
            }
            array_push($groups[$j], $triples[$i]);
        }
        /*for ($j=0; $j < count($score) ; $j++) {
        		
        		#now, the first line to solve will be the one socres the highest but not equal to 3
        		#if($score[$j]==2)
        		if($score[$j]==max($score))
        		{
        			$firsts[$j] = $or;
        			
        			#now eliminate the solved triple from the other triples
        			#$tick = array_search(0, $puzzle);
        			
        			
        			$tmp=split(' ',$triples[$j]);
        			$tick='';
        			foreach ($tmp as $t) {
        				if(ereg('^\?',$t))
        					$tick = $t;
        			}
        			
        			#if(ereg('(\?[A-Za-z0-9_]) ', $triples[$j],$tmp)){
        			if($tick!=''){
        			
        			
        			$triplesSolved=array();
        			foreach ($triples as $tmp) {
        				$triplesSolved[] = str_replace($tick,substr($tick, 1, strlen($tick)), $tmp);
        				
        			}
        			$triples = $triplesSolved;
        			
        			}
        			#$score[$j]=0;##since it was already added, we want a new score max
        			
        		}
        		else {
        			$firsts[$j]=0;
        		}
        
        	  
        		
        
        	}
        	
        	*/
        #ok, we're done, let's go back to the beginning
        /*if($triplesSolved)
        		{
        		$triplesSolved = array_filter($triplesSolved);
        		$or++;
        		$firsts = findTripleOrder($triples,$firsts,$or,$pred);
        	
        		}
        	}
        	else {
        		
        		$firsts = array(0=>0);
        	}
        	*/
    }
    return $groups;
}
Example #2
0
			<td>' . $data2display . '</td>
			</tr>



		</table>
				
		';
if ($_REQUEST['callback']) {
    ##
    $varName = ereg_replace('^\\?', '', $_REQUEST['callback']);
    ##Create a JSON variable that can be read and interpreted by the javascript in the other frame
    if (is_array($sparqlData)) {
        $newLeaf = array();
        foreach ($sparqlData as $key => $data) {
            $coreVar = isS3DBCore($data[$_REQUEST['callback']]);
            $forJS = $coreVar['letter'] . $coreVar['value'];
            switch ($coreVar['letter']) {
                case 'D':
                    $nextCallback = '?project_id';
                    $nextVar = ereg_replace('^\\?', '', $nextCallback);
                    $newLeaf[$key][1] = '[ "' . $forJS . '", 0 ]';
                    $newLeaf[$key][2] = '[ "Projects", "../frames/sparqlForm.php?query=select distinct ?project_id where { ' . $nextCallback . ' a s3db:s3dbProject . }&callback=?project_id&leadInd=' . $key . '"];';
                    break;
                case 'P':
                    $nextCallback = '?rule_id';
                    $nextVar = ereg_replace('^\\?', '', $nextCallback);
                    $newLeaf[$key][1] = '[ "' . $forJS . '", 0 ]';
                    $newLeaf[$key][2] = '[ "Collections", "../frames/sparqlForm.php?query=select distinct ?collection_id where { ?collection_id a s3db:s3dbCollection . ?collection_id rdfs:subClassOf :' . $forJS . ' . }&callback=?collection_id&leadInd=' . $key . '"];';
                    $newLeaf[$key][3] = '[ "Rules", "../frames/sparqlForm.php?query=select distinct ?rule_id where { ?rule_id a s3db:s3dbRule . ?rule_id rdfs:subClassOf :' . $forJS . ' . }&callback=?rule_id&leadInd=' . $key . '"];';
                    break;