def parse(cls, string): """Returns a Semantic object""" string = string.replace(" ", "") if "|" in string: quant_str, string = string.split("|") else: quant_str, string = "", string # Parse conjuncted relations relations = [] while len(string) > 0: relation, string = RelationParser.parse(string) relations.append(relation) sem = Semantics(relations) # Parse any quantifiers quantification_dict = QuantificationParser.parse(quant_str) sem.quantification_dict = quantification_dict return sem
def fromxml(cls, vn_class, xml, frame_num): """Returns a Frame object from the VerbNet XML representation""" primary = xml.find("DESCRIPTION").attrib.get("primary", "") secondary = xml.find("DESCRIPTION").attrib.get("secondary", "") sem_dict = Semantics.semdict_fromxml(xml.find("SEMANTICS")) # Need the order of np vars given in syntax for mapping to subst nodes nps = xml.find("SYNTAX").findall("NP") np_order = [np.attrib["value"] for np in nps] sem_vars = [v for s in sem_dict.values() for v in s.variables()] np_var_order = [] for np in np_order: match = [v for v in sem_vars if v.orig_name == np] if len(match) > 0 and not match[0].missing: # Ignore "?" variables np_var_order.append(match[0]) example = xml.find("EXAMPLES").find("EXAMPLE").text.replace('"', '') return Frame(vn_class, frame_num, primary, secondary, sem_dict, np_var_order, example)