Skip to content

Commit 4248fc8

Browse files
committed
Add script to generate RDFRules objects according to the Schema
1 parent 2f82aaf commit 4248fc8

File tree

4 files changed

+75
-43
lines changed

4 files changed

+75
-43
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ jdk
55
sample/
66
venv/
77
.DS_Store
8-
__pycache__
8+
__pycache__
9+
wip/

src/pyrdfrules/main.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/pyrdfrules/rdfrules.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# generated by datamodel-codegen:
2+
# filename: https://raw.githubusercontent.com/propi/rdfrules/master/http/schema.json
3+
# timestamp: 2024-09-11T13:34:02+00:00
4+
5+
from __future__ import annotations
6+
7+
from enum import Enum
8+
from typing import List, Literal, Optional, Union
9+
10+
from pydantic import AnyUrl, BaseModel, ConfigDict, Field, RootModel
11+
12+
13+
class BaseObject(BaseModel):
14+
pass
15+
16+
17+
class GraphPath(RootModel[str]):
18+
root: str = Field(
19+
...,
20+
pattern='^.+[.](ttl|nt|nq|json|jsonld|xml|rdf|owl|trig|trix|tsv|sql|cache)([.](gz|bz2))?$',
21+
title='Choose a file from the workspace',
22+
)
23+
"""
24+
Load a file from the workspace on the server side. The dataset format is detected automatically by the file extension. Supported extensions are .ttl (turtle), .nt (n-triples), .nq (n-quads), .json | .jsonld (JSON-LD), .xml | .rdf | .owl (RDF/XML), .trig (TriG), .trix (TriX), .tsv, .sql, .cache (internal binary format). All formats can be compressed by GZIP or BZ2 (e.g. data.ttl.gz).
25+
"""
26+
27+
28+
class GraphUrl(RootModel[AnyUrl]):
29+
root: AnyUrl = Field(..., title='URL')
30+
"""
31+
A URL to a remote file to be loaded. If this is specified then the workspace file is ommited.
32+
"""
33+
34+
35+
class GraphName(RootModel[str]):
36+
root: str = Field(..., pattern='^<.*>$', title='Graph name')
37+
"""
38+
Name for this loaded graph. It must have the URI notation in angle brackets, e.g., <dbpedia> or `<http://dbpedia.org>`.
39+
"""
40+
41+
42+
class SourceSettings(Enum):
43+
tsvRaw = 'tsvRaw'
44+
tsvParsedUris = 'tsvParsedUris'
45+
tsvParsedLiterals = 'tsvParsedLiterals'
46+
47+
48+
class QuadFilter(BaseModel):
49+
model_config = ConfigDict(
50+
extra='forbid',
51+
)
52+
subject: Optional[str] = None
53+
predicate: Optional[str] = None
54+
object: Optional[str] = None
55+
graph: Optional[str] = None
56+
inverse: Optional[bool] = None
57+
58+
59+
class LoadGraph(BaseModel):
60+
name: Literal['LoadGraph'] = 'LoadGraph'
61+
parameters: Optional[BaseObject] = None
62+
63+
64+
class FilterQuads(BaseModel):
65+
name: Literal['FilterQuads'] = 'FilterQuads'
66+
parameters: Optional[BaseObject] = None
67+
68+
69+
class Model(RootModel[List[Union[LoadGraph, FilterQuads]]]):
70+
root: List[Union[LoadGraph, FilterQuads]]

update_schema.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
datamodel-codegen --url https://raw.githubusercontent.com/propi/rdfrules/master/http/schema.json --field-constraints --use-field-description --collapse-root-models --output-model-type pydantic_v2.BaseModel > src/pyrdfrules/rdfrules.py

0 commit comments

Comments
 (0)