示例#1
0
文件: api.php 项目: TaiBIF/MyMatch
function render_table($data, $time, $hardcsv = false)
{
    header("Content-type: text/html; charset=utf-8");
    $src_conf = read_src_conf();
    global $against, $best;
    $not_show = array('name_cleaned', 'url_id', 'a_url_id', 'kingdom', 'phylum', 'class', 'order');
    echo "<head>";
    echo "<link href='http://fonts.googleapis.com/css?family=Roboto|Slabo+27px&subset=latin,latin-ext' rel='stylesheet' type='text/css'>";
    echo "<script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>";
    echo "<link href='https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cerulean/bootstrap.min.css' rel='stylesheet' integrity='sha384-zF4BRsG/fLiTGfR9QL82DrilZxrwgY/+du4p/c7J72zZj+FLYq4zY00RylP9ZjiT' crossorigin='anonymous'>";
    echo "<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa' crossorigin='anonymous'></script>";
    echo "<script src='./js/diff.js'></script>";
    echo "</head>";
    $prev_name = "";
    $row_class = "even";
    $serial_no = 0;
    echo "<style>";
    echo "table, tr, td { border:solid 1px black;}\n";
    echo ".row_red { background:#FF9999;}\n";
    echo ".row_orange { background:#FFB547;}\n";
    echo ".row_yellow { background:#FFFF70;}\n";
    echo ".row_green { background:#8DE28D;}\n";
    echo ".row_blue { background:#91DAFF;}\n";
    echo ".row_purple { background:#E9A9FF;}\n";
    echo "</style>";
    echo "<body>";
    echo "<div class='navbar navbar-fixed-top navbar-default'>";
    echo "<div class='container-fluid'>";
    echo "<div class='navbar-header'>";
    echo "<button type='button' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#bs-example-navbar-collapse-2'>";
    echo "<span class='sr-only'>Toggle navigation</span>";
    echo "<span class='icon-bar'></span>";
    echo "<span class='icon-bar'></span>";
    echo "<span class='icon-bar'></span>";
    echo "</button>";
    echo "<a class='navbar-brand' href='index.html' style='color:#fff' >NomenMatch</a>";
    echo "</div>";
    echo "<div class='collapse navbar-collapse' id='bs-example-navbar-collapse-2'>";
    echo "<ul class='nav navbar-nav'>";
    echo "<li><a href='about.html'>About</a></li>";
    echo "<li><a href='index.html'>Match</a></li>";
    echo "<li><a href='howto.html'>How-To</a></li>";
    echo "<li><a href='api-doc.html'>API</a></li>";
    echo "</ul>";
    echo "</div>";
    echo "</div>";
    echo "</div><div class='container'><br/><br/><br/></div>";
    echo "<div class='container' style='margin-left:50px;'>";
    echo "<h1 class='navbar-brand m-b-0'>Matching results</h1>";
    echo "<p>";
    echo "query time: " . round($time, 3) . " s<br/>";
    echo "memory usage: " . round(memory_get_usage(true) / (1024 * 1024), 1) . " MB<br/>";
    echo "matched diff: <span style='color:red;'>removed</span> <span style='color:blue;'>added</span> <span style='color:grey;'>common</span><br/>";
    echo "source: <span style='color:red;'>Accepted</span> <span>Invalid</span>";
    echo "</p>";
    echo "<table class='table table-striped table-bordered'>";
    $tmp_data0 = $data[0][0];
    foreach ($not_show as $ns) {
        unset($tmp_data0[$ns]);
    }
    $columns = array_keys($tmp_data0);
    echo "<tr><td>no.</td><td>" . implode("</td><td>", $columns) . "</td></tr>\n";
    $prev_score = -100;
    foreach ($data as $nidx => $name_d) {
        foreach ($name_d as $d) {
            $d['name'] = htmlentities($d['name']);
            /*
            			if ($d['name'] != $prev_name) {
            				$prev_name = $d['name'];
            				$serial_no++;
            				$row_class = color_class($serial_no - 1);
            			}
            			elseif ($d['score'] > $prev_score) {
            				$serial_no++;
            				$row_class = color_class($serial_no - 1);
            			}
            			$prev_score = $d['score'];
            			//*/
            $serial_no = $nidx + 1;
            $row_class = color_class($nidx);
            echo "<tr class='row_result' id='row_" . $serial_no . "'><td>{$serial_no}</td><td>";
            $ncs = $d['namecode'];
            $ancs = $d['accepted_namecode'];
            $sources = $d['source'];
            $url_ids = $d['url_id'];
            $aurl_ids = $d['a_url_id'];
            $html_ncs = array();
            $html_ancs = array();
            $html_sources = array();
            $url_anc_srcs = array();
            foreach ($sources as $src_idx => $src) {
                // TODO: this part must be implemented dynamicaly reading configurations from some file
                if (!empty($src_conf[$src]['url_base'])) {
                    $url_base = $src_conf[$src]['url_base'];
                } else {
                    $url_base = "http://example.org/species/id/";
                }
                $url = $url_base . $url_ids[$src_idx];
                $aurl = $url_base . $aurl_ids[$src_idx];
                $html_ncs[$src_idx] = "<a target='_blank' href='{$url}'>" . $ncs[$src_idx] . "</a>";
                $html_ancs[$src_idx] = "<a target='_blank' href='{$aurl}'>" . $ancs[$src_idx] . "</a>";
                $url_anc_srcs[$src][$ancs[$src_idx]] = "<a target='_blank' href='{$aurl}'>" . $ancs[$src_idx] . "</a>";
                if ($ncs[$src_idx] == $ancs[$src_idx]) {
                    $html_sources[$src_idx] = "<font color='#ff0000'>{$src}</font>";
                } else {
                    $html_sources[$src_idx] = $src;
                }
            }
            $d['source'] = implode("<br/>", $html_sources);
            $d['namecode'] = implode("<br/>", $html_ncs);
            $d['accepted_namecode'] = implode("<br/>", $html_ancs);
            $d['higher_than_family'] = implode("<br/>", $d['higher_than_family']);
            $d['family'] = implode("<br/>", $d['family']);
            $bests = $d['best'];
            if (!empty($bests)) {
                foreach ($bests as $src => $best_anc) {
                    $d['best'][$src] = $src . ":" . $url_anc_srcs[$src][$best_anc];
                }
                $d['best'] = implode("<br/>", $d['best']);
            }
            if (empty($d['best']) && $best == 'yes' && $d['score'] === 'N/A') {
                $d['best'] = "<a target='_blank' href='api.php?names=" . urlencode($d['name']) . "&format=table&best=no&against=" . $against . "'>" . 'undecidable</a>';
            } elseif (empty($d['best'])) {
                $d['best'] = '';
            }
            if ($best !== 'yes') {
                unset($d['best']);
            }
            $d['matched'] = str_replace("|", "<br/>", $d['matched']);
            $d['type'] = str_replace("|", "<br/>", $d['type']);
            $d['name'] = "<span name_cleaned='" . $d['name_cleaned'] . "'>" . $d['name'] . "</span>";
            foreach ($not_show as $ns) {
                unset($d[$ns]);
            }
            if ($hardcsv) {
                echo str_replace("<br/>", "|", implode("</td><td>", $d));
            } else {
                echo implode("</td><td>", $d);
            }
            echo "</td></tr>\n";
        }
    }
    echo "</table>\n";
    echo "<script src='./js/diffName.js'></script>";
}
示例#2
0
文件: count.php 项目: TaiBIF/MyMatch
<?php

require_once "./include/functions.php";
$src_conf = read_src_conf();
$ep = !empty($_REQUEST['ep']) ? $_REQUEST['ep'] : file_get_contents("./conf/solr_endpoint");
$ep = trim($ep, " /\r\n");
$query_url = $ep . "/select?q=*:*&rows=0&wt=json&facet=true&facet.field=source";
$f_jo = json_decode(file_get_contents($query_url));
$fieldCounts = array();
foreach ($f_jo->facet_counts->facet_fields->source as $idx => $fieldCount) {
    if ($idx & 1) {
        // odd
        if (!$fieldCount) {
            continue;
        }
        $fieldCounts[] = array('source' => $current_field, 'count' => $fieldCount, 'name' => $src_conf[$current_field]['name'], 'citation' => $src_conf[$current_field]['citation'], 'url' => $src_conf[$current_field]['url'], 'version' => $src_conf[$current_field]['version']);
        $current_field = '';
    } else {
        // even
        $current_field = $fieldCount;
    }
}
echo json_encode($fieldCounts);