Code Monkey home page Code Monkey logo

python-yaml-ld's Introduction

python-yaml-ld

A Python implementation for handling YAML-LD documents.

What is YAML-LD?

YAML-LD is a YAML-based serialization for Linked Data, drawing inspiration from JSON-LD. It aims to bring the ease of YAML along with the structured linked data principles of JSON-LD. The YAML-LD specification provides detailed information on the structure and usage of YAML-LD.

Installation

pip install python-yaml-ld

Functions

yaml_ld.expand

Expands a given YAML-LD document into a standardized, expanded form following the JSON-LD Expansion algorithm.

  • Parameters:
    • document (str | bytes | Document): The YAML-LD document to expand.
    • base (str | None): The base IRI to use.
    • context (Document | None): A context to expand with.
    • extract_all_scripts (bool): True to extract all JSON-LD script elements from HTML, False to extract just the first.
    • mode (ProcessingMode): The JSON-LD processing mode (defaults to JSON-LD 1.1).
    • document_loader (DocumentLoader | None): The document loader to use.

yaml_ld.to_rdf

Converts the YAML-LD document to RDF (quads) form, enabling interoperability with other RDF tools and systems.

  • Parameters:
    • document (str | bytes | Document): The YAML-LD document to convert.
    • base (str | None): The base IRI to use.
    • document_loader (DocumentLoader | None): The document loader to use.

Development

  • Clone the repository
  • Set up a Python virtual environment
  • Install Poetry:
pip install -U pip poetry
  • Install the project:
poetry install
  • Retrieve submodules:
j update-submodule

python-yaml-ld's People

Contributors

anatoly-scherbakov avatar dependabot[bot] avatar

Stargazers

Nikolaus Schlemm avatar

Watchers

 avatar

python-yaml-ld's Issues

`tests/test_specification.py::test_expand[html-manifest#te014]` failing

j test tests/test_specification.py::test_expand[html-manifest#te014]

fails with

    raise NoYAMLWithinHTML()
E   yaml_ld.errors.NoYAMLWithinHTML: No YAML-LD fragments found in an HTML document.

During handling of the above exception, another exception occurred:
tests/test_specification.py:47: in test_expand
    assert error.code == test_case.result
E   AssertionError: assert 'loading document failed' == 'invalid script element'

`test_local_context` failing

Why

j test tests/test_expand.py::test_local_context

which leads to

E   URL of the context: file:///home/anatoly/projects/python-yaml-ld/specifications/json-ld-api/tests/expand/0127-context-1.jsonld
E   Reason: ('URL could not be dereferenced; only "http" and "https" URLs are supported.',)
E   Type: jsonld.InvalidUrl
E   Code: loading document failed
E   Details: {'url': 'file:///home/anatoly/projects/python-yaml-ld/specifications/json-ld-api/tests/expand/0127-context-1.jsonld'}
=========================== short test summary info ============================
FAILED tests/test_expand.py::test_local_context - yaml_ld.errors.LoadingRemoteContextFailed: Failed to load the context.

`test_expand[expand-manifest#tc037]` failing

(python-yaml-ld) anatoly@anatoly-workstation:python-yaml-ld$ j test tests/test_specification.py::test_expand[expand-manifest#tc037]
============================= test session starts ==============================
platform linux -- Python 3.11.7, pytest-7.4.4, pluggy-1.4.0
Using --randomly-seed=2642312871
rootdir: /home/anatoly/projects/python-yaml-ld
plugins: randomly-3.15.0, cov-4.1.0
collected 1 item                                                               

tests/test_specification.py F                                            [100%]

=================================== FAILURES ===================================
______________________ test_expand[expand-manifest#tc037] ______________________
tests/test_specification.py:92: in test_expand
    assert actual == expected
E   AssertionError: assert [{'http://exa... in /nest'}]}] == [{'http://exa... in /nest'}]}]
E     At index 0 diff: {'http://example.org/property': [{'@value': 'should be in /nest'}]} != {'http://example.org/nest/property': [{'@value': 'should be in /nest'}]}
E     Use -v to get more diff
=========================== short test summary info ============================
FAILED tests/test_specification.py::test_expand[expand-manifest#tc037] - AssertionError: assert [{'http://exa... in /nest'}]}] == [{'http://exa... i...
=========

Throw an error when tried to process a document against JSON-LD 1.0 standard

Why

YAML-LD spec states clealry that the Processing Mode must be JSON-LD 1.1. Thus, there is no point in running 1.0 tests against YAML-LD.

What

  • Throw a special error if trying to run 1.0,
  • but keep the processing_mode stuff as it is, otherwise we'll have to add it back when JSON-LD spec reaches a > 1.1 version
  • Double check the spec itself to make sure it does mention 1.1
  • Remove the filtering which excludes 1.0 in the tests, just catch the special error introduced above, and skip the test

`options` types are inadequate

  • Existing types are not verified against the specification
    • Shall we describe them manually?
    • Or perhaps generate somehow?
  • And hence not well documented
    • Is there a tool for that? mkdocstrings perhaps?
    • If to implement it, -- how to do so? With intermediate LD layer or without that?

`tests/test_parse.py::test_html` failing

$ j test tests/test_parse.py::test_html
============================= test session starts ==============================
platform linux -- Python 3.11.7, pytest-7.4.4, pluggy-1.3.0
Using --randomly-seed=2607194394
rootdir: /home/anatoly/projects/python-yaml-ld
plugins: randomly-3.15.0, cov-4.1.0
collected 1 item                                                               

tests/test_parse.py F                                                    [100%]

=================================== FAILURES ===================================
__________________________________ test_html ___________________________________
tests/test_parse.py:18: in test_html
    assert yaml_ld.parse(document_path) == []
yaml_ld/parse.py:99: in parse
    return _parse_html(
yaml_ld/parse.py:54: in _parse_html
    raise NoYAMLWithinHTML()
E   yaml_ld.errors.NoYAMLWithinHTML: No YAML-LD fragments found in an HTML document.
=========================== short test summary info ============================
FAILED tests/test_parse.py::test_html - yaml_ld.errors.NoYAMLWithinHTML: No YAML-LD fragments found in an HTML docu...
============================== 1 failed in 0.51s ===============================

Tests failing @ `master`

ImportError while importing test module '/home/runner/work/python-yaml-ld/python-yaml-ld/tests/test_parse.py'.

There are no `good-first-issue` issues in this repo

graph LR
    subgraph WHY
    A[We need to attract contributors!] --> B[Need 'good-first-issue' Tags on Issues]
    B --> C[Lack of Documentation Prevents Tagging]
    end

    subgraph WHAT
    D[Prepare Documentation] --> E[Document Project Setup]
    D --> F[Document Contribution Guidelines]
    D --> G[Document Codebase Structure]
    E --> H[Create 'good-first-issue' Issues]
    F --> H
    G --> H
    end

WHY --> WHAT

YAML-LD functions won't recognize an `str` as a URL or file path

Why

Currently, we rely upon URL or Path types to distinguish between different methods to specify location of the file we're processing. When provided with an str, we will always interpret it as a YAML-LD document content.

What

Write an ADR about this.

  • Either keep it as is,
  • Or implement some kind of heuristic to recognize paths and URLs encoded in plain str instances.

`html-manifest#te016` test failing

j test tests/test_specification.py::test_expand[html-manifest#te016]

prints:

    self.current_event = self.state()
../../.pyenv/versions/3.11.7/envs/python-yaml-ld/lib/python3.11/site-packages/yaml/parser.py:171: in parse_document_start
    raise ParserError(None, None,
E   yaml.parser.ParserError: expected '<document start>', but found '<scalar>'
E     in "<unicode string>", line 8, column 5:
E           -->
E           ^
=========================== short test summary info ============================
FAILED tests/test_specification.py::test_expand[html-manifest#te016] - yaml.parser.ParserError: expected '<document start>', but found '<scalar>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.