data.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:indefinite-pronouns 作者: dnrb 项目源码 文件源码
def get_tf_associations(self, test):
        # test = {not dissociated,associated}
        tf_set = set()
        # this is the set in which all Term - Function pairs will be contained
        # that cannot be dissociated (i.e, for which we do not know for sure that
        # they are not associated) - done with Fisher Exact tests
        for onto in set(self.ontological):
            if onto not in ['body','thing']: continue
            d_onto = self.data[self.ontological == onto]
            for li in range(30):
                terms = set([w for dd in d_onto for w in dd[li]])
                for term in terms:
                    for annot in set(self.annotation):
                        valid = False
                        if annot == 'UF': continue
                        d_onto_annot = self.data[(self.ontological == onto) * (self.annotation == annot)]
                        aa = len([t for t in d_onto_annot if term in t[li]]) # + term + function
                        ab = len(d_onto_annot) - aa # - term + function
                        ba = len([t for t in d_onto if term in t[li]]) - aa # + term - function
                        bb = len(d_onto) - (aa + ab + ba) # - term - function
                        if test == 'not dissociated' and fisher_exact([[aa,ab],[ba,bb]],'less')[1] > .05:
                            valid = True
                            tf_set.add((li,term,annot))
                        if test == 'associated' and fisher_exact([[aa,ab],[ba,bb]],'greater')[1] < .05:
                            valid = True
                            tf_set.add((li,term,annot))
                        # if aa > 0: print('%s,%d,%s,%s,%r,%d,%d,%d' % (onto,li,term,annot,valid,aa,ba,ab))
        return tf_set
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号