Exemple #1
0
function showSelect($videos, $select)
{
    print '<option value=""></option>';
    $maxsim = 0;
    foreach ($videos as $vid) {
        $thissim = 0;
        $sim = similarity($select, $vid[title]);
        if ($sim > $thissim) {
            $thissim = $sim;
        }
        $sim = similarity($select, $vid[subtitle]);
        if ($sim > $thissim) {
            $thissim = $sim;
        }
        $sim = similarity($select, $vid[filename]);
        if ($sim > $thissim) {
            $thissim = $sim;
        }
        if ($thissim > $maxsim) {
            $SEL = "selected";
            $maxsim = $thissim;
        } else {
            $SEL = "";
        }
        print '<option value="' . $vid[id] . '" ' . $SEL . '>';
        print $vid[title];
        print ' - ';
        print $vid[subtitle];
        print '   (' . $thissim . '%)';
        print '</option>';
    }
}
     if (isset($_GET["smiles"])) {
         $variable = $_GET["smiles"];
     } elseif (isset($_GET["smarts"])) {
         $variable = convertSMARTS($_GET["smarts"]);
     }
     //Second section depending of the optional inputs
     if (isset($variable) && isset($_GET["fingerprint"]) && isset($_GET["method"])) {
         $value = similarity($variable, $_GET["fingerprint"], $_GET["method"]);
     } else {
         if (isset($variable) && isset($_GET["fingerprint"])) {
             $value = similarity($variable, $_GET["fingerprint"], "Tanimoto");
         } elseif (isset($variable) && isset($_GET["method"])) {
             $value = similarity($variable, "Morgan", $_GET["method"]);
         } else {
             if (isset($variable)) {
                 $value = similarity($variable, "Morgan", "Tanimoto");
             } else {
                 $value = "Missing argument";
             }
         }
     }
     break;
 case "properties":
     if (isset($_GET["smiles"])) {
         $variable = $_GET["smiles"];
         $value = properties($variable);
     } elseif (isset($_GET["smarts"])) {
         $variable = convertSMARTS($_GET["smarts"]);
         $value = properties($variable);
     } else {
         $value = "Missing argument";
Exemple #3
0
function group_list($branch_list, $depth, $min_similarity)
{
    $min_similarity = 2;
    $depth = 2;
    // $branch_list est un array de labels composés de ngrammes séparés par des virgules
    /// retour un array contenant
    // ['grouped_indexes']: un array de groupes d'indices mentionnant les labels similaires
    // ['Ngram_arrays']: un array contenant pour chaque groupe d'indices, un array pour labelliser le groupe dont les clés sont des NGram pris jusqu'à une profondeur $depth et les valeurs leur nombre d'occurrences dans les labels
    // calcul des similarités entre labels de branches
    $label_rows_groups = array();
    $label_groups = array();
    $nb_labels_treated = 0;
    $label_rows_remaining_to_process = array();
    // index des labels non encore catégorisés
    // initialisation de ce tableau
    for ($i = 0; $i < count($branch_list); $i++) {
        array_push($label_rows_remaining_to_process, $i);
    }
    while (count($label_rows_remaining_to_process) > 0) {
        $target_row = array_pop($label_rows_remaining_to_process);
        $target_label_raw = array();
        // liste des rangs groupés avec target_row
        $target_labels = array();
        // liste des labels des rangs associés
        array_push($target_labels, $branch_list[$target_row][label]);
        array_push($target_label_raw, $target_row);
        $label_rows_remaining_to_process_second_pass = $label_rows_remaining_to_process;
        while (count($label_rows_remaining_to_process_second_pass) > 0) {
            $candidate_row = array_pop($label_rows_remaining_to_process_second_pass);
            $candidate_label = remove_popo($branch_list[$candidate_row][label]);
            $exit_here = 0;
            $j = 0;
            while ($j < count($target_labels) && exit_here == 0) {
                $p = similarity($candidate_label, remove_popo($target_labels[$j]));
                // echo 'candidate labels'.$candidate_label.'<br/>';
                // echo 'target labels'.$target_labels[$j].'<br/>';
                // echo $p.'<br/>';
                //similar_text ( $candidate_label,$target_labels[$j],$p );
                if ($p > $min_similarity) {
                    $exit_here = 1;
                    // echo 'similarity: '.$p.'<br/>';
                    // echo 'candidate labels '.$candidate_label.'<br/>';
                    // echo 'target labels' .$target_labels[$j].'<br/><br/> ';
                }
                $j++;
            }
            if ($exit_here == 1) {
                //echo $branch_list[$candidate_row][label].'<br/>';
                array_push($target_labels, $branch_list[$candidate_row][label]);
                array_push($target_label_raw, $candidate_row);
                $label_rows_remaining_to_process = array_diff($label_rows_remaining_to_process, $target_label_raw);
                array_push($target_branches, $candidate_branch);
                array_push($target_label_raw, $candidate_row);
            }
        }
        array_push($label_rows_groups, $target_label_raw);
        /////////////////
        // on reconstruit l'array des labels_id de branche
        $target_branches_label_ids = array();
        for ($i = 0; $i < count($target_labels); $i++) {
            array_push($target_branches_label_ids, $target_labels[$i]['label_ids']);
        }
        if (count($target_branches_label_ids) > 3) {
            array_push($label_groups, groups_labels($target_branches_label_ids, 4, $target_label_raw, $branch_list));
        } else {
            array_push($label_groups, groups_labels($target_branches_label_ids, $depth, $target_label_raw, $branch_list));
        }
        /////////////////
        array_push($label_groups, label_label_group($target_labels, $depth));
        $resultat = array();
    }
    /// on réordonne par nombre de sujets groupés
    $groups_sizes = array();
    for ($i = 0; $i < count($label_rows_groups); $i++) {
        array_push($groups_sizes, count($label_rows_groups[$i]));
    }
    uasort($groups_sizes, 'compare');
    $new_order = array_keys($groups_sizes);
    //
    $label_rows_groups_temp = array();
    for ($i = 0; $i < count($label_rows_groups); $i++) {
        array_push($label_rows_groups_temp, $label_rows_groups[$new_order[$i]]);
    }
    $label_rows_groups = $label_rows_groups_temp;
    //
    $label_groups_temp = array();
    for ($i = 0; $i < count($label_groups); $i++) {
        array_push($label_groups_temp, $label_groups[$new_order[$i]]);
    }
    $label_groups = $label_groups_temp;
    //
    $resultat['grouped_indexes'] = $label_rows_groups;
    $resultat['Ngram_arrays'] = $label_groups;
    return $resultat;
}