-
Notifications
You must be signed in to change notification settings - Fork 1
Enhanced Ingestion with Named Graph Restrictions #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
096e809
816e1d9
2f109c7
fedb7b7
ad7f206
3a9413c
08f9ca2
bc8d263
2ec9f6f
b27e37f
c645a04
ec5fe1f
d322e35
c66d071
047b3f7
136ea9d
f261d7e
98f033a
d380973
331300d
6edb19d
ac30ae2
5d94afb
a5d58f5
3276a8f
9efbe07
fa40552
3204684
3f51ceb
57b856b
fab8a60
a8e1a58
8204b7a
056549a
78282ef
55bc6eb
a3ed7c2
f1f2403
6b86e0b
21b2be8
efb2def
acb9311
acc27fc
ff104b5
4ec473f
438e5fc
1a0a92f
162726c
f3c1ade
e49d26c
ab412ae
0624dcf
49f9d6f
7dab3a0
efd76ac
af0be6c
ea91562
8f94d8f
cb62036
dbfe977
780cb6b
1e18f77
b6f837e
481c79e
4560602
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ class Config: | |
|
||
class InputJSONSLdchema(BaseModel): | ||
user: str | ||
graph: str | ||
kg_data: Dict[Any, Any] | ||
|
||
|
||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
from rdflib import Graph | ||
import requests | ||
import logging | ||
|
||
from core.configuration import load_environment | ||
logger = logging.getLogger(__name__) | ||
|
||
# Helper function to resolve issues during the conversion from JSON-LD to Turtle representation. | ||
|
@@ -121,3 +121,61 @@ def is_valid_jsonld(jsonld_str): | |
except ValueError: | ||
return False | ||
|
||
def check_url_for_slash(url:str): | ||
if not url.endswith("/"): | ||
return url + "/" | ||
return url | ||
|
||
def check_if_url_wellformed(url:str): | ||
"We want to ensure that the name graph IRI is wellformed, i.e., starts with http or https, not www" | ||
if url is None: | ||
return False | ||
else: | ||
return True if url.startswith("http://") or url.startswith("https://") else False | ||
|
||
|
||
import requests | ||
|
||
|
||
def named_graph_exists(named_graph_iri: str) -> dict: | ||
""" | ||
Checks whether a named graph exists in the registered named graphs list. | ||
|
||
Args: | ||
named_graph_iri (str): The IRI of the named graph to check. | ||
|
||
Returns: | ||
dict: A dictionary indicating success or failure with a relevant message. | ||
""" | ||
|
||
query_service_url = load_environment().get("QUERY_SERVICE_BASE_URL", "") | ||
endpoint = f"{check_url_for_slash(query_service_url)}query/registered-named-graphs" | ||
|
||
# Validate the named graph IRI | ||
print(check_if_url_wellformed(named_graph_iri)) | ||
if not check_if_url_wellformed(named_graph_iri): | ||
return { | ||
"status": "error", | ||
"message": "The graph IRI is not well-formed. It should start with 'http' or 'https'." | ||
} | ||
|
||
try: | ||
response = requests.get(endpoint) | ||
response.raise_for_status() # Raise an error for bad responses (4xx, 5xx) | ||
|
||
registered_graphs = response.json() | ||
formatted_iri= check_url_for_slash(named_graph_iri) | ||
if formatted_iri in registered_graphs: | ||
return { | ||
"status": True, | ||
"formatted_iri": formatted_iri | ||
} | ||
return { | ||
"status": False, | ||
"message": f"The graph is not registered. Available graphs: {list(registered_graphs.keys())}" | ||
} | ||
except requests.exceptions.RequestException as e: | ||
return { | ||
"status": "error", | ||
"message": f"Error connecting to query service: {str(e)}" | ||
} | ||
Comment on lines
+178
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have an HTTP status code indicating it is an error returned as well? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,17 @@ | |
from core.rabbit_mq_listener import start_consuming | ||
from core.configure_logging import configure_logging | ||
from core.routers.worker import router as index_router | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
async def background_task(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also be apart of the |
||
print("waiting for messages...") | ||
asyncio.create_task(start_consuming()) | ||
logger.info("#### waiting for messages... ####") | ||
loop = asyncio.get_event_loop() | ||
# This will run start_consuming in a separate thread | ||
await loop.run_in_executor(None, start_consuming) | ||
|
||
app = FastAPI() | ||
logger = logging.getLogger(__name__) | ||
app.add_middleware(CorrelationIdMiddleware) | ||
|
||
|
||
|
@@ -27,7 +30,7 @@ async def background_task(): | |
async def startup_event(): | ||
asyncio.create_task(background_task()) | ||
configure_logging() | ||
logger.info("Starting FastAPI") | ||
logger.info("#### Starting FastAPI... ####") | ||
|
||
|
||
# log all HTTP exception when raised | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requests
is a synchronous call -- is this function eventually being called in an upstreamasync
call?