File: index.rst

package info (click to toggle)
rudof 0.2.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 9,968 kB
  • sloc: python: 1,404; makefile: 32; sh: 1
file content (179 lines) | stat: -rw-r--r-- 4,707 bytes parent folder | download | duplicates (2)
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
pyrudof |release|
====================

``pyrudof`` is a Python library for working with RDF data that implements `Shape Expressions <https://shex.io/>`_, `SHACL <https://www.w3.org/TR/shacl/>`_, `DCTAP <https://www.dublincore.org/specifications/dctap/>`_, and other technologies in the RDF ecosystem.

.. important::
   ``pyrudof`` is under active development. APIs may change between versions.

Key features:

* **Validation**: Validate RDF data against ShEx and SHACL schemas
* **Schema Conversion**: Convert between ShEx, SHACL, and DCTAP formats
* **SPARQL Queries**: Execute queries against local data or remote endpoints
* **Visualization**: Generate UML-like diagrams from schemas and data
* **Data Generation**: Generate synthetic RDF data from schemas


Installation
------------

``pyrudof`` is available on `PyPI <https://pypi.org/project/pyrudof/>`_ and can be installed using pip:

.. code-block:: bash

    pip install pyrudof


Quick Links
-----------

* :doc:`library` - Complete API reference
* :doc:`generate` - Data generation guide
* :doc:`examples` - Practical examples
* `GitHub Repository <https://github.com/rudof-project/rudof>`_
* `Issue Tracker <https://github.com/rudof-project/rudof/issues>`_


Documentation Contents
----------------------

.. toctree::
   :maxdepth: 2
   :caption: User Guide

   library
   generate
   examples


Quick Start Examples
--------------------

Below are a few quick examples to get you started with ``pyrudof``. For more comprehensive examples and use cases, see the :doc:`examples` section.

SHACL Validation
~~~~~~~~~~~~~~~~

Validate RDF data against SHACL shapes:

.. code-block:: python

    from pyrudof import Rudof, RudofConfig, ShaclValidationMode, ShapesGraphSource

    rudof = Rudof(RudofConfig())

    # Load SHACL shapes
    rudof.read_shacl_str("""
        prefix : <http://example.org/>
        prefix sh: <http://www.w3.org/ns/shacl#>
        prefix xsd: <http://www.w3.org/2001/XMLSchema#>

        :Person a sh:NodeShape;
            sh:targetNode :ok, :ko ;
            sh:property [
                sh:path :name ;
                sh:minCount 1;
                sh:maxCount 1;
                sh:datatype xsd:string ;
            ] .
    """)

    # Load RDF data
    rudof.read_data_str("""
        prefix : <http://example.org/>
        :ok :name "alice" .
        :ko :name 1 .
    """)

    # Validate and display results
    result = rudof.validate_shacl(
        ShaclValidationMode.Native,
        ShapesGraphSource.CurrentSchema
    )
    print(result.show_as_table())


Synthetic Data Generation
~~~~~~~~~~~~~~~~~~~~~~~~~~

Generate synthetic RDF data from schemas:

.. code-block:: python

    from pyrudof import GeneratorConfig, DataGenerator, OutputFormat, CardinalityStrategy

    # Configure the generator
    config = GeneratorConfig()
    config.set_entity_count(100)
    config.set_output_path("output.ttl")
    config.set_output_format(OutputFormat.Turtle)
    config.set_seed(42)  # For reproducible results
    config.set_cardinality_strategy(CardinalityStrategy.Balanced)

    # Generate data from schema
    generator = DataGenerator(config)
    generator.run("schema.shex")


.. seealso::
   See :doc:`generate` for advanced configuration options and parallel processing.


SPARQL Queries
~~~~~~~~~~~~~~

Execute SPARQL queries against remote endpoints:

.. code-block:: python

    from pyrudof import Rudof, RudofConfig, QueryResultFormat

    rudof = Rudof(RudofConfig())
    rudof.use_endpoint("https://query.wikidata.org/sparql")

    result = rudof.run_query_construct_str("""
        PREFIX wd: <http://www.wikidata.org/entity/>
        PREFIX wdt: <http://www.wikidata.org/prop/direct/>
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

        CONSTRUCT {
            ?p a :Person ;
               :name ?personLabel .
        }
        WHERE {
            ?p wdt:P31 wd:Q5 ;
               rdfs:label ?personLabel .
            FILTER (lang(?personLabel) = "en")
        }
        LIMIT 5
    """, QueryResultFormat.Turtle)

    print(result)


Schema Conversion
~~~~~~~~~~~~~~~~~

Convert between different schema formats:

.. code-block:: python

    from pyrudof import Rudof, RudofConfig, ShExFormatter

    rudof = Rudof(RudofConfig())

    # Read DCTAP schema
    rudof.read_dctap_str("""
    shapeId,propertyId,Mandatory,Repeatable,valueDatatype,valueShape
    Person,name,true,false,xsd:string,
    ,birthdate,false,false,xsd:date,
    ,enrolledIn,false,true,,Course
    Course,name,true,false,xsd:string,
    ,student,false,true,,Person
    """)

    # Convert to ShEx
    rudof.dctap2shex()
    result = rudof.serialize_current_shex(ShExFormatter())
    print(result)