Esempio n. 1
0
function doSearch(array $words, array $searchWords, $limit, $searchFunction)
{
    foreach ($searchWords as $searchWord) {
        $words = array_merge($words, $searchFunction($searchWord, $limit));
        $words = removeDuplicates($words);
        if (count($words) >= $limit) {
            array_splice($words, $limit);
        }
    }
    return $words;
}
     listSynonyms($synonyms);
 } else {
     //IF REWRITE IS NOT REQUESTED, PROCESS QUERY:
     //CALL FUNCTIONS TO GET RESULTS FROM SEARCH ENGINES
     getBlekkoResults($blekkoResultsOrig);
     //get Blekko
     getGoogleResults($googleResultsOrig);
     //get Google
     getBingResults($bingResultsOrig);
     //get Bing
     //**************************************************************************
     //**************************************************************************
     //CALL FUNCTIONS TO REMOVE DUPLICATE URLS AND RE-SCORE DOCUMENTS
     removeDuplicates($blekkoResultsOrig, $blekkoResults);
     removeDuplicates($googleResultsOrig, $googleResults);
     removeDuplicates($bingResultsOrig, $bingResults);
     //**************************************************************************
     //**************************************************************************
     //(IF NON-AGGREGATED CHOSEN THEN DISPLAY RESULTS:)
     if ($_POST['result_type'] === 'Non-Aggregated') {
         echo "<div class=\"row-fluid\">" . "<div class=\"span4\">";
         echo "<h2 class=\"text-center\">Bing</h2>";
         displayResults($bingResults);
         //display Bing
         echo "</div>";
         echo "<div class=\"span4\">";
         echo "<h2 class=\"text-center\">Google</h2>";
         displayResults($googleResults);
         //display Google
         echo "</div>";
         echo "<div class=\"span4\">";
 * findDuplicates([1,2, 3, "jablko", 'banan']) => [1,2, 3, "jablko", 'banan']
 */
/**
 * @param $myArray
 * @return array
 */
function removeDuplicates($myArray)
{
    $removeDuplicates = array_unique($myArray);
    $j = 0;
    $results = array();
    foreach ($removeDuplicates as $value) {
        $results[$j] = $value;
        $j++;
    }
    return $results;
}
/*
 * Kod popniżej służy wygenerowaniu testów i strony poglądaowej - nie modyfikujcie go!
 */
$testCases = [[[1, 2, "jan", "kowlaski", 2, "jan"], [1, 2, "jan", "kowlaski"]], [[3.4, "jablko", 'banan', 'banan', "gruszka", 5], [3.4, "jablko", 'banan', "gruszka", 5]], [[1, 2, 3, "jablko", 'banan'], [1, 2, 3, "jablko", 'banan']], [[], []], [[1, 2, 3, 4], [1, 2, 3, 4]]];
$results = "";
foreach ($testCases as $case) {
    if (($funcValue = removeDuplicates($case[0])) === $case[1]) {
        $results .= "<tr class='success'><td> Ok </td><td>[" . implode($case[0], ",") . "] </td><td>[" . implode($case[1], ",") . "]</td><td>[" . implode($funcValue, ",") . "]</td></tr>";
    } else {
        var_dump($funcValue);
        $results .= "<tr class='danger'><td> Fail </td><td> [" . implode($case[0], ",") . "] </td><td>[" . implode($case[1], ",") . "]</td><td>[" . implode($funcValue, ",") . "]</td></tr>";
    }
}
echo "\n<!DOCTYPE html>\n<html lang='pl'>\n  <head>\n    <meta charset='utf-8'>\n    <title>Usuń duplikaty</title>\n    <link href='./css/bootstrap.min.css' rel='stylesheet'>\n\n  </head>\n\n  <body>\n\n    <div class='container'>\n      <div class='jumbotron'>\n        <h1>Usuń duplikaty</h1>\n        <p><a class='btn btn-lg btn-success' href='javascript:window.location.reload();' role='button'>Odświerz</a></p>\n      </div>\n\n      <div class='row'>\n          <h1>Testy:</h1>\n          <table class='table'>\n            <thead>\n              <tr>\n                <th>Stan testu:</th>\n                <th>Dane:</th>\n                <th>Wartość spodziewana:</th>\n                <th>Wartość otrzymana:</th>\n              </tr>\n            </thead>\n            <tbody>\n                {$results}\n            </tbody>\n          </table>\n      </div>\n    </div>\n  </body>\n</html>\n";
Esempio n. 4
0
function getBooks($dbpid)
{
    $format = 'json';
    $query = 'PREFIX dbp: <http://dbpedia.org/resource/>
   PREFIX dbp2: <http://dbpedia.org/ontology/>
 
   SELECT ?book,?author,?name,?thumbnail,?published,?released,?wikilink,?abstract
   WHERE {
	 ?book a dbpedia-owl:Book.
	 ?book dbpedia-owl:author ?author.
	 ?book foaf:name ?name.
	 ?book prov:wasDerivedFrom ?wikilink.
	 OPTIONAL{
		?book dbpprop:published ?published.
	 }
	 OPTIONAL{
		?book dbpprop:releaseDate ?released.
	 }
	 OPTIONAL{
		?book dbpedia-owl:thumbnail ?thumbnail.
	 }
	  OPTIONAL{
		?book dbpedia-owl:abstract ?abstract
		FILTER(LANG(?abstract)="de")
	 }
	 
	 FILTER(?author=<' . $dbpid . '>)
   }
   LIMIT 100';
    $searchUrl = 'http://dbpedia.org/sparql?' . 'query=' . urlencode($query) . '&format=' . $format;
    $dbPediaResult = DDPediaRequest($searchUrl);
    $jsonResult = json_decode($dbPediaResult);
    if (property_exists($jsonResult, "results") && property_exists($jsonResult->results, "bindings") && count($jsonResult->results->bindings) > 0) {
        return removeDuplicates($jsonResult->results->bindings, "book");
    } else {
        return array();
    }
}
Esempio n. 5
0
                if ($tempArray[$i]['drug_code'] === $resultArray[$j]['drug_code']) {
                    array_push($resultArray[$j]['ingredients'], array('ingredient' => $tempArray[$i]['ingredient'], 'ai_code' => $tempArray[$i]['active_ingredient_code'], 'strength' => formatStrength($tempArray[$i]['strength']), 'strength_unit' => $tempArray[$i]['strength_unit'], 'dosage_form' => $tempArray[$i]['pharmaceutical_form']));
                    $match = true;
                }
            }
            if ($match === false) {
                array_push($resultArray, array('drug_code' => $tempArray[$i]['drug_code'], 'ingredients' => array(array('ingredient' => $tempArray[$i]['ingredient'], 'ai_code' => $tempArray[$i]['active_ingredient_code'], 'strength' => formatStrength($tempArray[$i]['strength']), 'strength_unit' => $tempArray[$i]['strength_unit'], 'dosage_form' => $tempArray[$i]['pharmaceutical_form'])), 'match' => 0));
            }
        }
    }
    // Sorts the ingredient array by generic_name
    for ($i = 0; $i < count($resultArray); $i++) {
        usort($resultArray[$i]['ingredients'], "sortAICode");
    }
    // Removes entries with duplicate ingredients
    $resultArray = removeDuplicates($resultArray);
}
/****************************************************************************
 *	FINDING DRUG MATCH														*/
/****************************************************************************
 *	Uses the result array returned above to see if there is a good match	*
 *	A good match means that all the strengths for a drug code match the $q	*
 *	provided and only one such entry meets this requirement					*
 *																			*
 *	Runs only if $resultArray has at least one entry						*
 *																			*
 * 	If a match is found, returns an array of matches						*
 ****************************************************************************/
if (count($resultArray) > 0) {
    $errorReport .= "FINDING DRUG MATCH\n";
    // Cycles through all the resultArray entries and determine match status
Esempio n. 6
0
 function makeSlugs($string = '', $maxlen = 0)
 {
     $newStringTab = array();
     $string = strtolower(noDiacritics($string));
     if (function_exists('str_split')) {
         $stringTab = str_split($string);
     } else {
         $stringTab = my_str_split($string);
     }
     $numbers = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-");
     //$numbers=array("0","1","2","3","4","5","6","7","8","9");
     foreach ($stringTab as $letter) {
         if (in_array($letter, range("a", "z")) || in_array($letter, $numbers)) {
             $newStringTab[] = $letter;
             //print($letter);
         } elseif ($letter == " ") {
             $newStringTab[] = "-";
         }
     }
     if (count($newStringTab)) {
         $newString = implode($newStringTab);
         if ($maxlen > 0) {
             $newString = substr($newString, 0, $maxlen);
         }
         $newString = removeDuplicates('--', '-', $newString);
     } else {
         $newString = '';
     }
     return $newString;
 }
Esempio n. 7
0
                    $outname = substr($file, $rdLen);
                    $zip->addFile($file, $outname);
                }
            }
        }
    }
    foreach ($fileList['files'] as $file) {
        $outname = substr($file, $rdLen);
        $zip->addFile($file, $outname);
    }
    $res = $zip->close();
    return $destination;
}
// Output the directory listing as JSON
$fileList = cleanseFileList();
$fileList = removeDuplicates($fileList);
if (count($fileList['folders']) || count($fileList['files'])) {
    $fullName = zipTheFiles($fileList);
    if ($fullName) {
        $docRoot = $_SERVER['DOCUMENT_ROOT'];
        $output = substr($fullName, strlen($docRoot . '/tmp/'));
    }
} else {
    $output = '';
}
$info = "\n{$fullName}";
$info .= ' ' . filesize($fullName);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
Esempio n. 8
0
        //take first on and replace in towns
        if (count($ids) > 1) {
            print '<br>' . $name . ' ' . count($ids);
        }
        removeDuplicates($ids);
        $name = $row[1];
        $gov_id = $row[2];
        //if(count($ids)>1) exit();
        $ids = array();
    }
    array_push($ids, $row[0]);
}
if (count($ids) > 1) {
    print '<br>' . $name . ' ' . count($ids);
}
removeDuplicates($ids);
print '<br>Removed: ' . $removed;
//
//
//
function removeDuplicates($ids)
{
    global $mysqli, $removed;
    if (count($ids) > 1) {
        //take first on and replace in towns
        $rec_id = array_shift($ids);
        $ids_todel = implode(',', $ids);
        $query = 'update recDetails set dtl_Value=' . $rec_id . ' where dtl_Value in (' . $ids_todel . ') and dtl_DetailTypeID=170';
        //print $query; return;
        $res = $mysqli->query($query);
        $mysqli->query('SET foreign_key_checks = 0');
    $sqlCheckTableExists = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'international_cities_rrr' AND table_name = '" . $country['short_name'] . "';";
    $resultsTableExistsCheck = mysql_query($sqlCheckTableExists) or die('died trying to see if the table exists: ' . mysql_error());
    if (mysql_num_rows($resultsTableExistsCheck) > 0) {
        //		echo $country['short_name']." ";
        $tableExists = mysql_fetch_assoc($resultsTableExistsCheck);
        //		echo $tableExists['COUNT(*)'];
        //		echo '<br />';
        if ($tableExists['COUNT(*)'] > 0) {
            //see if the country table exists in the international_cities db
            mysql_select_db('international_cities_rrr', $dbconnectINTCities);
            //get all duplicate city entries for this country
            $sqlGetDuplicates = "SELECT cc1, COUNT(name), name FROM `" . $country['short_name'] . "` GROUP BY name HAVING(COUNT(name) > 1);";
            $resultDuplicates = mysql_query($sqlGetDuplicates) or die('died trying to get duplicates: ' . mysql_error());
            while ($city = mysql_fetch_assoc($resultDuplicates)) {
                echo "Duplicate Found: " . $city['name'] . '<br />';
                removeDuplicates($city['name'], $city['cc1']);
            }
        }
    }
}
function removeDuplicates($cityName = null, $countryCode = null)
{
    $duplicates = array();
    //get all id's for city duplicates
    $sql = "SELECT id FROM `{$countryCode}` WHERE name = '" . addslashes($cityName) . "'";
    $results = mysql_query($sql) or die('died getting all this city\'s duplicate entries: ' . mysql_error());
    while ($city = mysql_fetch_assoc($results)) {
        $duplicates[] = $city['id'];
    }
    //go through and delete all the duplicate cities (leaving the last city record only)
    for ($i = 0; $i < count($duplicates) - 1; $i++) {