Exemplo n.º 1
0
def _add_optional_dataset_props(dataset: Dataset, es_hit: Mapping) -> None:
    dataset.contactpoint = utils.create_contact(es_hit)
    dataset.creator = URI(os.environ["PUBLISHER"])
    dataset.frequency = URI(es_hit.get("periodicity", ""))
    dataset.license = URI(es_hit["license"]["url"])
    dataset.temporal_coverage = utils.create_temporal_coverage(
        es_hit["temporal"])
def test_to_graph_should_return_temporal_coverage() -> None:
    """It returns a temporal coverage graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    # Create PeriodOfTime:
    temporal_coverage = PeriodOfTime()
    temporal_coverage.start_date = "2019-12-31"
    temporal_coverage.end_date = "2020-12-31"
    # Add temporal_coverage to dataset:
    dataset.temporal_coverage = temporal_coverage

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:temporal [ a dct:PeriodOfTime ;
            dcat:startDate "2019-12-31"^^xsd:date ;
            dcat:endDate   "2020-12-31"^^xsd:date ;
        ]
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic