-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Enable CLI support for content variants and custom extensions #46
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
Open
vaibhav45sktech
wants to merge
3
commits into
dbpedia:main
Choose a base branch
from
vaibhav45sktech:fix/dbpedia-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+484
−13
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """ | ||
| SPARQL Queries for Databus Python Client | ||
|
|
||
| This module contains SPARQL queries used for interacting with the DBpedia Databus. | ||
| """ | ||
|
|
||
| # Query to fetch ontologies with proper content variant aggregation | ||
| # Uses GROUP_CONCAT to handle multiple content variants per distribution | ||
| ONTOLOGIES_QUERY = """ | ||
| PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | ||
| PREFIX databus: <https://databus.dbpedia.org/> | ||
| PREFIX dataid: <http://dataid.dbpedia.org/ns/core#> | ||
| PREFIX dataid-cv: <http://dataid.dbpedia.org/ns/cv#> | ||
| PREFIX dct: <http://purl.org/dc/terms/> | ||
| PREFIX dcat: <http://www.w3.org/ns/dcat#> | ||
| PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> | ||
|
|
||
| SELECT DISTINCT | ||
| ?group ?art ?version ?title ?publisher ?comment ?description | ||
| ?license ?file ?extension ?type ?bytes ?shasum | ||
| (GROUP_CONCAT(DISTINCT ?variantStr; separator=", ") AS ?contentVariants) | ||
| WHERE { | ||
| ?dataset dataid:account databus:ontologies . | ||
| ?dataset dataid:group ?group . | ||
| ?dataset dataid:artifact ?art. | ||
| ?dataset dcat:distribution ?distribution . | ||
| ?dataset dct:license ?license . | ||
| ?dataset dct:publisher ?publisher . | ||
| ?dataset rdfs:comment ?comment . | ||
| ?dataset dct:description ?description . | ||
| ?dataset dct:title ?title . | ||
| ?distribution dcat:downloadURL ?file . | ||
| ?distribution dataid:formatExtension ?extension . | ||
| ?distribution dataid-cv:type ?type . | ||
| ?distribution dcat:byteSize ?bytes . | ||
| ?distribution dataid:sha256sum ?shasum . | ||
| ?dataset dct:hasVersion ?version . | ||
|
|
||
| # Excludes dev versions | ||
| FILTER (!regex(?art, "--DEV")) | ||
|
|
||
| # OPTIONAL: Check for variants, but don't fail if none exist | ||
| OPTIONAL { | ||
| ?distribution dataid:contentVariant ?cv . | ||
| BIND(STR(?cv) AS ?variantStr) | ||
| } | ||
|
|
||
| } | ||
| GROUP BY ?group ?art ?version ?title ?publisher ?comment ?description ?license ?file ?extension ?type ?bytes ?shasum | ||
| ORDER BY ?version | ||
| """ | ||
|
|
||
|
|
||
| def parse_content_variants_string(variants_str: str) -> dict: | ||
| """ | ||
| Parse a comma-separated content variants string from SPARQL GROUP_CONCAT result. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| variants_str : str | ||
| Comma-separated string of content variants, e.g., "lang=en, type=full, sorted" | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | ||
| Dictionary of parsed content variants. For key=value pairs, both the key | ||
| and value are returned as strings (no type conversion is performed, so | ||
| "true" remains the string "true", not a boolean). For standalone values | ||
| without an "=" sign, the value is recorded as the boolean ``True``. | ||
|
|
||
| Example: "lang=en, type=full, sorted" -> {"lang": "en", "type": "full", "sorted": True} | ||
|
|
||
| Notes | ||
| ----- | ||
| - All values from key=value pairs are kept as strings. If you need boolean | ||
| or numeric conversion, perform it after calling this function. | ||
| - Standalone items (e.g., "sorted") are stored with boolean ``True`` as | ||
| their value, indicating presence rather than a specific string value. | ||
| """ | ||
| if not variants_str or variants_str.strip() == "": | ||
| return {} | ||
|
|
||
| variants = {} | ||
| for part in variants_str.split(","): | ||
| part = part.strip() | ||
| if "=" in part: | ||
| key, value = part.split("=", 1) | ||
| variants[key.strip()] = value.strip() | ||
| elif part: | ||
| # Handle standalone values (no key=value format) | ||
| variants[part] = True | ||
|
|
||
| return variants |
|
Contributor
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. I would prefer to keep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
File seems useless? Is
ONTOLOGIES_QUERYorparse_content_variants_stringused at all?