View Source

{excerpt}The {{SemanticQuery}} class is the core of the {{QueryAPI}} service. {excerpt}Its main part describes complex, yet formalized, criteria for retrieval of entities (properties {{RequestedVars}}, {{ClassRestrs}}, {{PatternRestrs}}, {{AttributeRestrs}}). Some of the properties control the form in which the results are delivered ({{SortCrits}}, {{GroupVars}}, {{ReturnLabels}}, {{MaxResultLength}}). In addition, some properties set keyword filtering and entity co-occurrence criterion over the document part of the returned {{SemanticQueryResult}} object ({{BoundVars}}, {{KeywordCrits}}).

The semantic queries are based upon a set of variables. They are packed with a set of constraints over the possible values of the variables and a set of semantic relation constraints between them. The result set of semantic queries consists of all sets of entities that can replace the variables, while complying with all preset conditions and relations.

The following properties are included:

||Property||Description||
| {{RequestedVars}} | an array of strings with variable names. These are the variables which values form the final result set.|
| {{BoundVars}} | an array of strings with variable names. These are the variables which values are used for searching relevant documents. For a single row of the semantic result set, only documents containing all entities given by the {{BoundVars}} list can be retrieved.|
| {{ClassRestrs}} | an array of objects of the type {{ClassRestriction}} containing pairs of a variable name {{SubjectVar}} property and an ontology class URI {{ClassUri}} property. This list sets class restrictions over the used variables. Every variable must have a class restriction, otherwise an exception is thrown.|
| {{PatternRestrs}} | an array of objects of the type {{PatternRestriction}} containing triples of a subject variable name {{SubjectVar}} property, an ontology property URI {{PropertyUri}}, and an object variable name {{ObjectVar}}. This list sets semantic relation restrictions over the used variables.|
| {{AttributeRestrs}} | an array of objects of the type {{AttributeRestriction}} containing tuples of a subject variable name {{SubjectVar}}, an ontology property URI {{PropertyUri}}, a compare style constant {{CompareStyle}}, and a string with "literal" value {{ObjectLiteral}}. This list sets textual restrictions over attributes of the used variables.|
| {{KeywordCrits}} | an array of objects of the type {{KeywordCriterion}} containing tuples of a document field name {{Field}}, a string with keyword {{Keyword}}, and a compare style constant {{CompareStyle}}. This list sets textual restrictions over the fields of the relevant documents retrieved for every result set row. Non-compliant documents are not gathered.|
| {{SortCrits}} | an array of objects of the type {{SortCriterion}} containing pairs of a variable name {{SubjectVar}} and a sort style constant {{SortStyle}}. This list sets ordering criterion for the returned result set.|
| {{GroupVars}} | an array of strings with variable names. These are the variables which values are used for grouping the rows of the result set.|
| {{ReturnLabels}} | Boolean flag that determines if the requested entities in {{RequestedVars}} should be returned as pairs of their URIs and their main label. If it is set to "false", only the URIs are returned.|
| {{MaxResultLength}} | integer limiting the number of rows in the returned result set.|

For fields named {{CompareStyle}}, you can use the following constants:

* {{COMPARE_STYLE_IS_EXACTLY}}
* {{COMPARE_STYLE_STARTS_WITH}}
* {{COMPARE_STYLE_ENDS_WITH}}
* {{COMPARE_STYLE_CONTAINS}}

For fields named {{SortStyle}}, you can use the following constants:

* {{SORT_URI_ASCv'''}}
{{* '''\[@SORT_URI_DESC}}
* {{SORT_URI_DESC}}
* {{SORT_LABEL_ASC}}
* {{SORT_LABEL_DESC}}
* {{SORT_NUMBER_ASC}}
* {{SORT_NUMBER_DESC}}

The constants can be obtained through the method {{getConstants}} of {{QueryAPI}} service as a {{QueryConstants}} object.