snapquery API Documentation
basequeryview
Created on 2024-06-23 @author: wf
BaseQueryView
general search for queries
Source code in snapquery/basequeryview.py
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 |
|
on_search_change(_args=None)
async
react on changes in the search input
Source code in snapquery/basequeryview.py
41 42 43 44 45 |
|
perform_search()
async
Performs the search based on the current QuerySelector values.
Source code in snapquery/basequeryview.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
setup_ui()
setup my user interface
Source code in snapquery/basequeryview.py
27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
show_lod(q_lod)
show the given list of dicts
Source code in snapquery/basequeryview.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
ceurws
Created on 2024-07-02 @author: wf
CeurWSQueries
A class to handle the extraction and management of CEUR-WS queries.
Source code in snapquery/ceurws.py
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
__init__(nqm, debug=False)
Constructor Args: nqm (NamedQueryManager): The NamedQueryManager to use for storing queries. debug (bool): Enable debug output. Defaults to False.
Source code in snapquery/ceurws.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
extract_queries(limit=None)
Extract all queries from the CEUR-WS challenge wiki. Args: limit (int, optional): Limit the number of queries fetched. Defaults to None.
Source code in snapquery/ceurws.py
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 |
|
save_to_json(file_path='/tmp/ceurws-queries.json')
Save the NamedQueryList to a JSON file. Args: file_path (str): Path to the JSON file.
Source code in snapquery/ceurws.py
96 97 98 99 100 101 102 |
|
store_queries()
Store the named queries into the database.
Source code in snapquery/ceurws.py
104 105 106 107 108 |
|
dblp
Created on 2024-06-07
@author: wf
DblpPersonLookup
lookup persons in dblp
Source code in snapquery/dblp.py
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 |
|
search(name_part, limit=10)
search persons by part of their name using a SPARQL query with regex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_part |
str
|
The part of the name to search for. |
required |
limit |
int
|
The maximum number of results to return. |
10
|
Returns:
Type | Description |
---|---|
List[Person]
|
List[Person]: A list of Person objects. |
Source code in snapquery/dblp.py
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 |
|
endpoint
Created on 29.06.2024 @author: wf
Endpoint
A query endpoint for SPARQL, SQL or other storage systems
Source code in snapquery/endpoint.py
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 |
|
__post_init__()
Perform post-initialization processing if needed.
Source code in snapquery/endpoint.py
29 30 31 32 33 |
|
get_samples()
classmethod
Get samples for Endpoint
Source code in snapquery/endpoint.py
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 |
|
EndpointManager
Manages the storage and retrieval of Endpoint configurations.
Source code in snapquery/endpoint.py
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 |
|
get_endpoint(name)
Retrieve an endpoint by name.
Source code in snapquery/endpoint.py
80 81 82 83 84 |
|
error_filter
Created on 2024-05-06
@author: wf
ErrorFilter
handle technical error message to retrieve user friendly content
Source code in snapquery/error_filter.py
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 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 198 199 200 201 202 203 |
|
categorize_error()
Categorizes the error message into predefined types.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The category of the error message. |
Source code in snapquery/error_filter.py
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 |
|
get_message(for_html=True)
get the filtered message
Source code in snapquery/error_filter.py
194 195 196 197 198 199 200 201 202 203 |
|
execution
Created on 2024-07-09
@author: wf
Execution
supports execution of named queries
Source code in snapquery/execution.py
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 |
|
__init__(nqm, debug=False)
Source code in snapquery/execution.py
17 18 19 20 21 |
|
execute(nq, endpoint_name, title, context='test', prefix_merger=QueryPrefixMerger.SIMPLE_MERGER)
execute the given named query
Source code in snapquery/execution.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
graph
Created on 27.06.2024
@author: wf
Graph
A class representing a graph with its basic properties.
Source code in snapquery/graph.py
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 |
|
__post_init__()
Perform post-initialization processing if needed.
Source code in snapquery/graph.py
25 26 27 28 29 |
|
get_samples()
classmethod
get samples for Graph
Source code in snapquery/graph.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 |
|
GraphManager
Manages the storage and retrieval of Graph configurations.
Source code in snapquery/graph.py
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 |
|
get_graph(name)
Retrieve a graph by name.
Source code in snapquery/graph.py
72 73 74 75 76 |
|
models
person
Created 2023 refactored to snapquery by WF 2024-05
@author: th
Affiliation
dataclass
affiliation of a person
Source code in snapquery/models/person.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Person
dataclass
Bases: PersonName
A person
Source code in snapquery/models/person.py
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 |
|
has_pid: bool
property
Checks if the scholar has any persistent identifier (PID) set.
merge_with(other)
Merge this person with another person. Args: other: person to merge with
Source code in snapquery/models/person.py
102 103 104 105 106 107 108 109 110 111 112 |
|
share_identifier(other)
Check if the given person shares an identifier with this person. Args:
other: another person
Returns:
Type | Description |
---|---|
bool
|
true if the person shares an identifier, false otherwise |
Source code in snapquery/models/person.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
PersonName
dataclass
person name handling
Source code in snapquery/models/person.py
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 |
|
parse_label()
get family name and given name from label
Source code in snapquery/models/person.py
52 53 54 55 56 57 58 59 60 61 |
|
mwlogin
Created on 04.05.2024
@author: wf
Login
login to mediawiki
Source code in snapquery/mwlogin.py
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 |
|
complete_login(response_qs)
Step 3: Complete -- obtain authorized key/secret for "resource owner"
Source code in snapquery/mwlogin.py
37 38 39 40 41 42 |
|
identify_user()
Step 4: Identify -- (optional) get identifying information about the user
Source code in snapquery/mwlogin.py
44 45 46 47 48 49 50 51 52 |
|
initiate_login()
Step 1: Initialize -- ask MediaWiki for a temporary key/secret for user
Source code in snapquery/mwlogin.py
29 30 31 32 33 34 35 |
|
namespace_stats_view
Created on 2024-06-23
@author: wf
NamespaceStatsView
Class to view and manage SPARQL query statistics using NiceGUI.
Attributes:
Name | Type | Description |
---|---|---|
solution |
WebSolution
|
The web solution context which provides access to shared resources. |
nqm |
NamedQueryManager
|
The manager to handle named queries and database interactions. |
results_row |
row
|
UI component that holds the results grid. |
lod_grid |
ListOfDictsGrid
|
Grid component to display the query statistics. |
Source code in snapquery/namespace_stats_view.py
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 |
|
__init__(solution)
Initialize the NamespaceStatsView with a given web solution context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
solution |
WebSolution
|
The web solution context which includes shared resources like the NamedQueryManager. |
required |
Source code in snapquery/namespace_stats_view.py
31 32 33 34 35 36 37 38 39 40 41 |
|
execute_queries(namespace, endpoint_name, domain)
execute queries with progress updates. Args: namespace (str): The namespace of the queries to execute. endpoint_name (str): The endpoint name where the queries will be executed. domain: domain name
Source code in snapquery/namespace_stats_view.py
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 |
|
fetch_query_lod()
Fetch data from the database based on the named query 'query_success_by_namespace'.
Returns:
Type | Description |
---|---|
List[Dict[str, any]]
|
List[Dict[str, any]]: A list of dictionaries containing the query results. |
Source code in snapquery/namespace_stats_view.py
90 91 92 93 94 95 96 97 98 |
|
on_cell_clicked(event)
async
Handle cell click events to perform specific actions based on the cell content.
Source code in snapquery/namespace_stats_view.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
on_fetch_lod(_args=None)
async
Fetches data asynchronously and loads it into the grid upon successful retrieval.
Source code in snapquery/namespace_stats_view.py
79 80 81 82 83 84 85 86 87 88 |
|
process_stats_lod(raw_lod)
Process the raw list of dictionaries to format suitable for the grid display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_lod |
List[Dict[str, any]]
|
The raw data fetched from the SQL query. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, any]]
|
List[Dict[str, any]]: The processed list of dictionaries formatted for grid display. |
Source code in snapquery/namespace_stats_view.py
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 |
|
setup_ui()
Sets up the user interface for displaying SPARQL query statistics.
Source code in snapquery/namespace_stats_view.py
43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
orcid
OrcidAccessToken
orcid access token response
Source code in snapquery/orcid.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
OrcidAuth
authenticate with orcid
Source code in snapquery/orcid.py
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 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 |
|
logout()
logout user by deleting cached access token
Source code in snapquery/orcid.py
115 116 117 118 119 |
|
OrcidConfig
orcid authentication configuration
Source code in snapquery/orcid.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
OrcidSearchParams
dataclass
Orcid search api params see https://info.orcid.org/documentation/api-tutorials/api-tutorial-searching-the-orcid-registry/
Source code in snapquery/orcid.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
params_view
Created on 06.05.2024
@author: wf
ParamsView
a view for Query Parameters
Source code in snapquery/params_view.py
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 |
|
__init__(solution, params)
construct me with the given solution and params
Source code in snapquery/params_view.py
15 16 17 18 19 20 |
|
close()
hide the details of the dict edit
Source code in snapquery/params_view.py
28 29 30 31 32 |
|
get_dict_edit()
Return a DictEdit instance for editing parameters.
Source code in snapquery/params_view.py
34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
open()
show the details of the dict edit
Source code in snapquery/params_view.py
22 23 24 25 26 |
|
person_selector
Created 2023
@author: th
PersonSelector
Provides an interface for searching and selecting people with auto-suggestions.
Source code in snapquery/person_selector.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
__init__(solution, selection_callback, limit=10)
Constructor
Source code in snapquery/person_selector.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
load_person_suggestions(search_name)
async
Load person suggestions based on the search name. This method fetches data concurrently from multiple sources and updates suggestions as they arrive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_name(str) |
the search name to search for |
required |
Source code in snapquery/person_selector.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
merge_and_update_suggestions(new_persons)
Merges new persons with existing ones based on shared identifiers or adds them if unique. Ensures no duplicates are present in the list of suggested persons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_persons |
List[Person]
|
New person suggestions to be added or merged. |
required |
Source code in snapquery/person_selector.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
person_selection()
Display input fields for person data with auto-suggestion
Source code in snapquery/person_selector.py
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 |
|
select_person_suggestion(person)
Select the given Person by updating the input fields to the selected person and storing the object internally Args: person: person that should be selected
Source code in snapquery/person_selector.py
247 248 249 250 251 252 253 254 255 256 |
|
suggest_persons()
async
Use debouncer to suggest potential persons based on the input.
Source code in snapquery/person_selector.py
178 179 180 181 182 183 |
|
update_suggestions_view()
update the suggestions view
Source code in snapquery/person_selector.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
PersonSuggestion
Bases: PersonView
Display a Person
Source code in snapquery/person_selector.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
on_select()
Handle selection of the suggestion card
Source code in snapquery/person_selector.py
85 86 87 88 89 |
|
PersonView
Bases: Element
Display a person
Source code in snapquery/person_selector.py
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 |
|
pid
Created on 2024-05-26 @author: wf
PID
dataclass
A persistent identifier source e.g. ORCID, dblpID or wikidata id
Source code in snapquery/pid.py
11 12 13 14 15 16 17 18 19 20 |
|
PIDValue
dataclass
Represents a specific instance of a persistent identifier with its value.
Source code in snapquery/pid.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
PIDs
Available PIDs
Source code in snapquery/pid.py
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 |
|
pid4id(identifier)
Create a PIDValue instance based on the identifier type.
Source code in snapquery/pid.py
71 72 73 74 75 76 77 78 |
|
pid_lookup
Created on 2024-05-26 @author: wf
PersonLookup
Lookup potential persons from various databases such as Wikidata, ORCID, and DBLP.
Source code in snapquery/pid_lookup.py
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 |
|
__init__(nqm)
Initialize the PersonLookup with a Named Query Manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nqm |
NamedQueryManager
|
The named query manager to execute SPARQL queries. |
required |
Source code in snapquery/pid_lookup.py
23 24 25 26 27 28 29 30 31 32 33 |
|
suggest_from_dblp(search_name, limit=10)
Suggest persons using DBLP author search.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_name |
str
|
The name to search for suggestions. |
required |
limit |
int
|
The maximum number of results to return. |
10
|
Returns:
Type | Description |
---|---|
List[Person]
|
List[Person]: A list of suggested persons from DBLP. |
Source code in snapquery/pid_lookup.py
118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
suggest_from_orcid(search_name, limit=10)
Suggest persons using the ORCID registry search.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_name |
str
|
The name to search for suggestions. |
required |
limit |
int
|
The maximum number of results to return. |
10
|
Returns:
Type | Description |
---|---|
List[Person]
|
List[Person]: A list of suggested persons from ORCID. |
Source code in snapquery/pid_lookup.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
suggest_from_wikidata(search_name, limit=10)
Suggest persons using WikidataSearch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_name |
str
|
The name to search for suggestions. |
required |
limit |
int
|
The maximum number of results to return. |
10
|
Returns:
Type | Description |
---|---|
List[Person]
|
List[Person]: A list of suggested persons from Wikidata. |
Source code in snapquery/pid_lookup.py
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 |
|
qimport
Created on 2024-05-05
@author: wf
QueryImport
Import named queries from a given URL or file.
Source code in snapquery/qimport.py
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 |
|
__init__(nqm=None)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nqm |
NamedQueryManager
|
The NamedQueryManager to use for storing queries. |
None
|
Source code in snapquery/qimport.py
21 22 23 24 25 26 27 28 29 |
|
import_from_json_file(json_file, with_store=False, show_progress=False)
Import named queries from a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_file |
str
|
Path to the JSON file. |
required |
with_store |
bool
|
If True, store the results in the NamedQueryManager. |
False
|
show_progress |
bool
|
If True, show a progress bar during the import. |
False
|
Returns:
Name | Type | Description |
---|---|---|
NamedQuerySet |
NamedQuerySet
|
A NamedQuerySet object containing the imported NamedQuery objects. |
Source code in snapquery/qimport.py
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 |
|
import_samples(with_store=True, show_progress=False)
import all sample json files
Parameters:
Name | Type | Description | Default |
---|---|---|---|
with_store(bool) |
if True store the result |
required | |
show_progress(bool) |
if True show a tqdm progress bar |
required |
Source code in snapquery/qimport.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
qimport_view
Created on 2024-05-05
@author: wf
QueryImportView
display Query Import UI
Source code in snapquery/qimport_view.py
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 |
|
on_import_button(_args)
import a query
Source code in snapquery/qimport_view.py
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 |
|
on_input_button(_args)
imput a query
Source code in snapquery/qimport_view.py
110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
setup_ui()
setup the user interface
Source code in snapquery/qimport_view.py
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 |
|
qlever
Created on 2024-06-20
@author: wf
QLever
handle https://github.com/ad-freiburg/qlever specifics
Source code in snapquery/qlever.py
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 |
|
named_queries_for_tickets(ticket_dict)
Create named queries for each ticket's extracted URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticket_dict |
dict
|
Dictionary mapping tickets to a list of URLs. |
required |
Returns:
Name | Type | Description |
---|---|---|
NamedQuerySet |
A set of named queries generated from the URLs. |
Source code in snapquery/qlever.py
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 |
|
wd_urls_for_ticket(ticket)
Extracts and returns all URLs from a ticket's body and comments that match the specified pattern.
Source code in snapquery/qlever.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
QLeverUrl
Bases: ShortUrl
Handles operations related to QLever short URLs.
Source code in snapquery/qlever.py
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 |
|
read_query()
Read a query from a QLever short URL.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The SPARQL query extracted from the short URL. |
Source code in snapquery/qlever.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
query_annotate
Created on 2024-05-15
@author: tholzheim
NamespaceStat
contains namespace information
Source code in snapquery/query_annotate.py
101 102 103 104 105 106 107 108 |
|
SparqlQueryAnnotater
Annotate a query
Source code in snapquery/query_annotate.py
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 |
|
query_selector
Created on 2024-07-04 @author: wf
QuerySelector
A class to select domain, namespace, and name for a query using comboboxes. Uses a single change handler to update selections dynamically.
Source code in snapquery/query_selector.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 |
|
create_combobox(label, options, width_chars)
Create a ComboBox with the given label, options, and width.
Source code in snapquery/query_selector.py
38 39 40 41 42 43 44 45 46 |
|
handle_change()
async
Update self.qn and call the provided on_change callback
Source code in snapquery/query_selector.py
48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
setup_ui()
Setup the user interface for query selection using comboboxes.
Source code in snapquery/query_selector.py
29 30 31 32 33 34 35 36 |
|
update_ui()
Update UI components based on filtered results using the custom update_options method for safe sorting.
Source code in snapquery/query_selector.py
65 66 67 68 69 70 71 |
|
scholia
Created on 2024-05-04
@author: wf
ScholiaQueries
A class to handle the extraction and management of Scholia queries.
Source code in snapquery/scholia.py
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
__init__(nqm, debug=False)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nqm |
NamedQueryManager
|
The NamedQueryManager to use for storing queries. |
required |
debug |
bool
|
Enable debug output. Defaults to False. |
False
|
Source code in snapquery/scholia.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
extract_queries(limit=None)
Extract all queries from the Scholia repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit |
int
|
Limit the number of queries fetched. Defaults to None. |
None
|
Source code in snapquery/scholia.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
extract_query(file_info)
Extract a single query from file information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_info |
dict
|
Dictionary containing information about the file. |
required |
Returns:
Name | Type | Description |
---|---|---|
NamedQuery |
NamedQuery
|
The extracted NamedQuery object. |
Source code in snapquery/scholia.py
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 |
|
get_scholia_file_list()
Retrieve the list of SPARQL files from the Scholia repository.
Returns:
Name | Type | Description |
---|---|---|
list |
List of dictionaries representing file information. |
Source code in snapquery/scholia.py
35 36 37 38 39 40 41 42 43 44 45 |
|
save_to_json(file_path='/tmp/scholia-queries.json')
Save the NamedQueryList to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to the JSON file. |
'/tmp/scholia-queries.json'
|
Source code in snapquery/scholia.py
96 97 98 99 100 101 102 103 |
|
store_queries()
Store the named queries into the database.
Source code in snapquery/scholia.py
105 106 107 108 109 |
|
snapquery_cmd
Created on 2024-05-03
@author: wf
SnapQueryCmd
Bases: WebserverCmd
Command line for diagrams server
Source code in snapquery/snapquery_cmd.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
cmd_parse(argv=None)
parse the argument lists and prepare
Parameters:
Name | Type | Description | Default |
---|---|---|---|
argv(list) |
list of command line arguments |
required |
Source code in snapquery/snapquery_cmd.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
getArgParser(description, version_msg)
override the default argparser call
Source code in snapquery/snapquery_cmd.py
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 |
|
handle_args()
handle the command line args
Source code in snapquery/snapquery_cmd.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
handle_import(json_file)
Handle the import of named queries from a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_file |
str
|
Path to the JSON file to import. |
required |
Source code in snapquery/snapquery_cmd.py
223 224 225 226 227 228 229 230 231 232 233 |
|
main(argv=None)
main call
Source code in snapquery/snapquery_cmd.py
236 237 238 239 240 241 242 243 244 245 |
|
snapquery_core
Created on 2024-05-03
@author: wf
NamedQuery
dataclass
Bases: QueryName
A named query that encapsulates the details and SPARQL query for a specific purpose.
Attributes:
Name | Type | Description |
---|---|---|
title |
str
|
A brief one-line title that describes the query. |
description |
str
|
A detailed multiline description of what the query does and the data it accesses. |
sparql |
str
|
The SPARQL query string. This might be hidden in future to encapsulate query details. |
query_id |
str
|
A unique identifier for the query, generated from namespace and name, used as a primary key. |
Source code in snapquery/snapquery_core.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
as_link()
get me as a link
Source code in snapquery/snapquery_core.py
331 332 333 334 335 336 337 338 339 |
|
as_viewrecord()
Return a dictionary representing the NamedQuery with keys ordered as Name, Namespace, Title, Description.
Source code in snapquery/snapquery_core.py
370 371 372 373 374 375 376 377 378 379 380 381 |
|
from_record(record)
classmethod
Class method to instantiate NamedQuery from a dictionary record.
Source code in snapquery/snapquery_core.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
get_samples()
classmethod
get samples
Source code in snapquery/snapquery_core.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
NamedQueryManager
Manages the storage, retrieval, and execution of named SPARQL queries.
Source code in snapquery/snapquery_core.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
|
__init__(db_path=None, debug=False)
Initializes the NamedQueryManager with a specific database path and a debug mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_path |
Optional[str]
|
The file path to the SQLite database. If None, the default cache path is used. |
None
|
debug |
bool
|
If True, enables debug mode which may provide additional logging and error reporting. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
debug |
bool
|
Stores the debug state. |
sql_db |
SQLDB
|
An instance of SQLDB to manage the SQLite database interactions. |
endpoints |
dict
|
A dictionary of SPARQL endpoints configured for use. |
Source code in snapquery/snapquery_core.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
|
add_and_store(nq)
Adds a new NamedQuery instance and stores it in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nq |
NamedQuery
|
The NamedQuery instance to add and store. |
required |
Source code in snapquery/snapquery_core.py
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 |
|
as_query_bundle(named_query, endpoint_name, limit=None, prefix_merger=QueryPrefixMerger.SIMPLE_MERGER)
Assembles a QueryBundle from a NamedQuery, endpoint name, and optional limit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
named_query |
NamedQuery
|
Named query object. |
required |
endpoint_name |
str
|
Name of the endpoint where the query should be executed. |
required |
limit |
int
|
Optional limit for the query. |
None
|
Returns:
Name | Type | Description |
---|---|---|
QueryBundle |
QueryBundle
|
A bundle containing the named query, the query object, and the endpoint. |
Source code in snapquery/snapquery_core.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 |
|
execute_query(named_query, params_dict, endpoint_name='wikidata', limit=None, with_stats=True, prefix_merger=QueryPrefixMerger.SIMPLE_MERGER)
execute the given named_query
Parameters:
Name | Type | Description | Default |
---|---|---|---|
named_query(NamedQuery) |
the query to execute |
required | |
params_dict(Dict) |
the query parameters to apply (if any) |
required | |
endpoint_name(str) |
the endpoint where to the excute the query |
required | |
limit(int) |
the record limit for the results (if any) |
required | |
with_stats(bool) |
if True run the stats |
required | |
prefix_merger |
QueryPrefixMerger
|
prefix merger to use |
SIMPLE_MERGER
|
Source code in snapquery/snapquery_core.py
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 |
|
from_samples(db_path=None, force_init=False, with_backup=True, debug=False)
classmethod
Creates and returns an instance of NamedQueryManager, optionally initializing it from sample data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_path |
Optional[str]
|
Path to the database file. If None, the default path is used. |
None
|
force_init |
bool
|
If True, the existing database file is dropped and recreated, and backed up if with_backup is True. |
False
|
with_backup |
bool
|
If True and force_init is True, moves the database file to a backup location before reinitialization. |
True
|
debug |
bool
|
If True, enables debug mode which may provide additional logging. |
False
|
Returns:
Name | Type | Description |
---|---|---|
NamedQueryManager |
NamedQueryManager
|
An instance of the manager initialized with the database at |
Source code in snapquery/snapquery_core.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
|
get_all_queries(namespace='snapquery-examples', domain='wikidata.org', limit=None)
Retrieves named queries stored in the database, filtered by domain and namespace with pattern matching. Optionally limits the number of results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace |
str
|
Namespace filter, supports wildcard '%', e.g., 'example%' for partial matches. |
'snapquery-examples'
|
domain |
str
|
Domain filter, supports wildcard '%', e.g., 'wikidata%' for partial matches. |
'wikidata.org'
|
limit |
int
|
Maximum number of NamedQueries to retrieve, defaults to None for unlimited. |
None
|
Returns:
Type | Description |
---|---|
List[NamedQuery]
|
List[NamedQuery]: A list of NamedQuery instances in the database. |
Source code in snapquery/snapquery_core.py
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 |
|
get_entity_info(source_class)
Gets or creates EntityInfo for the given source class.
Source code in snapquery/snapquery_core.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
|
get_namespaces()
Retrieves all unique namespaces and the count of NamedQueries associated with each from the database, sorted by the count of queries from lowest to highest.
Returns:
Type | Description |
---|---|
Dict[str, int]
|
Dict[str, int]: A dictionary where keys are namespaces and values are the counts of associated queries, sorted by count. |
Source code in snapquery/snapquery_core.py
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 |
|
get_query(query_name, endpoint_name='wikidata', limit=None, prefix_merger=QueryPrefixMerger.SIMPLE_MERGER)
Get the query for the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_name |
QueryName
|
(QueryName):a structured query name |
required |
endpoint_name |
str
|
The name of the endpoint to send the SPARQL query to, default is 'wikidata'. |
'wikidata'
|
limit |
int
|
The query limit (if any). |
None
|
prefix_merger |
QueryPrefixMerger
|
Prefix merger to use |
SIMPLE_MERGER
|
Returns: QueryBundle: named_query, query, and endpoint.
Source code in snapquery/snapquery_core.py
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
|
get_query_stats(query_id)
Get query stats for the given query name Args: query_id: id of the query
Returns:
Type | Description |
---|---|
list[QueryStats]
|
list of query stats |
Source code in snapquery/snapquery_core.py
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 |
|
get_query_stats_by_context(context)
Get query stats for the given query name Args: query_id: id of the query
Returns:
Type | Description |
---|---|
list[QueryStats]
|
list of query stats |
Source code in snapquery/snapquery_core.py
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
|
get_sample_records(source_class)
classmethod
Generates a list of dictionary records based on the sample instances
provided by a source class. This method utilizes the get_samples
method
of the source class, which should return a dictionary of sample instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_class |
Type
|
The class from which to fetch sample instances.
This class must implement a |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A list of dictionaries where each dictionary is a record that corresponds to a sample instance from the source class. |
Raises:
Type | Description |
---|---|
AttributeError
|
If the source_class does not have a |
Source code in snapquery/snapquery_core.py
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
|
lookup(query_name, lenient=True)
lookup the named query for the given structured query name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_name(QueryName) |
the structured query name |
required | |
lenient(bool) |
if True handle multiple entry errors as warnings |
required |
Returns: NamedQuery: the named query
Source code in snapquery/snapquery_core.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
|
store(lod, source_class=NamedQuery, with_create=False)
Stores the given list of dictionaries in the database using entity information derived from a specified source class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lod |
List[Dict[str, Any]]
|
List of dictionaries that represent the records to be stored. |
required |
source_class |
Type
|
The class from which the entity information is derived. This class
should have an attribute or method that defines its primary key and must have a |
NamedQuery
|
Raises: AttributeError: If the source class does not have the necessary method or attribute to define the primary key.
Source code in snapquery/snapquery_core.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 |
|
store_endpoints(endpoints=None)
Stores the given endpoints or self.endpoints into the SQL database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoints |
Optional[Dict[str, LODStorageEndpoint]]
|
A dictionary of endpoints to store. If None, uses self.endpoints. |
None
|
Source code in snapquery/snapquery_core.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
|
store_graphs(gm=None)
Stores all graphs managed by the given GraphManager into my SQL database
Source code in snapquery/snapquery_core.py
849 850 851 852 853 854 855 856 857 858 859 |
|
store_named_query_list(nq_set)
store the given named query set
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nq_list |
NamedQueryList |
required |
Source code in snapquery/snapquery_core.py
813 814 815 816 817 818 819 820 821 822 823 |
|
store_query_details_list(qd_list)
Stores a list of QueryDetails instances into the database. This function converts each QueryDetails instance into a dictionary and then stores the entire list of dictionaries. It utilizes the 'store' method to handle database operations based on the entity information derived from the QueryDetails class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qd_list |
List[QueryDetails]
|
List of QueryDetails instances to be stored. |
required |
Source code in snapquery/snapquery_core.py
825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
|
store_stats(stats_list)
store the given list of query statistics
Source code in snapquery/snapquery_core.py
840 841 842 843 844 845 846 847 |
|
NamedQuerySet
a list/set of named queries which defines a namespace
Source code in snapquery/snapquery_core.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
__post_init__()
Initialize the dictionary after the object is created
Source code in snapquery/snapquery_core.py
483 484 485 486 487 |
|
add(query)
Add a query to both the list and dictionary
Source code in snapquery/snapquery_core.py
489 490 491 492 493 494 495 |
|
QueryBundle
Bundles a named query, a query, and an endpoint into a single manageable object, facilitating the execution of SPARQL queries.
Attributes:
Name | Type | Description |
---|---|---|
named_query |
NamedQuery
|
The named query object, which includes metadata about the query. |
query |
Query
|
The actual query object that contains the SPARQL query string. |
endpoint |
Endpoint
|
The endpoint object where the SPARQL query should be executed. |
sparql |
SPARQL
|
A SPARQL service object initialized with the endpoint URL. |
Source code in snapquery/snapquery_core.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
__init__(named_query, query, endpoint=None)
Initializes a new instance of the QueryBundle class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
named_query |
NamedQuery
|
An instance of NamedQuery that provides a named reference to the query. |
required |
query |
Query
|
An instance of Query containing the SPARQL query string. |
required |
endpoint |
Endpoint
|
An instance of Endpoint representing the SPARQL endpoint URL. |
None
|
Source code in snapquery/snapquery_core.py
508 509 510 511 512 513 514 515 516 517 518 519 |
|
format_result(qlod=None, r_format=Format.json)
Formats the query results based on the specified format and prints them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qlod |
List[Dict[str, Any]]
|
The list of dictionaries that represent the query results. |
None
|
query |
Query
|
The query object which contains details like the endpoint and the database. |
required |
r_format |
Format
|
The format in which to print the results. |
json
|
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The formatted string representation of the query results, or None if printed directly. |
Source code in snapquery/snapquery_core.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
get_lod()
Executes the stored query using the SPARQL service and returns the results as a list of dictionaries.
Returns:
Type | Description |
---|---|
List[dict]
|
List[dict]: A list where each dictionary represents a row of results from the SPARQL query. |
Source code in snapquery/snapquery_core.py
556 557 558 559 560 561 562 563 564 |
|
get_lod_with_stats()
Executes the stored query using the SPARQL service and returns the results as a list of dictionaries.
Returns:
Type | Description |
---|---|
tuple[list[dict], QueryStats]
|
List[dict]: A list where each dictionary represents a row of results from the SPARQL query. |
Source code in snapquery/snapquery_core.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
|
raw_query(resultFormat, mime_type=None, timeout=10.0)
returns raw result of the endpoint
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resultFormat |
str
|
format of the result |
required |
mime_type |
str
|
mime_type to use (if any) |
None
|
timeout |
float
|
timeout in seconds |
10.0
|
Returns:
Type | Description |
---|---|
raw result of the query |
Source code in snapquery/snapquery_core.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|
set_limit(limit=None)
set the limit of my query
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit(int) |
the limit to set - default: None |
required |
Source code in snapquery/snapquery_core.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
QueryDetails
Details for a named query
Source code in snapquery/snapquery_core.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
from_sparql(query_id, sparql)
classmethod
Creates an instance of QueryDetails from a SPARQL query string.
This method parses the SPARQL query to determine the number of lines and the size of the query. It also identifies and lists the parameters used within the SPARQL query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_id |
str
|
The identifier of the query. |
required |
sparql |
str
|
The SPARQL query string from which to generate the query details. |
required |
Returns:
Name | Type | Description |
---|---|---|
QueryDetails |
QueryDetails
|
An instance containing details about the SPARQL query. |
Source code in snapquery/snapquery_core.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
get_samples()
classmethod
get samples
Source code in snapquery/snapquery_core.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
QueryName
A structured query name with a fully qualifying query id that is URL-friendly Attributes: domain(str): the domain of the owner of this namespace namespace (str): The namespace of the query, which helps in categorizing the query. name (str): The unique name or identifier of the query within its namespace. query_id(str): encoded id e.g. cats--examples@wikidata.org
Source code in snapquery/snapquery_core.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
from_query_id(query_id, namespace='examples', domain='wikidata.org')
classmethod
Parse a URL-friendly query_id string into a QueryName object. Args: query_id (str): The URL-friendly query_id string to parse. namespace (str): Default namespace if not specified in query_id domain (str): Default domain if not specified in query_id Returns: QueryName: A QueryName object containing name, namespace, and domain.
Source code in snapquery/snapquery_core.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
get_query_id(name, namespace, domain)
classmethod
Generate a URL-friendly query_id
Source code in snapquery/snapquery_core.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
to_dict()
Convert the QueryName object to a dictionary
Source code in snapquery/snapquery_core.py
228 229 230 231 232 233 234 235 236 237 |
|
QueryNameSet
Manages a set of QueryNames filtered by domain and namespaces SQL like patterns
Attributes:
nqm (NamedQueryManager): A manager to handle named queries and interactions with the database.
limit(int): the maximum number of names and top_queries
Calculated on update
total (int): Total number of queries that match the current filter criteria. domains (set): A set of domains that match the current filter criteria. namespaces (set): A set of namespaces that match the current filter criteria. names (set): A set of names that match the current filter criteria. top_queries (list): List of top queries based on the specified limit.
Source code in snapquery/snapquery_core.py
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 |
|
update(domain, namespace, limit=None)
update my attributes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain |
str
|
The domain part of the filter, supports SQL-like wildcards. |
required |
namespace |
str
|
The namespace part of the filter, supports SQL-like wildcards. |
required |
limit |
int
|
Maximum number of queries to fetch. If None, no limit is applied. |
None
|
Source code in snapquery/snapquery_core.py
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 |
|
QueryPrefixMerger
Bases: Enum
SPARQL Query prefix merger
Source code in snapquery/snapquery_core.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
|
analysis_prefix_merger(query_str)
classmethod
Analysis prefix merger Args: query_str
Returns:
Type | Description |
---|---|
str
|
merged query |
Source code in snapquery/snapquery_core.py
697 698 699 700 701 702 703 704 705 706 707 708 |
|
merge_prefixes(named_query, query, endpoint, merger)
classmethod
Merge prefixes with the given merger Args: named_query (NamedQuery): query (Query): endpoint (Endpoint): merger (QueryPrefixMerger):
Returns:
Type | Description |
---|---|
str
|
merged query |
Source code in snapquery/snapquery_core.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
|
simple_prefix_merger(query_str, endpoint)
classmethod
Simple prefix merger Args: query_str (str): the query string endpoint (Endpoint): the endpoint
Returns:
Type | Description |
---|---|
str
|
merged query |
Source code in snapquery/snapquery_core.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
|
QueryStats
statistics about a query
Source code in snapquery/snapquery_core.py
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 |
|
__post_init__()
Post-initialization processing to construct a unique identifier for the query and record the timestamp when the query stats object is created.
Source code in snapquery/snapquery_core.py
55 56 57 58 59 60 61 |
|
apply_error_filter(for_html=False)
Applies an error filter to the error message and sets the filtered message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
for_html |
bool
|
If True, formats the message for HTML output. |
False
|
Returns:
Name | Type | Description |
---|---|---|
ErrorFilter |
ErrorFilter
|
the error filter that has been applied |
Source code in snapquery/snapquery_core.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
as_record()
convert my declared attributes to a dict @TODO may be use asdict from dataclasses instead?
Source code in snapquery/snapquery_core.py
111 112 113 114 115 116 117 118 119 120 121 |
|
done()
Set the duration by calculating the elapsed time since the time_stamp
.
Source code in snapquery/snapquery_core.py
63 64 65 66 67 |
|
error(ex)
Handle exception of query
Source code in snapquery/snapquery_core.py
84 85 86 87 88 89 90 |
|
from_record(record)
classmethod
Class method to instantiate NamedQuery from a dictionary record.
Source code in snapquery/snapquery_core.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
get_samples()
classmethod
get samples for QueryStats
Source code in snapquery/snapquery_core.py
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 |
|
is_successful()
Returns True if the query was successful
Source code in snapquery/snapquery_core.py
156 157 158 159 160 |
|
QueryStatsList
a list of query statistics
Source code in snapquery/snapquery_core.py
458 459 460 461 462 463 464 465 |
|
snapquery_view
Created on 2024-05-03
@author: wf
NamedQuerySearch
Bases: BaseQueryView
search for namedqueries
Source code in snapquery/snapquery_view.py
233 234 235 236 237 238 239 |
|
NamedQueryView
display a named Query
Source code in snapquery/snapquery_view.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
load_query_results()
async
(re) load the query results
Source code in snapquery/snapquery_view.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
load_stats()
display query stats
Source code in snapquery/snapquery_view.py
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 |
|
run_query(_args)
async
run the current query
Source code in snapquery/snapquery_view.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
setup_ui()
setup my user interface
Source code in snapquery/snapquery_view.py
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 |
|
snapquery_webserver
Created on 2024-05-03 @author: wf
SnapQuerySolution
Bases: InputWebSolution
the Snap Query solution
Source code in snapquery/snapquery_webserver.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
__init__(webserver, client)
Initialize the solution
Calls the constructor of the base solution Args: webserver (SnapQueryWebServer): The webserver instance associated with this context. client (Client): The client instance this context is associated with.
Source code in snapquery/snapquery_webserver.py
286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
admin_ui()
async
admin ui
Source code in snapquery/snapquery_webserver.py
386 387 388 389 390 391 392 393 394 395 |
|
configure_settings()
add additional settings
Source code in snapquery/snapquery_webserver.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
get_user_endpoint()
staticmethod
Get the endpoint selected by the user. If no endpoint is selected return the default endpoint wikidata
Source code in snapquery/snapquery_webserver.py
453 454 455 456 457 458 459 |
|
get_user_prefix_merger()
staticmethod
Get the prefix merger selected by the user. If no merger is selected the default merger Simple merger is used
Source code in snapquery/snapquery_webserver.py
461 462 463 464 465 466 467 468 469 470 |
|
home()
async
Generates the home page
Source code in snapquery/snapquery_webserver.py
420 421 422 423 424 |
|
login_ui()
async
login ui
Source code in snapquery/snapquery_webserver.py
397 398 399 400 401 |
|
nominate_ui()
async
nominate a new query
Source code in snapquery/snapquery_webserver.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
setup_menu(detailed=True)
setup the menu
Source code in snapquery/snapquery_webserver.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
setup_ui()
setup my user interface
Source code in snapquery/snapquery_webserver.py
414 415 416 417 418 |
|
stats_ui()
async
stats ui
Source code in snapquery/snapquery_webserver.py
403 404 405 406 407 408 409 410 411 412 |
|
SnapQueryWebServer
Bases: InputWebserver
server to supply named Queries
Source code in snapquery/snapquery_webserver.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
__init__()
Constructs all the necessary attributes for the WebServer object.
Source code in snapquery/snapquery_webserver.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
authenticated()
Check if the user is authenticated. Returns: True if the user is authenticated, False otherwise.
Source code in snapquery/snapquery_webserver.py
272 273 274 275 276 277 278 |
|
get_config()
classmethod
get the configuration for this Webserver
Source code in snapquery/snapquery_webserver.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
get_r_format(name, default_format_str='html')
get the result format from the given query name following the
dot convention that
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the query/meta query |
required |
default_format_str |
str
|
the name of the default format to use |
'html'
|
Returns:
Name | Type | Description |
---|---|---|
Format |
Format
|
the result format |
Source code in snapquery/snapquery_webserver.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
query(name, namespace, domain, endpoint_name='wikidata', limit=None)
Queries an external API to retrieve data based on a given namespace and name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name identifier of the data to be queried. |
required |
namespace |
str
|
The namespace to which the query belongs. It helps in categorizing the data. |
required |
domain |
str
|
The domain identifying the domain of the query. |
required |
endpoint_name |
str
|
The name of the endpoint to be used for the query. Defaults to 'wikidata'. |
'wikidata'
|
limit |
int
|
the limit for the query default: None |
None
|
Returns |
str: the content retrieved |
required |
Source code in snapquery/snapquery_webserver.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
sparql_analyzer
SparqlAnalyzer
SPARQL Query Analyzer
Source code in snapquery/sparql_analyzer.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
add_missing_prefixes(query)
classmethod
Add missing prefixes to SPARQL query Args: query: SPARQL query
Returns:
Type | Description |
---|---|
SPARQL query |
Source code in snapquery/sparql_analyzer.py
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 |
|
bind_parameters_to_query(query, params)
classmethod
Bind the parameters to the given query Args: query: SPARQL query params: quera params
Returns:
Type | Description |
---|---|
str
|
Query with parameters binded |
Source code in snapquery/sparql_analyzer.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
extract_used_prefixes(query)
classmethod
Extract used prefixes from SPARQL query Args: query: SPARQL query
Returns:
Type | Description |
---|---|
tuple[dict[str, str], set[str]]
|
dict of declared prefixes |
Source code in snapquery/sparql_analyzer.py
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 |
|
fill_with_sample_query_parameters(query)
classmethod
Fill the given SPARQL query with sample query parameters Args: query: SPARQL query
Returns:
Source code in snapquery/sparql_analyzer.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
has_blazegraph_with_clause(query)
classmethod
Check if the given query has a WITH clause (named subquery) For details see https://github.com/blazegraph/database/wiki/NamedSubquery Args: query: SPARQL query
Returns:
Type | Description |
---|---|
bool
|
True if the query has a WITH clause (named subquery) |
Source code in snapquery/sparql_analyzer.py
197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
has_parameter(query)
classmethod
Check if the given query has parameters that need to need set Args: query: SPARQL query
Returns:
Type | Description |
---|---|
bool
|
True if the query has parameters that need to need set |
Source code in snapquery/sparql_analyzer.py
226 227 228 229 230 231 232 233 234 235 236 237 |
|
is_valid(query)
classmethod
Check if query is valid SPARQL query Args: query: SPARQL query
Returns:
Type | Description |
---|---|
True if query is valid SPARQL query |
Source code in snapquery/sparql_analyzer.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
prefix_clause(prefix, iri)
classmethod
Provide SPARQL refix clause for given prefix and url Args: prefix: prefix name iri: iri
Returns:
Type | Description |
---|---|
str
|
prefix clause |
Source code in snapquery/sparql_analyzer.py
79 80 81 82 83 84 85 86 87 88 89 90 |
|
transform_with_clause_to_subquery(query)
classmethod
Transform blazegraph with clause to subquery statement Args: query:
Returns:
Source code in snapquery/sparql_analyzer.py
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 |
|
stats_view
QueryStatsView
display Query Import UI
Source code in snapquery/stats_view.py
8 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 |
|
setup_ui()
setup the user interface
Source code in snapquery/stats_view.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
show_entity_usage()
show entity usage in the queries
Source code in snapquery/stats_view.py
35 36 37 38 39 40 41 42 43 44 |
|
show_property_usage()
show property usage in the queries
Source code in snapquery/stats_view.py
46 47 48 49 50 51 52 53 54 55 |
|
version
Created on 2024-05-01
@author: wf
Version
dataclass
Version handling for nicepdf
Source code in snapquery/version.py
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 |
|
wd_page_query_extractor
Created on 2024-05-04 Author: tholzheim
WikipediaQueryExtractor
A class to handle the extraction and management of SPARQL queries from a Wikipedia page.
Source code in snapquery/wd_page_query_extractor.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
__init__(nqm, base_url, domain, namespace, target_graph_name, template_name='SPARQL', debug=False)
Constructor
Source code in snapquery/wd_page_query_extractor.py
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 |
|
extract_queries(wikitext=None)
Extract all queries from the base_url page.
Source code in snapquery/wd_page_query_extractor.py
202 203 204 205 206 207 208 209 210 |
|
extract_queries_from_section(section)
Extract named queries from section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
section |
Section
|
Wikitext section containing a SPARQL query. |
required |
Source code in snapquery/wd_page_query_extractor.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
extract_query_from_wiki_markup(title, markup, sparql, url=None)
Extracts a named query from wiki markup.
This method processes the title, markup, and SPARQL query to create a NamedQuery object. It sanitizes the text, removes section headers from the description, and constructs a URL that points to the specific section of the Wikipedia page.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
The title of the query section. |
required |
markup |
str
|
The wiki markup text containing the query description. |
required |
sparql |
str
|
The SPARQL query string. |
required |
url(str) |
the url to assign - if not given derive from base_url and section title |
required |
Returns:
Name | Type | Description |
---|---|---|
NamedQuery |
NamedQuery
|
A NamedQuery object containing the processed information. |
Note
The method sanitizes the title and description, removes section headers from the description, and constructs a URL with a section anchor based on the title.
Source code in snapquery/wd_page_query_extractor.py
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 |
|
get_template(templates)
Get template from the list of templates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
templates |
list[Template]
|
List of Wikitext templates. |
required |
Returns:
Name | Type | Description |
---|---|---|
Template |
Template
|
template if available, otherwise None. |
Source code in snapquery/wd_page_query_extractor.py
189 190 191 192 193 194 195 196 197 198 199 200 |
|
get_wikitext()
Get wiki text with SPARQL query examples.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Raw wikitext of the page. |
Source code in snapquery/wd_page_query_extractor.py
60 61 62 63 64 65 66 67 68 |
|
sanitize_text(text)
General method to sanitize text by removing translation tags, comments, and other non-essential markup.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to be sanitized. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The sanitized text. |
Source code in snapquery/wd_page_query_extractor.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
save_to_json(file_path)
Save the NamedQueryList to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to the JSON file. |
required |
Source code in snapquery/wd_page_query_extractor.py
212 213 214 215 216 217 218 219 |
|
store_queries()
Store the named queries into the database.
Source code in snapquery/wd_page_query_extractor.py
221 222 223 224 225 |
|
wd_short_url
Created on 2024-05-12
@author: wf
ShortIds
short id handling
Source code in snapquery/wd_short_url.py
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 |
|
get_random(k=4)
get a random short id
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
a random short id |
Source code in snapquery/wd_short_url.py
46 47 48 49 50 51 52 53 54 |
|
id_to_int(id_str)
Convert an ID string to an integer using my base character set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_str |
str
|
The custom ID string to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The converted integer value. |
Source code in snapquery/wd_short_url.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
ShortUrl
Handles operations related to wikidata and similar short URLs such as QLever. see https://meta.wikimedia.org/wiki/Wikimedia_URL_Shortener for
Source code in snapquery/wd_short_url.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
name
property
Extracts and returns the name part of the short URL.
Returns:
Name | Type | Description |
---|---|---|
str |
The name part of the short URL. |
__init__(short_url, scheme='https', netloc='query.wikidata.org')
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
short_url |
str
|
The URL to be processed. |
required |
scheme |
str
|
URL scheme to be used (e.g., 'https' or 'http') for validating URL format. |
'https'
|
netloc |
str
|
Network location part of the URL, typically the domain name, to be used for validating URL format. |
'query.wikidata.org'
|
Source code in snapquery/wd_short_url.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
fetch_final_url()
Follow the redirection to get the final URL with rate limiting.
Returns:
Name | Type | Description |
---|---|---|
str |
The final URL after redirection. |
Source code in snapquery/wd_short_url.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
get_random_query_list(namespace, count, max_postfix='9pfu', with_llm=False, with_progress=False, debug=False)
classmethod
Read a specified number of random queries from a list of short URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace(str) |
the name to use for the named query list |
required | |
count |
int
|
Number of random URLs to fetch. |
required |
max_postfix(str) |
the maximum ID to try |
required | |
with_progress(bool) |
if True show progress |
required |
Returns:
Name | Type | Description |
---|---|---|
NamedQueryList |
NamedQuerySet
|
A NamedQueryList containing the queries read from the URLs. |
Source code in snapquery/wd_short_url.py
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 198 199 200 201 202 203 204 205 206 207 |
|
read_query()
Read a query from a short URL.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The SPARQL query extracted from the short URL. |
Source code in snapquery/wd_short_url.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|