snapquery API Documentation
authorization
Created on 20.10.2024
@author: wf
Authorization
Authorization check.
Source code in snapquery/authorization.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 52 53 54 | |
check_right_by_orcid(orcid, rights=None)
Check if the user with the given ORCID has rights. Optionally checks for specific rights if provided.
Source code in snapquery/authorization.py
45 46 47 48 49 50 51 52 53 54 | |
load(yaml_path=None)
classmethod
Load user rights from a YAML file, ensuring the file exists.
Source code in snapquery/authorization.py
32 33 34 35 36 37 38 39 40 41 42 43 | |
UserRights
the rights of a single user
Source code in snapquery/authorization.py
14 15 16 17 18 19 20 21 | |
basequeryview
Created on 2024-06-23 @author: wf
BaseQueryView
general search for queries
Source code in snapquery/basequeryview.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 | |
on_search_change(_args=None)
async
react on changes in the search input
Source code in snapquery/basequeryview.py
42 43 44 45 46 | |
perform_search()
async
Performs the search based on the current QuerySelector values qn (query_name) and like (LIKE or =) comparison
Source code in snapquery/basequeryview.py
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 | |
setup_ui()
setup my user interface
Source code in snapquery/basequeryview.py
28 29 30 31 32 33 34 35 36 37 38 39 40 | |
show_lod(q_lod)
show the given list of dicts
Source code in snapquery/basequeryview.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
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
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 | |
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
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 | |
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
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 204 | |
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
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 | |
get_message(for_html=True)
get the filtered message
Source code in snapquery/error_filter.py
195 196 197 198 199 200 201 202 203 204 | |
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 57 58 59 60 61 62 63 | |
__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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
parameterize(nq)
parameterize the given named query see https://github.com/WolfgangFahl/snapquery/issues/33
Source code in snapquery/execution.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
graph
Created on 27.06.2024
@author: wf
Graph
A class representing a graph with its basic properties.
Source code in snapquery/graph.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 | |
__post_init__()
Perform post-initialization processing if needed.
Source code in snapquery/graph.py
26 27 28 29 30 | |
get_samples()
classmethod
get samples for Graph
Source code in snapquery/graph.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
GraphManager
Manages the storage and retrieval of Graph configurations.
Source code in snapquery/graph.py
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 | |
get_graph(name)
Retrieve a graph by name.
Source code in snapquery/graph.py
73 74 75 76 77 | |
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
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 | |
sparql_components
SPARQLFunction
Bases: SparqlComponent
sparql function
Source code in snapquery/models/sparql_components.py
20 21 22 23 | |
SPARQLKeyword
Bases: SparqlComponent
sparql keyword
Source code in snapquery/models/sparql_components.py
26 27 28 29 | |
SPARQLLanguage
Bases: BaseModel
Source code in snapquery/models/sparql_components.py
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 | |
get_function_wd_entity(name)
Get the wikidata entity for a given SPARQL function Args: name: name of the SPARQL keyword
Returns:
| Type | Description |
|---|---|
AnyHttpUrl
|
wikidata entity IRI |
Source code in snapquery/models/sparql_components.py
47 48 49 50 51 52 53 54 55 56 | |
get_keyword_wd_entity(name)
Get the wikidata entity for a given SPARQL keyword Args: name: name of the SPARQL keyword
Returns:
| Type | Description |
|---|---|
AnyHttpUrl
|
wikidata entity IRI |
Source code in snapquery/models/sparql_components.py
36 37 38 39 40 41 42 43 44 45 | |
load_sparql_language()
classmethod
loaf SPARQLLanguage data from cache Returns: SPARQLLanguage
Source code in snapquery/models/sparql_components.py
109 110 111 112 113 114 115 116 117 118 119 | |
load_sparql_language_data_from_wikidata(cache=True)
classmethod
Query the SPARQL language data from wikidata
Source code in snapquery/models/sparql_components.py
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 | |
SparqlComponent
Bases: BaseModel
component of the sparql language
Source code in snapquery/models/sparql_components.py
11 12 13 14 15 16 17 | |
mwlogin
Created on 04.05.2024
@author: wf
Login
login to mediawiki
Source code in snapquery/mwlogin.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 | |
complete_login(response_qs)
Step 3: Complete -- obtain authorized key/secret for "resource owner"
Source code in snapquery/mwlogin.py
38 39 40 41 42 43 | |
identify_user()
Step 4: Identify -- (optional) get identifying information about the user
Source code in snapquery/mwlogin.py
45 46 47 48 49 50 51 52 53 | |
initiate_login()
Step 1: Initialize -- ask MediaWiki for a temporary key/secret for user
Source code in snapquery/mwlogin.py
30 31 32 33 34 35 36 | |
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 170 171 172 173 174 | |
__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 170 171 172 173 174 | |
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
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 | |
__init__(solution, params)
construct me with the given solution and params
Source code in snapquery/params_view.py
16 17 18 19 20 21 | |
close()
hide the details of the dict edit
Source code in snapquery/params_view.py
29 30 31 32 33 | |
get_dict_edit()
Return a DictEdit instance for editing parameters.
Source code in snapquery/params_view.py
35 36 37 38 39 40 41 42 43 44 45 46 47 | |
open()
show the details of the dict edit
Source code in snapquery/params_view.py
23 24 25 26 27 | |
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
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 | |
__init__(solution, selection_callback, limit=10)
Constructor
Source code in snapquery/person_selector.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
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
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
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
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
person_selection()
Display input fields for person data with auto-suggestion
Source code in snapquery/person_selector.py
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 | |
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
248 249 250 251 252 253 254 255 256 257 | |
suggest_persons()
async
Use debouncer to suggest potential persons based on the input.
Source code in snapquery/person_selector.py
179 180 181 182 183 184 | |
update_suggestions_view()
update the suggestions view
Source code in snapquery/person_selector.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
PersonSuggestion
Bases: PersonView
Display a Person
Source code in snapquery/person_selector.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
on_select()
Handle selection of the suggestion card
Source code in snapquery/person_selector.py
86 87 88 89 90 | |
PersonView
Bases: Element
Display a person
Source code in snapquery/person_selector.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 | |
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 131 132 133 134 135 136 137 | |
__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
125 126 127 128 129 130 131 132 133 134 135 136 137 | |
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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
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 100 101 102 103 104 105 106 | |
prefix_merger
Created 2024
@author: tholzheim
Move to separate module in 2025-12-01 by wf
QueryPrefixMerger
Bases: Enum
SPARQL Query prefix merger
Source code in snapquery/prefix_merger.py
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 | |
analysis_prefix_merger(query_str)
classmethod
Analysis prefix merger Args: query_str
Returns:
| Type | Description |
|---|---|
str
|
merged query |
Source code in snapquery/prefix_merger.py
88 89 90 91 92 93 94 95 96 97 98 99 | |
merge_prefixes(query, endpoint, merger)
classmethod
Merge prefixes with the given merger Args: query (Query): endpoint (Endpoint): merger (QueryPrefixMerger):
Returns:
| Type | Description |
|---|---|
str
|
merged query |
Source code in snapquery/prefix_merger.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
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/prefix_merger.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
qimport
Created on 2024-05-05
@author: wf
QueryImport
Import named queries from a given URL or file.
Source code in snapquery/qimport.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 | |
__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
22 23 24 25 26 27 28 29 30 | |
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
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 | |
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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
read_from_short_url(short_url, domain, namespace)
Read and process a single short URL, optionally enriching it with LLM-generated metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
short_url
|
ShortUrl
|
The ShortUrl instance to process |
required |
domain
|
str
|
the domain for the named query |
required |
namespace
|
str
|
the namespace for the named query |
required |
with_llm
|
bool
|
If True, use LLM to generate metadata |
required |
Returns:
| Type | Description |
|---|---|
NamedQuery | None
|
NamedQuery | None: A NamedQuery object if successful, None if processing fails |
Source code in snapquery/qimport.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 | |
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 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 | |
clear_inputs()
clear the inputs
Source code in snapquery/qimport_view.py
141 142 143 144 145 146 147 148 149 150 | |
nominate_ui()
query nomination ui
Source code in snapquery/qimport_view.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
on_import_button(_args)
async
input a query
Source code in snapquery/qimport_view.py
185 186 187 188 189 190 191 192 193 194 195 196 197 | |
on_publish_button(_args)
publish a query
Source code in snapquery/qimport_view.py
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 | |
on_select_person(person=None)
react on a person having been selected
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
person
|
Person
|
the selected Person (if any) |
None
|
Source code in snapquery/qimport_view.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
process_input()
async
Process input in background
Source code in snapquery/qimport_view.py
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 | |
setup_ui_public()
setup the general public user interface common for both users that need to identify and those that are preauthorized
Source code in snapquery/qimport_view.py
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 | |
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
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
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
FunctionStat
contains function information
Source code in snapquery/query_annotate.py
241 242 243 244 245 246 247 248 | |
NamespaceStat
contains namespace information
Source code in snapquery/query_annotate.py
230 231 232 233 234 235 236 237 238 | |
SparqlQueryAnnotater
Annotate a query
Source code in snapquery/query_annotate.py
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 | |
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
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 | |
create_combobox(label, options, width_chars)
Create a ComboBox with the given label, options, and width.
Source code in snapquery/query_selector.py
41 42 43 44 45 46 47 48 49 | |
handle_change()
async
Update self.qn and call the provided on_change callback
Source code in snapquery/query_selector.py
51 52 53 54 55 56 57 58 59 60 61 62 63 | |
setup_ui()
Setup the user interface for query selection using comboboxes.
Source code in snapquery/query_selector.py
31 32 33 34 35 36 37 38 39 | |
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
68 69 70 71 72 73 74 | |
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
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 | |
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
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
getArgParser(description, version_msg)
override the default argparser call
Source code in snapquery/snapquery_cmd.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 | |
handle_args(args)
handle the command line args
Source code in snapquery/snapquery_cmd.py
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 | |
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
224 225 226 227 228 229 230 231 232 233 234 | |
main(argv=None)
main call
Source code in snapquery/snapquery_cmd.py
237 238 239 240 241 242 243 244 245 246 | |
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
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 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 | |
as_link()
get me as a link
Source code in snapquery/snapquery_core.py
330 331 332 333 334 335 336 337 338 | |
as_viewrecord()
Return a dictionary representing the NamedQuery with keys ordered as Name, Namespace, Title, Description.
Source code in snapquery/snapquery_core.py
369 370 371 372 373 374 375 376 377 378 379 380 | |
from_record(record)
classmethod
Class method to instantiate NamedQuery from a dictionary record.
Source code in snapquery/snapquery_core.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
get_samples()
classmethod
get samples
Source code in snapquery/snapquery_core.py
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 | |
NamedQueryManager
Manages the storage, retrieval, and execution of named SPARQL queries.
Source code in snapquery/snapquery_core.py
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 709 710 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 | |
__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
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 | |
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
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
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
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 | |
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
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 | |
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
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 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 | |
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
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 | |
get_entity_info(source_class)
Gets or creates EntityInfo for the given source class.
Source code in snapquery/snapquery_core.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | |
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
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
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
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 | |
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
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 | |
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
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
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
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 | |
get_unique_sets(namespace='snapquery-examples', domain='wikidata.org')
Gets the unique URLs and names for a given domain and namespace
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
str
|
The namespace to get unique sets for |
'snapquery-examples'
|
domain
|
str
|
The domain to get unique sets for |
'wikidata.org'
|
Returns:
| Type | Description |
|---|---|
tuple[set, set]
|
tuple[set, set]: A tuple of (unique URLs, unique names) sets |
Source code in snapquery/snapquery_core.py
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 | |
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
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 | |
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
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | |
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
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
store_graphs(gm=None)
Stores all graphs managed by the given GraphManager into my SQL database
Source code in snapquery/snapquery_core.py
783 784 785 786 787 788 789 790 791 792 793 | |
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
747 748 749 750 751 752 753 754 755 756 757 | |
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
759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
store_stats(stats_list)
store the given list of query statistics
Source code in snapquery/snapquery_core.py
774 775 776 777 778 779 780 781 | |
NamedQuerySet
a list/set of named queries which defines a namespace
Source code in snapquery/snapquery_core.py
467 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 496 497 498 499 500 501 502 503 504 505 | |
__post_init__()
Initialize the dictionary after the object is created
Source code in snapquery/snapquery_core.py
482 483 484 485 486 | |
add(query)
Add a query to both the list and dictionary
Source code in snapquery/snapquery_core.py
488 489 490 491 492 493 494 | |
get_query_by_id(query_id)
Get named query by name Args: query_id: id of the query.
Returns:
| Type | Description |
|---|---|
Union[NamedQuery, None]
|
NamedQuery or None |
Source code in snapquery/snapquery_core.py
496 497 498 499 500 501 502 503 504 505 | |
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
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 632 633 634 635 636 637 638 639 640 641 642 | |
__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
519 520 521 522 523 524 525 526 527 528 529 530 | |
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
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 | |
get_lod(*, param_dict=None)
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
567 568 569 570 571 572 573 574 575 | |
get_lod_with_stats(*, param_dict=None)
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
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
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
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 | |
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
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
QueryDetails
Details for a named query
Source code in snapquery/snapquery_core.py
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 | |
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
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 | |
get_samples()
classmethod
get samples
Source code in snapquery/snapquery_core.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
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
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 | |
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
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 | |
get_query_id(name, namespace, domain)
classmethod
Generate a URL-friendly query_id
Source code in snapquery/snapquery_core.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
to_dict()
Convert the QueryName object to a dictionary
Source code in snapquery/snapquery_core.py
227 228 229 230 231 232 233 234 235 236 | |
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
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 1220 1221 | |
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
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 1220 1221 | |
QueryStats
statistics about a query
Source code in snapquery/snapquery_core.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 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 | |
__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
54 55 56 57 58 59 60 | |
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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
as_record()
convert my declared attributes to a dict @TODO may be use asdict from dataclasses instead?
Source code in snapquery/snapquery_core.py
110 111 112 113 114 115 116 117 118 119 120 | |
done()
Set the duration by calculating the elapsed time since the time_stamp.
Source code in snapquery/snapquery_core.py
62 63 64 65 66 | |
error(ex)
Handle exception of query
Source code in snapquery/snapquery_core.py
83 84 85 86 87 88 89 | |
from_record(record)
classmethod
Class method to instantiate NamedQuery from a dictionary record.
Source code in snapquery/snapquery_core.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
get_samples()
classmethod
get samples for QueryStats
Source code in snapquery/snapquery_core.py
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 | |
is_successful()
Returns True if the query was successful
Source code in snapquery/snapquery_core.py
155 156 157 158 159 | |
QueryStatsList
a list of query statistics
Source code in snapquery/snapquery_core.py
457 458 459 460 461 462 463 464 | |
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
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 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 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
__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
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
admin_ui()
async
admin ui
Source code in snapquery/snapquery_webserver.py
424 425 426 427 428 429 430 431 432 433 434 435 436 | |
configure_settings()
add additional settings
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 | |
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
494 495 496 497 498 499 500 | |
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
502 503 504 505 506 507 508 509 510 511 | |
home()
async
Generates the home page
Source code in snapquery/snapquery_webserver.py
461 462 463 464 465 | |
login_ui()
async
login ui
Source code in snapquery/snapquery_webserver.py
438 439 440 441 442 | |
nominate_ui()
async
nominate a new query
Source code in snapquery/snapquery_webserver.py
410 411 412 413 414 415 416 417 418 419 420 421 422 | |
setup_menu(detailed=True)
setup the menu
Source code in snapquery/snapquery_webserver.py
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 | |
setup_ui()
setup my user interface
Source code in snapquery/snapquery_webserver.py
455 456 457 458 459 | |
stats_ui()
async
stats ui
Source code in snapquery/snapquery_webserver.py
444 445 446 447 448 449 450 451 452 453 | |
SnapQueryWebServer
Bases: InputWebserver
server to supply named Queries
Source code in snapquery/snapquery_webserver.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 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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
__init__()
Constructs all the necessary attributes for the WebServer object.
Source code in snapquery/snapquery_webserver.py
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 | |
authenticated()
Check if the user is authenticated. Returns: True if the user is authenticated, False otherwise.
Source code in snapquery/snapquery_webserver.py
319 320 321 322 323 324 325 | |
get_config()
classmethod
get the configuration for this Webserver
Source code in snapquery/snapquery_webserver.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
get_query_builder(domain, namespace, name, endpoint_name, limit=None)
Get query builder for given parameters.
Source code in snapquery/snapquery_webserver.py
234 235 236 237 238 | |
get_r_format(name, default_format_str='html', request=None, format_param=None)
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'
|
request
|
Request
|
the request object for content negotiation |
None
|
format_param
|
str
|
format override parameter (json, html, yaml, etc.) |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, Format]
|
tuple[str, Format]: the name and result format |
Source code in snapquery/snapquery_webserver.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 | |
query(name, namespace, domain, endpoint_name='wikidata', limit=None, param_dict=None, format=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
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 | |
sparql_analyzer
Created on 2024-05-03 @author: tholzheim
SparqlAnalyzer
SPARQL Query Analyzer
Source code in snapquery/sparql_analyzer.py
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 303 304 305 306 307 308 309 310 | |
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
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 | |
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
267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
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
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 | |
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
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
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
202 203 204 205 206 207 208 209 210 211 212 213 214 | |
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
231 232 233 234 235 236 237 238 239 240 241 242 | |
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
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
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
83 84 85 86 87 88 89 90 91 92 93 94 | |
transform_with_clause_to_subquery(query)
classmethod
Transform blazegraph with clause to subquery statement Args: query: SPARQL query string
Returns:
| Type | Description |
|---|---|
str
|
Transformed query with WITH clause replaced by nested subquery |
Source code in snapquery/sparql_analyzer.py
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 | |
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 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 | |
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 34 35 36 | |
show_entity_usage()
show entity usage in the queries
Source code in snapquery/stats_view.py
38 39 40 41 42 43 44 45 46 47 | |
show_property_usage()
show property usage in the queries
Source code in snapquery/stats_view.py
49 50 51 52 53 54 55 56 57 58 | |
version
Created on 2024-05-01
@author: wf
Version
dataclass
Version handling for snapquery
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 Refactored on 2024-05-22 Author: tholzheim
This module provides the WikipediaQueryExtractor class, which is responsible for parsing MediaWiki page content to extract SPARQL queries. It supports extracting queries from 'short url' blocks (w.wiki) and explicit SPARQL templates.
WikidataQueryExtractor
A class to handle the extraction of SPARQL queries from a Wikidata MediaWiki page content.
It parses the wikitext to find SPARQL queries embedded either via templates
(e.g. {{SPARQL|query=...}}) or via w.wiki short URLs.
Source code in snapquery/wd_page_query_extractor.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 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 | |
__init__(nqm, base_url, domain, namespace, target_graph_name, template_name='SPARQL', debug=False)
Initialize the extractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nqm
|
NamedQueryManager
|
The manager to store/process query names. |
required |
base_url
|
str
|
The URL of the wiki page to extract from. |
required |
domain
|
str
|
The domain of the wiki (e.g., 'wikidata.org'). |
required |
namespace
|
str
|
A logical namespace for the queries (e.g., 'examples'). |
required |
target_graph_name
|
str
|
The target graph identifier. |
required |
template_name
|
Optional[str]
|
The name of the template hosting SPARQL queries. Defaults to "SPARQL". If None, looks for Short URLs. |
'SPARQL'
|
debug
|
bool
|
If True, enables verbose logging to stdout. |
False
|
Source code in snapquery/wd_page_query_extractor.py
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 | |
create_named_query(title, markup, sparql, url=None)
Factory method to create a NamedQuery object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
The title of the query. |
required |
markup
|
str
|
The description text surrounding the query. |
required |
sparql
|
str
|
The actual SPARQL code. |
required |
url
|
Optional[str]
|
The source URL (specific anchor or short URL). Defaults to base_url + anchor if None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
NamedQuery |
NamedQuery
|
The populated query object. |
Source code in snapquery/wd_page_query_extractor.py
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 | |
extract_queries(wikitext=None)
Main entry point for extraction.
Behavior:
1. If wikitext is provided (e.g., from a local file during testing),
it processes that string directly.
2. If wikitext is None, it utilizes the Wikidata() helper to fetch
the content from self.base_url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wikitext
|
Optional[str]
|
Raw wikitext content. If None, fetches from URL. |
None
|
Source code in snapquery/wd_page_query_extractor.py
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 | |
extract_queries_from_section(section)
Process a specific section of the parsed wikitext. If a template_name is defined, it looks for that template. Otherwise, it falls back to looking for short URLs in the plain text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section
|
Section
|
A wikitextparser Section object. |
required |
Source code in snapquery/wd_page_query_extractor.py
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 | |
extract_queries_from_wiki_markup(markup)
Parse raw wiki markup to find 'w.wiki' short URLs, resolve them to get SPARQL, and add them to the query list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markup
|
str
|
The wikimarkup content of a section. |
required |
Source code in snapquery/wd_page_query_extractor.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 | |
get_template(templates)
Filter a list of templates to find the one matching self.template_name.
Source code in snapquery/wd_page_query_extractor.py
215 216 217 218 219 220 | |
log(message, is_error=False)
Log a message to stdout (if debug is True) and to the internal logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to log. |
required |
is_error
|
bool
|
If True, logs as warning and tracks in self.errors. |
False
|
Source code in snapquery/wd_page_query_extractor.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
sanitize_text(text)
Remove translation tags and comments from the text to get clean descriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The raw wikitext snippet. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The sanitized text. |
Source code in snapquery/wd_page_query_extractor.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
save_to_json(file_path)
Serialize the extracted named queries to a JSON file.
Source code in snapquery/wd_page_query_extractor.py
254 255 256 257 258 | |
show_errors()
Debug helper to print runtime errors to stdout.
Source code in snapquery/wd_page_query_extractor.py
274 275 276 277 278 279 280 | |
show_queries()
Debug helper to print extracted queries to stdout.
Source code in snapquery/wd_page_query_extractor.py
266 267 268 269 270 271 272 | |
store_queries()
Store the extracted queries into the main NamedQueryManager instance.
Source code in snapquery/wd_page_query_extractor.py
260 261 262 263 264 | |
wd_short_url
Created on 2024-05-12
@author: wf
ShortIds
short id handling
Source code in snapquery/wd_short_url.py
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 | |
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
49 50 51 52 53 54 55 56 57 | |
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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
ShortUrl
Bases: Wikidata
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
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 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
ask_llm_for_name_and_title(llm, nq, unique_names)
add name, title and description to ghe given query by asking a large language model
Source code in snapquery/wd_short_url.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
get_random_query_list(namespace, count, max_postfix='9pfu', nqm=None, 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 |
|---|---|---|---|
nqm
|
NamedQueryManager
|
optional NamedQueryManager |
None
|
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 |
'9pfu'
|
with_progress
|
bool
|
if True show progress |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
NamedQueryList |
NamedQuerySet
|
A NamedQueryList containing the queries read from the URLs. |
Source code in snapquery/wd_short_url.py
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 | |
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
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
Wikidata
Handles rate-limited access to Wikidata and Wikimedia projects, managing User-Agents and HTTP requests.
Source code in snapquery/wd_short_url.py
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 | |
__init__()
Constructor.
Source code in snapquery/wd_short_url.py
70 71 72 73 74 75 76 | |
fetch_final_url(url)
Follow the redirection to get the final URL with rate limiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The initial URL to fetch. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The final URL after redirection. |
Source code in snapquery/wd_short_url.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
get_user_agent()
classmethod
Constructs a User-Agent string compliant with Wikimedia policy.
Source code in snapquery/wd_short_url.py
79 80 81 82 83 84 85 86 | |
get_wikitext(url)
Get raw wiki text from the configured base_url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The url to fetch. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Raw wikitext of the page. |
Source code in snapquery/wd_short_url.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |