コード例 #1
0
 def persistent(self):
     if not self.is_edges_persistent():
         filepath = config.get_data_file_path(self.name, 'edges.parq')
         self.persistent_edges(filepath)
     if self.has_ground_truth():
         for k, v in self.get_ground_truth().items():
             if not v.is_persistent():
                 filepath = config.get_data_file_path(
                     self.name, 'gt_{}.parq'.format(k))
                 v.persistent(filepath)
コード例 #2
0
    def testFromSnap(self):
        name = "testFromSnap"

        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = snap.GenRndGnm(snap.PNGraph, 100, 1000) 
        d = convert.from_snap(name, G, overide=True)
        print ("testFromSnap", d)

        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = snap.GenRndGnm(snap.PUNGraph, 100, 1000) 
        d = convert.from_snap(name, G, overide=True)
        print ("testFromSnap", d) 
コード例 #3
0
def load_local(name):
    '''
    load a local dataset
    
    :param name: name of a dataset 
    '''
    path = config.get_data_file_path(name, create=False)
    if not utils.file_exists(path):
        raise Exception("path not exists: " + path)
    with open(os.path.join(path, 'meta.info')) as f:
        meta = json.load(f)
    edges = meta['parq_edges']
    gt = None
    if meta["has_ground_truth"]:
        gt = {k: Clustering(v) for k, v in meta['parq_ground_truth'].items()}
    additional_meta = None if not "additional" in meta else meta['additional']
    is_edge_mirrored = meta['is_edge_mirrored']
    return Dataset(name=meta['name'],
                   description=meta['description'],
                   groundtruthObj=gt,
                   edgesObj=edges,
                   directed=meta['directed'],
                   weighted=meta['weighted'],
                   overide=False,
                   additional_meta=additional_meta,
                   is_edge_mirrored=is_edge_mirrored)
コード例 #4
0
def local_exists(name):
    '''
    check if dataset 'name' exists locally.
    
    :param name: name of a dataset
    :rtype: bool
    '''
    path = config.get_data_file_path(name)
    return utils.file_exists(path)
コード例 #5
0
def remove_local(name, rm_graph_data=True, rm_clustering_result=True):
    '''
    remove a local dataset 

    :param name: name of a dataset
    :param rm_clustering_result: remove local graph data
    :param rm_clustering_result: remove clustering results associated with the graph.
    '''
    if rm_graph_data:
        path = config.get_data_file_path(name)
        utils.remove_if_file_exit(path, is_dir=True)
    if rm_clustering_result:
        path = config.get_result_file_path(name)
        utils.remove_if_file_exit(path, is_dir=True)
コード例 #6
0
    def testFromIGraph(self):
        name = "testFromIGraph"

        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = igraph.Graph.Full(5, directed=False)
        d = convert.from_igraph(name, G)
        print (d)

        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = igraph.Graph.Full(5, directed=True)
        d = convert.from_igraph(name, G)
        print (d)
        
        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = igraph.Graph.Full(5, directed=False)
        G.es['weight'] = [1] * G.ecount()
        d = convert.from_igraph(name, G)
        print (d) 

        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = igraph.Graph.Full(5, directed=True)
        G.es['weight'] = [1] * G.ecount()        
        d = convert.from_igraph(name, G)
        print (d) 
コード例 #7
0
    def testFromNextworkx(self):
        name = "testFromNextworkx"

        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = nx.complete_graph(5)
        d = convert.from_networkx(name, G, weighted=False, overide=True)
        print (d) 

        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = nx.complete_graph(5).to_directed()
        d = convert.from_networkx(name, G, weighted=False, overide=True)
        print (d)
       
        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = nx.complete_graph(5) 
        G.add_weighted_edges_from((u, v, 1) for u, v in nx.complete_graph(5).edges())
        d = convert.from_networkx(name, G, weighted=True, overide=True)
        print (d)
                
        utils.remove_if_file_exit(config.get_data_file_path(name), is_dir=True)
        G = nx.complete_graph(5).to_directed()
        G.add_weighted_edges_from((u, v, 1) for u, v in nx.complete_graph(5).edges())
        d = convert.from_networkx(name, G, weighted=True, overide=True)
        print (d)
コード例 #8
0
 def update_meta(self):
     if not self.is_anonymous():
         meta_file = config.get_data_file_path(self.name, 'meta.info')
         json.dump(self.get_meta(), open(meta_file, 'wt'))
コード例 #9
0
    def __init__(self,
                 name=None,
                 description="",
                 groundtruthObj=None,
                 edgesObj=None,
                 directed=False,
                 weighted=False,
                 overide=False,
                 additional_meta=None,
                 is_edge_mirrored=False):
        assert edgesObj is not None
        self.name = name
        self.description = description
        self.additional_meta = additional_meta
        self.logger = utils.get_logger("{}:{}".format(
            type(self).__name__, self.name))
        self.directed = directed
        self.weighted = weighted
        self.is_edge_mirrored = is_edge_mirrored

        self.parq_edges = None

        if name:
            assert name
            self.file_edges = config.get_data_file_path(self.name, 'edges.txt')
            self.file_pajek = config.get_data_file_path(self.name, 'pajek.txt')
            self.file_hig = config.get_data_file_path(self.name, 'pajek.hig')
            self.file_scanbin = config.get_data_file_path(self.name, 'scanbin')
            self.file_anyscan = config.get_data_file_path(
                self.name, 'anyscan.txt')
            self.file_snap = config.get_data_file_path(self.name, 'snap.bin')
            self.file_mcl_mci = config.get_data_file_path(self.name, 'mcl.mci')
            self.file_mcl_tab = config.get_data_file_path(self.name, 'mcl.tab')
            self.file_topgc = config.get_data_file_path(self.name, 'topgc.txt')
            self.file_mirror_edges = config.get_data_file_path(
                self.name, 'edges_mirror.txt')

            if self.is_weighted():
                self.file_unweighted_edges = self.file_edges
            else:
                self.file_unweighted_edges = config.get_data_file_path(
                    self.name, 'unweighted_edges.txt')

        self.set_ground_truth(groundtruthObj)
        self.set_edges(edgesObj)

        if name:
            is_persistent = self.is_edges_persistent(
            ) and self.is_ground_truth_persistent()
            self.home = config.get_data_file_path(name, create=False)
            if utils.file_exists(self.home):
                if overide:
                    utils.remove_if_file_exit(self.home, is_dir=True)
                elif is_persistent:
                    pass
                else:
                    raise Exception(
                        "Dataset {} exists at {}. Use overide=True or load it locally."
                        .format(name, self.home))

            if not is_persistent:
                utils.remove_if_file_exit(config.get_result_file_path(
                    self.name),
                                          is_dir=True)
                utils.create_dir_if_not_exists(self.home)
                self.persistent()
                self.update_meta()