本文整理汇总了PHP中MetadataDescription类的典型用法代码示例。如果您正苦于以下问题:PHP MetadataDescription类的具体用法?PHP MetadataDescription怎么用?PHP MetadataDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetadataDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMetadataDescriptionDummyAdapter
/**
* @covers MetadataDescriptionDummyAdapter
*/
public function testMetadataDescriptionDummyAdapter()
{
$schema = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema';
// Instantiate a test description.
$originalDescription = new MetadataDescription($schema, ASSOC_TYPE_CITATION);
$originalDescription->addStatement('source', $originalTitle = 'original source');
$originalDescription->addStatement('article-title', $originalTitle = 'original title');
// Test constructor.
$adapter = new MetadataDescriptionDummyAdapter($originalDescription);
self::assertEquals(ASSOC_TYPE_CITATION, $adapter->getAssocType());
self::assertEquals($schema, $adapter->getMetadataSchemaName());
self::assertInstanceOf('Nlm30CitationSchema', $adapter->getMetadataSchema());
// Test metadata injection.
$sourceDescription = new MetadataDescription($schema, ASSOC_TYPE_CITATION);
$sourceDescription->addStatement('article-title', $injectedTitle = 'injected title');
$resultDescription =& $adapter->injectMetadataIntoDataObject($sourceDescription, $originalDescription);
$expectedResult = array('source' => array('en_US' => 'original source'), 'article-title' => array('en_US' => 'injected title'));
self::assertEquals($expectedResult, $resultDescription->getStatements());
// Test meta-data extraction.
$extractedDescription = $adapter->extractMetadataFromDataObject($originalDescription);
self::assertEquals($originalDescription, $extractedDescription);
// Test meta-data field names (only test one field of each
// category (translated or not) so that the test doesn't
// break when we expand the NLM schema).
$fieldNames = $adapter->getMetadataFieldNames(false);
self::assertTrue(in_array('date', $fieldNames));
// NB: no namespace pre-fix in this case!
$fieldNames = $adapter->getMetadataFieldNames(true);
self::assertTrue(in_array('article-title', $fieldNames));
}
示例2: getTestOpenurl10Description
/**
* Creates a test description in Openurl10 format
* @return MetadataDescription
*/
protected function getTestOpenurl10Description()
{
$citationData = array('aulast' => 'von Surname1', 'aufirst' => 'Given1 P', 'auinit1' => 'G', 'auinitm' => 'P', 'auinit' => 'GP', 'ausuffix' => 'suff', 'au' => array(0 => 'Surname1 suff, P. (Given1) von', 1 => 'Surname2, (Given2)'), 'genre' => 'article', 'jtitle' => 'Some Journal Title', 'atitle' => 'Some Article Title', 'date' => '2005-07-03', 'issn' => '0694760949645', 'spage' => 17, 'epage' => 33, 'volume' => '7', 'issue' => '5', 'eissn' => '3049674960475', 'artnum' => '45', 'coden' => 'coden', 'sici' => 'sici');
$openurl10Description = new MetadataDescription('lib.pkp.plugins.metadata.openurl10.schema.Openurl10JournalSchema', ASSOC_TYPE_CITATION);
self::assertTrue($openurl10Description->setStatements($citationData));
return $openurl10Description;
}
示例3: serializeCitationDescription
private function serializeCitationDescription(MetadataDescription &$citationDescription)
{
// Prepare transformation tables for the output serialization:
// - the following lines will be deleted from our output file
static $linesToDelete = array(' [0-9]+ => ', ' array \\(', ' \'_data\' => ', ' \\),');
// Transform person descriptions to arrays
$citationDescriptionArray = $citationDescription->getStatements();
$personDescriptionProperties = array('person-group[@person-group-type="author"]', 'person-group[@person-group-type="editor"]');
foreach ($personDescriptionProperties as $personDescriptionProperty) {
if (isset($citationDescriptionArray[$personDescriptionProperty])) {
foreach ($citationDescriptionArray[$personDescriptionProperty] as &$person) {
$person = $person->getStatements();
}
}
}
// Transform the result into an array that we can serialize
// in a human-readable form and also re-import as PHP-parsable code.
$citationDescriptionOutput = var_export($citationDescriptionArray, true);
$citationDescriptionOutputArray = explode("\n", $citationDescriptionOutput);
foreach ($citationDescriptionOutputArray as $key => &$citationDescriptionOutputLine) {
// Remove redundant lines
foreach ($linesToDelete as $lineToDelete) {
if (preg_match('/^' . $lineToDelete . '$/', $citationDescriptionOutputLine)) {
unset($citationDescriptionOutputArray[$key]);
}
}
// Correctly indent the output line
$citationDescriptionOutputLine = "\t\t\t" . preg_replace('/^\\t\\t\\t/', "\t\t", str_replace(' ', "\t", $citationDescriptionOutputLine));
}
// Create the final serialized format
return implode("\n", $citationDescriptionOutputArray);
}
示例4: testNlm30CitationSchemaCitationAdapter
/**
* @covers Nlm30CitationSchemaCitationAdapter
*/
public function testNlm30CitationSchemaCitationAdapter()
{
// Test constructor.
$adapter = new Nlm30CitationSchemaCitationAdapter(PersistableFilter::tempGroup('metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)', 'class::lib.pkp.classes.citation.Citation'));
self::assertEquals(ASSOC_TYPE_CITATION, $adapter->getAssocType());
self::assertType('Nlm30CitationSchema', $adapter->getMetadataSchema());
self::assertEquals('Citation', $adapter->getDataObjectClass());
// Instantiate a test description.
$authorDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', ASSOC_TYPE_AUTHOR);
$authorDescription->addStatement('surname', $surname = 'some surname');
$citationDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema', ASSOC_TYPE_CITATION);
$citationDescription->addStatement('article-title', $articleTitle = 'article title');
$citationDescription->addStatement('person-group[@person-group-type="author"]', $authorDescription);
// Instantiate test citation.
$citation = new Citation();
// Test metadata injection.
$resultCitation =& $adapter->injectMetadataIntoDataObject($citationDescription, $citation);
$expectedResult = array('rawCitation' => '', 'nlm30:person-group[@person-group-type="author"]' => array(array('surname' => 'some surname')), 'nlm30:article-title' => array('en_US' => 'article title'));
self::assertEquals($expectedResult, $resultCitation->getAllData());
// Instantiate and inject a second test description.
$authorDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', ASSOC_TYPE_AUTHOR);
$authorDescription->addStatement('surname', $anotherSurname = 'another surname');
$secondDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema', ASSOC_TYPE_CITATION);
$secondDescription->addStatement('person-group[@person-group-type="author"]', $authorDescription);
$secondDescription->addStatement('source', $source = 'some source');
$resultCitation =& $adapter->injectMetadataIntoDataObject($secondDescription, $citation);
$expectedResult = array('rawCitation' => '', 'nlm30:person-group[@person-group-type="author"]' => array(array('surname' => 'another surname')), 'nlm30:article-title' => array('en_US' => 'article title'), 'nlm30:source' => array('en_US' => 'some source'));
self::assertEquals($expectedResult, $resultCitation->getAllData());
// Test meta-data extraction.
$adapter = new Nlm30CitationSchemaCitationAdapter(PersistableFilter::tempGroup('class::lib.pkp.classes.citation.Citation', 'metadata::lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema(CITATION)'));
$extractedDescription =& $adapter->extractMetadataFromDataObject($resultCitation);
$secondDescription->addStatement('article-title', $articleTitle = 'article title');
self::assertEquals($secondDescription, $extractedDescription);
}
示例5: testExecute
/**
* @covers PKPSubmissionNlm30XmlFilter
*/
public function testExecute()
{
// Instantiate test meta-data for a citation.
import('lib.pkp.classes.metadata.MetadataDescription');
$nameSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema';
$nameDescription = new MetadataDescription($nameSchemaName, ASSOC_TYPE_AUTHOR);
$nameDescription->addStatement('given-names', $value = 'Peter');
$nameDescription->addStatement('given-names', $value = 'B');
$nameDescription->addStatement('surname', $value = 'Bork');
$nameDescription->addStatement('prefix', $value = 'Mr.');
$citationSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema';
$citationDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
$citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
$citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
$citationDescription->addStatement('date', $value = '2009-08-17');
$citationDescription->addStatement('size', $value = 320);
$citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
$citationDescription->addStatement('[@publication-type]', $value = 'book');
$citation =& $this->getCitation($citationDescription);
// Persist a few copies of the citation for testing.
$citationDao =& $this->getCitationDao();
for ($seq = 1; $seq <= 10; $seq++) {
$citation->setSeq($seq);
$citation->setCitationState(CITATION_APPROVED);
$citationId = $citationDao->insertObject($citation);
self::assertTrue(is_numeric($citationId));
self::assertTrue($citationId > 0);
}
// Execute the filter and check the outcome.
$mockSubmission =& $this->getTestSubmission();
// FIXME: Add NLM 3.0 tag set schema validation as soon as we implement the full tag set, see #5648.
$filter = new PKPSubmissionNlm30XmlFilter(PersistableFilter::tempGroup('class::lib.pkp.classes.submission.Submission', 'xml::*'));
$nlm30Xml = $filter->execute($mockSubmission);
self::assertXmlStringEqualsXmlFile('./lib/pkp/tests/plugins/metadata/nlm30/filter/sample-nlm30-citation.xml', $nlm30Xml);
}
示例6: testExecuteWithMultiplePersonDescriptions
/**
* @covers Nlm30NameSchemaPersonStringFilter
* @covers Nlm30PersonStringFilter
* @depends testExecuteWithSinglePersonDescription
*/
public function testExecuteWithMultiplePersonDescriptions($personDescription1)
{
$personDescription2 = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', ASSOC_TYPE_AUTHOR);
$personDescription2->addStatement('given-names', $givenNames1 = 'Bernardo');
$personDescription2->addStatement('given-names', $givenNames2 = 'Antonio');
$personDescription2->addStatement('surname', $surname = 'Elis');
$personDescriptions = array($personDescription1, $personDescription2, PERSON_STRING_FILTER_ETAL);
$nlm30NameSchemaPersonStringFilter = new Nlm30NameSchemaPersonStringFilter(PERSON_STRING_FILTER_MULTIPLE);
self::assertEquals('Assis Jr, (Machado) de; Elis, A. (Bernardo); et al', $nlm30NameSchemaPersonStringFilter->execute($personDescriptions));
// Test template and delimiter
$nlm30NameSchemaPersonStringFilter->setDelimiter(':');
$nlm30NameSchemaPersonStringFilter->setTemplate('%firstname%%initials%%prefix% %surname%%suffix%');
self::assertEquals('Machado de Assis Jr:Bernardo A. Elis:et al', $nlm30NameSchemaPersonStringFilter->execute($personDescriptions));
}
示例7: testCitationCrud
public function testCitationCrud()
{
$nameSchema = new NlmNameSchema();
$nameDescription = new MetadataDescription($nameSchema, ASSOC_TYPE_AUTHOR);
$nameDescription->addStatement('given-names', $value = 'Peter');
$nameDescription->addStatement('given-names', $value = 'B');
$nameDescription->addStatement('surname', $value = 'Bork');
$nameDescription->addStatement('prefix', $value = 'Mr.');
$citationSchema = new NlmCitationSchema();
$citationDescription = new MetadataDescription($citationSchema, ASSOC_TYPE_CITATION);
$citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
$citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
$citationDescription->addStatement('article-title', $value = 'PHPUnit in Kürze', 'de_DE');
$citationDescription->addStatement('date', $value = '2009-08-17');
$citationDescription->addStatement('size', $value = 320);
$citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
$citation = new Citation('raw citation');
$citation->setAssocType(ASSOC_TYPE_ARTICLE);
$citation->setAssocId(5);
$citation->setEditedCitation('edited citation');
$citation->setParseScore(50);
$citation->injectMetadata($citationDescription);
$citationId = $this->citationDAO->insertCitation($citation);
self::assertTrue(is_numeric($citationId));
self::assertTrue($citationId > 0);
}
示例8: testExecuteWithMultiplePersonDescriptions
/**
* @covers NlmNameSchemaPersonStringFilter::supports
* @covers NlmNameSchemaPersonStringFilter::execute
* @covers NlmNameSchemaPersonStringFilter::isValid
* @covers NlmNameSchemaPersonStringFilter::_flattenPersonsDescriptions
* @depends testExecuteWithSinglePersonDescription
*/
public function testExecuteWithMultiplePersonDescriptions($personDescription1)
{
$nlmNameSchema = new NlmNameSchema();
$personDescription2 = new MetadataDescription($nlmNameSchema, ASSOC_TYPE_AUTHOR);
$personDescription2->addStatement('given-names', $givenNames1 = 'Bernardo');
$personDescription2->addStatement('given-names', $givenNames2 = 'Antonio');
$personDescription2->addStatement('surname', $surname = 'Elis');
$personDescriptions = array($personDescription1, $personDescription2);
$this->_nlmNameSchemaPersonStringFilter->setFilterMode(PERSON_STRING_FILTER_MULTIPLE);
self::assertEquals('Assis Jr, (Machado) de; Elis, A. (Bernardo)', $this->_nlmNameSchemaPersonStringFilter->execute($personDescriptions));
// Test template and delimiter
$this->_nlmNameSchemaPersonStringFilter->setDelimiter(':');
$this->_nlmNameSchemaPersonStringFilter->setTemplate('%firstname%%initials%%prefix% %surname%%suffix%');
self::assertEquals('Machado de Assis Jr:Bernardo A. Elis', $this->_nlmNameSchemaPersonStringFilter->execute($personDescriptions));
}
示例9: testCitationCrud
public function testCitationCrud()
{
$nameSchema = new NlmNameSchema();
$nameDescription = new MetadataDescription($nameSchema, ASSOC_TYPE_AUTHOR);
$nameDescription->addStatement('given-names', $value = 'Peter');
$nameDescription->addStatement('given-names', $value = 'B');
$nameDescription->addStatement('surname', $value = 'Bork');
$nameDescription->addStatement('prefix', $value = 'Mr.');
$citationSchema = new NlmCitationSchema();
$citationDescription = new MetadataDescription($citationSchema, ASSOC_TYPE_CITATION);
$citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
$citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
$citationDescription->addStatement('article-title', $value = 'PHPUnit in Kürze', 'de_DE');
$citationDescription->addStatement('date', $value = '2009-08-17');
$citationDescription->addStatement('size', $value = 320);
$citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
$citation = new Citation('raw citation');
$citation->setAssocType(ASSOC_TYPE_ARTICLE);
$citation->setAssocId(999999);
$citation->setEditedCitation('edited citation');
$citation->setParseScore(50);
$citation->injectMetadata($citationDescription);
// Create citation
$citationId = $this->citationDAO->insertCitation($citation);
self::assertTrue(is_numeric($citationId));
self::assertTrue($citationId > 0);
// Retrieve citation
$citationById = $this->citationDAO->getCitation($citationId);
$citationById->getMetadataFieldNames();
// Initializes internal state for comparison.
self::assertEquals($citation, $citationById);
$citationsByAssocIdDaoFactory = $this->citationDAO->getCitationsByAssocId(ASSOC_TYPE_ARTICLE, 999999);
$citationsByAssocId = $citationsByAssocIdDaoFactory->toArray();
self::assertEquals(1, count($citationsByAssocId));
$citationsByAssocId[0]->getMetadataFieldNames();
// Initializes internal state for comparison.
self::assertEquals($citation, $citationsByAssocId[0]);
// Update citation
$citationDescription->removeStatement('date');
$citationDescription->addStatement('article-title', $value = 'PHPUnit rápido', 'pt_BR');
$updatedCitation = new Citation('another raw citation');
$updatedCitation->setId($citationId);
$updatedCitation->setAssocType(ASSOC_TYPE_ARTICLE);
$updatedCitation->setAssocId(999998);
$updatedCitation->setEditedCitation('another edited citation');
$updatedCitation->setParseScore(50);
$updatedCitation->injectMetadata($citationDescription);
$this->citationDAO->updateCitation($updatedCitation);
$citationAfterUpdate = $this->citationDAO->getCitation($citationId);
$citationAfterUpdate->getMetadataFieldNames();
// Initializes internal state for comparison.
self::assertEquals($updatedCitation, $citationAfterUpdate);
// Delete citation
$this->citationDAO->deleteCitationsByAssocId(ASSOC_TYPE_ARTICLE, 999998);
self::assertNull($this->citationDAO->getCitation($citationId));
}
示例10: MetadataDescription
/**
* This implementation of the CrosswalkFilter
* simply removes statements from the incoming meta-data
* description that are not in the target description's schema.
* @see Filter::process()
* @param $input MetadataDescription
* @return MetadataDescription
*/
function &process(&$input)
{
// Create the target description
$output = new MetadataDescription($this->_toSchema);
// Compare the property names of the incoming description with
// the property names allowed in the target schema.
$sourceProperties = $input->getSetPropertyNames();
$targetProperties = $output->getPropertyNames();
$propertiesToBeRemoved = array_diff($sourceProperties, $targetProperties);
// Remove statements for properties that are not in the target schema.
$statements =& $input->getStatements();
foreach ($propertiesToBeRemoved as $propertyToBeRemoved) {
assert(isset($statements[$propertyToBeRemoved]));
unset($statements[$propertyToBeRemoved]);
}
// Set the remaining statements in the target description
$success = $output->setStatements($statements);
assert($success);
return $output;
}
示例11: NlmCitationSchema
/**
* Map OpenURL properties to NLM 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;
// Instantiate the target description.
$outputSchema = new NlmCitationSchema();
$output = new MetadataDescription($outputSchema, $input->getAssocType());
// Parse au statements into name descriptions
import('metadata.nlm.PersonStringNlmNameSchemaFilter');
$personStringFilter = new PersonStringNlmNameSchemaFilter(ASSOC_TYPE_AUTHOR);
$authors =& $input->getStatement('au');
if (is_array($authors) && count($authors)) {
// TODO: We might improve results here by constructing the
// first author from aufirst, aulast fields.
foreach ($authors as $author) {
$authorDescription =& $personStringFilter->execute($author);
$success = $output->addStatement('person-group[@person-group-type="author"]', $authorDescription);
assert($success);
unset($authorDescription);
}
}
// Publication type
if ($input->hasStatement('genre')) {
$genre = $input->getStatement('genre');
$genreMap = $this->_getOpenUrlGenreTranslationMapping();
$publicationType = isset($genreMap[$genre]) ? $genreMap[$genre] : $genre;
$success = $output->addStatement('[@publication-type]', $publicationType);
assert($success);
}
// Get NLM => OpenURL property mapping.
$propertyMap =& $this->nlmOpenUrlMapping($publicationType, $input->getMetadataSchema());
// Transfer mapped properties with default locale
foreach ($propertyMap as $nlmProperty => $openUrlProperty) {
if ($input->hasStatement($openUrlProperty)) {
$success = $output->addStatement($nlmProperty, $input->getStatement($openUrlProperty));
assert($success);
}
}
return $output;
}
示例12: validate
/**
* Custom implementation of Form::validate() that validates
* meta-data form data and injects it into the internal citation
* object.
*
* NB: The configuration of the internal citation object
* would normally be done in readInputData(). Validation and
* injection can easily be done in one step. It therefore avoids
* code duplication and improves performance to do both here.
*/
function validate()
{
// Make sure that this method is not called twice which
// would corrupt internal state.
assert(empty($this->_metadataDescriptions));
parent::validate();
// Validate form data and inject it into
// the associated citation object.
$citation =& $this->getCitation();
$citation->setRawCitation($this->getData('rawCitation'));
if ($this->getData('citationApproved') == 'citationApproved') {
// Editor's shortcut to the approved state, e.g. for manually edited citations.
$citation->setCitationState(CITATION_APPROVED);
} elseif (in_array($this->getData('citationState'), Citation::_getSupportedCitationStates())) {
// Reset citation state if necessary
if ($this->getData('citationState') == CITATION_APPROVED) {
$this->setData('citationState', CITATION_LOOKED_UP);
}
$citation->setCitationState($this->getData('citationState'));
}
// Extract data from citation form fields and inject it into the citation
import('lib.pkp.classes.metadata.MetadataDescription');
$metadataSchemas = $citation->getSupportedMetadataSchemas();
foreach ($metadataSchemas as $metadataSchema) {
/* @var $metadataSchema MetadataSchema */
// Instantiate a meta-data description for the given schema
$metadataDescription = new MetadataDescription($metadataSchema->getClassName(), ASSOC_TYPE_CITATION);
// Set the meta-data statements
foreach ($metadataSchema->getProperties() as $propertyName => $property) {
$fieldName = $metadataSchema->getNamespacedPropertyId($propertyName);
$fieldValue = trim($this->getData($fieldName));
if (empty($fieldValue)) {
// Delete empty statements so that previously set
// statements (if any) will be deleted.
$metadataDescription->removeStatement($propertyName);
if ($property->getMandatory()) {
// A mandatory field is missing - add a validation error.
$this->addError($fieldName, __($property->getValidationMessage()));
$this->addErrorField($fieldName);
}
} else {
// Try to convert the field value to (a) strongly
// typed object(s) if applicable. Start with the most
// specific allowed type so that we always get the
// most strongly typed result possible.
$allowedTypes = $property->getAllowedTypes();
switch (true) {
case isset($allowedTypes[METADATA_PROPERTY_TYPE_VOCABULARY]) && is_numeric($fieldValue):
case isset($allowedTypes[METADATA_PROPERTY_TYPE_INTEGER]) && is_numeric($fieldValue):
$typedFieldValues = array((int) $fieldValue);
break;
case isset($allowedTypes[METADATA_PROPERTY_TYPE_DATE]):
import('lib.pkp.classes.metadata.DateStringNormalizerFilter');
$dateStringFilter = new DateStringNormalizerFilter();
assert($dateStringFilter->supportsAsInput($fieldValue));
$typedFieldValues = array($dateStringFilter->execute($fieldValue));
break;
case isset($allowedTypes[METADATA_PROPERTY_TYPE_COMPOSITE]):
// We currently only support name composites
$allowedAssocIds = $allowedTypes[METADATA_PROPERTY_TYPE_COMPOSITE];
if (in_array(ASSOC_TYPE_AUTHOR, $allowedAssocIds)) {
$assocType = ASSOC_TYPE_AUTHOR;
} elseif (in_array(ASSOC_TYPE_EDITOR, $allowedAssocIds)) {
$assocType = ASSOC_TYPE_EDITOR;
} else {
assert(false);
}
// Try to transform the field to a name composite.
import('lib.pkp.plugins.metadata.nlm30.filter.PersonStringNlm30NameSchemaFilter');
$personStringFilter = new PersonStringNlm30NameSchemaFilter($assocType, PERSON_STRING_FILTER_MULTIPLE);
assert($personStringFilter->supportsAsInput($fieldValue));
$typedFieldValues =& $personStringFilter->execute($fieldValue);
break;
default:
$typedFieldValues = array($fieldValue);
}
// Inject data into the meta-data description and thereby
// implicitly validate the field value.
foreach ($typedFieldValues as $typedFieldValue) {
if (!$metadataDescription->addStatement($propertyName, $typedFieldValue)) {
// Add form field error
$this->addError($fieldName, __($property->getValidationMessage()));
$this->addErrorField($fieldName);
}
unset($typedFieldValue);
}
unset($typedFieldValues);
}
}
// Inject the meta-data into the citation.
//.........这里部分代码省略.........
示例13: testExecute
/**
* @covers Nlm30Nlm23CrosswalkFilter
*/
public function testExecute()
{
$this->markTestSkipped('Weird class interaction with ControlledVocabEntryDAO leads to failure');
// Instantiate test meta-data for a citation. This must use the complete
// available schema (although in practice this doesn't make sense) so that
// we can make sure all tags are correctly converted.
import('lib.pkp.classes.metadata.MetadataDescription');
$nameSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema';
$nameDescription = new MetadataDescription($nameSchemaName, ASSOC_TYPE_AUTHOR);
$nameDescription->addStatement('given-names', $value = 'Peter');
$nameDescription->addStatement('given-names', $value = 'B');
$nameDescription->addStatement('surname', $value = 'Bork');
$nameDescription->addStatement('prefix', $value = 'Mr.');
$nameDescription->addStatement('suffix', $value = 'Jr');
$citationSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema';
$citationDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
$citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
$citationDescription->addStatement('person-group[@person-group-type="editor"]', $nameDescription);
$citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
$citationDescription->addStatement('source', $value = 'PHPUnit in a nutshell', 'en_US');
$citationDescription->addStatement('date', $value = '2009-08-17');
$citationDescription->addStatement('date-in-citation[@content-type="access-date"]', $value = '2009-08');
$citationDescription->addStatement('issue', $value = 5);
$citationDescription->addStatement('volume', $value = 6);
$citationDescription->addStatement('season', $value = 'Summer');
$citationDescription->addStatement('chapter-title', $value = 'Introduction');
$citationDescription->addStatement('edition', $value = '2nd edition');
$citationDescription->addStatement('series', $value = 7);
$citationDescription->addStatement('supplement', $value = 'Summer Special');
$citationDescription->addStatement('conf-date', $value = '2009-08-17');
$citationDescription->addStatement('conf-loc', $value = 'Helsinki');
$citationDescription->addStatement('conf-name', $value = 'PHPUnit Hackfest');
$citationDescription->addStatement('conf-sponsor', $value = 'Basti himself');
$citationDescription->addStatement('institution', $value = 'PKP');
$citationDescription->addStatement('fpage', $value = 9);
$citationDescription->addStatement('lpage', $value = 312);
$citationDescription->addStatement('size', $value = 320);
$citationDescription->addStatement('publisher-loc', $value = 'Vancouver');
$citationDescription->addStatement('publisher-name', $value = 'SFU');
$citationDescription->addStatement('isbn', $value = '123456789');
$citationDescription->addStatement('issn[@pub-type="ppub"]', $value = '987654321');
$citationDescription->addStatement('issn[@pub-type="epub"]', $value = '111111111');
$citationDescription->addStatement('pub-id[@pub-id-type="doi"]', $value = '10420/39406');
$citationDescription->addStatement('pub-id[@pub-id-type="publisher-id"]', $value = 'xyz');
$citationDescription->addStatement('pub-id[@pub-id-type="coden"]', $value = 'abc');
$citationDescription->addStatement('pub-id[@pub-id-type="sici"]', $value = 'def');
$citationDescription->addStatement('pub-id[@pub-id-type="pmid"]', $value = '999999');
$citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
$citationDescription->addStatement('comment', $value = 'just nonsense');
$citationDescription->addStatement('annotation', $value = 'more nonsense');
$citationDescription->addStatement('[@publication-type]', $value = 'conf-proc');
$citation =& $this->getCitation($citationDescription);
// Persist one copy of the citation for testing.
$citationDao =& $this->getCitationDao();
$citation->setSeq(1);
$citation->setCitationState(CITATION_APPROVED);
$citationId = $citationDao->insertObject($citation);
self::assertTrue(is_numeric($citationId));
self::assertTrue($citationId > 0);
// Construct the expected output.
$expectedOutput = '';
// Prepare NLM 3.0 input.
$mockSubmission =& $this->getTestSubmission();
import('lib.pkp.plugins.metadata.nlm30.filter.PKPSubmissionNlm30XmlFilter');
$nlm30Filter = new PKPSubmissionNlm30XmlFilter(PersistableFilter::tempGroup('class::lib.pkp.classes.submission.Submission', 'xml::*'));
$nlm30Xml = $nlm30Filter->execute($mockSubmission);
// Test the downgrade filter.
import('lib.pkp.classes.xslt.XSLTransformationFilter');
// FIXME: Add NLM 2.3 and 3.0 tag set schema validation as soon as we implement the full tag set, see #5648.
$downgradeFilter = new XSLTransformationFilter(PersistableFilter::tempGroup('xml::*', 'xml::*'), 'NLM 3.0 to 2.3 ref-list downgrade');
$downgradeFilter->setXSLFilename('lib/pkp/plugins/metadata/nlm30/filter/nlm30-to-23-ref-list.xsl');
$nlm30Xml = $downgradeFilter->execute($nlm30Xml);
self::assertXmlStringEqualsXmlFile('./lib/pkp/tests/plugins/metadata/nlm30/filter/sample-nlm23-citation.xml', $nlm30Xml);
}
示例14: extractMetadataFromDataObject
/**
* @copydoc MetadataDataObjectAdapter::extractMetadataFromDataObject()
* @param $dataObject Citation
* @return MetadataDescription
*/
function extractMetadataFromDataObject(&$dataObject)
{
$metadataDescription = $this->instantiateMetadataDescription();
// Establish the association between the meta-data description
// and the citation object.
$metadataDescription->setAssocId($dataObject->getId());
// Identify the length of the name space prefix
$namespacePrefixLength = strlen($this->getMetadataNamespace()) + 1;
// Get all meta-data field names
$fieldNames = array_merge($this->getDataObjectMetadataFieldNames(false), $this->getDataObjectMetadataFieldNames(true));
// Retrieve the statements from the data object
$statements = array();
foreach ($fieldNames as $fieldName) {
if ($dataObject->hasData($fieldName)) {
// Remove the name space prefix
$propertyName = substr($fieldName, $namespacePrefixLength);
if (in_array($propertyName, array('person-group[@person-group-type="author"]', 'person-group[@person-group-type="editor"]'))) {
// Retrieve the names array (must not be by-ref
// to protect the original citation object!)
$names = $dataObject->getData($fieldName);
// Convert key/value arrays to MetadataDescription objects.
foreach ($names as $key => $name) {
if (is_array($name)) {
// Construct a meta-data description from
// this name array.
switch ($propertyName) {
case 'person-group[@person-group-type="author"]':
$assocType = ASSOC_TYPE_AUTHOR;
break;
case 'person-group[@person-group-type="editor"]':
$assocType = ASSOC_TYPE_EDITOR;
break;
}
$nameDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', $assocType);
$nameDescription->setStatements($name);
$names[$key] =& $nameDescription;
unset($nameDescription);
} else {
// The only non-structured data allowed here
// is the et-al string.
import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30PersonStringFilter');
assert($name == PERSON_STRING_FILTER_ETAL);
}
}
$statements[$propertyName] =& $names;
unset($names);
} else {
$statements[$propertyName] =& $dataObject->getData($fieldName);
}
}
}
// Set the statements in the meta-data description
$success = $metadataDescription->setStatements($statements);
assert($success);
return $metadataDescription;
}
示例15: testExecuteWithConferenceProceeding
public function testExecuteWithConferenceProceeding()
{
$this->markTestSkipped('Weird class interaction with ControlledVocabEntryDAO leads to failure');
$nameSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema';
$citationSchemaName = 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema';
// An author
$personDescription = new MetadataDescription($nameSchemaName, ASSOC_TYPE_AUTHOR);
$personDescription->addStatement('surname', $surname = 'Liu');
$personDescription->addStatement('given-names', $givenName = 'Sen');
// A conference paper found on the web
$citationDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
$citationDescription->addStatement('[@publication-type]', $pubType = NLM30_PUBLICATION_TYPE_CONFPROC);
$citationDescription->addStatement('person-group[@person-group-type="author"]', $personDescription);
$citationDescription->addStatement('article-title', $articleTitle = 'Defending against business crises with the help of intelligent agent based early warning solutions');
$citationDescription->addStatement('conf-name', $confName = 'The Seventh International Conference on Enterprise Information Systems');
$citationDescription->addStatement('conf-loc', $confLoc = 'Miami, FL');
$citationDescription->addStatement('date', $date = '2005-05');
$citationDescription->addStatement('date-in-citation[@content-type="access-date"]', $accessDate = '2006-08-12');
$citationDescription->addStatement('uri', $uri = 'http://www.iceis.org/iceis2005/abstracts_2005.htm');
$citationOutputFilter = $this->getFilterInstance();
$result = $citationOutputFilter->execute($citationDescription);
$expectedResult = $this->getConfProcResult();
self::assertEquals($expectedResult[0] . $this->getConfProcResultGoogleScholar() . $expectedResult[1], $result);
}
开发者ID:PublishingWithoutWalls,项目名称:pkp-lib,代码行数:24,代码来源:Nlm30CitationSchemaCitationOutputFormatFilterTest.inc.php