def test_to_dict(self): proxy = model.get_proxy(ENTITY, cleaned=False) graph = Graph(edge_types=registry.pivots) graph.add(proxy) data = graph.to_dict() assert "nodes" in data, data assert "edges" in data, data
class GraphExporter(Exporter): """Base functions for exporting a property graph from a stream of entities.""" def __init__(self, edge_types=DEFAULT_EDGE_TYPES): super(GraphExporter, self).__init__() self.edge_types = edge_types self.graph = Graph(edge_types=edge_types) def get_attributes(self, element): attributes = {} if element.proxy: for prop, values in self.exportable_fields(element.proxy): attributes[prop.name] = prop.type.join(values) return attributes def write(self, proxy, **kwargs): self.graph.add(proxy) self.write_graph(**kwargs) def finalize(self): self.finalize_graph() self.graph.flush() def write_graph(self, **kwargs): pass def finalize_graph(self): pass
def test_to_dict(self): proxy = model.get_proxy(ENTITY) graph = Graph(edge_types=registry.pivots) graph.add(proxy) data = graph.to_dict() assert 'nodes' in data, data assert 'edges' in data, data
class GraphExporter(Exporter): """Base functions for exporting a property graph from a stream of entities.""" def __init__(self, edge_types: Iterable[str] = DEFAULT_EDGE_TYPES) -> None: super(GraphExporter, self).__init__() types = registry.get_types(edge_types) self.graph = Graph(edge_types=types) def get_attributes(self, element: Union[Node, Edge]) -> Dict[str, str]: attributes = {} if element.proxy: for prop, values in self.exportable_fields(element.proxy): attributes[prop.name] = prop.type.join(values) return attributes def write(self, proxy: E, extra: Optional[List[str]] = None) -> None: self.graph.add(proxy) self.write_graph() def finalize(self) -> None: self.finalize_graph() self.graph.flush() def write_graph(self) -> None: pass def finalize_graph(self) -> None: pass
def test_basic_graph(self): proxy = model.get_proxy(ENTITY) graph = Graph(edge_types=registry.pivots) graph.add(proxy) assert len(graph.iternodes()) > 1, graph.to_dict() assert len(graph.proxies) == 1, graph.proxies assert len(graph.queued) == 0, graph.proxies graph.add(None) assert len(graph.proxies) == 1, graph.proxies assert len(graph.queued) == 0, graph.proxies
def __init__(self, edge_types=DEFAULT_EDGE_TYPES): super(GraphExporter, self).__init__() self.edge_types = edge_types self.graph = Graph(edge_types=edge_types)
def __init__(self, edge_types=DEFAULT_EDGE_TYPES): self.edge_types = edge_types self.graph = Graph(edge_types=edge_types)
def test_adjacent(self): graph = Graph(edge_types=registry.pivots) graph.add(model.get_proxy(ENTITY)) graph.add(model.get_proxy(ENTITY2)) graph.add(model.get_proxy(REL)) graph.add(model.get_proxy(PASS)) node = Node(registry.entity, 'jodie') adj = list(graph.get_adjacent(node)) assert len(adj) == 3, adj node = Node(registry.entity, 'ralph') adj = list(graph.get_adjacent(node)) assert len(adj) == 7, adj node = Node(registry.entity, 'passpoat') adj = list(graph.get_adjacent(node)) assert len(adj) == 2, adj node = Node(registry.entity, 'passpoat') prop = model.get_qname('Passport:holder') adj = list(graph.get_adjacent(node, prop)) assert len(adj) == 1, adj assert adj[0].source_prop == prop, adj[0].source_prop assert adj[0].target_prop == prop.reverse, adj[0].target_prop node = Node(registry.entity, 'jodie') prop = model.get_qname('Person:familyPerson') adj = list(graph.get_adjacent(node, prop)) assert len(adj) == 1, adj assert adj[0].source_prop == prop, adj[0].source_prop node = Node(registry.entity, 'ralph') prop = model.get_qname('Person:familyRelative') adj2 = list(graph.get_adjacent(node, prop)) assert len(adj2) == 1, adj2 assert adj2[0].target_prop == prop, adj2[0].target_prop assert adj[0] == adj2[0], (adj[0], adj2[0]) assert adj[0].id in repr(adj[0]), repr(adj[0])
def test_adjacent(self): graph = Graph(edge_types=registry.pivots) graph.add(model.get_proxy(ENTITY, cleaned=False)) graph.add(model.get_proxy(ENTITY2, cleaned=False)) graph.add(model.get_proxy(REL, cleaned=False)) graph.add(model.get_proxy(PASS, cleaned=False)) node = Node(registry.entity, "jodie") adj = list(graph.get_adjacent(node)) assert len(adj) == 3, adj node = Node(registry.entity, "ralph") adj = list(graph.get_adjacent(node)) assert len(adj) == 7, adj node = Node(registry.entity, "passpoat") adj = list(graph.get_adjacent(node)) assert len(adj) == 2, adj node = Node(registry.entity, "passpoat") prop = model.get_qname("Identification:holder") adj = list(graph.get_adjacent(node, prop)) assert len(adj) == 1, adj assert adj[0].source_prop == prop, adj[0].source_prop assert adj[0].target_prop == prop.reverse, adj[0].target_prop node = Node(registry.entity, "jodie") prop = model.get_qname("Person:familyPerson") adj = list(graph.get_adjacent(node, prop)) assert len(adj) == 1, adj assert adj[0].source_prop == prop, adj[0].source_prop node = Node(registry.entity, "ralph") prop = model.get_qname("Person:familyRelative") adj2 = list(graph.get_adjacent(node, prop)) assert len(adj2) == 1, adj2 assert adj2[0].target_prop == prop, adj2[0].target_prop assert adj[0] == adj2[0], (adj[0], adj2[0]) assert adj[0].id in repr(adj[0]), repr(adj[0])
def __init__(self, edge_types: Iterable[str] = DEFAULT_EDGE_TYPES) -> None: super(GraphExporter, self).__init__() types = registry.get_types(edge_types) self.graph = Graph(edge_types=types)