Beispiel #1
0
    def replaceAndShred(self, fact, raw_or_fil, head_or_tail):
        head, rel, tail, years, months, days = fact
        if head_or_tail == "head":
            ret_facts = [(i, rel, tail, years, months, days)
                         for i in range(self.dataset.numEnt())]
        if head_or_tail == "tail":
            ret_facts = [(head, rel, i, years, months, days)
                         for i in range(self.dataset.numEnt())]

        filt = list(set(ret_facts) & self.dataset.all_facts_as_tuples)
        filt = [f[0] if head_or_tail == 'head' else f[2] for f in filt]
        # print(filt)
        # assert False

        if raw_or_fil == "raw":
            ret_facts = [tuple(fact)] + ret_facts
        elif raw_or_fil == "fil":
            ret_facts = [
                tuple(fact)
            ] + list(set(ret_facts) - self.dataset.all_facts_as_tuples)

        heads, rels, tails, years, months, days = shredFacts(
            np.array(ret_facts))

        return heads, rels, tails, years, months, days, filt
Beispiel #2
0
 def replaceAndShred(self,fact,raw_or_fil,head_or_tail):
     head,rel,tail,date=fact
     if head_or_tail == "head":
         ret_facts = [(i, rel, tail, date) for i in range(self.dataset.numEnt())]
     if head_or_tail == "tail":
         ret_facts = [(head, rel, i, date) for i in range(self.dataset.numEnt())]
     
     if raw_or_fil == "raw":
         ret_facts = [tuple(fact)] + ret_facts
     elif raw_or_fil == "fil":
         ret_facts = [tuple(fact)] + list(set(ret_facts) - self.dataset.all_facts_as_tuples)        
     
     return shredFacts(np.array(ret_facts))
    def replaceAndShred(self, fact, raw_or_fil, head_or_tail):
        head, rel, tail, absolute_time, years, months, days = fact
        if head_or_tail == "head":  #predict head
            ret_facts = [(i, rel, tail, absolute_time, years, months, days)
                         for i in range(self.dataset.numEnt())]
        if head_or_tail == "tail":  #predict tail
            ret_facts = [(head, rel, i, absolute_time, years, months, days)
                         for i in range(self.dataset.numEnt())]

        if raw_or_fil == "raw":
            ret_facts = [tuple(fact)] + ret_facts
        elif raw_or_fil == "fil":
            ret_facts = [
                tuple(fact)
            ] + list(set(ret_facts) - self.dataset.all_facts_as_tuples)

        return shredFacts(np.array(ret_facts))
Beispiel #4
0
    def replaceAndShred(self, fact, hiss, raw_or_fil, head_or_tail):
        head, rel, tail, years, months, days, yid, mid, did = fact
        if head_or_tail == "tail":
            ret_facts = [(i, rel, tail, years, months, days, yid, mid, did)
                         for i in range(self.dataset.numEnt())]
        if head_or_tail == "head":
            ret_facts = [(head, rel, i, years, months, days, yid, mid, did)
                         for i in range(self.dataset.numEnt())]

        if raw_or_fil == "raw":
            ret_facts = [tuple(fact)] + ret_facts
        elif raw_or_fil == "fil":
            ret_facts = [
                tuple(fact)
            ] + list(set(ret_facts) - self.dataset.all_facts_as_tuples)

        return shredFacts(np.array(ret_facts), hiss, fact.reshape(1, -1))
Beispiel #5
0
 def nextBatch(self, batch_size, neg_ratio=1):
     bp_facts = self.nextPosBatch(batch_size)
     batch = shredFacts(self.addNegFacts2(bp_facts, neg_ratio))
     return batch
 def nextBatch(self, batch_size, neg_ratio=1):
     bp_facts = self.nextPosBatch(batch_size)  #(512,6)
     #the final batch size: positive batchsize * (1+negative ratio)*(relation+reverse relation)
     batch = shredFacts(self.addNegFacts2(
         bp_facts, neg_ratio))  #513024: 512*(500+1)*2
     return batch
Beispiel #7
0
 def nextBatch(self, batch_size, neg_ratio=1):
     bp_facts, shiss, ohiss = self.nextPosBatch(batch_size)
     batch1, batch2 = self.addNegFacts2(bp_facts, neg_ratio)
     return shredFacts(batch1, ohiss,
                       bp_facts), shredFacts(batch2, shiss, bp_facts)