Пример #1
0
def perm2edge(perm_str):
    """Transforms a permutation string from a database query into an edge."""
    try:
        tokens = ed.split_edge_str(perm_str[1:])
        nper = int(tokens[-1])
        tokens = tokens[:-1]
        tokens = unpermutate(tokens, nper)
        return ed.str2edge(' '.join(tokens))
    except ValueError as v:
        print(u'VALUE ERROR! %s perm2edge %s' % (v, perm_str))
Пример #2
0
def perm2edge(perm_str):
    """Transforms a permutation string from a database query into an edge."""
    try:
        tokens = ed.split_edge_str(perm_str[1:])
        if tokens is None:
            return None
        nper = int(tokens[-1])
        tokens = tokens[:-1]
        tokens = unpermutate(tokens, nper)
        return ed.str2edge(' '.join(tokens))
    except ValueError as v:
        return None
Пример #3
0
def cur2edges(cur):
    """Transforms a cursor from a database query into a set of edges."""
    edges = []
    for row in cur:
        res = row[0]
        tokens = ed.split_edge_str(res)
        nper = int(tokens[-1])
        tokens = tokens[:-1]
        tokens = unpermutate(tokens, nper)
        edge = ed.str2edge(' '.join(tokens))
        edges.append(edge)
    return set(edges)
Пример #4
0
 def symbols_with_root(self, root):
     """Find all symbols with the given root."""
     start_str = '%s/' % root
     end_str = str_plus_1(start_str)
     cur = self.open_cursor()
     cur.execute('SELECT id FROM perms WHERE id>=%s AND id<%s' % (self.ph, self.ph), (start_str, end_str))
     symbs = []
     for row in cur:
         res = row[0]
         symb = ed.split_edge_str(res)[0]
         symbs.append(symb)
     self.close_cursor(cur, local=True, commit=False)
     return set(symbs)
Пример #5
0
 def test_split_edge_str(self):
     self.assertEqual(ed.split_edge_str('(is graphbrain/1 great/1)'), ('is', 'graphbrain/1', 'great/1'))
     self.assertEqual(ed.split_edge_str('(size graphbrain/1 7)'), ('size', 'graphbrain/1', '7'))
     self.assertEqual(ed.split_edge_str('(size graphbrain/1 7.0)'), ('size', 'graphbrain/1', '7.0'))
     self.assertEqual(ed.split_edge_str('(size graphbrain/1 -7)'), ('size', 'graphbrain/1', '-7'))
     self.assertEqual(ed.split_edge_str('(size graphbrain/1 -7.0)'), ('size', 'graphbrain/1', '-7.0'))
     self.assertEqual(ed.split_edge_str('(src graphbrain/1 (is graphbrain/1 great/1))'),
                      ('src', 'graphbrain/1', '(is graphbrain/1 great/1)'))
Пример #6
0
 def test_split_edge_str(self):
     self.assertEqual(ed.split_edge_str('is graphbrain/1 great/1'),
                      ('is', 'graphbrain/1', 'great/1'))
     self.assertEqual(ed.split_edge_str('size graphbrain/1 7'),
                      ('size', 'graphbrain/1', '7'))
     self.assertEqual(ed.split_edge_str('size graphbrain/1 7.0'),
                      ('size', 'graphbrain/1', '7.0'))
     self.assertEqual(ed.split_edge_str('size graphbrain/1 -7'),
                      ('size', 'graphbrain/1', '-7'))
     self.assertEqual(ed.split_edge_str('size graphbrain/1 -7.0'),
                      ('size', 'graphbrain/1', '-7.0'))
     self.assertEqual(
         ed.split_edge_str('src graphbrain/1 (is graphbrain/1 great/1)'),
         ('src', 'graphbrain/1', '(is graphbrain/1 great/1)'))