rqlrewrite.py
branchreldefsecurity
changeset 3877 7ca53fc72a0a
parent 3826 0c0c051863cb
child 3998 94cc7cad3d2d
equal deleted inserted replaced
3876:1169d3154be6 3877:7ca53fc72a0a
   400         try:
   400         try:
   401             if target == 'object':
   401             if target == 'object':
   402                 orel = self.varinfo['lhs_rels'][sniprel.r_type]
   402                 orel = self.varinfo['lhs_rels'][sniprel.r_type]
   403                 cardindex = 0
   403                 cardindex = 0
   404                 ttypes_func = rschema.objects
   404                 ttypes_func = rschema.objects
   405                 rprop = rschema.rproperty
   405                 rdef = rschema.rdef
   406             else: # target == 'subject':
   406             else: # target == 'subject':
   407                 orel = self.varinfo['rhs_rels'][sniprel.r_type]
   407                 orel = self.varinfo['rhs_rels'][sniprel.r_type]
   408                 cardindex = 1
   408                 cardindex = 1
   409                 ttypes_func = rschema.subjects
   409                 ttypes_func = rschema.subjects
   410                 rprop = lambda x, y, z: rschema.rproperty(y, x, z)
   410                 rdef = lambda x, y: rschema.rdef(y, x)
   411         except KeyError, ex:
   411         except KeyError, ex:
   412             # may be raised by self.varinfo['xhs_rels'][sniprel.r_type]
   412             # may be raised by self.varinfo['xhs_rels'][sniprel.r_type]
   413             return None
   413             return None
   414         # can't share neged relation or relations with different outer join
   414         # can't share neged relation or relations with different outer join
   415         if (orel.neged(strict=True) or sniprel.neged(strict=True)
   415         if (orel.neged(strict=True) or sniprel.neged(strict=True)
   417             return None
   417             return None
   418         # if cardinality is in '?1', we can ignore the snippet relation and use
   418         # if cardinality is in '?1', we can ignore the snippet relation and use
   419         # variable from the original query
   419         # variable from the original query
   420         for etype in self.varinfo['stinfo']['possibletypes']:
   420         for etype in self.varinfo['stinfo']['possibletypes']:
   421             for ttype in ttypes_func(etype):
   421             for ttype in ttypes_func(etype):
   422                 if rprop(etype, ttype, 'cardinality')[cardindex] in '+*':
   422                 if rdef(etype, ttype).cardinality[cardindex] in '+*':
   423                     return None
   423                     return None
   424         return orel
   424         return orel
   425 
   425 
   426     def _use_orig_term(self, snippet_varname, term):
   426     def _use_orig_term(self, snippet_varname, term):
   427         key = (self.current_expr, self.varmap, snippet_varname)
   427         key = (self.current_expr, self.varmap, snippet_varname)