Skip to content

Commit

Permalink
add description property
Browse files Browse the repository at this point in the history
  • Loading branch information
rimmoussa committed Dec 9, 2024
1 parent 1625465 commit 21b94ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
23 changes: 18 additions & 5 deletions mardi_importer/mardi_importer/publications/ZenodoResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ZenodoResource():
api: MardiIntegrator
zenodo_id: str
title: str = None
_description: str = None
_publication_date: str = None
_authors: List[Author] = field(default_factory=list)
_resource_type: str = None
Expand Down Expand Up @@ -59,6 +60,19 @@ def __post_init__(self):
self._authors.append(author)
return self.QID

@property
def description(self):
desc_long = ""
if "description" in self.metadata.keys():
desc_long = self.metadata["description"]
desc_long = re.sub(CLEANR, '', desc_long) # parse out html tags from the description
desc_long = re.sub(r'\n|\\N|\t|\\T', ' ', desc_long) # parse out tabs and new lines
desc_long = re.sub(r'^\s+|\s+$', '', desc_long) # parse out leading and trailing white space
if re.match("\w+", desc_long):
self._description = desc_long
return self._description


@property
def publication_date(self):
if not self._publication_date:
Expand Down Expand Up @@ -185,13 +199,12 @@ def create(self, update = False):
else:
desc = "Resource published at Zenodo repository. "

if "description" in self.metadata.keys():
desc = desc + self.metadata["description"]
item.descriptions.set(language="en", value=desc)

desc = re.sub(CLEANR, '', desc)
desc = (desc[:1998] + '..') if len(desc) > 2000 else desc
if self.description:
prop_nr = self.api.get_local_id_by_label("description", "property")
item.add_claim(prop_nr, self.description)

item.descriptions.set(language="en", value=desc)

# Publication date
if self.publication_date:
Expand Down
5 changes: 5 additions & 0 deletions mardi_importer/mardi_importer/zenodo/new_entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"label": "Internal Project ID",
"description": "An identifier for a project, e.g. from a community such as MATH+ or SFB1234",
"datatype": "wikibase-item"
},
{
"label": "description",
"description": "long description of an item",
"datatype": "string"
}
],
"items": [
Expand Down

0 comments on commit 21b94ba

Please sign in to comment.