Closed Adrien-H closed 7 years ago
For information, if it can help, this seems to be related to a problem with the autoShow option. When set to true
, the autocompletion pop-in is not triggered after the :
sign. However, when the autocompletion is fired manually with Ctrl + Space
while the cursor is right after the :
, the autocompletion pop-in is correctly displayed.
Hope this helps. I did not dig very deeply in the library's code, though.
Not sure if I completely get the problem. In YASGUI, the prefix declaration autocompletion is set to autoshow. Here, the popup is displayed directly when having typed PREFIX
. I.e. it seems autoshow should work when there are no characters typed yet.
Are you re-using the propertly autocompleter? If so, you might want to check out this line: https://github.com/OpenTriply/YASGUI.YASQE/blob/gh-pages/src/autocompleters/properties.js#L30
If that line is indeed the culprit, you should be able to modify your autocompleter with the properties.js
file as boilerplate, and update it as you see fit
Yep, that's what I used. Let's say my autocompleter configuration looks like this:
// Custom classes
const classes = [
":Ninja", ":Jedi", ":Dinosaur", "schema:Vehicle", "foaf:Agent"
];
YASQE.registerAutocompleter("customClassCompleter", (yasqe) => {
return {
"get": (token, callback) => {
callback(classes);
},
"isValidCompletionPosition": () => {
return YASQE.Autocompleters.classes.isValidCompletionPosition(yasqe);
},
"preProcessToken": (token) => {
return YASQE.Autocompleters.classes.preProcessToken(yasqe, token);
},
"persistent": "rdf_classes",
"async": true,
"bulk": true,
"autoShow": true
}
});
// Custom prefixes
YASQE.Autocompleters._prefixes = YASQE.Autocompleters.prefixes;
YASQE.Autocompleters.prefixes = (yasqe, completerName) => {
let completer = YASQE.Autocompleters._prefixes(yasqe, completerName);
completer.async = true;
completer.bulk = true;
completer.autoShow = true;
completer.get = () => {
return [
": <http://www.foo.org/>",
"foaf: <http://xmlns.com/foaf/0.1/>",
"schema: <http://schema.org/>"
];
},
completer.persistent = "rdf_prefixes";
return completer;
};
// Overriding defaults
YASQE.defaults.autocompleters = ["customPropertyCompleter", "prefixes", "customClassCompleter"];
I skipped the properties configuration and simplified some things in order to keep it simple. As you can see, I don't configure postProcessToken
, since my classes are a list of prefixed IRIs. The properties are configured the same way.
Now in the editor, as you say I have no problem with the PREFIX
position, which works pretty well indeed. I don't think this is related to it. My troubles are more in the query's body itself. Given this query.
PREFIX : <http://www.foo.org/>
CONSTRUCT WHERE {
?s a :_ # _ sign representing my cursor
}
In autoShow: true
mode, the completion pop-in does not trigger automatically after the :
. Tell me if I am wrong somewhere, really that's quite possible and I would be happy to fix my code. But I have to think this is a bug since the feature works well in autoShow: false
when manually pressing Ctrl + Space
.
I did not find an example working on the web. YASGUI uses the autoShow
for the PREFIX
indeed, but not for the classes or properties.
Your autocompleter seems a bit strange, as the class autocompletion entries include your prefixes. I.e., you have a class autocompletion :Ninja
, which actually is http://www.foo.org/Ninja
.
With your setup, and this class autocompleter, if somebody would change the :
prefix to foo:
, then it wouldnt work anymore. This is why the autocompleter assumes a full URI when autocompleting.
In your MWE, if you would remove the line PREFIX : <http://www.foo.org/>
, it would probably work as expected (as YASQE can't expand the prefixed term to an IRI).
You've got two options:
preProcessToken
snippet, and simply return the token instead of calling YASQE.Autocompleters.classes.preProcessToken
. (this function is responsible for expanding a prefixed term to a full iri)
SPARQL specifications allow empty prefixes declarations, such as following:
However, Yasqe does not seem to support empty strings as prefixes during autocomplete.
I based my custom autocompleter upon @LaurensRietveld's work in #120. While not being very beautiful, as pointed by the quoted issue, the solution is functional. Except for the empty prefix case, as said.
Let me detail the problem. Let's say my custom prefixes look like this:
When typing
:
at the right position (predicate for example), thePREFIX : <http://www.foo.org/>
part will be correctly filled. But Yasqe won't be able to suggest the property list since it uses the string before:
for this, which does not exist here.I have three custom autocompleters : properties, classes and prefixes. Hundreds of properties and classes, more than a dozen prefixes, etc. Everything works except the described issue.
Prefixes are defined by the ontology's context and cannot, of course, be modified for this purpose. I have to figure it out in a way or another, can't ninja dodge here. (:
I hope this is clear enough, english is not my native language. Ask me more details if needed.
Adrien H