Пример #1
0
 def __aspect_elements(self):
     current_name = None
     builder = None
     saw_aspect_element = False
     for prefix, event, value in self.__parser:
         if event == 'start_map':
             m = self.__ITEM_NAME_ITEM_RE.fullmatch(prefix)
             if m is not None:
                 current_name = m.group(1)
                 builder = ObjectBuilder()
         if builder is not None and current_name is not None:
             builder.event(event, value)
             if event == 'end_map':
                 if prefix == 'item.%s.item' % current_name:
                     val = builder.value
                     builder = None
                     if current_name == CxConstants.META_DATA:
                         if saw_aspect_element:
                             self.__post_meta_data.append(
                                 AspectElement(current_name, val))
                         else:
                             self.__pre_meta_data.append(
                                 AspectElement(current_name, val))
                             yield None
                     else:
                         saw_aspect_element = True
                         if current_name not in self.__aspect_element_counts:
                             self.__aspect_element_counts[current_name] = 1
                         else:
                             self.__aspect_element_counts[current_name] += 1
                         yield AspectElement(current_name, val)
     raise StopIteration()
Пример #2
0
    def test_1(self):
        print('\n---------- cxio tests start -----------\n')

        node_0 = AspectElement(CxConstants.NODES, {"id": "_:0"})
        node_1 = AspectElement(CxConstants.NODES, {"id": "_:1"})

        nodes = []
        nodes.append(node_0)
        nodes.append(node_1)

        fo = io.StringIO()

        # Creating a CX writer
        w = CxWriter(fo)

        # Starting the json list
        w.start()

        w.start_aspect_fragment(CxConstants.NODES)

        w.write_aspect_element(node_0)
        w.write_aspect_element(node_1)

        w.end_aspect_fragment()

        w.end()
Пример #3
0
    def create_hidden_attributes_aspect_element(sub_network_id,
                                                name,
                                                value,
                                                data_type=None):
        """
        :rtype: AspectElement
        """
        e = {'n': name}

        if isinstance(value, list):
            if data_type is None:
                raise IOError(
                    'data type missing for (list) hidden attributes "' + name +
                    '"')
            if data_type not in CxConstants.LIST_ATTRIBUTE_TYPES:
                raise IOError(
                    'illegal data type for (list) hidden attributes "' + name +
                    '": ' + data_type)
            e['d'] = data_type
            e['v'] = value
        else:
            if data_type:
                if data_type not in CxConstants.SINGLE_ATTRIBUTE_TYPES:
                    raise IOError(
                        'illegal data type for (single) hidden attributes "' +
                        name + '": ' + data_type)
                if data_type != CxConstants.DATA_TYPE_STRING:
                    e['d'] = data_type
            e['v'] = str(value)
        if sub_network_id:
            e['s'] = sub_network_id
        return AspectElement(CxConstants.HIDDEN_ATTRIBUTES, e)
Пример #4
0
    def create_visual_properties_aspect_element(properties_of,
                                                applies_to,
                                                view,
                                                properties,
                                                dependencies=None,
                                                mappings=None):
        """
        :rtype: AspectElement
        """

        if properties_of not in CxConstants.VP_PROPERTIES_OF:
            raise IOError('illegal properties of: ' + properties_of)

        e = {
            'properties_of': properties_of,
            'applies_to': applies_to,
        }
        if view:
            e['view'] = view
        if properties:
            e['properties'] = properties
        if dependencies:
            e['dependencies'] = dependencies
        if mappings:
            e['mappings'] = mappings
        return AspectElement(CxConstants.VISUAL_PROPERTIES, e)
Пример #5
0
 def create_edges_aspect_element(edge_id, source_id, target_id,
                                 interaction):
     """
     :rtype: AspectElement
     """
     e = {'@id': edge_id, 's': source_id, 't': target_id, 'i': interaction}
     return AspectElement(CxConstants.EDGES, e)
Пример #6
0
 def create_cartesian_layout_element(node_id, view_id, x, y, z=None):
     """
     :rtype: AspectElement
     """
     e = {'node': node_id, 'x': x, 'y': y}
     if view_id:
         e['view'] = view_id
     if z:
         e['z'] = z
     return AspectElement(CxConstants.CARTESIAN_LAYOUT, e)
Пример #7
0
 def create_ndex_support_aspect_element(support_id, cx_citation_id, text):
     """
     :rtype: AspectElement
     """
     e = {
         '@id': support_id,
         'citation': cx_citation_id,
         'text': text,
         'attributes': []
     }
     return AspectElement('supports', e)
Пример #8
0
 def create_nodes_aspect_element(node_id,
                                 node_name=None,
                                 node_represents=None):
     """ Convenience method to create a nodes aspect element
     :rtype: AspectElement
     """
     if node_name is None and node_represents is None:
         e = {'@id': node_id}
     elif node_represents is None:
         e = {'@id': node_id, 'n': node_name}
     else:
         e = {'@id': node_id, 'n': node_name, 'r': node_represents}
     return AspectElement(CxConstants.NODES, e)
Пример #9
0
 def create_groups_aspect_element(group_id, view_id, name, nodes,
                                  external_edges, internal_edges):
     """
     :rtype: AspectElement
     """
     e = {
         '@id': group_id,
         'view': view_id,
         'name': name,
         'nodes': nodes,
         'external_edges': external_edges,
         'internal_edges': internal_edges
     }
     return AspectElement(CxConstants.GROUPS, e)
Пример #10
0
    def create_table_column_aspect_element(sub_network, applies_to, name,
                                           data_type):
        """
        :rtype: AspectElement
        """
        if (data_type not in CxConstants.SINGLE_ATTRIBUTE_TYPES) and (
                data_type not in CxConstants.LIST_ATTRIBUTE_TYPES):
            raise IOError('illegal data type for "' + name + '": ' + data_type)

        e = {
            's': sub_network,
            'n': name,
            'applies_to': applies_to,
            'd': data_type
        }
        return AspectElement(CxConstants.TABLE_COLUMN, e)
Пример #11
0
 def create_ndex_citation_aspect_element(citation_id, citation_type, title,
                                         contributors, identifier,
                                         description):
     """
     :rtype: AspectElement
     """
     e = {
         '@id': citation_id,
         'dc:title': title,
         'dc:contributor': contributors,
         'dc:identifier': identifier,
         'dc:type': citation_type,
         'dc:description': description,
         'attributes': []
     }
     return AspectElement('citations', e)
Пример #12
0
 def create_network_relations_aspect_element(child,
                                             parent,
                                             relationship=None,
                                             name=None):
     """
     :rtype: AspectElement
     """
     e = {'c': child}
     if parent:
         e['p'] = parent
     if relationship:
         if (relationship != CxConstants.RELATIONSHIP_TYPE_VIEW) and (
                 relationship != CxConstants.RELATIONSHIP_TYPE_SUBNETWORK):
             raise IOError('illegal relationship type: ' + relationship)
         e['r'] = relationship
     if name:
         e['name'] = name
     return AspectElement(CxConstants.NETWORK_RELATIONS, e)
Пример #13
0
CxUtil.write_aspect_fragment(w, cx[CxConstants.CARTESIAN_LAYOUT])

CxUtil.write_aspect_fragment(w, cx[CxConstants.EDGE_ATTRIBUTES])

# Adding post meta data
w.add_post_meta_data(cx_reader.get_post_meta_data())

# Printing out element counts written so far
for name, count in w.get_aspect_element_counts().items():
    print(name + ': ' + str(count))

print()
print()

# Adding element counts as post meta data
post = AspectElement(CxConstants.META_DATA, w.get_aspect_element_counts())
w.add_post_meta_data(post)

# Ending the json list
w.end()

# Printing to console
json_str = fo.getvalue()
print(json_str)

print()
print()

# READING (again)
# --------------
fi2 = io.StringIO(json_str)
Пример #14
0
 def create_views_aspect_element(view_id, sub_network_id):
     """
     :rtype: AspectElement
     """
     e = {'@id': view_id, 's': sub_network_id}
     return AspectElement(CxConstants.VIEWS, e)
Пример #15
0
 def create_sub_networks_aspect_element(sub_network_id, node_ids, edge_ids):
     """
     :rtype: AspectElement
     """
     e = {'@id': sub_network_id, 'nodes': node_ids, 'edges': edge_ids}
     return AspectElement(CxConstants.SUB_NETWORKS, e)
Пример #16
0
 def create_ndex_edge_support_aspect_element(edge_id, support_id):
     """
     :rtype: AspectElement
     """
     e = {'supports': [support_id], 'po': [edge_id]}
     return AspectElement('edgeSupports', e)
Пример #17
0
 def create_ndex_edge_citation_aspect_element(edge_id, citation_id):
     """
     :rtype: AspectElement
     """
     e = {'citations': [citation_id], 'po': [edge_id]}
     return AspectElement('edgeCitations', e)
Пример #18
0
 def create_ndex_function_term_aspect_element(function_term):
     """
     :rtype: AspectElement
     """
     e = {'function_term': function_term}
     return AspectElement('functionTerms', e)