def get_pa_from_sid(sid): SID2PAdb = CDB_Reader(SID2PA_KEYMAP) PAstr = SID2PAdb.get("%s:" % sid) if PAstr == None: return PAstr else : PAstr_payload = PAstr.split(" | ")[0] return PAstr_payload
def load_cfs(self): cf_keys = self.get_cf_keys() for key in cf_keys: cf_cdb = CDB_Reader(CF_FILE) xml = cf_cdb.get(key, exhaustive=True) #print xml if xml == None: continue for x in xml: root = ET.fromstring(x) for cfs in root: for cf in cfs: self.update_cfs(cf) for cf in self.cfs: sys.stderr.write("[%s] %s%s\n" % (cf['id'], cf['character'], self.verb)) sys.stderr.write("similarity: %.4f\n" % cf['predicate_factor']) sys.stderr.write("core: %s\n" % (" ".join(cf['core'])))
def get_original_sentence(key): KEY2SID = CDB_Reader(KEYMAP) value = KEY2SID.get(key) if value != None: value = value.split(",") else : sys.stderr.write("No SID corresponding to %s.\n" % (key)) return None all_pa_str = [] #orig_sentences = [] for instance in value: sid, relation = instance.split(":") relation = relation.split(";")[0] sent = get_orig_sentence(sid) pa_str = get_pa_from_sid(sid) if sent != None and pa_str != None: #orig_sentences.append(sent) all_pa_str.append((pa_str, sent)) return all_pa_str