lib/trait_bank/stats.rb
# Add query part to match the ancestor object Terms to return from the query, and return Array of the labels of said objects
Add query part to match the ancestor object Terms to return from the query, and return Array of the labels of said objects
Add query part to match the ancestor object Terms to return from the query and return Array of the labels of said objects
def sankey_add_match_anc_objs_part(query_parts, obj_var_pairs)
        anc_obj_vars = Array.new(obj_var_pairs.length)
        anc_matches = obj_var_pairs.map.with_index do |pair, i|
          anc_obj_var = "anc_obj#{i}"
          anc_obj_vars[i] = anc_obj_var
          if pair[:tgt_obj]
            "OPTIONAL MATCH (#{pair[:obj]})-[#{PARENT_TERMS}]->(#{anc_obj_var}:Term)\nWHERE (#{anc_obj_var})-[:parent_term]->(#{pair[:tgt_obj]})"
          else
            "OPTIONAL MATCH (#{pair[:obj]})-[#{PARENT_TERMS}]->(#{anc_obj_var}:Term)\nWHERE NOT (#{anc_obj_var})-[:parent_term|:synonym_of]->(:Term)"
          end
        end
        query_parts << anc_matches.join("\n")
        anc_obj_vars
      end
def sankey_add_match_anc_objs_part ( query_parts , obj_var_pairs ) anc_obj_vars = Array . new ( obj_var_pairs . length ) anc_matches = obj_var_pairs . map . with_index do | pair , i | anc_obj_var = "anc_obj#{i}" anc_obj_vars [ i ] = anc_obj_var if pair [ :tgt_obj ] "OPTIONAL MATCH (#{pair[:obj]})-[#{PARENT_TERMS}]->(#{anc_obj_var}:Term)\nWHERE (#{anc_obj_var})-[:parent_term]->(#{pair[:tgt_obj]})" else "OPTIONAL MATCH (#{pair[:obj]})-[#{PARENT_TERMS}]->(#{anc_obj_var}:Term)\nWHERE NOT (#{anc_obj_var})-[:parent_term|:synonym_of]->(:Term)" end end query_parts << anc_matches . join ( "\n" ) anc_obj_vars end
Add query part to match the ancestor object Terms to return from the query, and return Array of the labels of said objects
Add query part to match the ancestor object Terms to return from the query and return Array of the labels of said objects
# For each row, get the appropriate ancestor(s) of each object. In the case of a filter with an object term, we want the # ancestor(s) that is a child of the object term; in the case of a predicate-only filter, it is the term(s) w/o a parent. # NOTE: using a WHERE here, rather than a single match that also expresses the where condition, makes a significant difference in query performance. # The latter approach results in a query plan that gets all of the children of the tgt_obj (many in the case of a broad Term like Northern Hemisphere), # then does the other half of the query and joins the results. Using a WHERE clause resutls in a SemiApply which filters the results of the OPTIONAL MATCH # one by one using the WHERE clause test. tl;dr: WHERE results in going "up" the term hierarchy, and never down, which is better.
query_parts
<not_specific>
obj_var_pairs
<not_specific>