Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
Nlm30CitationSchemaOpenurl10CrosswalkFilter.inc.php
1 <?php
2 
21 import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30Openurl10CrosswalkFilter');
22 
28  $this->setDisplayName('Crosswalk from NLM Citation to Open URL');
29  parent::Nlm30Openurl10CrosswalkFilter('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema',
30  'lib.pkp.plugins.metadata.openurl10.schema.Openurl10BaseSchema');
31  }
32 
33 
34  //
35  // Implement template methods from Filter
36  //
45  function &process(&$input) {
46  $nullVar = null;
47  // Identify the genre of the target record and
48  // instantiate the target description.
49  $publicationType = $input->getStatement('[@publication-type]');
50  switch($publicationType) {
51  case NLM30_PUBLICATION_TYPE_JOURNAL:
52  case NLM30_PUBLICATION_TYPE_CONFPROC:
53  $outputSchemaName = 'lib.pkp.plugins.metadata.openurl10.schema.Openurl10JournalSchema';
54  break;
55 
56  case NLM30_PUBLICATION_TYPE_BOOK:
57  $outputSchemaName = 'lib.pkp.plugins.metadata.openurl10.schema.Openurl10BookSchema';
58  break;
59 
60  case NLM30_PUBLICATION_TYPE_THESIS:
61  $outputSchemaName = 'lib.pkp.plugins.metadata.openurl10.schema.Openurl10DissertationSchema';
62  break;
63 
64  default:
65  // Unsupported type
66  return $nullVar;
67  }
68 
69  // Create the target description
70  $output = new MetadataDescription($outputSchemaName, $input->getAssocType());
71 
72  // Transform authors
73  import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30NameSchemaPersonStringFilter');
74  $personStringFilter = new Nlm30NameSchemaPersonStringFilter();
75  $authors =& $input->getStatement('person-group[@person-group-type="author"]');
76  if (is_array($authors) && count($authors)) {
77  $aulast = ($authors[0]->hasStatement('prefix') ? $authors[0]->getStatement('prefix').' ' : '');
78  $aulast .= $authors[0]->getStatement('surname');
79  if (!empty($aulast)) {
80  $success = $output->addStatement('aulast', $aulast);
81  assert($success);
82  }
83 
84  $givenNames = $authors[0]->getStatement('given-names');
85  if(is_array($givenNames) && count($givenNames)) {
86  $aufirst = implode(' ', $givenNames);
87  if (!empty($aufirst)) {
88  $success = $output->addStatement('aufirst', $aufirst);
89  assert($success);
90  }
91 
92  $initials = array();
93  foreach($givenNames as $givenName) {
94  $initials[] = substr($givenName, 0, 1);
95  }
96 
97  $auinit1 = array_shift($initials);
98  if (!empty($auinit1)) {
99  $success = $output->addStatement('auinit1', $auinit1);
100  assert($success);
101  }
102 
103  $auinitm = implode('', $initials);
104  if (!empty($auinitm)) {
105  $success = $output->addStatement('auinitm', $auinitm);
106  assert($success);
107  }
108 
109  $auinit = $auinit1.$auinitm;
110  if (!empty($auinit)) {
111  $success = $output->addStatement('auinit', $auinit);
112  assert($success);
113  }
114  }
115 
116  $ausuffix = $authors[0]->getStatement('suffix');
117  if (!empty($ausuffix)) {
118  $success = $output->addStatement('ausuffix', $ausuffix);
119  assert($success);
120  }
121 
122  foreach ($authors as $author) {
123  if ($author == PERSON_STRING_FILTER_ETAL) {
124  $au = $author;
125  } else {
126  $au = $personStringFilter->execute($author);
127  }
128  $success = $output->addStatement('au', $au);
129  assert($success);
130  unset($au);
131  }
132  }
133 
134  // Genre: Guesswork
135  if (is_a($output->getMetadataSchema(), 'Openurl10JournalBookBaseSchema')) {
136  switch($publicationType) {
137  case NLM30_PUBLICATION_TYPE_JOURNAL:
138  $genre = ($input->hasProperty('article-title') ? OPENURL10_GENRE_ARTICLE : OPENURL10_GENRE_JOURNAL);
139  break;
140 
141  case NLM30_PUBLICATION_TYPE_CONFPROC:
142  $genre = ($input->hasProperty('article-title') ? OPENURL10_GENRE_PROCEEDING : OPENURL10_GENRE_CONFERENCE);
143  break;
144 
145  case NLM30_PUBLICATION_TYPE_BOOK:
146  $genre = ($input->hasProperty('article-title') ? OPENURL10_GENRE_BOOKITEM : OPENURL10_GENRE_BOOK);
147  break;
148  }
149  assert(!empty($genre));
150  $success = $output->addStatement('genre', $genre);
151  assert($success);
152  }
153 
154  // Map remaining properties (NLM => OpenURL)
155  $propertyMap =& $this->nlmOpenurl10Mapping($publicationType, $output->getMetadataSchema());
156 
157  // Transfer mapped properties with default locale
158  foreach ($propertyMap as $nlm30Property => $openurl10Property) {
159  if ($input->hasStatement($nlm30Property)) {
160  $success = $output->addStatement($openurl10Property, $input->getStatement($nlm30Property));
161  assert($success);
162  }
163  }
164 
165  return $output;
166  }
167 }
168 ?>
& nlmOpenurl10Mapping($publicationType, &$openurl10Schema)
setDisplayName($displayName)
Definition: Filter.inc.php:140
addStatement($propertyName, $value, $locale=null, $replace=false)
Filter that converts from NLM citation to OpenURL schemas.
Filter that converts from NLM name to a string.
Filter that converts from NLM citation to OpenURL schemas.
Class modeling a description (DCMI abstract model) or subject- predicate-object graph (RDF)...