/** * Map the source data to record properties */ protected function map(array $document) { $json = new Json($document); $this->database_name = $json->extractValue('Header/DbLabel'); $this->record_id = $json->extractValue('Header/DbId') . '-' . $json->extractValue('Header/An'); $this->score = $json->extractValue('Header/RelevancyScore'); // title $this->title = $json->extractValue('RecordInfo/BibRecord/BibEntity/Titles/0/TitleFull'); $this->sub_title; // basic info $this->language = $json->extractValue("RecordInfo/BibRecord/BibEntity/Languages/0/Text"); $this->extent = $json->extractValue("RecordInfo/BibRecord/BibEntity/PhysicalDescription/Pagination/PageCount"); // date $this->year = (int) $json->extractValue('RecordInfo/BibRecord/BibRelationships/IsPartOfRelationships/0/BibEntity/Dates/0/Y'); $this->month = (int) $json->extractValue('RecordInfo/BibRecord/BibRelationships/IsPartOfRelationships/0/BibEntity/Dates/0/M'); $this->day = (int) $json->extractValue('RecordInfo/BibRecord/BibRelationships/IsPartOfRelationships/0/BibEntity/Dates/0/D'); // format $format = $json->extractValue("Header/PubType"); $this->format->setPublicFormat($format); $this->format->setInternalFormat($format); $this->format->setNormalizedFormat($this->normalizeFormat($format)); // Item data foreach ($json->extractData('Items') as $item) { // title if ($item['Name'] == 'Title') { $this->title = $item['Data']; } // abstract if ($item['Name'] == 'Abstract') { $this->abstract = $item['Data']; } // publication source if ($item['Name'] == 'TitleSource' && $this->journal == "") { $this->journal = strip_tags(html_entity_decode($item['Data'])); } // pmid if ($item['Label'] == 'PMID') { $this->pubmed_id = $item['Data']; } // notes if ($item['Label'] == 'Notes') { $this->notes[] = $item['Data']; } } // books $this->edition = $json->extractValue("Edition/0"); $this->publisher = $this->toTitleCase($json->extractValue("Publisher/0")); $this->place = $json->extractValue("PublicationPlace_xml/0/name"); // article $this->journal_title = $json->extractValue("RecordInfo/BibRecord/BibRelationships/IsPartOfRelationships/0/BibEntity/Titles/0/TitleFull"); $this->start_page = $json->extractValue("RecordInfo/BibRecord/BibEntity/PhysicalDescription/Pagination/StartPage"); if ($this->start_page != "" && $this->extent != "") { $this->end_page = $this->start_page + $this->extent - 1; } foreach ($json->extractData('RecordInfo/BibRecord/BibRelationships/IsPartOfRelationships/0/BibEntity/Numbering') as $number) { if ($number['Type'] == 'volume') { $this->volume = $number['Value']; } elseif ($number['Type'] == 'issue') { $this->issue = $number['Value']; } } // links foreach ($json->extractData('FullText/Links') as $link) { $type = $link['Type']; if (strstr($type, 'pdf')) { $type = Xerxes\Record\Link::PDF; } if (array_key_exists('Url', $link)) { $url = $link['Url']; $this->links[] = new Xerxes\Record\Link($url, $type); } } // subjects foreach ($json->extractData('RecordInfo/BibRecord/BibEntity/Subjects') as $subject) { $subject = Parser::toSentenceCase($subject['SubjectFull']); $subject_object = new Xerxes\Record\Subject(); $subject_object->display = $subject; $subject_object->value = $subject; array_push($this->subjects, $subject_object); } // identifiers foreach ($json->extractData('RecordInfo/BibRecord/BibEntity/Identifiers') as $identifier) { // doi if ($identifier['Type'] == 'doi') { $this->doi = $identifier['Value']; } } foreach ($json->extractData('RecordInfo/BibRecord/BibRelationships/IsPartOfRelationships/0/BibEntity/Identifiers') as $identifier) { // isbn if (strstr($identifier['Type'], 'isbn')) { $this->isbns[] = $identifier['Value']; } // issn if (strstr($identifier['Type'], 'issn')) { $this->issns[] = $identifier['Value']; } } // authors foreach ($json->extractData('RecordInfo/BibRecord/BibRelationships/HasContributorRelationships') as $author) { $json_author = new Json($author); $author_object = new Xerxes\Record\Author($json_author->extractValue('PersonEntity/Name/NameFull'), null, 'personal'); array_push($this->authors, $author_object); } if (array_key_exists('debugrec', $_GET)) { header('Content-type: text/plain'); print_r($this); exit; } }
/** * Parse out query expansion * * @param array $summon_results * @return array of terms, if expanded */ protected function extractQueryExpansion(array $summon_results) { $json = new Json($summon_results); $terms = $json->extractData('queryExpansion/searchTerms'); $terms = str_replace('"', '', $terms); return $terms; }
/** * Parse records out of the response * * @param Json $json * @return Record[] */ protected function extractRecords(Json $json) { $records = array(); // single record $record = $json->extractData('Record'); if (count($record) > 0) { $xerxes_record = new Record(); $xerxes_record->load($json->extractData('Record')); array_push($records, $xerxes_record); } else { foreach ($json->extractData('SearchResult/Data/Records') as $document) { $xerxes_record = new Record(); $xerxes_record->load($document); array_push($records, $xerxes_record); } } return $records; }