Skip to content

Commit

Permalink
Merge pull request #84 from stopfstedt/add_registry_number_list_and_r…
Browse files Browse the repository at this point in the history
…egistry_number

Updates MeSH parser for 2025 release.
  • Loading branch information
jrjohnson authored Dec 13, 2024
2 parents 5c485ad + 84e1aca commit 398e1c1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This PHP code library provides tools for extracting [Medical Subject Headings](https://www.nlm.nih.gov/mesh/meshhome.html)
(MeSH) descriptors and associated data from a given XML file into an object representation.

It expects its input to be compliant with the 2023 or 2024 [MeSH DTDs](https://www.nlm.nih.gov/databases/download/mesh.html).
It expects its input to be compliant with the 2024 or 2025 [MeSH DTDs](https://www.nlm.nih.gov/databases/download/mesh.html).

## Installation

Expand Down
24 changes: 12 additions & 12 deletions src/Ilios/MeSH/Model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class Concept extends Reference

protected ?string $casn1Name = null;

protected ?string $registryNumber = null;

protected ?string $scopeNote = null;

protected ?string $translatorsEnglishScopeNote = null;
Expand All @@ -28,6 +26,8 @@ class Concept extends Reference

protected array $terms = [];

protected array $registryNumbers = [];

public function isPreferred(): bool
{
return $this->preferred;
Expand All @@ -48,16 +48,6 @@ public function setCasn1Name(?string $casn1Name): void
$this->casn1Name = $casn1Name;
}

public function getRegistryNumber(): ?string
{
return $this->registryNumber;
}

public function setRegistryNumber(?string $registryNumber): void
{
$this->registryNumber = $registryNumber;
}

public function getScopeNote(): ?string
{
return $this->scopeNote;
Expand Down Expand Up @@ -117,4 +107,14 @@ public function addTerm(Term $term): void
{
$this->terms[] = $term;
}

public function getRegistryNumbers(): array
{
return $this->registryNumbers;
}

public function addRegistryNumber(string $registryNumber): void
{
$this->registryNumbers[] = $registryNumber;
}
}
2 changes: 1 addition & 1 deletion src/Ilios/MeSH/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function parse(string $uri): DescriptorSet
break;
case self::REGISTRY_NUMBER:
$number = $this->getNodeContents($reader);
$currentConcept->setRegistryNumber($number);
$currentConcept->addRegistryNumber($number);
break;
case self::RELATED_REGISTRY_NUMBER:
$number = $this->getNodeContents($reader);
Expand Down
4 changes: 2 additions & 2 deletions tests/Ilios/MeSH/Model/ConceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function testGetSetCasn1Name(): void
$this->basicSetTest($this->object, 'casn1Name', 'string', true);
}

public function testGetSetRegistryNumber(): void
public function testAddGetRegistryNumbers(): void
{
$this->basicSetTest($this->object, 'registryNumber', 'string', true);
$this->addTextToListTest($this->object, 'registryNumber');
}

public function testGetSetScopeNote(): void
Expand Down
15 changes: 10 additions & 5 deletions tests/Ilios/MeSH/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ public function testParse(): void
$this->assertTrue($concept->isPreferred());
$this->assertEquals('M0000001', $concept->getUi());
$this->assertEquals('a casn1 name', $concept->getCasn1Name());
$this->assertEquals('00000AAAAA', $concept->getRegistryNumber());

$registryNumbers = $concept->getRegistryNumbers();
$this->assertEquals(2, count($registryNumbers));
$this->assertEquals('00000AAAAA', $registryNumbers[0]);
$this->assertEquals('11111BBBBB', $registryNumbers[1]);

$this->assertEquals('a scope note', $concept->getScopeNote());
$this->assertEquals('something in English.', $concept->getTranslatorsEnglishScopeNote());
$this->assertEquals('i got nothing', $concept->getTranslatorsScopeNote());

$registryNumbers = $concept->getRelatedRegistryNumbers();
$this->assertEquals(1, count($registryNumbers));
$this->assertEquals('a related registry number', $registryNumbers[0]);
$relatedRegistryNumbers = $concept->getRelatedRegistryNumbers();
$this->assertEquals(1, count($relatedRegistryNumbers));
$this->assertEquals('a related registry number', $relatedRegistryNumbers[0]);

$relations = $concept->getConceptRelations();
$this->assertEquals(1, count($relations));
Expand Down Expand Up @@ -202,7 +207,7 @@ public function testParse(): void
$this->assertFalse($concept->isPreferred());
$this->assertEquals('M0000002', $concept->getUi());
$this->assertEquals('another concept', $concept->getName());
$this->assertEquals('0', $concept->getRegistryNumber());
$this->assertCount(0, $concept->getRegistryNumbers());

$relations = $concept->getConceptRelations();
$this->assertEquals(1, count($relations));
Expand Down
8 changes: 5 additions & 3 deletions tests/Ilios/MeSH/desc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Fake MeSH descriptors set, for testing purposes.
It contains all possible elements defined by the schema.
-->
<!DOCTYPE DescriptorRecordSet SYSTEM "https://www.nlm.nih.gov/databases/dtd/nlmdescriptorrecordset_20240101.dtd">
<!DOCTYPE DescriptorRecordSet SYSTEM "https://www.nlm.nih.gov/databases/dtd/nlmdescriptorrecordset_20250101.dtd">
<DescriptorRecordSet LanguageCode="eng">
<DescriptorRecord DescriptorClass="1">
<DescriptorUI>D000000</DescriptorUI>
Expand Down Expand Up @@ -133,7 +133,10 @@ It contains all possible elements defined by the schema.
<String>a concept</String>
</ConceptName>
<CASN1Name>a casn1 name</CASN1Name>
<RegistryNumber>00000AAAAA</RegistryNumber>
<RegistryNumberList>
<RegistryNumber>00000AAAAA</RegistryNumber>
<RegistryNumber>11111BBBBB</RegistryNumber>
</RegistryNumberList>
<ScopeNote>a scope note</ScopeNote>
<TranslatorsEnglishScopeNote>something in English.</TranslatorsEnglishScopeNote>
<TranslatorsScopeNote>i got nothing</TranslatorsScopeNote>
Expand Down Expand Up @@ -170,7 +173,6 @@ It contains all possible elements defined by the schema.
<ConceptName>
<String>another concept</String>
</ConceptName>
<RegistryNumber>0</RegistryNumber>
<ConceptRelationList>
<ConceptRelation RelationName="NRW">
<Concept1UI>M0000002</Concept1UI>
Expand Down

0 comments on commit 398e1c1

Please sign in to comment.