本文整理汇总了PHP中MetadataDescription::addStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP MetadataDescription::addStatement方法的具体用法?PHP MetadataDescription::addStatement怎么用?PHP MetadataDescription::addStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetadataDescription
的用法示例。
在下文中一共展示了MetadataDescription::addStatement方法的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: 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);
}
示例3: 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));
}
示例4: 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));
}
示例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: 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);
}
示例7: 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;
}
示例8: 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));
}
示例9: testMetadataDescriptionCrud
/**
* @covers MetadataDescriptionDAO
*
* FIXME: The test data used here and in the CitationDAOTest
* are very similar. We should find a way to not duplicate this
* test data.
*/
public function testMetadataDescriptionCrud()
{
$metadataDescriptionDao = DAORegistry::getDAO('MetadataDescriptionDAO');
$nameDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', 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.');
$testDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema', ASSOC_TYPE_CITATION);
$testDescription->setAssocId(999999);
$testDescription->setDisplayName('test meta-data description');
$testDescription->setSeq(5);
$testDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
$testDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
$testDescription->addStatement('article-title', $value = 'PHPUnit in Kürze', 'de_DE');
$testDescription->addStatement('date', $value = '2009-08-17');
$testDescription->addStatement('size', $value = 320);
$testDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
// Create meta-data description
$metadataDescriptionId = $metadataDescriptionDao->insertObject($testDescription);
self::assertTrue(is_numeric($metadataDescriptionId));
self::assertTrue($metadataDescriptionId > 0);
// Retrieve meta-data description by id
$metadataDescriptionById = $metadataDescriptionDao->getObjectById($metadataDescriptionId);
$testDescription->removeSupportedMetadataAdapter('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema');
// Required for comparison
$metadataDescriptionById->getMetadataSchema();
// Instantiates the internal metadata-schema.
self::assertEquals($testDescription, $metadataDescriptionById);
$metadataDescriptionsByAssocIdDaoFactory = $metadataDescriptionDao->getObjectsByAssocId(ASSOC_TYPE_CITATION, 999999);
$metadataDescriptionsByAssocId = $metadataDescriptionsByAssocIdDaoFactory->toArray();
self::assertEquals(1, count($metadataDescriptionsByAssocId));
$metadataDescriptionsByAssocId[0]->getMetadataSchema();
// Instantiates the internal metadata-schema.
self::assertEquals($testDescription, $metadataDescriptionsByAssocId[0]);
// Update meta-data description
$testDescription->removeStatement('date');
$testDescription->addStatement('article-title', $value = 'PHPUnit rápido', 'pt_BR');
$metadataDescriptionDao->updateObject($testDescription);
$testDescription->removeSupportedMetadataAdapter('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema');
// Required for comparison
$metadataDescriptionAfterUpdate = $metadataDescriptionDao->getObjectById($metadataDescriptionId);
$metadataDescriptionAfterUpdate->getMetadataSchema();
// Instantiates the internal metadata-schema.
self::assertEquals($testDescription, $metadataDescriptionAfterUpdate);
// Delete meta-data description
$metadataDescriptionDao->deleteObjectsByAssocId(ASSOC_TYPE_CITATION, 999999);
self::assertNull($metadataDescriptionDao->getObjectById($metadataDescriptionId));
}
示例10: 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.
//.........这里部分代码省略.........
示例11: 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
示例12: extractMetadataFromDataObject
/**
* @see MetadataDataObjectAdapter::extractMetadataFromDataObject()
* @param $submission Submission
* @return MetadataDescription
*/
function extractMetadataFromDataObject(&$submission)
{
assert(is_a($submission, 'Submission'));
$mods34Description = $this->instantiateMetadataDescription();
// Retrieve the primary locale.
$catalogingLocale = AppLocale::getPrimaryLocale();
$catalogingLanguage = AppLocale::get3LetterIsoFromLocale($catalogingLocale);
// Establish the association between the meta-data description
// and the submission.
$mods34Description->setAssocId($submission->getId());
// Title
$localizedTitles = $submission->getTitle(null);
// Localized
$this->addLocalizedStatements($mods34Description, 'titleInfo/title', $localizedTitles);
// Authors
// FIXME: Move this to a dedicated adapter in the Author class.
$authors = $submission->getAuthors();
foreach ($authors as $author) {
/* @var $author Author */
// Create a new name description.
$authorDescription = new MetadataDescription('lib.pkp.plugins.metadata.mods34.schema.Mods34NameSchema', ASSOC_TYPE_AUTHOR);
// Type
$authorType = 'personal';
$authorDescription->addStatement('[@type]', $authorType);
// Family Name
$authorDescription->addStatement('namePart[@type="family"]', $author->getLastName());
// Given Names
$firstName = (string) $author->getFirstName();
$middleName = (string) $author->getMiddleName();
$givenNames = trim($firstName . ' ' . $middleName);
if (!empty($givenNames)) {
$authorDescription->addStatement('namePart[@type="given"]', $givenNames);
}
// Affiliation
// NB: Our MODS mapping currently doesn't support translation for names.
// This can be added when required by data consumers. We therefore only use
// translations in the cataloging language.
$affiliation = $author->getAffiliation($catalogingLocale);
if ($affiliation) {
$authorDescription->addStatement('affiliation', $affiliation);
}
// Terms of address (unmapped field)
$termsOfAddress = $author->getData('nlm34:namePart[@type="termsOfAddress"]');
if ($termsOfAddress) {
$authorDescription->addStatement('namePart[@type="termsOfAddress"]', $termsOfAddress);
}
// Date (unmapped field)
$date = $author->getData('nlm34:namePart[@type="date"]');
if ($date) {
$authorDescription->addStatement('namePart[@type="date"]', $date);
}
// Role
$authorDescription->addStatement('role/roleTerm[@type="code" @authority="marcrelator"]', 'aut');
// Add the author to the MODS schema.
$mods34Description->addStatement('name', $authorDescription);
unset($authorDescription);
}
// Sponsor
// NB: Our MODS mapping currently doesn't support translation for names.
// This can be added when required by data consumers. We therefore only use
// translations in the cataloging language.
$supportingAgency = $submission->getSponsor($catalogingLocale);
if ($supportingAgency) {
$supportingAgencyDescription = new MetadataDescription('lib.pkp.plugins.metadata.mods34.schema.Mods34NameSchema', ASSOC_TYPE_AUTHOR);
$sponsorNameType = 'corporate';
$supportingAgencyDescription->addStatement('[@type]', $sponsorNameType);
$supportingAgencyDescription->addStatement('namePart', $supportingAgency);
$sponsorRole = 'spn';
$supportingAgencyDescription->addStatement('role/roleTerm[@type="code" @authority="marcrelator"]', $sponsorRole);
$mods34Description->addStatement('name', $supportingAgencyDescription);
}
// Type of resource
$typeOfResource = 'text';
$mods34Description->addStatement('typeOfResource', $typeOfResource);
// Creation & copyright date
$submissionDate = $submission->getDateSubmitted();
if (strlen($submissionDate) >= 4) {
$mods34Description->addStatement('originInfo/dateCreated[@encoding="w3cdtf"]', $submissionDate);
$mods34Description->addStatement('originInfo/copyrightDate[@encoding="w3cdtf"]', substr($submissionDate, 0, 4));
}
// Submission language
$language = $submission->getLanguage();
if ($language) {
$submissionLanguage = AppLocale::get3LetterFrom2LetterIsoLanguage($submission->getLanguage());
} else {
$submissionLanguage = null;
}
if (!$submissionLanguage) {
// Assume the cataloging language by default.
$submissionLanguage = $catalogingLanguage;
}
$mods34Description->addStatement('language/languageTerm[@type="code" @authority="iso639-2b"]', $submissionLanguage);
// Pages (extent)
$mods34Description->addStatement('physicalDescription/extent', $submission->getPages());
// Abstract
//.........这里部分代码省略.........
示例13: dirname
//.........这里部分代码省略.........
$metadata[$pageProperty] = (int) $metadata[$pageProperty];
}
}
// Convert titles to title case
foreach (array('title', 'chapter', 'publication') as $titleProperty) {
if (isset($metadata[$titleProperty])) {
$metadata[$titleProperty] = String::titleCase($metadata[$titleProperty]);
}
}
// Map ParaCite results to OpenURL - null means
// throw the value away.
$metadataMapping = array('genre' => 'genre', '_class' => null, 'any' => null, 'authors' => 'au', 'aufirst' => 'aufirst', 'aufull' => null, 'auinit' => 'auinit', 'aulast' => 'aulast', 'atitle' => 'atitle', 'cappublication' => null, 'captitle' => null, 'date' => 'date', 'epage' => 'epage', 'featureID' => null, 'id' => null, 'issue' => 'issue', 'jnl_epos' => null, 'jnl_spos' => null, 'match' => null, 'marked' => null, 'num_of_fig' => null, 'pages' => 'pages', 'publisher' => 'pub', 'publoc' => 'place', 'ref' => null, 'rest_text' => null, 'spage' => 'spage', 'targetURL' => 'url', 'text' => null, 'ucpublication' => null, 'uctitle' => null, 'volume' => 'volume', 'year' => 'date');
// Ignore 'year' if 'date' is set
if (isset($metadata['date'])) {
$metadataMapping['year'] = null;
}
// Set default genre
if (empty($metadata['genre'])) {
$metadata['genre'] = OPENURL_GENRE_ARTICLE;
}
// Handle title, chapter and publication depending on
// the (inferred) genre. Also instantiate the target schema.
switch ($metadata['genre']) {
case OPENURL_GENRE_BOOK:
case OPENURL_GENRE_BOOKITEM:
case OPENURL_GENRE_REPORT:
case OPENURL_GENRE_DOCUMENT:
$metadataMapping += array('publication' => 'btitle', 'chapter' => 'atitle');
if (isset($metadata['title'])) {
if (!isset($metadata['publication'])) {
$metadata['publication'] = $metadata['title'];
} elseif (!isset($metadata['chapter'])) {
$metadata['chapter'] = $metadata['title'];
}
unset($metadata['title']);
}
$openUrlSchemaName = 'lib.pkp.classes.metadata.openurl.OpenUrlBookSchema';
$openUrlSchemaClass = 'OpenUrlBookSchema';
break;
case OPENURL_GENRE_ARTICLE:
case OPENURL_GENRE_JOURNAL:
case OPENURL_GENRE_ISSUE:
case OPENURL_GENRE_CONFERENCE:
case OPENURL_GENRE_PROCEEDING:
case OPENURL_GENRE_PREPRINT:
default:
$metadataMapping += array('publication' => 'jtitle');
if (isset($metadata['title'])) {
if (!isset($metadata['publication'])) {
$metadata['publication'] = $metadata['title'];
} elseif (!isset($metadata['atitle'])) {
$metadata['atitle'] = $metadata['title'];
}
unset($metadata['title']);
}
$openUrlSchemaName = 'lib.pkp.classes.metadata.openurl.OpenUrlJournalSchema';
$openUrlSchemaClass = 'OpenUrlJournalSchema';
break;
}
// Instantiate an OpenURL description
$openUrlDescription = new MetadataDescription($openUrlSchemaName, ASSOC_TYPE_CITATION);
$openUrlSchema = new $openUrlSchemaClass();
// Map the ParaCite result to OpenURL
foreach ($metadata as $paraciteElementName => $paraciteValue) {
if (!empty($paraciteValue)) {
// Trim punctuation
if (is_string($paraciteValue)) {
$paraciteValue = String::trimPunctuation($paraciteValue);
}
// Transfer the value to the OpenURL result array
assert(array_key_exists($paraciteElementName, $metadataMapping));
$openUrlPropertyName = $metadataMapping[$paraciteElementName];
if (!is_null($openUrlPropertyName) && $openUrlSchema->hasProperty($openUrlPropertyName)) {
if (is_array($paraciteValue)) {
foreach ($paraciteValue as $singleValue) {
$success = $openUrlDescription->addStatement($openUrlPropertyName, $singleValue);
assert($success);
}
} else {
$success = $openUrlDescription->addStatement($openUrlPropertyName, $paraciteValue);
assert($success);
}
}
}
}
// Crosswalk to NLM
$crosswalkFilter = new OpenUrlNlmCitationSchemaCrosswalkFilter();
$nlmDescription =& $crosswalkFilter->execute($openUrlDescription);
assert(is_a($nlmDescription, 'MetadataDescription'));
// Add 'rest_text' as NLM comment (if given)
if (isset($metadata['rest_text'])) {
$nlmDescription->addStatement('comment', String::trimPunctuation($metadata['rest_text']));
}
// Set display name and sequence id in the meta-data description
// to the corresponding values from the filter. This is important
// so that we later know which result came from which filter.
$nlmDescription->setDisplayName($this->getDisplayName());
$nlmDescription->setSeq($this->getSeq());
return $nlmDescription;
}
开发者ID:ingmarschuster,项目名称:MindResearchRepository,代码行数:101,代码来源:ParaciteRawCitationNlmCitationSchemaFilter.inc.php
示例14: array
/**
* Fills the given citation object with
* meta-data retrieved from PubMed.
* @param $pmid string
* @param $citationDescription MetadataDescription
* @return MetadataDescription
*/
function &_lookup($pmid, &$citationDescription)
{
$nullVar = null;
// Use eFetch to get XML metadata for the given PMID
$lookupParams = array('db' => 'pubmed', 'mode' => 'xml', 'tool' => 'pkp-wal', 'id' => $pmid);
if (!is_null($this->getEmail())) {
$lookupParams['email'] = $this->getEmail();
}
// Call the eFetch URL and get an XML result
if (is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_EFETCH, $lookupParams))) {
return $nullVar;
}
$metadata = array('pub-id[@pub-id-type="pmid"]' => $pmid, 'article-title' => $resultDOM->getElementsByTagName("ArticleTitle")->item(0)->textContent, 'source' => $resultDOM->getElementsByTagName("MedlineTA")->item(0)->textContent);
if ($resultDOM->getElementsByTagName("Volume")->length > 0) {
$metadata['volume'] = $resultDOM->getElementsByTagName("Volume")->item(0)->textContent;
}
if ($resultDOM->getElementsByTagName("Issue")->length > 0) {
$metadata['issue'] = $resultDOM->getElementsByTagName("Issue")->item(0)->textContent;
}
// get list of author full names
$nlmNameSchema = new NlmNameSchema();
foreach ($resultDOM->getElementsByTagName("Author") as $authorNode) {
if (!isset($metadata['person-group[@person-group-type="author"]'])) {
$metadata['person-group[@person-group-type="author"]'] = array();
}
// Instantiate an NLM name description
$authorDescription = new MetadataDescription($nlmNameSchema, ASSOC_TYPE_AUTHOR);
// Surname
$authorDescription->addStatement('surname', $authorNode->getElementsByTagName("LastName")->item(0)->textContent);
// Given names
$givenNamesString = '';
if ($authorNode->getElementsByTagName("FirstName")->length > 0) {
$givenNamesString = $authorNode->getElementsByTagName("FirstName")->item(0)->textContent;
} elseif ($authorNode->getElementsByTagName("ForeName")->length > 0) {
$givenNamesString = $authorNode->getElementsByTagName("ForeName")->item(0)->textContent;
}
if (!empty($givenNamesString)) {
foreach (explode(' ', $givenNamesString) as $givenName) {
$authorDescription->addStatement('given-names', String::trimPunctuation($givenName));
}
}
// Suffix
if ($authorNode->getElementsByTagName("Suffix")->length > 0) {
$authorDescription->addStatement('suffix', $authorNode->getElementsByTagName("Suffix")->item(0)->textContent);
}
// Include collective names
/*if ($resultDOM->getElementsByTagName("CollectiveName")->length > 0 && $authorNode->getElementsByTagName("CollectiveName")->item(0)->textContent != '') {
// FIXME: This corresponds to an NLM-citation <collab> tag and should be part of the Metadata implementation
}*/
$metadata['person-group[@person-group-type="author"]'][] =& $authorDescription;
unset($authorDescription);
}
// Extract pagination
if (String::regexp_match_get("/^[:p\\.\\s]*(?P<fpage>[Ee]?\\d+)(-(?P<lpage>\\d+))?/", $resultDOM->getElementsByTagName("MedlinePgn")->item(0)->textContent, $pages)) {
$fPage = (int) $pages['fpage'];
$metadata['fpage'] = $fPage;
if (!empty($pages['lpage'])) {
$lPage = (int) $pages['lpage'];
// Deal with shortcuts like '382-7'
if ($lPage < $fPage) {
$lPage = (int) (String::substr($pages['fpage'], 0, -String::strlen($pages['lpage'])) . $pages['lpage']);
}
$metadata['lpage'] = $lPage;
}
}
// Get publication date
// TODO: The publication date could be in multiple places
if ($resultDOM->getElementsByTagName("ArticleDate")->length > 0) {
$publicationDate = $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Year")->item(0)->textContent . '-' . $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Month")->item(0)->textContent . '-' . $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Day")->item(0)->textContent;
$metadata['date'] = $publicationDate;
}
// Get publication type
if ($resultDOM->getElementsByTagName("PublicationType")->length > 0) {
foreach ($resultDOM->getElementsByTagName("PublicationType") as $publicationType) {
// The vast majority of items on PubMed are articles so catch these...
if (String::strpos(String::strtolower($publicationType->textContent), 'article') !== false) {
$metadata['[@publication-type]'] = NLM_PUBLICATION_TYPE_JOURNAL;
break;
}
}
}
// Get DOI if it exists
foreach ($resultDOM->getElementsByTagName("ArticleId") as $idNode) {
if ($idNode->getAttribute('IdType') == 'doi') {
$metadata['pub-id[@pub-id-type="doi"]'] = $idNode->textContent;
}
}
// Use eLink utility to find fulltext links
$lookupParams = array('dbfrom' => 'pubmed', 'cmd' => 'llinks', 'tool' => 'pkp-wal', 'id' => $pmid);
if (!is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_ELINK, $lookupParams))) {
// Get a list of possible links
foreach ($resultDOM->getElementsByTagName("ObjUrl") as $linkOut) {
$attributes = '';
//.........这里部分代码省略.........
示例15: testCitationCrud
/**
* @covers CitationDAO
*/
public function testCitationCrud()
{
$citationDao = DAORegistry::getDAO('CitationDAO');
/* @var $citationDao CitationDAO */
$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('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');
// Add a simple source description.
$sourceDescription = new MetadataDescription($citationSchemaName, ASSOC_TYPE_CITATION);
$sourceDescription->setDisplayName('test');
$sourceDescription->addStatement('article-title', $value = 'a simple source description', 'en_US');
$sourceDescription->setSeq(0);
$citation = new Citation('raw citation');
$citation->setAssocType(ASSOC_TYPE_ARTICLE);
$citation->setAssocId(999999);
$citation->setSeq(50);
$citation->addSourceDescription($sourceDescription);
$citation->injectMetadata($citationDescription);
// Create citation.
$citationId = $citationDao->insertObject($citation);
self::assertTrue(is_numeric($citationId));
self::assertTrue($citationId > 0);
// Retrieve citation.
$citationById = $citationDao->getObjectById($citationId);
// Fix state differences for comparison.
$citation->removeSupportedMetadataAdapter($citationSchemaName);
$citationById->removeSupportedMetadataAdapter($citationSchemaName);
$citationById->_extractionAdaptersLoaded = true;
$citationById->_injectionAdaptersLoaded = true;
$sourceDescription->setAssocId($citationId);
$sourceDescription->removeSupportedMetadataAdapter($citationSchemaName);
$sourceDescriptions = $citationById->getSourceDescriptions();
$sourceDescriptions['test']->getMetadataSchema();
// this will instantiate the meta-data schema internally.
self::assertEquals($citation, $citationById);
$citationsByAssocIdDaoFactory = $citationDao->getObjectsByAssocId(ASSOC_TYPE_ARTICLE, 999999);
$citationsByAssocId = $citationsByAssocIdDaoFactory->toArray();
self::assertEquals(1, count($citationsByAssocId));
// Fix state differences for comparison.
$citationsByAssocId[0]->_extractionAdaptersLoaded = true;
$citationsByAssocId[0]->_injectionAdaptersLoaded = true;
$citationsByAssocId[0]->removeSupportedMetadataAdapter($citationSchemaName);
$sourceDescriptionsByAssocId = $citationsByAssocId[0]->getSourceDescriptions();
$sourceDescriptionsByAssocId['test']->getMetadataSchema();
// this will instantiate the meta-data schema internally.
self::assertEquals($citation, $citationsByAssocId[0]);
// Update citation.
$citationDescription->removeStatement('date');
$citationDescription->addStatement('article-title', $value = 'PHPUnit rápido', 'pt_BR');
// Update source descriptions.
$sourceDescription->addStatement('article-title', $value = 'edited source description', 'en_US', true);
$updatedCitation = new Citation('another raw citation');
$updatedCitation->setId($citationId);
$updatedCitation->setAssocType(ASSOC_TYPE_ARTICLE);
$updatedCitation->setAssocId(999998);
$updatedCitation->setSeq(50);
$updatedCitation->addSourceDescription($sourceDescription);
$updatedCitation->injectMetadata($citationDescription);
$citationDao->updateObject($updatedCitation);
$citationAfterUpdate = $citationDao->getObjectById($citationId);
// Fix state differences for comparison.
$updatedCitation->removeSupportedMetadataAdapter($citationSchemaName);
$citationAfterUpdate->removeSupportedMetadataAdapter($citationSchemaName);
$citationAfterUpdate->_extractionAdaptersLoaded = true;
$citationAfterUpdate->_injectionAdaptersLoaded = true;
$sourceDescriptionsAfterUpdate = $citationAfterUpdate->getSourceDescriptions();
$sourceDescriptionsAfterUpdate['test']->getMetadataSchema();
// this will instantiate the meta-data schema internally.
$sourceDescription->removeSupportedMetadataAdapter($citationSchemaName);
self::assertEquals($updatedCitation, $citationAfterUpdate);
// Delete citation
$citationDao->deleteObjectsByAssocId(ASSOC_TYPE_ARTICLE, 999998);
self::assertNull($citationDao->getObjectById($citationId));
}