Skip to content

Commit

Permalink
[#143] remove null from json+ld creator name
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdash committed Nov 25, 2024
1 parent 520d4e3 commit 04a1029
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion dspback/schemas/discovery.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import re
from datetime import datetime
from enum import Enum
from typing import Any, List, Optional

from pydantic import BaseModel, Field, HttpUrl
from pydantic import BaseModel, Field, HttpUrl, validator


class Provider(BaseModel):
Expand All @@ -21,6 +22,10 @@ class SpatialCoverage(BaseModel):
class Creator(BaseModel):
name: str = Field(description="The creator name")

@validator("name")
def name_remove_null(cls, v):
v = re.sub(r"\bnull\b", "", v).strip()
return v

class CreatorList(BaseModel):
list: List[Creator] = Field(alias="@list", default=[], description="A list of creator names")
Expand Down
2 changes: 1 addition & 1 deletion tests/data/earthchem_jsonld.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"familyName": "Andrews"
}, {
"@type": "Person",
"name": "George Holmes",
"name": "George null Holmes",
"givenName": "George",
"familyName": "Holmes"
}, {
Expand Down
6 changes: 5 additions & 1 deletion tests/test_jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def test_external_jsonld():
"keywords": ["CZNet", "Dryland Critical Zone", "Seismic", "Jornada Experimental Range"],
"creators": [
{
"name": "asdf Karplus",
"name": "asdf null Karplus",
"organization": "University of Texas at El Paso (UTEP)",
"email": "mkarplus@mail",
"orcid": "0000-0001-2345-6789",
Expand Down Expand Up @@ -168,3 +168,7 @@ async def test_earthchem_jsonld(earthchem_jsonld):
assert jsonld.funding[0].identifier == "http://www.nsf.gov/awardsearch/showAward.do?AwardNumber=2012123"
assert len(jsonld.clusters) == 1
assert jsonld.clusters[0] == "Big Data Cluster"

# check creator name does not contain null
for cr in jsonld.creator.list:
assert 'null' not in cr.name

0 comments on commit 04a1029

Please sign in to comment.