Reference
GraphFormatConfig
Bases: BaseModel
Graph formatting configuration class
This class stores configuration of how to convert tabular data into RDF graph data.
Some examples of sample configurations can be found in the examples/
directory.
Attributes:
Name | Type | Description |
---|---|---|
source_name |
str
|
A string that is used to describe the source (i.e. "wikipedia" for data from wikipedia) |
predicate_mapping |
Dict[str, PredicateMapping]
|
A dictionary that maps the column_name to a predicate in URI form |
primary_key |
str
|
The primary key of the row (usually something like |
subject_namespace |
Optional[Namespace]
|
A string prepended to the quad's subject as a namespace, instead of just using the value of the |
graph_namespace |
Optional[Namespace]
|
Similar to |
date_field |
Optional[str]
|
The column in your dataset that the fact's "date" will be pulled from. When specified, the named graph field in each fact will be build from the date. |
Source code in quadipy/schemas/graph_format_config.py
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
Config
Pydantic config class
Source code in quadipy/schemas/graph_format_config.py
36 37 38 39 40 41 |
|
build_graph_from_date(record)
Builds named graph URI from a date field in the record
If you have a field like created_at
or updated_at
and want to store that metadata in the named graph
field, this method will build the named graph URI from the date_field
Examples:
record = {"created_at": "2022-01-01"} -> URIRef("2022-01-01")
If the config has a graph_namespace
defined this would change to
self.graph_namespace = "graph://wikipedia.org/"
record = {"created_at": "2022-01-01"} -> URIRef("graph://wikipedia.org/2022-01-01")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict
|
A dictonary that contains the data |
required |
Returns:
Type | Description |
---|---|
URIRef
|
a rdflib.URIRef of the named graph built from the |
Raises:
Type | Description |
---|---|
ParserError
|
If the value in the |
AssertionError
|
If the |
Source code in quadipy/schemas/graph_format_config.py
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 |
|
quadify(record)
Takes a record and translates into a list of Quads
This process is explained more in-depth in the README but this is the high level method that translates a record into a list of Quads that can be inserted in an RDF graph
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict
|
A dictionary that contains the data to be quadified |
required |
Returns:
Type | Description |
---|---|
List[Quad]
|
A list of Quads |
Source code in quadipy/schemas/graph_format_config.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
subject(record)
Creates URI out of primary key of the record
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record |
Dict
|
A dictonary that contains the data. Must contain the |
required |
Returns:
Type | Description |
---|---|
URIRef
|
An rdflib.URIRef with the value of the primary_key value in the record |
Raises:
Type | Description |
---|---|
AssertionError
|
The |
Source code in quadipy/schemas/graph_format_config.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
PredicateMapping
Bases: BaseModel
Source code in quadipy/schemas/predicate_mapping.py
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 |
|
obj_namespace: Optional[Namespace]
class-attribute
Class to define relationship between data and predicate
predicate_uri: The URI the data will be mapped to obj_datatype: Datatype that the object will be serialized to defaults to literal but can be one of (literal, date, uri) obj_namespace: If the object value should be mapped to a specific namespace
Config
Pydantic config class
Source code in quadipy/schemas/predicate_mapping.py
42 43 44 45 46 |
|
Quad
Bases: BaseModel
Base RDF Fact class.
Each RDF fact is modeled as subject predicate object with an optional 4th term to specify the named graph. This is sometimes referred to as SPOG.
Attributes:
Name | Type | Description |
---|---|---|
subject |
Union[BNode, URIRef]
|
Must be a blank node or uri |
predicate |
URIRef
|
Must be a uri |
obj |
Union[URIRef, Literal]
|
We use obj to not use the built-in object keyword in python. Must be a blank node, uri, or literal |
graph |
Optional[URIRef]
|
An optional argument that can be used to specify the named graph the fact will belong to. Must be an uri |
Source code in quadipy/schemas/quad.py
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 |
|
Config
Pydantic config class
Source code in quadipy/schemas/quad.py
27 28 29 30 |
|
to_tuple()
Converts quad to a tuple. This method is useful for adding Quad to rdflib Graphs
Source code in quadipy/schemas/quad.py
64 65 66 67 68 |
|