当前位置: 首页>>代码示例>>Python>>正文


Python Graph.vs()[vertex_count]['node_type']方法代码示例

本文整理汇总了Python中igraph.Graph.vs()[vertex_count]['node_type']方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.vs()[vertex_count]['node_type']方法的具体用法?Python Graph.vs()[vertex_count]['node_type']怎么用?Python Graph.vs()[vertex_count]['node_type']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在igraph.Graph的用法示例。


在下文中一共展示了Graph.vs()[vertex_count]['node_type']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_activity_graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs()[vertex_count]['node_type'] [as 别名]
    def get_activity_graph(self, episodes):
        """Generates the qstag for a set of input episode QSRs.

        :param episodes: list of QSR Epiosdes generated using `compute_episodes(world_qsr)``
        :type episodes: list
        :return: igraph.Graph: An igraph graph object containing all the object, spatial and temporal nodes.
        :rtype: igraph.Graph
        """

        temporal_map = {'after': 'before',
                        'metby' : 'meets',
                        'overlapped_by': 'overlaps',
                        'started_by': 'starts',
                        'contains':'during',
                        'finished_by': 'finishes'
                        }

        spatial_nodes_edges = {"rcc2": 2, "rcc3": 2, "rcc8": 2, "cardir": 2,
                    "qtcbs": 2, "qtccs": 2, "qtcbcs": 2, "argd": 2, "argprobd": 2, "mos": 1}

        objects = {}
        spatial_data    = []
        vertex_count = 0
        graph = Graph(directed=True)

        #print("Looping through the episodes...")
        for (objs, relations, (intv_start, intv_end)) in episodes:
            #print(objs, relations, (intv_start, intv_end))


            #############################################
            #   Object Nodes:                           #
            #############################################
            number_of_edges = set([])
            for rel in relations.keys():
                number_of_edges.add(spatial_nodes_edges[rel])
            if len(number_of_edges) != 1:
                raise ValueError("QSRs with different spatial node edges selected.")
            else:
                spatial_edges = number_of_edges.pop()

            for o in objs:
                if o in objects: continue

                graph.add_vertex(o)
                objects[o] = vertex_count

                if o in self.__object_types:
                    graph.vs()[vertex_count]['obj_type'] = self.__object_types[o]

                graph.vs()[vertex_count]['node_type'] = 'object'
                vertex_count += 1

            object_ids = []
            for o in objs:
                object_ids.append(objects[o])
            #print("   OBJECT IDS ", object_ids)
            #############################################
            #   Spatial Nodes:                          #
            #############################################
            graph.add_vertex(relations)
            graph.vs()[vertex_count]['node_type'] = 'spatial_relation'

            # Add edges from spatial node to objects
            edge_from_object = objects[objs[0]]

            #print("adding edge: : ", edge_from_object, vertex_count)
            graph.add_edge(edge_from_object, vertex_count)
            self.__spatial_obj_edges.append( (edge_from_object, vertex_count) )

            if spatial_edges is 2:
                #print("TWO OBJECTS -- ")
                edge_to_object = objects[objs[1]]
                graph.add_edge(vertex_count, edge_to_object)
                self.__spatial_obj_edges.append( (vertex_count, edge_to_object) )

            elif spatial_edges is 3:
                #print("THREE OBJECTS -- ")
                edge_from_object_2 = objects[objs[1]]
                edge_from_object_3  = objects[objs[2]]
                graph.add_edge(edge_from_object_2, vertex_count)
                graph.add_edge(edge_from_object_3, vertex_count)
                self.__spatial_obj_edges.append( (edge_from_object_2, vertex_count) )
                self.__spatial_obj_edges.append( (edge_from_object_3, vertex_count) )

            spatial_data.append( (object_ids, vertex_count,  (intv_start, intv_end)) )
            vertex_count += 1

        #############################################
        #   Temporal Nodes:                         #
        #############################################
        #print("data: \n", spatial_data)
        #print("objects \n", objects)

        (E_s, E_f) = self.get_E_set(objects, spatial_data)
        #print("E_s: ", E_s)
        #print("E_f: ", E_f)

        temporal_vertices = {}

#.........这里部分代码省略.........
开发者ID:gatsoulis,项目名称:strands_qsr_lib,代码行数:103,代码来源:qstag.py

示例2: get_activity_graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs()[vertex_count]['node_type'] [as 别名]
    def get_activity_graph(self, input_episodes, COLLAPSE_TEMPORAL_NODES):
        # Generate activity graph from file with object interaction information
        temporal_map = {'after': 'before',
                        'metby' : 'meets',
                        'overlapped_by': 'overlaps',
                        'started_by': 'starts',
                        'contains':'during',
                        'finished_by': 'finishes'
                        }
        
        if type(input_episodes) != list:
            # Episodes are given in a file
            episodes = self._get_episodes_from_file(input_episodes)
        else:
            episodes = input_episodes
            
        self.episodes = episodes
        
        objects = {}                        
        data    = []
        types   = []
        spatial_rels = {}
        vertex_count = 0
        graph = Graph(directed=True)
        
        for (o1, o1t, o2, o2t, rel, intv_start, intv_end) in episodes:

            # Add objects to the graph
            if o1 not in objects:
                graph.add_vertex(o1)
                objects[o1] = vertex_count
                graph.vs()[vertex_count]['obj_type'] = o1t
                graph.vs()[vertex_count]['node_type'] = 'object'
                vertex_count += 1
            if o2 not in objects:
                graph.add_vertex(o2)
                objects[o2] = vertex_count
                graph.vs()[vertex_count]['obj_type'] = o2t
                graph.vs()[vertex_count]['node_type'] = 'object'
                vertex_count += 1
            # Add spatial node to the graph    
            graph.add_vertex(rel)
            graph.vs()[vertex_count]['node_type'] = 'spatial_relation'
            # Add edges from spatial node to objects
            graph.add_edge(objects[o1], vertex_count)
            graph.add_edge(vertex_count, objects[o2])
            self.spatial_obj_edges.append((objects[o1], vertex_count))
            self.spatial_obj_edges.append((vertex_count, objects[o2]))
            data.append((objects[o1], objects[o2], vertex_count, intv_start, intv_end))
            vertex_count += 1
        
        (E_s, E_f) = self.get_E_set(objects, data)
        
        temporal_vertices = {}
        for ((o11, o12, rel1, s1, e1),(o21, o22, rel2, s2, e2)) in combinations(data,2):

            
            #No temporal relation between two starting episodes or between two final episodes
            if ((o11, o12, s1, e1) in E_s and (o21, o22, s2, e2) in E_s) or ((o11, o12, s1, e1) in E_f and (o21, o22, s2, e2) in E_f):
                continue
                         
            temporal_rel = get_allen_relation(s1, e1, s2, e2)
            # If temporal_rel is in temporal_map get its value otherwise keep it the same
            # If the edges are directed, then we need to change the direction of the edges
            # if we change change the temporal relation to its inverse
            temporal_rel_new = temporal_map.get(temporal_rel, temporal_rel)
            # Add temporal node to the graph
            if COLLAPSE_TEMPORAL_NODES and temporal_rel_new in temporal_vertices:
                temporal_rel_vertex_id = temporal_vertices[temporal_rel_new]
            else:
                graph.add_vertex(temporal_rel_new)
                graph.vs()[vertex_count]['node_type'] = 'temporal_relation'
                temporal_rel_vertex_id          = vertex_count
                temporal_vertices[temporal_rel_new] = vertex_count
                vertex_count += 1       
                
            if temporal_rel_new == temporal_rel:                           
                # Add edges from temporal node to the spatial nodes
                graph.add_edge(rel1, temporal_rel_vertex_id)
                graph.add_edge(temporal_rel_vertex_id, rel2)            
                self.temp_spatial_edges.append((rel1, temporal_rel_vertex_id))
                self.temp_spatial_edges.append((temporal_rel_vertex_id, rel2))
            else:
                # PD: if an inverse temporal relation has been used, switch the edges around
                graph.add_edge(temporal_rel_vertex_id, rel1)
                graph.add_edge(rel2, temporal_rel_vertex_id)            
                self.temp_spatial_edges.append((temporal_rel_vertex_id, rel1))
                self.temp_spatial_edges.append((rel2, temporal_rel_vertex_id)) 
        return graph        
开发者ID:gatsoulis,项目名称:trajectory_behaviours,代码行数:91,代码来源:Activity_Graph.py


注:本文中的igraph.Graph.vs()[vertex_count]['node_type']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。