예제 #1
0
 def checkUnsafeRule(self, ruleQuery):
     if ruleQuery in ["", "true", "fail", "false"]:
         return False
     
     condition = False
     time_start = time.time()
     ruleSQLQuery = getSQLQuery(ruleQuery, self.open_world)
     self._time_getSQLQuery = self._time_getSQLQuery + time.time() - time_start
     self._stats_getSQLQuery += 1
     
     if ruleSQLQuery == "Query is unsafe":
         getLogger(self._logger).log(9, "Rule unsafe\t\t\t\t\t\t:" + ruleQuery)
         condition = True
         
     return condition
예제 #2
0
 def getConjunctProbability(self, query):
     canonicalQuery, tableList, variableMapping = self.getCanonicalForm(query)
     canonicalSQLQuery = ""
     if canonicalQuery in self.queryDict:        
         canonicalSQLQuery = self.queryDict[canonicalQuery]
     else:
         time_start = time.time()
         canonicalSQLQuery = getSQLQuery(canonicalQuery, self.open_world)
         self._time_getSQLQuery = self._time_getSQLQuery + time.time() - time_start
         self._stats_getSQLQuery += 1
         self.queryDict[canonicalQuery] = canonicalSQLQuery
     
     prob = self.executeCanonicalSQLQuery(canonicalSQLQuery, tableList, variableMapping)
     return prob
     '''
예제 #3
0
 def getQueryProbability(self, query):
     
     #query = "r1(A) v r2(B),r3(C) v r4(D),r5(E),r3(F) v r6(G),r1(H),r7(I)"  #Test
     
     if query in ["", "true"]:
         return 1.0
     '''
     conjunctList = query.split(' v ')
     if len(conjunctList) > 1:
         
         newConjunctList = self.partitionUCQ(query)
         
         unsafe = True
         mainProbability = 1.0
         for conjunct in newConjunctList:
             probability = self.getConjunctProbability(conjunct)
             if probability != None:
                 mainProbability = mainProbability*(1 - probability)
                 unsafe = False
         
         if unsafe == False:
             mainProbability = 1 - mainProbability
         else:
             mainProbability = None
     else:
         mainProbability = self.getConjunctProbability(query)
     
     if  mainProbability < 1e-15:
         mainProbability = 0.0
     return mainProbability
     '''
     canonicalQuery, tableList, variableMapping = self.getCanonicalForm(query)
     canonicalSQLQuery = ""
     if canonicalQuery in self.queryDict:        
         canonicalSQLQuery = self.queryDict[canonicalQuery]
     else:
         time_start = time.time()
         canonicalSQLQuery = getSQLQuery(canonicalQuery, self.open_world)
         self._time_getSQLQuery = self._time_getSQLQuery + time.time() - time_start
         self._stats_getSQLQuery += 1
         self.queryDict[canonicalQuery] = canonicalSQLQuery
     
     prob = self.executeCanonicalSQLQuery(canonicalSQLQuery, tableList, variableMapping)
     return prob
예제 #4
0
    def getQueryProbability(self, query):

        #query = "r1(A) v r2(B),r3(C) v r4(D),r5(E),r3(F) v r6(G),r1(H),r7(I)"  #Test

        if query in ["", "true"]:
            return 1.0
        '''
        conjunctList = query.split(' v ')
        if len(conjunctList) > 1:
            
            newConjunctList = self.partitionUCQ(query)
            
            unsafe = True
            mainProbability = 1.0
            for conjunct in newConjunctList:
                probability = self.getConjunctProbability(conjunct)
                if probability != None:
                    mainProbability = mainProbability*(1 - probability)
                    unsafe = False
            
            if unsafe == False:
                mainProbability = 1 - mainProbability
            else:
                mainProbability = None
        else:
            mainProbability = self.getConjunctProbability(query)
        
        if  mainProbability < 1e-15:
            mainProbability = 0.0
        return mainProbability
        '''
        SQLQuery = getSQLQuery(query, self.open_world)
        self.cursor.execute(SQLQuery)
        output = self.cursor.fetchall()

        if output[0][0] not in ["Failed to parse", None, "Query is unsafe"]:
            if self.open_world:
                prob = 1 - exp(float(output[0][0]))
            else:
                prob = output[0][0]
        return prob