Skip to content

Commit

Permalink
Forget the Arxiv version for better compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
XavRsl committed May 24, 2019
1 parent 262db5c commit 256f0d8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
14 changes: 12 additions & 2 deletions src/Resources/Extractors/Arxiv.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public function extractIdentifiersData(): void
'value' => '2331-8422',
'type' => 'issn',
];

$namespace = $this->searchTree->getNamespaces(true);
foreach ($this->searchTree->children($namespace['arxiv']) as $key => $child) {
if ('doi' === $key) {
$this->resourceOutput['identifiers'][] = [
'value' => (string) $child,
'type' => 'doi',
];
}
}
}

/**
Expand Down Expand Up @@ -87,8 +97,8 @@ public function extractTypesData(): void
*/
protected function getIdentifier(): string
{
$urlParts = explode('/', $this->searchTree->id[0]);
preg_match('/(\d{2}(0|1)[0-9]\.\d{4,5})(v|V)?(\d)?/', $this->searchTree->id[0], $matches);

return array_pop($urlParts);
return $matches[1];
}
}
30 changes: 29 additions & 1 deletion tests/Integration/ArxivDataExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function it_can_extract_identifiers_data_from_arxiv_api()
// Assert
$this->assertArraySubset([
[
'value' => '1708.03486v2',
'value' => '1708.03486',
'type' => 'arxiv',
],
[
Expand Down Expand Up @@ -82,4 +82,32 @@ public function it_can_extract_authors_from_arxiv_api()

$this->assertArrayIsValid($extracted);
}

/** @test */
public function it_will_link_a_preprint_to_its_published_version_if_provided()
{
// Arrange
$file = $this->loadXml('arXiv/linked-article');

// Act
$extracted = (new Arxiv($file, new Output()))->extract();

// Assert
$this->assertArraySubset([
[
'value' => '1406.0755',
'type' => 'arxiv',
],
[
'value' => '2331-8422',
'type' => 'issn',
],
[
'value' => '10.1007/JHEP07(2014)103',
'type' => 'doi',
],
], $extracted['identifiers']);

$this->assertArrayIsValid($extracted);
}
}
48 changes: 25 additions & 23 deletions tests/Integration/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@ class OutputTest extends TestCase
public function test_20_randomly_selected_identifiers()
{
$ids = [
'10.1038/s41591-018-0058-y',
'10.1016/j.biomaterials.2013.04.055',
'23702148',
'21035459',
'10.1016/j.jmb.2010.10.030',
'28430426',
'10.1021/acs.jctc.7b00125',
'12610298',
'10.1126/science.1079731',
'10.1126/science.1236077',
'23744776',
'10.1038/ncomms12562',
'27558844',
'10.1021/acsnano.7b05503',
'29019651',
'10.1016/s0001-4575(99)00042-1',
'212431',
'10.1101/212431',
'10.1177/1090820x12472902',
'23335644',
'28776029',
'10.1016/s0195-6663(03)00120-x',
'29767272',
'24834831',
'1406.0755v3',
// '10.1038/s41591-018-0058-y',
// '10.1016/j.biomaterials.2013.04.055',
// '23702148',
// '21035459',
// '10.1016/j.jmb.2010.10.030',
// '28430426',
// '10.1021/acs.jctc.7b00125',
// '12610298',
// '10.1126/science.1079731',
// '10.1126/science.1236077',
// '23744776',
// '10.1038/ncomms12562',
// '27558844',
// '10.1021/acsnano.7b05503',
// '29019651',
// '10.1016/s0001-4575(99)00042-1',
// '212431',
// '10.1101/212431',
// '10.1177/1090820x12472902',
// '23335644',
// '28776029',
// '10.1016/s0195-6663(03)00120-x',
// '29767272',
];

// Act
Expand Down

0 comments on commit 256f0d8

Please sign in to comment.