Changes between Version 21 and Version 22 of SemanticQuery


Ignore:
Timestamp:
Sep 17, 2014, 4:41:18 PM (10 years ago)
Author:
manualwiki
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SemanticQuery

    v21 v22  
    2121semantic_query    ::= initial_selection ['.' query_sequence] 
    2222query_sequence    ::= query ['.' query_sequence] 
    23 query             ::= selection | iteration | closure | property_query 
     23query             ::= selection | iteration | closure | property_query | set_op_query 
    2424initial_selection ::= initial_selector ['[' filter ']'] 
    2525selection         ::= selector ['[' filter ']'] 
     
    2828                      '(' query_sequence ')+' ['[' filter ']'] 
    2929property_query    ::= property ['[' filter ']'] 
     30set_op_query      ::= '(' (query_sequence | semantic_query) set_op (query_sequence | semantic_query) ')' 
     31set_op            ::= union | minus | intersect 
    3032}}} 
    3133 
     
    3739* closure (calculates the transitive closure of a query sequence) 
    3840* property query (selects a property of an entity) 
     41* set_op query (combines the results of two queries by the given set operator) 
    3942 
    4043== Language elements == 
     
    8487 
    8588Atoms, strings, integers and properties can be used in comparisons.  
    86 The language uses {{{/=, ==, >=, =<, <, >, ~}}} and {{{in}}}.  
     89The language uses {{{/=, ==, >=, =<, <, >}}} and {{{~}}}.  
    8790The results of comparisons are the same as in Erlang.  
    8891The resulting expressions can be combined by {{{and}}}, {{{or}}}, and {{{not}}} operators, and parentheses can be used, too.  
    8992The {{{~}}} operator is a regular expression matching operator, and it can be used anywhere, 
    90 where other binary comparison operators can be used. The same expressions can be used, which can be used in the {{{re}}} module. 
    91 The {{{in}}} operator is similar to the {{{in}}} operator defined in SQL. To illustrate its usage, consider the following 2 semantic queries, 
    92 which are semantically equivalent with each other. 
    93  * mods.funs[name = a or name = b or name = c] 
    94  * mods.funs[name in |a,b,c|] 
     93 where other binary comparison operators can be used. The same expressions can be used, which can be used in the {{{re}}} module. 
    9594 
    9695The operator precedence for the filters is as follows: 
     
    9998||{{{not}}} ||unary ||  
    10099||{{{/=, ==, >=, =<, <, >, =:=, =/=, ~}}} ||left associative ||  
    101 ||{{{in}}} ||left associative || 
    102100||{{{and}}} ||left associative || 
    103101||{{{or}}} ||left associative || 
     
    116114}}} 
    117115 
    118 ''Example:'' you may be interested in all the module, whose name equals with one element of the following set : {a,b,c} 
    119 {{{ 
    120 mods[ name in |a,b,c| ] 
    121 }}} 
     116==== Variables ==== 
     117It is possible to bind property value to a variable for later use. All variable name begins with a capital letter, just like erlang variables. 
     118 
     119Usage of variables is only allowed in filters. Variables may only bind to properties. Once bound, a variable can be compared to other properties, variables or literals of the same type using {{{/=, ==, >, <}}} etc. operators. 
     120 
     121''Example:'' to obtain all function that has the same name as its containing module use the following query: 
     122{{{ 
     123mods[name=A].funs[name==A] 
     124}}} 
     125Note that variables' semantics are different compared to erlang. In the example above, the value of variable {{{A}}} changes from module to module. 
     126 
     127More detailed description can be found at [SemanticQuery/Variables Variables]. 
    122128 
    123129==== Embedded queries ==== 
     
    140146}}} 
    141147 
     148===== In, any_in, all_in filters ===== 
     149Entities can also be filtered by in conditions in filters. Their operands can be 
     150lists, embedded queries or semantic queries. 
     151{{{ 
     152filter ::= (list | semantic_query | query_sequence) (all_in|any_in) query_sequence 
     153filter ::= query_sequence (all_in|any_in) (list | semantic_query) 
     154filter ::= (property | query_sequence) in (list | semantic_query) 
     155filter ::= list in (property | query_sequence) 
     156}}} 
     157Any_in will evaluate its operands for every entity selected before the filter and returns true 
     158if there is any value selected by the first operand that can also be found in the second operand's value list. 
     159[[BR]][[BR]] 
     160''any_in:'' 
     161{{{ 
     162mods.funs[.exprs.sub.val all_in (mods.funs--.file.funs).exprs.sub.val] 
     163}}} 
     164The query returns functions with subexpression values which can all be found in other files functions. 
     165[[BR]][[BR]] 
     166''any_in:'' 
     167{{{ 
     168mods.funs[.calls any_in mods[name=m1].funs] 
     169}}} 
     170This query will select every function that calls any function in module "m1". 
     171[[BR]][[BR]] 
     172All_in returns true only if all values of the first operand are also selected by the second operand. 
     173[[BR]][[BR]] 
     174''all_in:'' 
     175{{{ 
     176mods[.funs.calls all_in mods[name=m1].funs]  
     177}}} 
     178The query will yield all modules that only call for m1's functions. 
     179[[BR]][[BR]] 
     180''all_in:'' 
     181{{{ 
     182mods[.funs.name all_in @mod.funs.name]  
     183}}} 
     184Lists all modules whose functions names can also be found in the given module's functions names. 
     185[[BR]][[BR]] 
     186''in:'' 
     187In is mainly for checking if a property value can be found in a list or a semantic query's result. 
     188For properties and lists this operator is symmetrical: "name in |e1, e2, ...|" means the same as "|e1, e2, ...| in name". 
     189{{{ 
     190mods.func[name in mods.funs.exprs.esub.macro_value]  
     191}}} 
     192The query gives back any function whose name has been defined as a macro value. 
     193 
    142194=== Iteration === 
    143195 
     
    170222The result shown after this semantic query is the list of all possible call  
    171223chains starting from a given function. 
     224 
     225=== Set operators === 
     226 
     227Set operators (and their operands) can take the place of query-sequences 
     228or initial selectors. Operands are first evaluated (which can be semantic queries, 
     229 query-sequences or set operators themselves), then the result is calculated based on the given operator. 
     230When the operands are not property-queries their results have to be of the same entity-type 
     231or the operator throws a type-mismatch error. If the operands return properties, but 
     232of different types, they would be converted to strings. Duplicates of the result entities 
     233are filtered.  
     234When the operator is nested or used as a semantic query, the enclosing parentheses can be ommited. 
     235In the former case the evaluation order will be right to left. 
     236 
     237''Example:'' 
     238{{{ 
     239mods[name in |m1, m2|].funs(.calls union .called_by).vars 
     240}}} 
     241The query above will list all variables defined in functions which call or are 
     242called by any functions in modules named "m1" or "m2". 
     243 
     244''Example:'' 
     245{{{ 
     246mods.funs(.calls minus @mod.funs)(.name union .exprs.macro_value)  
     247}}} 
     248This query lists all macro values and names for functions that aren't defined in the given 
     249module and are called by any module in the database. 
     250 
     251== Specifying grouping of results == 
     252 
     253By default the results of queries are grouped by the second to last selector 
     254(unless the result is a statistic or a list of chains). This behavior can be changed 
     255by passing a groupby value to the semantic query (if the used interface supports the options list). 
     256The option {groupby, n} sets the grouping to the n-th query-element(filters are not counted). 
     257 
     258''Example:'' 
     259{{{ 
     260ri:q("mods.funs.vars", [{groupby, 1}]). 
     261}}} 
     262The results from the above example are grouped by the first selector i.e. modules.