Trinity adds SPARQL parameters and automatic prefixes

Semiodesk Trinity Our enterprise grade Semantic Web platform just got better: With support for bindable SPARQL parameters and automatic prefix declarations, the new Semiodesk Trinity 0.9.122 release substantially improves the usability and performance of the query API.

Automatic Prefix Declaration

Trinity users will already know the Vocabulary Class Generator feature which allows to use ontology terms directly in source code to support all kind of code completion engines such as IntelliSense in Visual Studio. Based on the ontologies which are defined in the App.config file, the improved SparqlQuery class is now capable of declaring all registered prefixes automatically. This is a booster for developer productivity since it's no longer required to copy and paste prefix declarations from one query to another, which is time consuming and prone to errors. The following example illustrates the use of the new SparqlQuery class. The query uses the W3C PROV ontology and some terms from the Dublin Core Metadata Element Set to retrieve the time range of user activities and the files and websites which were used:
// NOTE: The prefixes used in the query will be declared by the SparqlQuery class.
ISparqlQuery query = new SparqlQuery(@"
   SELECT ?activity ?startTime ?endTime ?title ?description WHERE
   {
      ?activity prov:used ?entity ;
         prov:startedAtTime ?startTime .
         prov:endedAtTime ?endTime .

      ?entity dc:title ?title .

      OPTIONAL { ?entity dc:description ?description . }
   }
   ORDER BY ASC(?startTime)");

ISparqlQueryResult result = Model.ExecuteQuery(query);
The query is parsed once at construction time and all missing prefixes will be declared if they are found in App.config.

SPARQL Parameters

Adding runtime parameters to SPARQL query strings can be tricky: The string concatenation operator does not allow to reuse any parameterized query string with different values and string.Format() quickly leads to a pile of curly braces that is hard to maintain. To address this issue we have introduced bindable SPARQL parameters to our query API: an extension to the SPARQL syntax that allows to define special variables which may be bound to a given value at runtime. The syntax is similar to SqlParameters in Microsoft Entity Framework where a query parameter is preceded by '@'. The parameter value can later be bound to a specific value like in this example:
// NOTE: The parameter '@startTime' will later be bound to today's date.
ISparqlQuery query = new SparqlQuery(@"
   SELECT ?activity WHERE
   {
      ?activity prov:startedAtTime ?startTime .

      FILTER(?startTime > @startTime)
   }
   ORDER BY ASC(?startTime)");

query.Bind("@startTime", DateTime.Today);

ISparqlQueryResult result = Model.ExecuteQuery(query);
The new SparqlQuery class encapsulates a blazing fast StringBuilder that regenerates the query string only when a modified query is actually used. The result is a convenient API with high performance, especially when a query is subsequently executed with different parameter values.

Now Available

The new version of the API has been released by the time of this writing. Start your favourite C# IDE and add the Semiodesk Trinity Core NuGet package to try it now. Please refer to the Trinity website for more information.