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

Added the case "Other" for the reference type #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions example.php → example/example.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

use JATSParser\Body\Document as JATSDocument;
use JATSParser\HTML\Document as HTMLDocument;
Expand All @@ -24,4 +24,4 @@
$pdfHeaderLogo = __DIR__ . "/logo/logo.jpg";
$pdfDocument->SetHeaderData($pdfHeaderLogo, PDF_HEADER_LOGO_WIDTH, "Some Text Here", "Another text here");
$pdfDocument->writeHTML($htmlString, true, false, true, false, '');
$pdfDocument->Output('article.pdf', 'I');
$pdfDocument->Output('article.pdf', 'I');
File renamed without changes.
File renamed without changes
File renamed without changes
118 changes: 118 additions & 0 deletions src/JATSParser/Back/Other.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace JATSParser\Back;

use JATSParser\Back\AbstractReference as AbstractReference;

class Other extends AbstractReference {
/* @var $title string */

private $title;

/* @var $journal string */
private $journal;

/* @var $volume string */
private $volume;

/* @var $issue string */
private $issue;

/* @var $fpage string */
private $fpage;

/* @var $lpage string */
private $lpage;

public function __construct(\DOMElement $reference) {

parent::__construct($reference);

$this->title = $this->extractFromElement($reference, "mixed-citation/text()[1]");
}

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

/**
* @return string
*/
public function getTitle(): string {
return $this->title;
}

/**
* @return array
*/
public function getAuthors(): array {
return $this->authors;
}

/**
* @return array
*/
public function getEditors(): array {
return $this->editors;
}

/**
* @return string
*/
public function getYear(): string {
return $this->year;
}

/**
* @return string
*/
public function getFpage(): string {
return $this->fpage;
}

/**
* @return string
*/
public function getLpage(): string {
return $this->lpage;
}

/**
* @return string
*/
public function getIssue(): string {
return $this->issue;
}

/**
* @return string
*/
public function getVolume(): string {
return $this->volume;
}

/**
* @return array
*/
public function getPubIdType(): array {
return $this->pubIdType;
}

/**
* @return string
*/
public function getUrl(): string {
return $this->url;
}

/**
* @return string
*/
public function getJournal(): string {
return $this->journal;
}

}
69 changes: 66 additions & 3 deletions src/JATSParser/Body/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use JATSParser\Back\Book as Book;
use JATSParser\Back\Chapter as Chapter;
use JATSParser\Back\Conference as Conference;
use JATSParser\Back\Other as Other;
use \JATSParser\Front\JournalMeta as JournalMeta;

class Document {

Expand All @@ -22,13 +24,17 @@ class Document {

/* var $references array of article's References */
private $references = array();

/* var $metadata array */
private $metadata = array();



function __construct(?string $documentPath) {
public function __construct(?string $documentPath) {
$document = new \DOMDocument;
$this->document = $document->load($documentPath);
self::$xpath = new \DOMXPath($document);

$this->extractMetadata();
$this->extractContent();
$this->extractReferences();
}
Expand All @@ -48,11 +54,64 @@ public function getArticleSections() : array {
public function getReferences() : array {
return $this->references;
}

public function getMetadata() : array {
return $this->metadata;
}

private function extractMetadata() {

$metadata = array();
foreach(self::$xpath->evaluate("/article/front") as $meta ) {

/* @var $journalmeta \DOMElement */
$journalMetaNodes = self::$xpath->query(".//journal-meta[1]", $meta);
if ($journalMetaNodes->length > 0) {
foreach ($journalMetaNodes as $journalMetaNode) {

/* @var $journalMetaNode \DOMAttr */
$data = new JournalMeta($journalMetaNode);
$metadata[] = $data;

}

}

/* @var $journalmeta \DOMElement */
$articleMeta = self::$xpath->query(".//article-meta[1]", $meta);
if ($articleMeta->length > 0) {
foreach ($articleMeta as $articleMetaNode) {

/* @var $articleMetaNode \DOMAttr */
switch($articleMetaNode->nodeValue) {

case "article-id":
$journal = new Journal($reference);
$references[] = $journal;
break;

case "article-categories":
$journal = new Journal($reference);
$references[] = $journal;
break;


}

}

}

}

$this->metadata = $metadata;

}

/* @brief Constructor for references
* JATS XML can give us a little, if not at all, information about reference type;
* Here we are trying to determine the type of citation by element-citation node attribute or names of nodes which reference contains;
* Supported types are: journal, book, chapter, and conference.
* Supported types are: journal, book, chapter, and conference (+other).
*/
private function extractReferences() {
$references = array();
Expand All @@ -79,6 +138,10 @@ private function extractReferences() {
$conference = new Conference($reference);
$references[] = $conference;
break;
case "other":
$conference = new Other($reference);
$references[] = $conference;
break;
default:
$defaultRef = new Journal($reference);
$references[] = $defaultRef;
Expand Down
9 changes: 9 additions & 0 deletions src/JATSParser/Front/ArticleMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace JATSParser\Front;

use JATSParser\Body\Document as Document;

class ArticleMeta {

}
55 changes: 55 additions & 0 deletions src/JATSParser/Front/JournalMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace JATSParser\Front;

use JATSParser\Body\Document as Document;

class JournalMeta {

protected $journalTitle;

protected $abbrevJournalTitle;

protected $issn;

protected $publisherName;

public function __construct(\DOMElement $journalmeta) {

$this->xpath = Document::getXpath();
$this->journalTitle = $this->extractFromElement($journalmeta, './/journal-title[1]');
$this->abbrevJournalTitle = $this->extractFromElement($journalmeta, './/abbrev-journal-title[1]');
$this->issn = $this->extractFromElement($journalmeta, './/issn[1]');
$this->publisherName = $this->extractFromElement($journalmeta, './/publisher-name[1]');
}

public function getJournalTitle() {
return $this->journalTitle;
}

public function getAbbrevJournalTitle() {
return $this->abbrevJournalTitle;
}

public function getIssn() {
return $this->issn;
}

public function getPublisher() {
return $this->publisherName;
}

protected function extractFromElement(\DOMElement $reference, string $xpathExpression) {
$property = '';
$searchNodes = $this->xpath->query($xpathExpression, $reference);
if ($searchNodes->length > 0) {
foreach ($searchNodes as $searchNode) {
$property = $searchNode->nodeValue;
}
}
return $property;
}



}