def from_ova( cls, obj: ova.Node, nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> t.Optional[SchemeNode]: """Generate SchemeNode object from OVA Node object.""" ova_type = obj["type"] ova_scheme = obj["text"] if ova_type in aif2scheme: scheme = aif2scheme[t.cast(aif.SchemeType, ova_type)] if scheme and (found_scheme := text2scheme[type(scheme)].get(ova_scheme)): scheme = found_scheme premise_descriptors = [ str(node_id) for description, node_id in obj["descriptors"].items() if not description.lower().startswith("s_conclusion") ] timestamp = (dt.from_format(obj.get("date"), ova.DATE_FORMAT) or pendulum.now()) return cls( id=str(obj["id"]), metadata=Metadata(timestamp, timestamp), scheme=scheme, premise_descriptors=premise_descriptors, )
def from_aif( cls, obj: aif.Node, nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> t.Optional[SchemeNode]: """Generate SchemeNode object from AIF Node object.""" aif_type = obj["type"] aif_scheme: str = obj.get("scheme", obj["text"]) if aif_type in aif2scheme: scheme = aif2scheme[t.cast(aif.SchemeType, aif_type)] # TODO: Handle formatting like capitalization, spaces, underscores, etc. # TODO: Araucaria does not use spaces between scheme names # aif_scheme = re.sub("([A-Z])", r" \1", aif_scheme) if scheme and (found_scheme := text2scheme[type(scheme)].get(aif_scheme)): scheme = found_scheme timestamp = (dt.from_format(obj.get("timestamp"), aif.DATE_FORMAT) or pendulum.now()) return cls( id=obj["nodeID"], metadata=Metadata(timestamp, timestamp), scheme=scheme, )
def from_ova( cls, obj: ova.Analysis, nlp: t.Optional[t.Callable[[str], t.Any]] ) -> Resource: return cls( utils.parse(obj.get("plain_txt"), nlp), obj.get("documentTitle"), obj.get("documentSource"), dt.from_format(obj.get("documentDate"), ova.DATE_FORMAT_ANALYSIS), )
def from_ova( cls, obj: ova.Node, nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> AtomNode: """Generate AtomNode object from OVA Node object.""" timestamp = dt.from_format(obj.get("date"), ova.DATE_FORMAT) or pendulum.now() return cls( id=str(obj["id"]), metadata=Metadata(timestamp, timestamp), text=utils.parse(obj["text"], nlp), )
def from_aif( cls, obj: aif.Node, nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> AtomNode: """Generate AtomNode object from AIF Node object.""" timestamp = (dt.from_format(obj.get("timestamp"), aif.DATE_FORMAT) or pendulum.now()) return cls( id=obj["nodeID"], metadata=Metadata(timestamp, timestamp), text=utils.parse(obj["text"], nlp), )
def from_ova( cls, obj: ova.Edge, nodes: t.Mapping[str, Node], ) -> t.Optional[Edge]: """Generate Edge object from OVA Edge format.""" source_id = str(obj["from"]["id"]) target_id = str(obj["to"]["id"]) date = dt.from_format(obj.get("date"), ova.DATE_FORMAT) or pendulum.now() if source_id in nodes and target_id in nodes: return cls( id=utils.uuid(), source=nodes[source_id], target=nodes[target_id], metadata=Metadata(date, date), ) return None