-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom completion queries #10
base: master
Are you sure you want to change the base?
Conversation
910e945
to
2c609bc
Compare
Thank you very much for this pull request. I have played around with it quite a bit now. Overall, it works! I have found a few glitches, which were already in the previous code. See the respective (minor) issues. Here are a few more requests, which are important for using this in practice. They should be relatively simple to implement:
|
Noch eine kleine Bitte:
|
@jbuerklin Not sure whether you got these comments, so trying again with an @ tag |
I got all of them, thank you. I'm a bit busy this week but I will get to it tomorrow. |
|
|
I should have written #18 here instead of opening a separate issue. It's in the same spirit as the new field for suggestions that are always shown and the checkbox should probably be above that field |
Fixed #18 both in master and in this branch. Needs |
Implemented AND and OR, where AND binds stronger than OR |
Added # ELSE # construct and renamed CONNECTED_LINES_EMPTY to CONNECTED_TRIPLES_EMPTY |
Thanks a lot, it's working great so far! Here is another minor bug: In line 349 of backend/static/js/codemirror/modes/sparql/sparql-hint.js, prefixes in word (which is the %CURRENT_WORD% for the templates) are expanded to URL prefixes. However these URL prefixes typically contain dots. The typical use of %CURRENT_WORD% is in a prefix regex filter such as FILTER regex(?variable, "^%CURRENT_WORD"). When %CURRENT_WORD% contains dots, these dots have a special meaning in the regex (they match any character, not only a dot). The matches are usually the same, but it prevents the usage of binary search for prefix search in QLever. Long story short: the . should be escaped. One simple fix that worked for me, was to replace line 349 in backend/static/js/codemirror/modes/sparql/sparql-hint.js as follows. But maybe you have a more principled fix. Note the double escaping of the \
|
Here is another minor issue: The previous version of the UI did not make suggestions when there were no connected triples and no character has been typed yet. In particular, this is the situation at the very beginning of every SPARQL query body. The current version shows suggestions in this situation, but they don't make too much sense. I would suggest to add a checkbox to configure whether one wants suggestions in this situation (if yes, one can control which ones via the # IF ... # directives and with the new variables) or not. |
Added escaping for %CURRENT_WORD%
I'll look into that later |
I added that in cc80048. Needs to be |
Should we merge this branch into master now, or are there any major concerns left? |
…ompletion-queries
…ompletion-queries
We have played around with the templates a lot in the last months. The templates and the template substitution work very well, thank you! Before merging this into the master I have a question about the other fields in the backend configuration and the other modes:
|
Another issue that is maybe related to this PR and maybe deserves a seperate change is the following:
|
Changes Backend settings such that whole queries for autocompletions can be entered from start to end, instead of only defining some blocks that are then filled into predefined
SELECT { ... } GROUP BY
statements.This branch needs a
python manage.py migrate
if you're switching here from master.qleverui.sqlite3
unusable in the master branch.qleverui.sqlite3
before migratingImporting the example settings
In order to get a quick first impression, I advise you to import our example settings by logging in to /admin/, clicking on
Backends
/Examples
/Prefixes
and importing the respective*-sample.csv
file. The example files already implement the new Backend settings.What has changed?
When editing a backend, the three settings
Suggest subjects clause
Suggest predicates clause
Suggest objects clause
now accept whole SPARQL queries as input. These queries will be executed when retrieving completions.
In order to make this work, we needed to introduce some kind of template syntax that would make it possible to factor in the user's current query context for each query.
To explain this syntax, we'll have a look at the
Suggest objects clause
as it is used in the sample settings:1.
%CURRENT_SUBJECT%
,%CURRENT_PREDICATE%
and%CURRENT_WORD%
The current line of the query the user is typing will be split into these placeholders.
Examples:
current line:
?c wdt:P31 coun[cursor]
%CURRENT_SUBJECT%
=?c
%CURRENT_PREDICATE%
=wdt:P31
%CURRENT_WORD%
=coun
current line:
?c inst[cursor]
%CURRENT_SUBJECT%
=?c
%CURRENT_PREDICATE%
=inst
%CURRENT_WORD%
=inst
current line:
?c[cursor]
%CURRENT_SUBJECT%
=?c
%CURRENT_PREDICATE%
=[not defined]
%CURRENT_WORD%
=?c
2.
%<CURRENT_WORD%
Same as
%CURRENT_WORD%
, but prepends a<
if%CURRENT_WORD%
doesn't start with<
or"
Can be helpful in combination with
HAVING
and KBs such as FreebaseEasy where you don't want to always type the<
in order for autocompletion to work.3.
# IF #
,# ELSE #
and# ENDIF #
Can be used to alter the completion query depending on the users current input.
Text inside an
# IF #
or# ELSE #
block will be ignored if the given condition is not satisified.Defining an
# ELSE #
block is optional.IF / ELSE / ENDIF
statements can be nested.4. Conditions
Available conditions for
# IF #
statements are as follows:CURRENT_WORD_EMPTY
: true if the user hasn't startet typing a new wordCURRENT_SUBJECT_VARIABLE
: true if%CURRENT_SUBJECT%
is a variableCURRENT_PREDICATE_VARIABLE
: true if%CURRENT_PREDICATE%
is a variableCONNECTED_TRIPLES_EMPTY
: true if%CONNECTED_TRIPLES%
is emptyThese conditions can be combined into logical expressions of arbitraty length using
OR
- logical or (binds weakest)AND
- logical and (binds stronger than OR)!
- negation (binds stronger than AND)Example:
5.
%PREFIXES%
Inserts the prefix declarations the user has made.
6.
%CONNECTED_TRIPLES%
Inserts the lines of the user's query that are connected to
%CURRENT_WORD%
Further hints
LIMIT
andOFFSET
to limit the result. QLeverUI will do this by itself.SELECT
clause (like above:SELECT ?qleverui_entity [...]
). It does not need to be named?qleverui_entity
though.?qleverui_name
and?qleverui_altname
. Their position in theSELECT
clause does not matter.These last two restrictions will be changed in the future.
What has not changed
All the settings in the
Showing names
category have not been changed. These are now only needed for the tooltips when hovering the mouse over an entity.It stands to question whether they can stay the way they are or need to be changed to be more customizable, too.
The
Alternative [...] name clause
settings are not needed anymore and will be removed later.