Blog
RDF and SPARQL - Blog

How to look up a well-known IRI prefix and register a custom one?

How-Tos
Learn how the RDF and SPARQL plugin simplifies the look-up of an IRI prefix and remembers custom prefix declarations for future re-use. It uses the prefix.cc API to look up well-known prefixes.
In RDF Turtle, RDF TriG, ShEx and SPARQL, prefixes are used to write prefixed names as shorthand for longer IRIs (Internationalized Resource Identifiers). For example, schema:name is a shorthand for <https://schema.org/name> .
In all these formats, prefixes are declared with the @prefix keyword or, in the SPARQL case, also with the PREFIX keyword. For example:
@prefix schema: <https://schema.org/> .
or, also in the SPARQL case,
PREFIX schema: <https://schema.org/>

Completion suggestions

There are several situations when the plugin offers completion suggestions for an IRI prefix.
Situation 1: Immediately after typing @prefix or PREFIX.
Situation 2: The caret is placed after @prefix or PREFIX and Ctrl+Space (⌃ Space) is pressed.
There are situations when the plugin doesn't show completion suggestions, but automatically adds a missing prefix declaration to the file.
Situation 3: Immediately after the colon representing a prefixed name, e.g. ex. In this case, the prefix is automatically added to the top of the file without completion suggestions.
Situation 4: Alt+Enter (or ⌥ ⏎) is pressed to show context actions and "Try to lookup prefix URI to declare it" is chosen.

Lookup sources

By default, completion suggestions are based on prefix.cc. However, they can be overridden or new ones added in Settings -> Languages & Frameworks -> RDF and SPARQL -> Prefix Declarations. Right there the lookup with the prefix.cc can be enabled/disabled.
Remember, the plugin settings can be shared with other IDEs, it's applicable also for the prefix declarations. More at Share IDE settings.

Summary

That's it! You now know how to look up the IRI for a prefix in an RDF Turtle, RDF TriG, ShEx or SPARQL file. Remember to use Alt+Enter (or ⌥ ⏎) to check available context actions and Ctrl+Space (or ⌃ Space) to check available completion suggestions.