Пример #1
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
Пример #2
0
def test_load_context_from_file(context_file_path, context_iri_file):
    with open(context_file_path) as f:
        context_json = json.loads(f.read())
    context = Context(context_iri_file, context_iri_file)
    assert is_valid_document(context.document)
    assert context.document == context_json
    assert context.iri is context_iri_file
    assert context.is_http_iri() is False
Пример #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
Пример #4
0
def _as_graphs(resource: Resource, store_metadata: bool, context: Context,
               metadata_context: Context) -> Tuple[Graph, Graph, Dict]:
    """Returns a data and a metadata graph"""
    if hasattr(resource, "context"):
        output_context = resource.context
    else:
        output_context = context.iri if context.is_http_iri(
        ) else context.document["@context"]
    converted = _add_ld_keys(resource, output_context, context.base)
    converted["@context"] = context.document["@context"]
    return _dicts_to_graph(converted, resource._store_metadata, store_metadata,
                           metadata_context) + (converted, )
Пример #5
0
def test_load_context_as_dict(custom_context):
    context = Context(custom_context)
    assert is_valid_document(context.document)
    assert context.document == custom_context
    assert context.iri is None
    assert context.is_http_iri() is False