Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic title class and tests #68

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Import/Rules/Arxiv.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct()
* @param string $value Feldwert aus BibTeX-Record
* @return array
*/
protected function getValue($value)
public function getValue($value)
{
$type = 'url';

Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct()
* @param string $bibtexValue
* @return array
*/
protected function getValue($bibtexValue)
public function getValue($bibtexValue)
{
$collectionIds = explode(',', $bibtexValue);

Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/DocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function setDocumentTypeMapping($documentTypeMapping)
* @param string $value Name des BibTeX-Typs
* @return string Name des OPUS-Dokumenttyps
*/
protected function getValue($value)
public function getValue($value)
{
if ($this->documentTypeMapping === null) {
$this->documentTypeMapping = BibtexService::getInstance()->getTypeMapping();
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/Doi.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct()
* @param string $value Feldwert aus BibTeX-Record
* @return array
*/
protected function getValue($value)
public function getValue($value)
{
if (strtolower(substr($value, 0, 4)) === 'doi:') {
$value = trim(substr($value, 4)); // Präfix doi: abschneiden
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct()
* @param string $value Feldwert aus BibTeX-Record
* @return array
*/
protected function getValue($value)
public function getValue($value)
{
$values = explode(', ', $value);
$result = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/Licences.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct()
* @param string $bibtexValue
* @return array
*/
protected function getValue($bibtexValue)
public function getValue($bibtexValue)
{
$licenceIds = explode(',', $bibtexValue);

Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function setVisibility($visibility)
* @param string $value auszuwertender Wert aus BibTeX-Feld
* @return array
*/
protected function getValue($value)
public function getValue($value)
{
return [
'Visibility' => $this->visibility,
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct()
* @param string $value Wert des BibTeX-Felds
* @return array
*/
protected function getValue($value)
public function getValue($value)
{
$persons = explode(' and ', $value);
$result = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/PublishedYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct()
* @return array|null liefert null, wenn die Jahresangabe im BibTeX-Feld keine vierstellige Ziffernfolge ist;
* andernfalls wird der Feldwert für den OPUS-Metadatenfeld zurückgeliefert
*/
protected function getValue($value)
public function getValue($value)
{
$value = preg_replace('/[^0-9]/', '', $value);
if (strlen($value) === 4) {
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/SimpleRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function setOpusField($opusField)
* @param string $value Feldwert aus dem BibTeX-Record
* @return mixed
*/
protected function getValue($value)
public function getValue($value)
{
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/SourceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct()
* @param Feldwert $value BibTeX-Record
* @return array
*/
protected function getValue($value)
public function getValue($value)
{
return [
'KeyName' => self::SOURCE_DATA_KEY,
Expand Down
2 changes: 1 addition & 1 deletion src/Import/Rules/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function setLanguage($language)
* @param string $value kommaseparierte Liste von Schlagworten
* @return array
*/
protected function getValue($value)
public function getValue($value)
{
$keywords = explode(', ', $value);
$result = [];
Expand Down
110 changes: 110 additions & 0 deletions src/Import/Rules/Title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2023, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

namespace Opus\Bibtex\Import\Rules;

use function strtolower;
use function ucfirst;

/**
* Configurable mapping of titles.
*
* TODO verify configured title type against centrally maintained list of valid values
*/
class Title extends AbstractArrayRule
{
/** @var string Language of title */
private $language = 'eng';

/** @var string Type of title for OPUS 4 data model (main,parent,sub,additional) */
private $titleType = 'main';

/**
* Konstruktor
*/
public function __construct()
{
parent::__construct();
$this->setBibtexField('title');
$this->setTitleType('main');
}

/**
* @return string
*/
public function getLanguage()
{
return $this->language;
}

/**
* @param string $language
* @return $this
*/
public function setLanguage($language)
{
$this->language = $language;
return $this;
}

/**
* @return string
*/
public function getTitleType()
{
return $this->titleType;
}

/**
* @return $this
*/
public function setTitleType(string $type)
{
$this->titleType = strtolower($type);
$this->setOpusField('Title' . ucfirst($this->titleType));
return $this;
}

/**
* Returns array containing title properties.
*
* @param string $value BibTeX string for title
* @return array
*/
public function getValue($value)
{
return [
'Language' => $this->getLanguage(),
'Value' => $this->deleteBrace($value),
'Type' => $this->getTitleType(),
];
}
}
31 changes: 2 additions & 29 deletions src/Import/Rules/TitleMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,13 @@
*
* @copyright Copyright (c) 2021, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*
* @category BibTeX
* @package Opus\Bibtex\Import\Rules
* @author Sascha Szott <[email protected]>
*/

namespace Opus\Bibtex\Import\Rules;

/**
* Erlaubt das Setzen eines Feldwerts für den Haupttitel.
* Convenience class for configuring default TitleMain mapping.
*/
class TitleMain extends AbstractArrayRule
class TitleMain extends Title
{
/**
* Konstruktor
*/
public function __construct()
{
$this->setBibtexField('title');
$this->setOpusField('TitleMain');
}

/**
* Setzt den Haupttitel.
*
* @param string $value Wert des Haupttitels.
* @return array
*/
protected function getValue($value)
{
return [
'Language' => 'eng',
'Value' => $this->deleteBrace($value),
'Type' => 'main',
];
}
}
29 changes: 4 additions & 25 deletions src/Import/Rules/TitleParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,19 @@
*
* @copyright Copyright (c) 2021, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*
* @category BibTeX
* @package Opus\Bibtex\Import\Rules
* @author Sascha Szott <[email protected]>
*/

namespace Opus\Bibtex\Import\Rules;

/**
* Erlaubt das Setzen eines Feldwerts für den übergeordneten Titel.
* Convenience class for configuring default TitleParent mapping.
*/
class TitleParent extends AbstractArrayRule
class TitleParent extends Title
{
/**
* Konstruktor
*/
public function __construct()
{
parent::__construct();
$this->setBibtexField('journal');
$this->setOpusField('TitleParent');
}

/**
* Setzt den übergeordneten Titel.
*
* @param string $value Wert des übergeordneten Titels.
* @return array
*/
protected function getValue($value)
{
return [
'Language' => 'eng',
'Value' => $this->deleteBrace($value),
'Type' => 'parent',
];
$this->setTitleType('parent'); // TODO use constants from Opus\Common\Title
}
}
48 changes: 48 additions & 0 deletions test/Import/Rules/TitleMainTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2021, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

namespace OpusTest\Bibtex\Import\Rules;

use Opus\Bibtex\Import\Rules\TitleMain;
use PHPUnit\Framework\TestCase;

class TitleMainTest extends TestCase
{
public function testConstruct()
{
$mapping = new TitleMain();

$this->assertEquals('main', $mapping->getTitleType());
$this->assertEquals('title', $mapping->getBibtexField());
$this->assertEquals('eng', $mapping->getLanguage());
$this->assertEquals('TitleMain', $mapping->getOpusField());
}
}
Loading