-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelations.py
More file actions
41 lines (32 loc) · 882 Bytes
/
Copy pathrelations.py
File metadata and controls
41 lines (32 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
#!/usr/bin/env python
class Relation(object):
"""
Relation
"""
def __init__(self,sym,arity):
self.sym = sym
self.arity = arity
self.r = set()
def add(self, t):
self.r.add(t)
def __repr__(self):
return repr(self.r)
def __call__(self, *args):
return args in self.r
def __len__(self):
return len(self.r)
def __iter__(self):
return iter(self.r)
def spectrum(self):
result = set()
for t in self:
result.add(len(set(t)))
return result
def restrict(self,subuniverse):
result = Relation(self.sym,self.arity)
subuniverse= set(subuniverse)
for t in self.r:
if set(t) <= subuniverse:
result.add(t)
return result