Beispiel #1
0
 def _run_stochastic_block_model(self,
                                 write=False,
                                 write_property=None,
                                 **kwargs):
     raise CommunityDetector.PartitionError(
         "Stochastic block model is not implemented "
         "for Neo4j-based graphs")
Beispiel #2
0
 def _run_girvan_newman(self,
                        weight=None,
                        n_communitites=2,
                        intermediate=False):
     raise CommunityDetector.PartitionError(
         "Girvan-Newman algorithm is not implemented "
         "for Neo4j-based graphs")
Beispiel #3
0
 def detect_communities(self,
                        strategy="louvain",
                        weight=None,
                        n_communities=2,
                        intermediate=False,
                        write=False,
                        write_property=None,
                        **kwargs):
     """Detect community partition using the input strategy."""
     if strategy not in CommunityDetector._strategies.keys():
         raise CommunityDetector.PartitionError(
             f"Unknown community detection strategy '{strategy}'")
     partition = getattr(self, CommunityDetector._strategies[strategy])(
         weight=weight,
         n_communities=n_communities,
         intermediate=intermediate,
         write=write,
         write_property=write_property,
         **kwargs)
     return partition
Beispiel #4
0
    def _run_community_gdc_query(self,
                                 function,
                                 weight=None,
                                 write=False,
                                 write_property=None):
        """Run a query for computing various communities."""
        graph_view = Neo4jGraphView(self.driver,
                                    self.node_label,
                                    self.edge_label,
                                    directed=self.directed)

        node_edge_selector = graph_view.get_projection_query(weight)
        if write:
            if write_property is None:
                raise CommunityDetector.EvaluationError(
                    "Community processing has the write "
                    "option set to True, "
                    "the write property name must be specified")
            query = (f"""CALL gds.{function}.write({{
                  {node_edge_selector},\n
                  writeProperty: '{write_property}'
                }})
                YIELD communityCount
                """)
            result = self.execute(query)
        else:
            query = (f"""
                CALL gds.{function}.stream({{
                  {node_edge_selector}
                }})
                YIELD nodeId, communityId
                RETURN gds.util.asNode(nodeId).id AS node_id, communityId
                """)
            result = self.execute(query)
            return {
                record["node_id"]: record["communityId"]
                for record in result
            }
Beispiel #5
0
 def _run_stochastic_block_model(self, **kwargs):
     raise CommunityDetector.PartitionError(
         "Stochastic block model is not implemented "
         "for NetworkX-based graphs")
Beispiel #6
0
 def _run_label_propagation(self, **kwargs):
     raise CommunityDetector.PartitionError(
         "Label propagation algorithm is not implemented "
         "for Neo4j-based graphs")
Beispiel #7
0
 def _run_louvain(self, **kwargs):
     raise CommunityDetector.PartitionError(
         "Louvain algorithm is not implemented "
         "for graph-tool-based graphs")