Esempio n. 1
0
    def sim_lex_bk(self,head,dep):  ##similarity based on dependency of words
        ##handle special cases, if some counts are zero, there will be lookup error
        ##Question:::  lowercases????

        ##This is not the Backup version.
        num_c = find_head_dep(self.cache,head,dep)
        if num_c =="empty":
            numerator = dbtool.get_count_head_dep(self.lexdb, head, dep)
            cache_head_dep(self.cache,numerator,head,dep)
        else:
            numerator = num_c

        demon1_c = find_head(self.cache,head)
        if demon1_c == "empty":
            demon1 = dbtool.get_count_head(self.lexdb, head)
            cache_head(self.cache,demon1,head)
        else:
            demon1 = demon1_c

        demon2_c = find_dep(self.cache,dep)
        if demon2_c == "empty":
            demon2 = dbtool.get_count_dep(self.lexdb, dep)
            cache_dep(self.cache,demon2,dep)
        else:
            demon2 = demon2_c

        if (demon1 + demon2) ==0:
            return 0
        else:
            return 1.0* numerator/ (demon1 + demon2)
Esempio n. 2
0
    def sim_pos_ea_bk(self,head,dep,label):  ##similarity based on dependency of words
        num_c = find_head_dep(self.cache,head,dep)
        if num_c =="empty":
            numerator = dbtool.get_count_head_dep(self.posdb, head, dep)
            cache_head_dep(self.cache,numerator,head,dep)
        else:
            numerator = num_c

        demon1_c = find_head(self.cache,head)
        if demon1_c == "empty":
            demon1 = dbtool.get_count_head(self.posdb, head)
            cache_head(self.cache,demon1,head)
        else:
            demon1 = demon1_c

        demon2_c = find_dep(self.cache,dep)
        if demon2_c == "empty":
            demon2 = dbtool.get_count_dep(self.posdb, dep)
            cache_dep(self.cache,demon2,dep)
        else:
            demon2 = demon2_c

        if (demon1 + demon2) ==0:
            return 0
        else:
            return 1.0* numerator/ (demon1 + demon2)