コード例 #1
0
ファイル: cluster.php プロジェクト: rdmpage/phyloinformatics
function cluster($strings)
{
    $result = new stdclass();
    $n = count($strings);
    // clean
    for ($i = 0; $i < $n; $i++) {
        $strings[$i] = finger_print(trim($strings[$i]));
    }
    $map = array();
    $inv_map = array();
    $count = 0;
    foreach ($strings as $k => $v) {
        $map[$k] = $count;
        $inv_map[$count] = $k;
        $count++;
    }
    // Create adjacency matrix and fill with 0's
    $X = array();
    for ($i = 0; $i < $n; $i++) {
        $X[$i] = array();
        for ($j = 0; $j < $n; $j++) {
            $X[$i][$j] = 0;
        }
    }
    $nodes = '';
    $edges = '';
    // Compare names using approximate string matching
    $i = 0;
    foreach ($strings as $k1 => $v1) {
        $nodes .= "node {$i} [label=\"" . $v1 . "\"];\n";
        if ($i < $n - 1) {
            $j = 0;
            foreach ($strings as $k2 => $v2) {
                if ($j > $i && $j < $n) {
                    // Find longest common subsequence for this pair of cleaned names
                    $lcs = new LongestCommonSequence($v1, $v2);
                    $d = $lcs->score();
                    // Filter by longest common substring (to ensure we have a "meaningful"
                    // match), that is, so that we avoid subsequences that have little continuity
                    $str = '';
                    $lcstr = LongestCommonSubstring($v1, $v2, $str);
                    if ($lcstr >= 4) {
                        // Ignore matches just on date, we want more than that
                        if (is_numeric(trim($str))) {
                        } else {
                            // If longest common subsequence is > 70% of the length of both strings
                            // we accept it.
                            if ($d / strlen($v1) >= 0.7 || $d / strlen($v2) >= 0.7) {
                                $X[$map[$k1]][$map[$k2]] = 1;
                                $X[$map[$k2]][$map[$k1]] = 1;
                                $edges .= $i . " -- " . $j . " [label=\"" . $lcstr . "\"];\n";
                            }
                        }
                    } else {
                        // If just a short match is it the start if the string (e.g., an abbreviation)
                        $abbreviation = false;
                        if (strlen($v1) == $d) {
                            if (strpos($v2, $v1, 0) === false) {
                            } else {
                                $abbreviation = true;
                            }
                        } else {
                            if (strpos($v1, $v2, 0) === false) {
                            } else {
                                $abbreviation = true;
                            }
                        }
                        // Accept abbreviation
                        if ($abbreviation) {
                            $X[$map[$k1]][$map[$k2]] = 1;
                            $X[$map[$k2]][$map[$k1]] = 1;
                            $edges .= $i . " -- " . $j . " [label=\"" . $lcstr . "\"];\n";
                        }
                    }
                }
                $j++;
            }
            $i++;
        }
    }
    $result->graph = "graph {\n" . $nodes . $edges . "}\n";
    //echo $graph;
    // Get components of adjacency matrix
    $components = get_components($X);
    $result->clusters = array();
    foreach ($components as $component) {
        $cluster = array();
        foreach ($component as $k => $v) {
            $member = new stdclass();
            $member->id = $inv_map[$v];
            $member->string = $strings[$inv_map[$v]];
            $cluster[] = $member;
        }
        $result->clusters[] = $cluster;
    }
    //print_r($map);
    if (0) {
        print_r($c);
    }
    return $result;
}
コード例 #2
0
ファイル: index.php プロジェクト: Ike-Clinton/domeclone
     echo get_projects($_GET);
 } else {
     if (strpos($uri, '/companies') !== false) {
         echo get_company($_GET);
     } else {
         if (strpos($uri, '/company_reviews') !== false) {
             echo get_company_review($_GET);
         } else {
             if (strpos($uri, '/add_review_company') !== false) {
                 echo add_company_review($_POST);
             } else {
                 if (strpos($uri, '/get_account') !== false) {
                     echo get_account($_GET);
                 } else {
                     if (strpos($uri, '/components') !== false) {
                         echo get_components($_GET);
                     } else {
                         if (strpos($uri, '/documents') !== false) {
                             echo get_documents($_GET);
                         } else {
                             if (strpos($uri, '/products') !== false) {
                                 echo get_products($_GET);
                             } else {
                                 if (strpos($uri, '/add_to_project') !== false) {
                                     echo add_to_project($_POST);
                                 } else {
                                     if (strpos($uri, '/remove_from_project') !== false) {
                                         echo remove_from_project($_POST);
                                     } else {
                                         if (strpos($uri, '/uploadServiceImage') !== false) {
                                             echo upload_service_image($_POST, $_FILES);
コード例 #3
0
ファイル: frm_staff.php プロジェクト: anggadjava/payroll
$component_b = get_component_b($id);
$family = get_families($id);
// components A
$comp_a_data = '';
if ($component_a) {
    foreach ($component_a->result() as $gaji) {
        $component = get_components($gaji->gaji_component_id);
        $comp_a_data .= '["' . $gaji->gaji_component_id . '", "' . $component->comp_name . '", "' . $component->comp_type . '", "' . $gaji->gaji_daily_value . '", "' . number_format($gaji->gaji_amount_value, 2, ".", ",") . '"],';
    }
    $comp_a_data = substr($comp_a_data, 0, strlen($comp_a_data) - 1);
}
// components B
$comp_b_data = '';
if ($component_b) {
    foreach ($component_b->result() as $gaji) {
        $component = get_components($gaji->gaji_component_id);
        $comp_b_data .= '["' . $gaji->gaji_component_id . '", "' . $component->comp_name . '", "' . $component->comp_type . '", "' . $gaji->gaji_daily_value . '", "' . number_format($gaji->gaji_amount_value, 2, ".", ",") . '"],';
    }
    $comp_b_data = substr($comp_b_data, 0, strlen($comp_b_data) - 1);
}
// family
$families = '';
if ($family) {
    foreach ($family->result() as $f) {
        $families .= '["' . $f->staff_fam_order . '", "' . $f->staff_fam_name . '", "' . $f->staff_fam_birthdate . '", "' . $f->staff_fam_birthplace . '", "' . $f->staff_fam_sex . '", "' . $f->staff_fam_relation . '"],';
    }
    $families = substr($families, 0, strlen($families) - 1);
}
?>
<script type="text/javascript">
  var comp_a_data = [<?php