Пример #1
0
function items_from_titles($titles, &$items, &$volumes)
{
    global $db;
    $count = 0;
    foreach ($titles as $TitleID) {
        $sql = 'SELECT * FROM bhl_item WHERE TitleID=' . $TitleID;
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        while (!$result->EOF) {
            $item = new stdclass();
            $item->ItemID = $result->fields['ItemID'];
            $item->VolumeInfo = $result->fields['VolumeInfo'];
            $item->info = new stdclass();
            if (parse_bhl_date($result->fields['VolumeInfo'], &$item->info)) {
                if (isset($item->info->volume)) {
                    $volumes[$item->info->volume] = $count;
                } else {
                    if (isset($item->info->volume_from)) {
                        $volumes[$item->info->volume_from] = $count;
                    } else {
                        $volumes[$result->fields['VolumeInfo']] = $count;
                    }
                }
            } else {
                $volumes[$result->fields['VolumeInfo']] = $count;
            }
            $items[] = $item;
            $count++;
            $result->MoveNext();
        }
    }
    // Sort
    ksort($volumes);
    //print_r($volumes);
}
Пример #2
0
function bhl_retrieve_title($id)
{
    global $db;
    global $ADODB_FETCH_MODE;
    $title = NULL;
    $sql = 'SELECT * FROM bhl_title
		WHERE (TitleID=' . $id . ') LIMIT 1';
    $result = $db->Execute($sql);
    if ($result == false) {
        die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    }
    if ($result->NumRows() == 1) {
        $title = new stdclass();
        $title->id = $result->fields['TitleID'];
        $title->FullTitle = $result->fields['FullTitle'];
        $title->ShortTitle = $result->fields['ShortTitle'];
        $title->PublicationDetails = $result->fields['PublicationDetails'];
        $title->StartYear = $result->fields['StartYear'];
        $title->EndYear = $result->fields['EndYear'];
        $title->LanguageCode = $result->fields['LanguageCode'];
        $title->TL2Author = $result->fields['TL2Author'];
        // Identifiers
        $sql = 'SELECT * FROM bhl_title
			INNER JOIN bhl_title_identifier USING(TitleID)
			WHERE (TitleID=' . $id . ')';
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        $title->identifiers = array();
        while (!$result->EOF) {
            $title->identifiers[] = array('namespace' => $result->fields['IdentifierName'], 'identifier' => $result->fields['IdentifierValue']);
            $result->MoveNext();
        }
        // Institution
        // Date range
        $sql = 'SELECT VolumeInfo, Year FROM bhl_item
			WHERE (TitleID=' . $id . ')';
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        $title->years = array();
        while (!$result->EOF) {
            $info = new stdclass();
            $parsed = bhl_date_from_details($result->fields['Year'], $info);
            if (!$parsed) {
                $parsed = parse_bhl_date($result->fields['VolumeInfo'], $info);
            }
            if ($parsed) {
                //print_r($info);
                if (isset($info->start)) {
                    if (!isset($title->years[$info->start])) {
                        $title->years[$info->start] = 0;
                    }
                    $title->years[$info->start]++;
                    if (isset($info->end)) {
                        for ($i = $info->start; $i <= $info->end; $i++) {
                            if (!isset($title->years[$i])) {
                                $title->years[$i] = 0;
                            }
                            $title->years[$i]++;
                        }
                    }
                }
            }
            $result->MoveNext();
        }
        $years = array_keys($title->years);
        sort($years);
        $from = $years[0];
        $to = $years[count($years) - 1];
        for ($i = $from; $i < $to; $i++) {
            if (!in_array($i, $years)) {
                $title->years[$i] = 0;
            }
        }
        // sort
        ksort($title->years);
    }
    return $title;
}
Пример #3
0
    array_push($dates, 'v. 34 (1921)');
    array_push($dates, 'no.180 (1996)');
    array_push($dates, 'no.296-325 (1968-1969)');
    array_push($dates, 'no. 85-93 1991-92');
    array_push($dates, 'v. 1-2 1991-24');
    array_push($dates, 'v. 1-2 (1814-1826)');
    array_push($dates, 'v. 39, no. 2 (1996)');
    array_push($dates, 'v. 85, no. 1-4 (1986)');
    array_push($dates, 't. 4 (1891-1892)');
    array_push($dates, 't. 17-18 1882-85');
    array_push($dates, 't. 17; (ser. 2, t.7) (1889)');
    array_push($dates, 't. 3 no. 3-4 marzo-abr 1920');
    array_push($dates, 'new ser. v. 1 (1883-1886)');
    array_push($dates, 'v. 5 (18501851)');
    array_push($dates, 'no. 138 1926');
    $ok = 0;
    foreach ($dates as $str) {
        $info = new stdclass();
        $matched = parse_bhl_date($str, $info);
        if ($matched) {
            $ok++;
            print_r($info);
        } else {
            array_push($failed, $str);
        }
    }
    // report
    echo "--------------------------\n";
    echo count($refs) . ' dates, ' . (count($dates) - $ok) . ' failed' . "\n";
    print_r($failed);
}
Пример #4
0
function sparkline($id)
{
    //$id = 2475959;
    //$id = 530114;
    //$id = 4799126;
    //$id=4799142;
    //$id=2707985;
    //$id=31333;
    //$id=3851985;
    //$id = 27222;
    //$id=2478573;
    $url = 'http://www.biodiversitylibrary.org/services/name/NameService.ashx?op=NameGetDetail&nameBankID=' . $id . '&format=json';
    $url = 'http://www.biodiversitylibrary.org/api/httpquery.ashx?op=NameGetDetail&nameBankID=' . $id . '&format=json';
    //echo $url;
    //exit();
    $json = get($url);
    $obj = json_decode($json);
    //print_r($obj);
    $years = array();
    $decades = array();
    foreach ($obj->Result->Titles as $title) {
        // Try and get date for title
        $title_info = new stdclass();
        if (bhl_date_from_details($title->PublicationDetails, $title_info)) {
            //print_r($title_info);
        }
        foreach ($title->Items as $item) {
            $info = new stdclass();
            if (parse_bhl_date($item->VolumeInfo, $info)) {
            }
            if (isset($title_info->start) || isset($info->start)) {
                $event = new stdclass();
                if (isset($info->start)) {
                    $event->start = $info->start;
                    if (isset($info->end)) {
                        $event->end = $info->end;
                    }
                } else {
                    $event->start = $title_info->start;
                    if (isset($title_info->end)) {
                        $event->end = $title_info->end;
                    }
                }
                // Years
                echo $event->start . ' ' . $event->end . ' ';
                if (isset($event->end)) {
                    $weight = 1 / ($event->end - $event->start + 1);
                    echo $weight . '<br />';
                    for ($i = $event->start; $i <= $event->end; $i++) {
                        if (!isset($years[$i])) {
                            $years[$i] = 0;
                        }
                        $years[$i] += $weight;
                    }
                } else {
                    echo '1<br />';
                    if (!isset($years[$event->start])) {
                        $years[$event->start] = 0;
                    }
                    $years[$event->start]++;
                }
                /*
                // Decades
                if (isset($event->end))
                {
                	for ($i = $event->start; $i <= $event->end; $i++)
                	{
                		$weight = 1/($event->end - $event->start);
                	
                		$d = floor($i / 10) * 10;
                	
                		if (!isset($decades[$d]))
                		{
                			$decades[$d] = 0;
                		}
                		$decades[$d]++;
                	}
                }
                else
                {
                	$d = floor($event->start/ 10) * 10;
                	if (!isset($decades[$d]))
                	{
                		$decades[$d] = 0;
                	}
                	$decades[$d]++;
                }
                */
            } else {
                // Didn't get dates
            }
        }
    }
    print_r($years);
    /*
    $url = 'http://chart.apis.google.com/chart?chs=400x100&cht=ls&chco=0077CC&chm=B,e6f2fa,0,0.0,0.0&chd=t:';
    //$chxl = '&chtx=x&chxl=0:';
    
    $max_items = 0;
    foreach ($years as $k => $v)
    {
    	$max_items = max($max_items, $v);
    }
    
    $count = 0;
    for ($i = 1700; $i < 2000; $i++)
    {
    	if ($count > 0) { $url .= ','; }
    	if (isset($years[$i]))
    	{
    		$url .= round(($years[$i] * 100.0)/$max_items);
    	}
    	else
    	{
    		$url .= '0';
    	}
    	$count++;
    }
    
    echo $url;
    */
    //print_r($decades);
    $url = 'http://chart.apis.google.com/chart?chs=400x100&cht=ls&chco=0077CC&chm=B,e6f2fa,0,0.0,0.0&chd=t:';
    //$chxl = '&chtx=x&chxl=0:';
    // Aggregate into decades
    $decades = array();
    foreach ($years as $k => $v) {
        $d = floor($k / 10) * 10;
        if (!isset($decades[$d])) {
            $decades[$d] = 0;
        }
        $decades[$d] += $v;
    }
    $max_items = 0;
    foreach ($decades as $k => $v) {
        $max_items = max($max_items, $v);
    }
    $count = 0;
    for ($i = 1750; $i < 2010; $i += 10) {
        if ($count > 0) {
            $url .= ',';
        }
        if (isset($decades[$i])) {
            $url .= round($decades[$i] * 100.0 / $max_items);
        } else {
            $url .= '0';
        }
        $count++;
    }
    $url .= '&chxt=x,y&chxl=0:|1750|1800|1850|1900|1950|2000|1:||' . $max_items;
    for ($i = 1750; $i < 2010; $i += 10) {
        echo "{$i}|";
        if (isset($decades[$i])) {
            echo $decades[$i];
        } else {
        }
        echo "<br/>";
    }
    return $url;
}
Пример #5
0
}
*/
$timeline = new stdclass();
$timeline->dateTimeFormat = "iso8601";
$timeline->events = array();
foreach ($obj->NameResult->Titles as $title) {
    //echo $title->TitleID . ' ' . $title->PublicationTitle . ' ' . count($title->Items) . "\n";
    // Try and get date for title
    $title_info = new stdclass();
    if (bhl_date_from_details($title->PublicationDetails, $title_info)) {
        //print_r($title_info);
    }
    foreach ($title->Items as $item) {
        //echo '  ' . $item->VolumeInfo . "\n";
        $info = new stdclass();
        if (parse_bhl_date($item->VolumeInfo, $info)) {
            //print_r($info);
        }
        if (isset($title_info->start) || isset($info->start)) {
            $event = new stdclass();
            if (isset($info->start)) {
                $event->start = $info->start;
                if (isset($info->end)) {
                    $event->end = $info->end;
                }
            } else {
                $event->start = $title_info->start;
                if (isset($title_info->end)) {
                    $event->end = $title_info->end;
                }
            }
Пример #6
0
/**
 * @brief Find set of BHL items whose VolumeInfo field match a pattern
 *
 * Some articles have been treated as titles, e.g. large articles and monographs that are bound 
 * as single books. For these articles the journal and volume information may be contained in the
 * VolumeInfo field.
 *
 * @param search_pattern SQL search pattern, e.g. 'Fieldiana Zoology%'
 * @param mask_pattern Regular expression to remove title, e.g. '/^Fieldiana Zoology/'
 * @param volume Article volume we are searching for
 *
 * @result Array of BHL items that match query
 *
 */
function bhl_itemid_from_pattern($search_pattern, $mask_pattern, $volume)
{
    global $db;
    // Find ItemID of item that contains relevant volume
    $sql = 'SELECT * FROM bhl_item WHERE VolumeInfo LIKE ' . $db->qstr($search_pattern);
    $result = $db->Execute($sql);
    if ($result == false) {
        die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    }
    $items = array();
    while (!$result->EOF) {
        $info = new stdclass();
        $VolumeInfo = $result->fields['VolumeInfo'];
        if ($mask_pattern != '') {
            $VolumeInfo = trim(preg_replace($mask_pattern, '', $VolumeInfo));
        }
        $matched = parse_bhl_date($VolumeInfo, $info);
        if ($matched) {
            if (isset($info->volume_from)) {
                // range, we store the volume offset of target volume
                if ($volume >= $info->volume_from && $volume <= $info->volume_to) {
                    $item = new stdclass();
                    $item->ItemID = $result->fields['ItemID'];
                    if (isset($info->series)) {
                        $item->series = $info->series;
                    }
                    $item->volume_offset = $volume - $info->volume_from;
                    array_push($items, $item);
                }
            } else {
                if ($info->volume == $volume) {
                    $item = new stdclass();
                    $item->ItemID = $result->fields['ItemID'];
                    if (isset($info->series)) {
                        $item->series = $info->series;
                    }
                    $item->volume_offset = 0;
                    array_push($items, $item);
                }
            }
        } else {
            if ($debug) {
                echo '<pre>';
                echo "*** WARNING *** Line:" . __LINE__ . " Not matched \"" . $VolumeInfo . "\"<\n";
                echo '</pre>';
            }
        }
        $result->MoveNext();
    }
    return $items;
}
Пример #7
0
                 						$count++;
                 					}
                 					else
                 					{
                 						$id = $ItemID;
                 					}
                 					
                 					$id = 'item' . $id;*/
                 $id = $row['Title'] . $row['Volume'];
                 if (!isset($hits[$id])) {
                     $hit = new stdclass();
                     $hit->PageID = $PageID;
                     $hit->identifiers = array();
                     $hit->title = $row['Title'];
                     $info = new stdclass();
                     parse_bhl_date($row['Volume'], $info);
                     if (isset($info->start)) {
                         $hit->year = $info->start;
                     } else {
                         $hit->year = $row['Date'];
                     }
                     $identifier = new stdclass();
                     $identifier->type = 'bhl';
                     $identifier->id = $PageID;
                     $hit->identifiers[] = $identifier;
                     $hits[$id] = $hit;
                 }
             }
         }
     }
 }
Пример #8
0
function bhl_name_search($NameBankID)
{
    global $db;
    $hits = array();
    if ($NameBankID == 0) {
        return $hits;
    }
    $sql = 'SELECT DISTINCT bhl_item.TitleID, bhl_item.ItemID, bhl_item.VolumeInfo, bhl_page.PageID, 
	bhl_page.Year as y1,
	bhl_item.Year as y2,
	bhl_title.ShortTitle
	FROM bhl_page_name
	INNER JOIN bhl_page USING(PageID)
	INNER JOIN bhl_item USING(ItemID)
	INNER JOIN bhl_title USING(TitleID)
	WHERE (NameBankID=' . $NameBankID . ')';
    $result = $db->Execute($sql);
    if ($result == false) {
        die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    }
    while (!$result->EOF) {
        $ItemID = $result->fields['ItemID'];
        if (!isset($hits[$ItemID])) {
            $item = new stdclass();
            $item->ItemID = $ItemID;
            $item->type = 0;
            $item->pages = array();
            $item->TitleID = $result->fields['TitleID'];
            $item->title = $result->fields['ShortTitle'];
            $hits[$ItemID] = $item;
        }
        $hits[$ItemID]->pages[] = $result->fields['PageID'];
        $hits[$ItemID]->VolumeInfo = $result->fields['VolumeInfo'];
        if ($result->fields['y1'] != '') {
            $hits[$ItemID]->Year = $result->fields['y1'];
        } elseif ($result->fields['y2'] != '') {
            $hits[$ItemID]->Year = $result->fields['y2'];
        }
        $result->MoveNext();
    }
    // Try and date each item...
    foreach ($hits as $k => $v) {
        $hits[$k]->info = new stdclass();
        $have_year = false;
        if (parse_bhl_date($hits[$k]->VolumeInfo, $hits[$k]->info)) {
            $have_year = isset($hits[$k]->info->start);
        }
        if (!$have_year && isset($hits[$k]->Year)) {
            if (bhl_date_from_details($hits[$k]->Year, $hits[$k]->info)) {
                $have_year = isset($hits[$k]->info->start);
            }
        }
    }
    return $hits;
}
Пример #9
0
/**
 * @brief Test parse_bhl_date function using a range of test cases
 *
 */
function test_parse_bhl_date()
{
    $dates = array();
    $failed = array();
    array_push($dates, 'v.35:pt.1 (1952)');
    array_push($dates, 'v.15 (1961-1966)');
    array_push($dates, 'v. 34 (1921)');
    array_push($dates, 'no.180 (1996)');
    array_push($dates, 'no.296-325 (1968-1969)');
    array_push($dates, 'no. 85-93 1991-92');
    array_push($dates, 'v. 1-2 1991-24');
    array_push($dates, 'v. 1-2 (1814-1826)');
    array_push($dates, 'v. 39, no. 2 (1996)');
    array_push($dates, 'v. 85, no. 1-4 (1986)');
    array_push($dates, 't. 4 (1891-1892)');
    array_push($dates, 't. 17-18 1882-85');
    array_push($dates, 't. 17; (ser. 2, t.7) (1889)');
    array_push($dates, 't. 3 no. 3-4 marzo-abr 1920');
    array_push($dates, 'new ser. v. 1 (1883-1886)');
    array_push($dates, 'v. 5 (18501851)');
    array_push($dates, 'no. 138 1926');
    array_push($dates, '3rd ser. v. 8 (1861) ');
    array_push($dates, 'new ser.:v.5');
    array_push($dates, 'new ser.:v.45 (1901-1902)');
    array_push($dates, 'new ser. v. 19 (1906-1907)');
    $dates[] = 'v. 58-59';
    $ok = 0;
    foreach ($dates as $str) {
        $info = new stdclass();
        $matched = parse_bhl_date($str, $info);
        if ($matched) {
            $ok++;
            print_r($info);
        } else {
            array_push($failed, $str);
        }
    }
    // report
    echo "--------------------------\n";
    echo count($refs) . ' dates, ' . (count($dates) - $ok) . ' failed' . "\n";
    print_r($failed);
}