示例#1
0
 /**
  * Initialize form data from the associated citation.
  * @param $citation Citation
  */
 function initData()
 {
     $citation =& $this->getCitation();
     // The unparsed citation text
     $this->setData('editedCitation', $citation->getEditedCitation());
     // Citation meta-data
     foreach ($citation->getSupportedMetadataAdapters() as $metadataAdapter) {
         // Retrieve the meta-data schema
         $metadataSchema =& $metadataAdapter->getMetadataSchema();
         $metadataSchemaNamespace = $metadataSchema->getNamespace();
         // Loop over the properties in the schema and add string
         // values for all form fields.
         $citationVars = array();
         $properties = $metadataSchema->getProperties();
         $metadataDescription =& $citation->extractMetadata($metadataSchema);
         foreach ($properties as $propertyName => $property) {
             if ($metadataDescription->hasStatement($propertyName)) {
                 $value = $metadataDescription->getStatement($propertyName);
                 if ($property->getType() == METADATA_PROPERTY_TYPE_COMPOSITE) {
                     // We currently only support composite name arrays
                     assert(in_array($property->getCompositeType(), array(ASSOC_TYPE_AUTHOR, ASSOC_TYPE_EDITOR)));
                     import('metadata.nlm.NlmNameSchemaPersonStringFilter');
                     $personStringFilter = new NlmNameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE);
                     assert($personStringFilter->supportsAsInput($value));
                     $fieldValue = $personStringFilter->execute($value);
                 } else {
                     // We currently don't support repeated values
                     if ($property->getCardinality() == METADATA_PROPERTY_CARDINALITY_MANY && !empty($value)) {
                         assert(is_array($value) && count($value) <= 1);
                         $value = $value[0];
                     }
                     $fieldValue = (string) $value;
                 }
             } else {
                 $fieldValue = '';
             }
             $fieldName = $metadataSchema->getNamespacedPropertyId($propertyName);
             $citationVars[$fieldName] = array('translationKey' => $property->getDisplayName(), 'value' => $fieldValue);
         }
     }
     $this->setData('citationVars', $citationVars);
 }
 /**
  * Take a structured meta-data statement and transform it into a
  * plain text value that can be displayed to the end-user.
  *
  * @param $property MetadataProperty
  * @param $value mixed
  * @return string
  */
 function _getStringValueFromMetadataStatement(&$property, &$value)
 {
     if ($property->getCardinality() == METADATA_PROPERTY_CARDINALITY_MANY && !empty($value)) {
         $allowedTypes = $property->getAllowedTypes();
         if (isset($allowedTypes[METADATA_PROPERTY_TYPE_COMPOSITE])) {
             // We currently only can transform composite
             // name arrays to strings.
             $allowedAssocTypes = $allowedTypes[METADATA_PROPERTY_TYPE_COMPOSITE];
             assert(in_array(ASSOC_TYPE_AUTHOR, $allowedAssocTypes) || in_array(ASSOC_TYPE_EDITOR, $allowedAssocTypes));
             import('lib.pkp.classes.metadata.nlm.NlmNameSchemaPersonStringFilter');
             $personStringFilter = new NlmNameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE);
             assert($personStringFilter->supportsAsInput($value));
             $stringValue = $personStringFilter->execute($value);
         } else {
             // We currently can't transform properties of
             // cardinality "many" to strings.
             assert(is_array($value) && count($value) <= 1);
             $stringValue = $value[0];
         }
     } else {
         $stringValue = (string) $value;
     }
     return $stringValue;
 }
 /**
  * @see Filter::process()
  * @param $citationDescription MetadataDescription
  * @return MetadataDescription
  */
 function &process(&$citationDescription)
 {
     $pmid = $citationDescription->getStatement('pub-id[@pub-id-type="pmid"]');
     // If the citation does not have a PMID, try to get one from eSearch
     // otherwise skip directly to eFetch.
     if (empty($pmid)) {
         // Initialize search result arrays.
         $pmidArrayFromAuthorsSearch = $pmidArrayFromTitleSearch = $pmidArrayFromStrictSearch = array();
         // 1) Try a "loose" search based on the author list.
         //    (This works surprisingly well for pubmed.)
         $authors =& $citationDescription->getStatement('person-group[@person-group-type="author"]');
         import('metadata.nlm.NlmNameSchemaPersonStringFilter');
         $personNameFilter = new NlmNameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE, '%firstname%%initials%%prefix% %surname%%suffix%', ', ');
         $authorsString = (string) $personNameFilter->execute($authors);
         if (!empty($authorsString)) {
             $pmidArrayFromAuthorsSearch =& $this->_search($authorsString);
         }
         // 2) Try a "loose" search based on the article title
         $articleTitle = (string) $citationDescription->getStatement('article-title');
         if (!empty($articleTitle)) {
             $pmidArrayFromTitleSearch =& $this->_search($articleTitle);
         }
         // 3) Try a "strict" search based on as much information as possible
         $searchProperties = array('article-title' => '', 'person-group[@person-group-type="author"]' => '[Auth]', 'source' => '[Jour]', 'date' => '[DP]', 'volume' => '[VI]', 'issue' => '[IP]', 'fpage' => '[PG]');
         $searchTerms = '';
         $statements = $citationDescription->getStatements();
         foreach ($searchProperties as $nlmProperty => $pubmedProperty) {
             if (isset($statements[$nlmProperty])) {
                 if (!empty($searchTerms)) {
                     $searchTerms .= ' AND ';
                 }
                 // Special treatment for authors
                 if ($nlmProperty == 'person-group[@person-group-type="author"]') {
                     assert(isset($statements['person-group[@person-group-type="author"]'][0]));
                     $firstAuthor =& $statements['person-group[@person-group-type="author"]'][0];
                     // Add surname
                     $searchTerms .= (string) $firstAuthor->getStatement('surname');
                     // Add initial of the first given name
                     $givenNames = $firstAuthor->getStatement('given-names');
                     if (is_array($givenNames)) {
                         $searchTerms .= ' ' . String::substr($givenNames[0], 0, 1);
                     }
                 } else {
                     $searchTerms .= $citationDescription->getStatement($nlmProperty);
                 }
                 $searchTerms .= $pubmedProperty;
             }
         }
         $pmidArrayFromStrictSearch =& $this->_search($searchTerms);
         // TODO: add another search like strict, but without article title
         // e.g.  ...term=Baumgart+Dc[Auth]+AND+Lancet[Jour]+AND+2005[DP]+AND+366[VI]+AND+9492[IP]+AND+1210[PG]
         // Compare the arrays to try to narrow it down to one PMID
         switch (true) {
             // strict search has a single result
             case count($pmidArrayFromStrictSearch) == 1:
                 $pmid = $pmidArrayFromStrictSearch[0];
                 break;
                 // 3-way union
             // 3-way union
             case count($intersect = array_intersect($pmidArrayFromTitleSearch, $pmidArrayFromAuthorsSearch, $pmidArrayFromStrictSearch)) == 1:
                 $pmid = current($intersect);
                 break;
                 // 2-way union: title / strict
             // 2-way union: title / strict
             case count($pmid_2way1 = array_intersect($pmidArrayFromTitleSearch, $pmidArrayFromStrictSearch)) == 1:
                 $pmid = current($pmid_2way1);
                 break;
                 // 2-way union: authors / strict
             // 2-way union: authors / strict
             case count($pmid_2way2 = array_intersect($pmidArrayFromAuthorsSearch, $pmidArrayFromStrictSearch)) == 1:
                 $pmid = current($pmid_2way2);
                 break;
                 // 2-way union: authors / title
             // 2-way union: authors / title
             case count($pmid_2way3 = array_intersect($pmidArrayFromAuthorsSearch, $pmidArrayFromTitleSearch)) == 1:
                 $pmid = current($pmid_2way3);
                 break;
                 // we only have one result for title
             // we only have one result for title
             case count($pmidArrayFromTitleSearch) == 1:
                 $pmid = $pmidArrayFromTitleSearch[0];
                 break;
                 // we only have one result for authors
             // we only have one result for authors
             case count($pmidArrayFromAuthorsSearch) == 1:
                 $pmid = $pmidArrayFromAuthorsSearch[0];
                 break;
                 // we were unable to find a PMID
             // we were unable to find a PMID
             default:
                 $pmid = '';
         }
     }
     // If we have a PMID, get a metadata array for it
     if (!empty($pmid)) {
         $citationDescription =& $this->_lookup($pmid, $citationDescription);
         return $citationDescription;
     }
     // Nothing found
     $nullVar = null;
     return $nullVar;
 }
 /**
  * Construct an array of search strings from a citation
  * description and an array of search templates.
  * The templates may contain the placeholders
  *  %aulast%: the first author's surname
  *  %au%:     the first author full name
  *  %title%:  the article-title (if it exists),
  *            otherwise the source
  *  %date%:   the publication year
  *  %isbn%:   ISBN
  * @param $searchTemplates an array of templates
  * @param $citationDescription MetadataDescription
  * @return array
  */
 function constructSearchStrings(&$searchTemplates, &$citationDescription)
 {
     // Convert first authors' name description to a string
     import('lib.pkp.classes.metadata.nlm.NlmNameSchemaPersonStringFilter');
     $personStringFilter = new NlmNameSchemaPersonStringFilter();
     // Retrieve the authors
     $firstAuthorSurname = $firstAuthor = '';
     $authors = $citationDescription->getStatement('person-group[@person-group-type="author"]');
     if (is_array($authors) && count($authors)) {
         $firstAuthorSurname = (string) $authors[0]->getStatement('surname');
         $firstAuthor = $personStringFilter->execute($authors[0]);
     }
     // Retrieve the editors
     $firstEditorSurname = $firstEditor = '';
     $editors = $citationDescription->getStatement('person-group[@person-group-type="editor"]');
     if (is_array($editors) && count($editors)) {
         $firstEditorSurname = (string) $editors[0]->getStatement('surname');
         $firstEditor = $personStringFilter->execute($editors[0]);
     }
     // Retrieve (default language) title
     $title = (string) ($citationDescription->hasStatement('article-title') ? $citationDescription->getStatement('article-title') : $citationDescription->getStatement('source'));
     // Extract the year from the publication date
     $year = (string) $citationDescription->getStatement('date');
     $year = String::strlen($year) > 4 ? String::substr($year, 0, 4) : $year;
     // Retrieve ISBN
     $isbn = (string) $citationDescription->getStatement('isbn');
     // Replace the placeholders in the templates
     $searchStrings = array();
     foreach ($searchTemplates as $searchTemplate) {
         // Try editors and authors separately
         $searchStrings[] = str_replace(array('%aulast%', '%au%', '%title%', '%date%', '%isbn%'), array($firstAuthorSurname, $firstAuthor, $title, $year, $isbn), $searchTemplate);
         $searchStrings[] = str_replace(array('%aulast%', '%au%', '%title%', '%date%', '%isbn%'), array($firstEditorSurname, $firstEditor, $title, $year, $isbn), $searchTemplate);
     }
     // Remove empty or duplicate searches
     $searchStrings = array_map(array('String', 'trimPunctuation'), $searchStrings);
     $searchStrings = array_unique($searchStrings);
     $searchStrings = arrayClean($searchStrings);
     return $searchStrings;
 }
 /**
  * Map NLM properties to OpenURL properties.
  * NB: OpenURL has no i18n so we use the default
  * locale when mapping.
  * @see Filter::process()
  * @param $input MetadataDescription
  * @return MetadataDescription
  */
 function &process(&$input)
 {
     $nullVar = null;
     // Identify the genre of the target record and
     // instantiate the target description.
     $publicationType = $input->getStatement('[@publication-type]');
     switch ($publicationType) {
         case NLM_PUBLICATION_TYPE_JOURNAL:
         case NLM_PUBLICATION_TYPE_CONFPROC:
             $outputSchema = new OpenUrlJournalSchema();
             break;
         case NLM_PUBLICATION_TYPE_BOOK:
             $outputSchema = new OpenUrlBookSchema();
             break;
         case NLM_PUBLICATION_TYPE_THESIS:
             $outputSchema = new OpenUrlDissertationSchema();
             break;
         default:
             // Unsupported type
             return $nullVar;
     }
     // Create the target description
     $output = new MetadataDescription($outputSchema, $input->getAssocType());
     // Transform authors
     import('metadata.nlm.NlmNameSchemaPersonStringFilter');
     $personStringFilter = new NlmNameSchemaPersonStringFilter();
     $authors =& $input->getStatement('person-group[@person-group-type="author"]');
     if (is_array($authors) && count($authors)) {
         $aulast = $authors[0]->hasStatement('prefix') ? $authors[0]->getStatement('prefix') . ' ' : '';
         $aulast .= $authors[0]->getStatement('surname');
         if (!empty($aulast)) {
             $success = $output->addStatement('aulast', $aulast);
             assert($success);
         }
         $givenNames = $authors[0]->getStatement('given-names');
         if (is_array($givenNames) && count($givenNames)) {
             $aufirst = implode(' ', $givenNames);
             if (!empty($aufirst)) {
                 $success = $output->addStatement('aufirst', $aufirst);
                 assert($success);
             }
             $initials = array();
             foreach ($givenNames as $givenName) {
                 $initials[] = substr($givenName, 0, 1);
             }
             $auinit1 = array_shift($initials);
             if (!empty($auinit1)) {
                 $success = $output->addStatement('auinit1', $auinit1);
                 assert($success);
             }
             $auinitm = implode('', $initials);
             if (!empty($auinitm)) {
                 $success = $output->addStatement('auinitm', $auinitm);
                 assert($success);
             }
             $auinit = $auinit1 . $auinitm;
             if (!empty($auinit)) {
                 $success = $output->addStatement('auinit', $auinit);
                 assert($success);
             }
         }
         $ausuffix = $authors[0]->getStatement('suffix');
         if (!empty($ausuffix)) {
             $success = $output->addStatement('ausuffix', $ausuffix);
             assert($success);
         }
         foreach ($authors as $author) {
             $au = $personStringFilter->execute($author);
             $success = $output->addStatement('au', $au);
             assert($success);
             unset($au);
         }
     }
     // Genre: Guesswork
     if (is_a($outputSchema, 'OpenUrlJournalBookBaseSchema')) {
         switch ($publicationType) {
             case NLM_PUBLICATION_TYPE_JOURNAL:
                 $genre = $input->hasProperty('article-title') ? OPENURL_GENRE_ARTICLE : OPENURL_GENRE_JOURNAL;
                 break;
             case NLM_PUBLICATION_TYPE_CONFPROC:
                 $genre = $input->hasProperty('article-title') ? OPENURL_GENRE_PROCEEDING : OPENURL_GENRE_CONFERENCE;
                 break;
             case NLM_PUBLICATION_TYPE_BOOK:
                 $genre = $input->hasProperty('article-title') ? OPENURL_GENRE_BOOKITEM : OPENURL_GENRE_BOOK;
                 break;
         }
         assert(!empty($genre));
         $success = $output->addStatement('genre', $genre);
         assert($success);
     }
     // Map remaining properties (NLM => OpenURL)
     $propertyMap =& $this->nlmOpenUrlMapping($publicationType, $outputSchema);
     // Transfer mapped properties with default locale
     foreach ($propertyMap as $nlmProperty => $openUrlProperty) {
         if ($input->hasStatement($nlmProperty)) {
             $success = $output->addStatement($openUrlProperty, $input->getStatement($nlmProperty));
             assert($success);
         }
     }
     return $output;
 }
示例#6
0
 /**
  * Initialize form data from the associated citation.
  * @param $citation Citation
  */
 function initData()
 {
     $citation =& $this->getCitation();
     // The unparsed citation text and the citation state
     $this->setData('editedCitation', $citation->getEditedCitation());
     // Citation meta-data
     foreach ($citation->getSupportedMetadataAdapters() as $metadataAdapter) {
         // Retrieve the meta-data schema
         $metadataSchema =& $metadataAdapter->getMetadataSchema();
         $metadataSchemaNamespace = $metadataSchema->getNamespace();
         // Loop over the properties in the schema and add string
         // values for all form fields.
         $citationVars = array();
         $citationVarsEmpty = array();
         $properties = $metadataSchema->getProperties();
         $metadataDescription =& $citation->extractMetadata($metadataSchema);
         foreach ($properties as $propertyName => $property) {
             if ($metadataDescription->hasStatement($propertyName)) {
                 $value = $metadataDescription->getStatement($propertyName);
                 if ($property->getCardinality() == METADATA_PROPERTY_CARDINALITY_MANY && !empty($value)) {
                     // FIXME: The following is a work-around until we completely
                     // implement #5171 ("author: et.al"). Then we have to support
                     // true multi-type properties.
                     if (is_a($value[0], 'MetadataDescription')) {
                         // We currently only support composite name arrays
                         assert(in_array($value[0]->getAssocType(), array(ASSOC_TYPE_AUTHOR, ASSOC_TYPE_EDITOR)));
                         import('metadata.nlm.NlmNameSchemaPersonStringFilter');
                         $personStringFilter = new NlmNameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE);
                         assert($personStringFilter->supportsAsInput($value));
                         $fieldValue = $personStringFilter->execute($value);
                     } else {
                         // We currently don't support repeated values
                         assert(is_array($value) && count($value) <= 1);
                         $fieldValue = $value[0];
                     }
                 } else {
                     $fieldValue = (string) $value;
                 }
             } else {
                 $fieldValue = '';
             }
             $fieldName = $metadataSchema->getNamespacedPropertyId($propertyName);
             if ($fieldValue != '') {
                 $citationVars[$fieldName] = array('translationKey' => $property->getDisplayName(), 'value' => $fieldValue);
             } else {
                 $citationVarsEmpty[$fieldName] = array('translationKey' => $property->getDisplayName(), 'value' => $fieldValue);
             }
         }
     }
     // FIXME: at the moment, we just create two tabs -- one for filled elements, and one for empty ones.
     // any number of elements can be added, and they will appear as new tabs on the modal window.
     $citationVarArrays = array("Filled Elements" => $citationVars, "Empty Elements" => $citationVarsEmpty);
     $this->setData('citationVarArrays', $citationVarArrays);
     $this->setData('ts', time());
 }