mike dupont
commited on
Commit
•
41f1ee1
1
Parent(s):
5874113
adding ontology
Browse files- app.py +15 -2
- frontend/introspector.n3 +1 -0
- frontend/introspector.ttl +25 -0
- introspector_rdf.py +23 -0
app.py
CHANGED
@@ -5,7 +5,7 @@ from fastapi.staticfiles import StaticFiles
|
|
5 |
#import numpy as np
|
6 |
import argparse
|
7 |
import os
|
8 |
-
|
9 |
HOST = os.environ.get("API_URL", "0.0.0.0")
|
10 |
PORT = os.environ.get("PORT", 7860)
|
11 |
parser = argparse.ArgumentParser()
|
@@ -36,7 +36,20 @@ async def invert(text: str):
|
|
36 |
|
37 |
@app.get("/data")
|
38 |
async def get_data():
|
39 |
-
data =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
return JSONResponse(data)
|
41 |
|
42 |
|
|
|
5 |
#import numpy as np
|
6 |
import argparse
|
7 |
import os
|
8 |
+
import introspector_rdf
|
9 |
HOST = os.environ.get("API_URL", "0.0.0.0")
|
10 |
PORT = os.environ.get("PORT", 7860)
|
11 |
parser = argparse.ArgumentParser()
|
|
|
36 |
|
37 |
@app.get("/data")
|
38 |
async def get_data():
|
39 |
+
data = introspector_rdf.data()
|
40 |
+
# data = {"data": [
|
41 |
+
# dict(
|
42 |
+
# subject="this",
|
43 |
+
# predicate="self_reference",
|
44 |
+
# _object="<SELF>",
|
45 |
+
# ),
|
46 |
+
# dict(
|
47 |
+
# subject="introspector_rdf",
|
48 |
+
# predicate="data",
|
49 |
+
# _object=rows,
|
50 |
+
# ),
|
51 |
+
|
52 |
+
# ]}
|
53 |
return JSONResponse(data)
|
54 |
|
55 |
|
frontend/introspector.n3
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
frontend/introspector.ttl
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
|
2 |
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
3 |
+
@prefix dcterms: <http://purl.org/dc/terms/>.
|
4 |
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
5 |
+
<https://example.org/self-reflective-turtle>
|
6 |
+
a rdf:Statement ;
|
7 |
+
rdfs:label "A self-reflective Turtle RDF file"@en ;
|
8 |
+
dcterms:description "A Turtle RDF file that describes itself"@en ;
|
9 |
+
dcterms:creator "J. Mike DuPont"@en ;
|
10 |
+
dcterms:date "2024-10-02"^^xsd:date ;
|
11 |
+
dcterms:format "text/turtle"@en ;
|
12 |
+
dcterms:identifier <https://example.org/self-reflective-turtle> ;
|
13 |
+
dcterms:language "en"@en ;
|
14 |
+
dcterms:rights "AGPL 3.0"@en ;
|
15 |
+
dcterms:subject <https://example.org/self-reflective-turtle> ;
|
16 |
+
dcterms:title "Self-reflective Turtle RDF file"@en ;
|
17 |
+
|
18 |
+
rdf:type rdfs:Resource ;
|
19 |
+
rdf:type rdf:Statement ;
|
20 |
+
rdfs:seeAlso <https://www.w3.org/TR/turtle/> ;
|
21 |
+
|
22 |
+
rdfs:comment "This RDF file describes itself, including its metadata and structure."@en ;
|
23 |
+
|
24 |
+
rdfs:isDefinedBy <https://example.org/self-reflective-turtle> ;
|
25 |
+
rdfs:isReferencedBy <https://example.org/self-reflective-turtle>.
|
introspector_rdf.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import rdflib
|
2 |
+
import json
|
3 |
+
g = rdflib.Graph()
|
4 |
+
g.parse("./introspector.ttl")
|
5 |
+
|
6 |
+
knows_query = """
|
7 |
+
SELECT DISTINCT ?aname ?bname
|
8 |
+
WHERE {
|
9 |
+
?a ?b .
|
10 |
+
?a foaf:name ?aname .
|
11 |
+
?b foaf:name ?bname .
|
12 |
+
}"""
|
13 |
+
|
14 |
+
def data():
|
15 |
+
# qres = g.query(knows_query)
|
16 |
+
res = []
|
17 |
+
for x in g:
|
18 |
+
res.append(x)
|
19 |
+
return res
|
20 |
+
|
21 |
+
if __name__ == "__main__":
|
22 |
+
|
23 |
+
print(json.dumps(data(),indent=2))
|