Skip to content

Commit

Permalink
[#27] changes to relation and source models
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdash committed Jan 10, 2022
1 parent ebd834a commit 4fff842
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 56 deletions.
20 changes: 13 additions & 7 deletions hsmodels/schemas/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@ class UserIdentifierType(StringEnum):


class RelationType(StringEnum):
isCopiedFrom = 'The content of this resource was copied from'
isPartOf = 'The content of this resource is part of'
hasPart = 'Has Part'
isExecutedBy = 'The content of this resource can be executed by'
hasPart = 'This resource includes'
isExecutedBy = 'The content of this resource was created by a related App or software program'
isCreatedBy = 'The content of this resource was created by'
isVersionOf = 'Version Of'
isReplacedBy = 'Replaced By'
isDataFor = 'The content of this resource serves as the data for'
cites = 'This resource cites'
isVersionOf = 'This resource updates and replaces a previous version'
isReplacedBy = 'This resource has been replaced by a newer version'
isDescribedBy = 'This resource is described by'
conformsTo = 'This resource conforms to established standard described by'
hasFormat = 'This resource has a related resource in another format'
isFormatOf = 'This resource is a different format of'
isRequiredBy = 'This resource is required by'
requires = 'This resource requires'
isReferencedBy = 'This resource is referenced by'
references = 'The content of this resource references'
replaces = 'This resource replaces'
source = 'The content of this resource is derived from'


class AggregationType(StringEnum):
Expand Down
26 changes: 14 additions & 12 deletions hsmodels/schemas/rdf/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ class DCTypeInRDF(RDFBaseModel):
label: str = Field(rdf_predicate=RDFS.label)


class SourceInRDF(RDFBaseModel):
is_derived_from: str = Field(rdf_predicate=HSTERMS.isDerivedFrom, default=None)


class RelationInRDF(RDFBaseModel):
isHostedBy: str = Field(rdf_predicate=HSTERMS.isHostedBy, default=None)
isCopiedFrom: str = Field(rdf_predicate=HSTERMS.isCopiedFrom, default=None)
isPartOf: str = Field(rdf_predicate=HSTERMS.isPartOf, default=None)
hasPart: str = Field(rdf_predicate=HSTERMS.hasPart, default=None)
isExecutedBy: str = Field(rdf_predicate=HSTERMS.isExecutedBy, default=None)
isCreatedBy: str = Field(rdf_predicate=HSTERMS.isCreatedBy, default=None)
isVersionOf: str = Field(rdf_predicate=HSTERMS.isVersionOf, default=None)
isReplacedBy: str = Field(rdf_predicate=HSTERMS.isReplacedBy, default=None)
isDataFor: str = Field(rdf_predicate=HSTERMS.isDataFor, default=None)
cites: str = Field(rdf_predicate=HSTERMS.cites, default=None)
isDescribedBy: str = Field(rdf_predicate=HSTERMS.isDescribedBy, default=None)

isPartOf: str = Field(rdf_predicate=DCTERMS.isPartOf, default=None)
hasPart: str = Field(rdf_predicate=DCTERMS.hasPart, default=None)
isVersionOf: str = Field(rdf_predicate=DCTERMS.isVersionOf, default=None)
isReplacedBy: str = Field(rdf_predicate=DCTERMS.isReplacedBy, default=None)
conformsTo: str = Field(rdf_predicate=DCTERMS.conformsTo, default=None)
hasFormat: str = Field(rdf_predicate=DCTERMS.hasFormat, default=None)
isFormatOf: str = Field(rdf_predicate=DCTERMS.isFormatOf, default=None)
isRequiredBy: str = Field(rdf_predicate=DCTERMS.isRequiredBy, default=None)
requires: str = Field(rdf_predicate=DCTERMS.requires, default=None)
isReferencedBy: str = Field(rdf_predicate=DCTERMS.isReferencedBy, default=None)
references: str = Field(rdf_predicate=DCTERMS.references, default=None)
replaces: str = Field(rdf_predicate=DCTERMS.replaces, default=None)
source: str = Field(rdf_predicate=DCTERMS.source, default=None)

_parse_relation = root_validator(pre=True)(parse_relation_rdf)


Expand Down
4 changes: 0 additions & 4 deletions hsmodels/schemas/rdf/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
PublisherInRDF,
RelationInRDF,
RightsInRDF,
SourceInRDF,
)
from hsmodels.schemas.rdf.root_validators import (
parse_coverages,
Expand All @@ -31,7 +30,6 @@
coverages_spatial_constraint,
dates_constraint,
language_constraint,
parse_rdf_sources,
rdf_parse_identifier,
sort_creators,
)
Expand Down Expand Up @@ -79,7 +77,6 @@ class ResourceMetadataInRDF(BaseModel):
creators: List[CreatorInRDF] = Field(rdf_predicate=DC.creator, default=[])

contributors: List[ContributorInRDF] = Field(rdf_predicate=DC.contributor, default=[])
sources: List[SourceInRDF] = Field(rdf_predicate=DC.source, default=[])
relations: List[RelationInRDF] = Field(rdf_predicate=DC.relation, default=[])
extended_metadata: List[ExtendedMetadataInRDF] = Field(rdf_predicate=HSTERMS.extendedMetadata, default=[])
rights: RightsInRDF = Field(rdf_predicate=DC.rights, default=None)
Expand All @@ -95,7 +92,6 @@ class ResourceMetadataInRDF(BaseModel):
_parse_description = root_validator(pre=True, allow_reuse=True)(rdf_parse_description)

_parse_identifier = validator("identifier", pre=True, allow_reuse=True)(rdf_parse_identifier)
_parse_rdf_sources = validator("sources", pre=True, allow_reuse=True)(parse_rdf_sources)

_language_constraint = validator('language', allow_reuse=True)(language_constraint)
_dates_constraint = validator('dates', allow_reuse=True)(dates_constraint)
Expand Down
9 changes: 2 additions & 7 deletions hsmodels/schemas/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
split_coverages,
split_dates,
)
from hsmodels.schemas.validators import list_not_empty, parse_identifier, parse_sources, parse_spatial_coverage
from hsmodels.schemas.validators import list_not_empty, parse_identifier, parse_spatial_coverage


class ResourceMetadataIn(BaseMetadata):
Expand Down Expand Up @@ -62,11 +62,6 @@ class Config:
title="Contributors",
description="A list of Contributor objects indicating the entities that contributed to a resource",
)
sources: List[str] = Field(
default=[],
title="Sources",
description="A list of strings containing references to related resources from which a described resource was derived",
)
relations: List[Relation] = Field(
default=[],
title="Related resources",
Expand Down Expand Up @@ -109,7 +104,7 @@ class Config:
_parse_coverages = root_validator(pre=True, allow_reuse=True)(split_coverages)
_parse_additional_metadata = root_validator(pre=True, allow_reuse=True)(parse_additional_metadata)
_parse_abstract = root_validator(pre=True)(parse_abstract)
_parse_sources = validator("sources", pre=True)(parse_sources)

_parse_spatial_coverage = validator("spatial_coverage", allow_reuse=True, pre=True)(parse_spatial_coverage)

_normalize_additional_metadata = root_validator(allow_reuse=True, pre=True)(normalize_additional_metadata)
Expand Down
8 changes: 2 additions & 6 deletions tests/data/json/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,17 @@
}
}
],
"sources": [
"another",
"the source"
],
"relations": [
{
"type": "The content of this resource serves as the data for",
"type": "This resource is described by",
"value": "Bastidas Pacheco, C. J., Horsburgh, J. S., Tracy, R. J. (2020). A low-cost, open source monitoring system for collecting high-resolution water use data on magnetically-driven residential water meters, Sensors, 20(13), 3655, https://doi.org/10.3390/s20133655."
},
{
"type": "The content of this resource is part of",
"value": "https://sadf.com"
},
{
"type": "The content of this resource was copied from",
"type": "The content of this resource was created by",
"value": "https://www.google.com"
}
],
Expand Down
16 changes: 3 additions & 13 deletions tests/data/metadata/resourcemetadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
<hsterms:CompositeResource rdf:about="http://www.hydroshare.org/resource/84805fd615a04d63b4eada65644a1e20">
<dc:subject>Logan River</dc:subject>
<dcterms:bibliographicCitation>a custom citation</dcterms:bibliographicCitation>
<dc:source>
<rdf:Description>
<hsterms:isDerivedFrom>another</hsterms:isDerivedFrom>
</rdf:Description>
</dc:source>
<dc:subject>CUAHSI</dc:subject>
<dc:contributor>
<rdf:Description>
Expand All @@ -40,7 +35,7 @@
<dc:subject>fdas</dc:subject>
<dc:relation>
<rdf:Description>
<hsterms:isPartOf>https://sadf.com</hsterms:isPartOf>
<dcterms:isPartOf>https://sadf.com</dcterms:isPartOf>
</rdf:Description>
</dc:relation>
<hsterms:awardInfo>
Expand All @@ -54,12 +49,12 @@
<dc:subject>Time Series</dc:subject>
<dc:relation>
<rdf:Description>
<hsterms:isDataFor>Bastidas Pacheco, C. J., Horsburgh, J. S., Tracy, R. J. (2020). A low-cost, open source monitoring system for collecting high-resolution water use data on magnetically-driven residential water meters, Sensors, 20(13), 3655, https://doi.org/10.3390/s20133655.</hsterms:isDataFor>
<hsterms:isDescribedBy>Bastidas Pacheco, C. J., Horsburgh, J. S., Tracy, R. J. (2020). A low-cost, open source monitoring system for collecting high-resolution water use data on magnetically-driven residential water meters, Sensors, 20(13), 3655, https://doi.org/10.3390/s20133655.</hsterms:isDescribedBy>
</rdf:Description>
</dc:relation>
<dc:relation>
<rdf:Description>
<hsterms:isCopiedFrom>https://www.google.com</hsterms:isCopiedFrom>
<hsterms:isCreatedBy>https://www.google.com</hsterms:isCreatedBy>
</rdf:Description>
</dc:relation>
<dc:date>
Expand Down Expand Up @@ -135,11 +130,6 @@
</rdf:Description>
</dc:creator>
<dc:subject>key 1</dc:subject>
<dc:source>
<rdf:Description>
<hsterms:isDerivedFrom>the source</hsterms:isDerivedFrom>
</rdf:Description>
</dc:source>
<hsterms:awardInfo>
<rdf:Description>
<hsterms:fundingAgencyURL rdf:resource="https://google.com"/>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from hsmodels.schemas.resource import ResourceMetadata

schema_list_count = [
(ResourceMetadata, 6),
(ResourceMetadata, 5),
(GeographicRasterMetadata, 1),
(GeographicFeatureMetadata, 2),
(MultidimensionalMetadata, 2),
Expand All @@ -36,7 +36,7 @@
(TimeSeriesMetadata, 2),
(ModelProgramMetadata, 4),
(ModelInstanceMetadata, 1),
(ResourceMetadataInRDF, 9),
(ResourceMetadataInRDF, 8),
(GeographicRasterMetadataInRDF, 3),
(GeographicFeatureMetadataInRDF, 4),
(MultidimensionalMetadataInRDF, 4),
Expand Down
6 changes: 1 addition & 5 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ def test_resource_metadata(res_md):
assert "key2" in res_md.additional_metadata
assert res_md.additional_metadata["key2"] == "value2"

assert len(res_md.sources) == 2
assert "another" in res_md.sources
assert "the source" in res_md.sources

assert len(res_md.creators) == 3
creator = res_md.creators[0]
assert creator.organization == 'Utah State University'
Expand Down Expand Up @@ -121,7 +117,7 @@ def test_resource_metadata(res_md):
assert len(res_md.relations) == 3
assert any(x for x in res_md.relations if x.value == "https://sadf.com" and x.type == RelationType.isPartOf)
assert any(
x for x in res_md.relations if x.value == "https://www.google.com" and x.type == RelationType.isCopiedFrom
x for x in res_md.relations if x.value == "https://www.google.com" and x.type == RelationType.isCreatedBy
)

assert res_md.rights.statement == "my statement"
Expand Down

0 comments on commit 4fff842

Please sign in to comment.