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_sadface( cls, obj: sadface.Node, nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> AtomNode: """Generate AtomNode object from SADFace Node object.""" timestamp = pendulum.now() return cls( id=obj["id"], text=utils.parse(obj["text"], nlp), userdata=obj["metadata"], metadata=Metadata(timestamp, timestamp), )
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_protobuf( cls, obj: graph_pb2.Reference, resources: t.Mapping[str, Resource], nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> t.Optional[Reference]: """Generate Resource object from PROTOBUF format Graph's Resource object.""" if obj.text: if obj.resource: return cls( resources[obj.resource], obj.offset, utils.parse(obj.text, nlp), ) else: return cls( None, None, utils.parse(obj.text, nlp), ) return None
def from_protobuf( cls, id: str, obj: graph_pb2.Resource, nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> Resource: """Generate Resource object from PROTOBUF format Graph's Resource object.""" return cls( utils.parse(obj.text, nlp), obj.title, obj.source, dt.from_protobuf(obj.timestamp), Metadata.from_protobuf(obj.metadata), dict(obj.userdata.items()), id, )
def from_protobuf( cls, id: str, obj: graph_pb2.Node, resources: t.Mapping[str, Resource], participants: t.Mapping[str, Participant], reference_class: t.Type[Reference], nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> AtomNode: """Generate AtomNode object from PROTOBUF Node object.""" return cls( utils.parse(obj.atom.text, nlp), reference_class.from_protobuf(obj.atom.reference, resources, nlp), participants.get(obj.atom.participant), Metadata.from_protobuf(obj.metadata), dict(obj.userdata.items()), id=id, )
def from_aml( cls, obj: et.Element, nlp: t.Optional[t.Callable[[str], t.Any]] = None, ) -> AtomNode: """ Generate Node object from AML Node format. obj is a AML "PROP" element. """ # get id of PROP if "identifier" in obj.attrib: id = obj.get("identifier") else: id = None # read text of PROP text = obj.find("PROPTEXT").text # read owners of PROP owner_list = obj.findall("OWNER") owners_lst = [] if not owner_list: # if not empty, do something for owner in owner_list: owners_lst.append(owner.get("name")) owners = {"owners": ", ".join(owners_lst)} else: owners = {} # create timestamp timestamp = pendulum.now() return cls( id=id, text=utils.parse(text, nlp), metadata=Metadata(timestamp, timestamp), userdata=owners, )