djangordf 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 JudaicaLink
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.1
2
+ Name: djangordf
3
+ Version: 0.1.0
4
+ Summary: A RDF library for Django models
5
+ Home-page: https://github.com/judaicalink/djangordf
6
+ Author: Benjamin Schnabel
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+
14
+ # Djangordf
15
+
16
+ **Djangordf** is a powerful Django library designed to manage RDF (Resource Description Framework) data directly from Django models. It provides full **CRUD functionality** for RDF data, allowing developers to easily create, read, update, and delete RDF triples. The library also supports **ontology creation** and **automatic synchronization** with external triple stores, making it a perfect solution for building semantically enriched web applications.
17
+
18
+ ## Features
19
+
20
+ - Full **CRUD support** for RDF data
21
+ - **Ontology management** and custom RDF mappings
22
+ - **Automatic syncing** with external triple stores (e.g., RDF4J, Blazegraph)
23
+ - **SPARQL support** for querying RDF data
24
+ - Integration of **external RDF graphs** as alternative data sources
25
+ - Easy setup and usage within Django projects
26
+
27
+ ## Installation
28
+
29
+ To install Djangordf, run the following command:
30
+
31
+ ```bash
32
+ pip install djangordf
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Add `djangordf` to your Django project's `INSTALLED_APPS`.
38
+ Define RDF mappings for your Django models using the provided admin interface.
39
+ Use the API to interact with RDF triples or integrate them into your application.
40
+
41
+ ## License
42
+
43
+ This project is licensed under the MIT License.
@@ -0,0 +1,30 @@
1
+ # Djangordf
2
+
3
+ **Djangordf** is a powerful Django library designed to manage RDF (Resource Description Framework) data directly from Django models. It provides full **CRUD functionality** for RDF data, allowing developers to easily create, read, update, and delete RDF triples. The library also supports **ontology creation** and **automatic synchronization** with external triple stores, making it a perfect solution for building semantically enriched web applications.
4
+
5
+ ## Features
6
+
7
+ - Full **CRUD support** for RDF data
8
+ - **Ontology management** and custom RDF mappings
9
+ - **Automatic syncing** with external triple stores (e.g., RDF4J, Blazegraph)
10
+ - **SPARQL support** for querying RDF data
11
+ - Integration of **external RDF graphs** as alternative data sources
12
+ - Easy setup and usage within Django projects
13
+
14
+ ## Installation
15
+
16
+ To install Djangordf, run the following command:
17
+
18
+ ```bash
19
+ pip install djangordf
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Add `djangordf` to your Django project's `INSTALLED_APPS`.
25
+ Define RDF mappings for your Django models using the provided admin interface.
26
+ Use the API to interact with RDF triples or integrate them into your application.
27
+
28
+ ## License
29
+
30
+ This project is licensed under the MIT License.
@@ -0,0 +1 @@
1
+ from .functions import export_model_to_rdf
@@ -0,0 +1,51 @@
1
+ from rdflib import Graph, Literal, RDF, URIRef
2
+ from rdflib.namespace import FOAF, XSD, Namespace
3
+ from datetime import datetime
4
+ import os
5
+ from django.conf import settings
6
+
7
+
8
+ def export_model_to_rdf(model, dump_name):
9
+ # Namespace basierend auf dem Model
10
+ ns = Namespace(f"http://example.org/{model.__name__.lower()}/")
11
+
12
+ # Erstellen eines Graphen
13
+ g = Graph()
14
+
15
+ # Hinzufügen von Modelldaten zum Graphen
16
+ for instance in model.objects.all():
17
+ subject_uri = URIRef(ns[str(instance.id)])
18
+
19
+ # Alle Felder des Modells durchgehen und zu RDF konvertieren
20
+ for field in model._meta.fields:
21
+ field_name = field.name
22
+ field_value = getattr(instance, field_name)
23
+
24
+ # Feld-URI und Wert als Literal hinzufügen
25
+ predicate_uri = URIRef(ns[field_name])
26
+ if isinstance(field_value, str):
27
+ g.add((subject_uri, predicate_uri, Literal(field_value, datatype=XSD.string)))
28
+ elif isinstance(field_value, int):
29
+ g.add((subject_uri, predicate_uri, Literal(field_value, datatype=XSD.integer)))
30
+ elif isinstance(field_value, float):
31
+ g.add((subject_uri, predicate_uri, Literal(field_value, datatype=XSD.float)))
32
+ elif isinstance(field_value, bool):
33
+ g.add((subject_uri, predicate_uri, Literal(field_value, datatype=XSD.boolean)))
34
+ elif isinstance(field_value, datetime):
35
+ g.add((subject_uri, predicate_uri, Literal(field_value, datatype=XSD.dateTime)))
36
+ else:
37
+ # Andere Typen können hier behandelt werden
38
+ pass
39
+
40
+ # Name und Zeitstempel des Dumps hinzufügen
41
+ dump_metadata = URIRef(ns["dump_metadata"])
42
+ g.add((dump_metadata, RDF.type, Literal("Dump Metadata", datatype=XSD.string)))
43
+ g.add((dump_metadata, URIRef(ns["dump_name"]), Literal(dump_name, datatype=XSD.string)))
44
+ g.add((dump_metadata, URIRef(ns["timestamp"]), Literal(datetime.now().isoformat(), datatype=XSD.dateTime)))
45
+
46
+ # Den Graphen als RDF-Turtle speichern
47
+ dump_file_path = os.path.join(settings.BASE_DIR, f"{dump_name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.ttl")
48
+ with open(dump_file_path, 'w') as f:
49
+ f.write(g.serialize(format='turtle').decode('utf-8'))
50
+
51
+ return dump_file_path
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.1
2
+ Name: djangordf
3
+ Version: 0.1.0
4
+ Summary: A RDF library for Django models
5
+ Home-page: https://github.com/judaicalink/djangordf
6
+ Author: Benjamin Schnabel
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+
14
+ # Djangordf
15
+
16
+ **Djangordf** is a powerful Django library designed to manage RDF (Resource Description Framework) data directly from Django models. It provides full **CRUD functionality** for RDF data, allowing developers to easily create, read, update, and delete RDF triples. The library also supports **ontology creation** and **automatic synchronization** with external triple stores, making it a perfect solution for building semantically enriched web applications.
17
+
18
+ ## Features
19
+
20
+ - Full **CRUD support** for RDF data
21
+ - **Ontology management** and custom RDF mappings
22
+ - **Automatic syncing** with external triple stores (e.g., RDF4J, Blazegraph)
23
+ - **SPARQL support** for querying RDF data
24
+ - Integration of **external RDF graphs** as alternative data sources
25
+ - Easy setup and usage within Django projects
26
+
27
+ ## Installation
28
+
29
+ To install Djangordf, run the following command:
30
+
31
+ ```bash
32
+ pip install djangordf
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Add `djangordf` to your Django project's `INSTALLED_APPS`.
38
+ Define RDF mappings for your Django models using the provided admin interface.
39
+ Use the API to interact with RDF triples or integrate them into your application.
40
+
41
+ ## License
42
+
43
+ This project is licensed under the MIT License.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ djangordf/__init__.py
5
+ djangordf/functions.py
6
+ djangordf.egg-info/PKG-INFO
7
+ djangordf.egg-info/SOURCES.txt
8
+ djangordf.egg-info/dependency_links.txt
9
+ djangordf.egg-info/top_level.txt
10
+ tests/test_functions.py
@@ -0,0 +1 @@
1
+ djangordf
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,24 @@
1
+ from setuptools import find_packages, setup
2
+
3
+ setup(
4
+ name='djangordf',
5
+ packages=find_packages(include=['djangordf']),
6
+ version='0.1.0',
7
+ description='A RDF library for Django models',
8
+ classifiers=[
9
+ "Programming Language :: Python :: 3",
10
+ "License :: OSI Approved :: MIT License", # Deine Lizenz
11
+ "Operating System :: OS Independent",
12
+ ],
13
+ python_requires=">=3.6",
14
+ author='Benjamin Schnabel',
15
+ email='b.schnabel@hs-mannheim.de',
16
+ website='djangordf.readthedocs.org',
17
+ long_description=open("README.md", "r").read(),
18
+ long_description_content_type="text/markdown",
19
+ url="https://github.com/judaicalink/djangordf",
20
+ install_requires=[],
21
+ setup_requires=['pytest-runner'],
22
+ tests_require=['pytest==7.4.4'],
23
+ test_suite='tests',
24
+ )
File without changes