Exemplo n.º 1
0
 def _make_jsonld_expanded(resource, store_metadata, context):
     data = dict()
     if hasattr(resource, "id"):
         data["@id"] = resource.id
     ctx = Context(resource.context) if hasattr(resource, "context") else Context(context)
     latitude_term = ctx.terms.get("latitude")
     if latitude_term.type:
         latitude_node = {
             "@type": latitude_term.type,
             "@value": resource.geo["latitude"]
         }
     else:
         latitude_node = resource.geo["latitude"]
     geo_expanded = {
         latitude_term.id: latitude_node
     }
     data.update({
         "@type": ctx.expand(resource.type),
         ctx.expand("description"): resource.description,
         ctx.expand("geo"): geo_expanded,
         ctx.expand("image"): {"@id": resource.image},
         ctx.expand("name"): resource.name
     })
     if store_metadata and resource._store_metadata is not None:
         data.update(metadata_data_expanded)
     return data
Exemplo n.º 2
0
def test_load_context_from_url():
    context_url = "https://json-ld.org/contexts/person.jsonld"
    context = Context(context_url, context_url)
    assert is_valid_document(context.document)
    assert context.expand("affiliation") == "http://schema.org/affiliation"
    assert context.iri == context_url
    assert context.is_http_iri() is True
Exemplo n.º 3
0
def test_load_context_from_list(custom_context, context_iri_file,
                                model_prefixes):
    test_context = _merge_jsonld(custom_context, context_iri_file)
    context = Context(test_context)
    assert is_valid_document(context.document)
    assert context.iri is None
    assert context.is_http_iri() is False
    assert context.base == "http://example.org/"
    assert context.vocab == "http://example.org/vocab/"
    assert context.expand("Person") == "http://schema.org/Person"
    assert context.prefixes == model_prefixes