Beispiel #1
0
    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,
    ) -> SchemeNode:
        """Generate SchemeNode object from OVA Node object."""

        scheme_type = obj.scheme.WhichOneof("type")
        scheme = None

        if scheme_type is None:
            scheme = None
        elif scheme_type == "support":
            scheme = protobuf2support[obj.scheme.support]
        elif scheme_type == "attack":
            scheme = protobuf2attack[obj.scheme.attack]
        elif scheme_type == "rephrase":
            scheme = protobuf2rephrase[obj.scheme.rephrase]
        elif scheme_type == "preference":
            scheme = protobuf2preference[obj.scheme.preference]

        return cls(
            scheme,
            list(obj.scheme.premise_descriptors),
            Metadata.from_protobuf(obj.metadata),
            dict(obj.userdata.items()),
            id=id,
        )
Beispiel #2
0
 def from_protobuf(cls, id: str, obj: graph_pb2.Participant) -> Participant:
     """Generate Participant object from PROTOBUF format Graph's Participant object."""
     return cls(
         obj.name,
         obj.username,
         obj.email,
         obj.url,
         obj.location,
         obj.description,
         Metadata.from_protobuf(obj.metadata),
         dict(obj.userdata.items()),
         id,
     )
Beispiel #3
0
 def from_protobuf(
     cls,
     id: str,
     obj: graph_pb2.Edge,
     nodes: t.Mapping[str, Node],
 ) -> Edge:
     """Generate Edge object from PROTOBUF Edge format."""
     return cls(
         nodes[obj.source],
         nodes[obj.target],
         Metadata.from_protobuf(obj.metadata),
         dict(obj.userdata.items()),
         id=id,
     )
Beispiel #4
0
 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,
     )
Beispiel #5
0
 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,
     )