Skip to content

# `` parse_patch

Functions:

- `main` –

## `` main

    main()

Source code in `examples/parse_patch.py`

     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31

    def main():
        # RDF patch data
        add_patch = """
        TX .
        A _:bn1 <http://example.org/predicate1> "object1" .
        A _:bn1 <http://example.org/predicate2> "object2" .
        TC .
        """

        delete_patch = """
        TX .
        D _:bn1 <http://example.org/predicate1> "object1" .
        TC .
        """

        ds = Dataset()

        # Apply add patch
        ds.parse(data=add_patch, format="patch")
        print("After add patch:")
        for triple in ds:
            print(triple)

        # Apply delete patch
        ds.parse(data=delete_patch, format="patch")
        print("After delete patch:")
        for triple in ds:
            print(triple)

source: false show_docstring_attributes: false show_docstring_functions: false show_docstring_modules: false show_docstring_classes: false show_signature: false show_signature_annotations: false show_signature_type_parameters: false show_docstring_other_parameters: false show_docstring_parameters: false show_docstring_raises: false show_docstring_receives: false show_docstring_returns: false summary: false show_if_no_docstring: false

    from rdflib import Dataset

    def main():
        # RDF patch data
        add_patch = """
        TX .
        A _:bn1 <http://example.org/predicate1> "object1" .
        A _:bn1 <http://example.org/predicate2> "object2" .
        TC .
        """

        delete_patch = """
        TX .
        D _:bn1 <http://example.org/predicate1> "object1" .
        TC .
        """

        ds = Dataset()

        # Apply add patch
        ds.parse(data=add_patch, format="patch")
        print("After add patch:")
        for triple in ds:
            print(triple)

        # Apply delete patch
        ds.parse(data=delete_patch, format="patch")
        print("After delete patch:")
        for triple in ds:
            print(triple)

    if __name__ == "__main__":
        main()