Skip to content

Commit

Permalink
[import] Match author role separated by dash
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Dec 13, 2024
1 parent d3615db commit a255080
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/Matchers/AuthorityMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ protected function findByFullname($fullname)

public static function parse($author)
{
if (!preg_match('/^((?<surname>.*?)\s*(?<alt_surname>\(.*\))?(?<role>\s+-\s+.*)?,\s+)?(?<name>.*?)\s*(?<alt_name>\(.*\)|\/.*)?$/', $author, $matches)) {
if (!preg_match('/^((?<surname>.*?)\s*(?<alt_surname>\(.*\))?(?<role>\s+[-–]\s+.*)?,\s+)?(?<name>.*?)\s*(?<alt_name>\(.*\)|\/.*)?$/', $author, $matches)) {
return null;
}

return [
'surname' => $matches['surname'] ?: null,
'alt_surname' => trim($matches['alt_surname'], '()') ?: null,
'role' => ltrim($matches['role'], ' -') ?: null,
'role' => ltrim($matches['role'], ' -') ?: null,
'name' => $matches['name'] ?: null,
'alt_name' => trim($matches['alt_name'] ?? '', '()/') ?: null,
];
Expand Down
3 changes: 2 additions & 1 deletion tests/Matchers/AuthorityMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use App\Matchers\AuthorityMatcher;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Tests\WithoutSearchIndexing;

class AuthorityMatcherTest extends TestCase
{
use RefreshDatabase;
use RefreshDatabase, WithoutSearchIndexing;

public function testMatchAll()
{
Expand Down

0 comments on commit a255080

Please sign in to comment.