Attribute Sets

A collection of data structures for values of attributes on nodes/edges of graphs.

Implements the following data structures:

  • AttributeSet – a base class for attribute sets in ReGraph, provides an interface, implements some common behaviour;

  • FiniteSet – wrapper for Python finite sets, inherits AttributeSet;

  • RegexSet – a class for possibly infinite sets of strings given by regular expressions. It uses the greenery library for finding inclusion and intersection of regular expressions, its method match can be used to test if a given string is in a set of strings defined by regular expressions;

  • IntegerSet – a class for possibly infinite sets of integers defined by a set of disjoint intervals, inherits AttributeSet, provides the method contains for testing if a given integer is in the set of integers.

TODO:

  • RealSet – a class for possibly infinite sets of reals defined by a set of open/closed intervals, inherits AttributeSet, provides the method contains for testing if a given real is in the set of reals.

class regraph.attribute_sets.AttributeSet[source]

Base class for ReGraph attribute sets.

Methods

difference(self, other)

Find difference attribute set.

from_json(json_data)

Create attribute set object from json-like dictionary.

intersect(self, other)

Find intersection attribute set.

issubset(self, other)

Test if subset of another set.

union(self, other)

Find union attribute set.

toset

difference(self, other)[source]

Find difference attribute set.

classmethod from_json(json_data)[source]

Create attribute set object from json-like dictionary.

intersect(self, other)[source]

Find intersection attribute set.

issubset(self, other)[source]

Test if subset of another set.

union(self, other)[source]

Find union attribute set.

class regraph.attribute_sets.EmptySet[source]

Empty attribute set.

Methods

difference(self, other)

Find difference with another.

intersect(self, other)

Intersect with another set.

is_empty(self)

Test if empty.

is_universal(self)

Test if universal.

issubset(self, other)

Test if subset of another set.

to_json(self)

JSON represenation of EmptySet.

union(self, other)

Find union with another set.

difference(self, other)[source]

Find difference with another.

intersect(self, other)[source]

Intersect with another set.

is_empty(self)[source]

Test if empty.

is_universal(self)[source]

Test if universal.

issubset(self, other)[source]

Test if subset of another set.

to_json(self)[source]

JSON represenation of EmptySet.

union(self, other)[source]

Find union with another set.

class regraph.attribute_sets.FiniteSet(fset=None)[source]

Wrapper for finite sets as attribute sets.

Attributes
fsetset

Python finite set that is being wrapped by the object

Methods

add(self, element)

Add an element.

difference(self, other)

Find the difference set with another set.

intersection(self, other)

Find the intersection set with another set.

is_empty(self)

Test if finite set is empty.

is_universal(self)

Test if finite set is universal.

issubset(self, other)

Test if subset of another set.

to_json(self)

JSON represenation.

union(self, other)

Find the union with another set.

update(self, element)

Update finite set.

add(self, element)[source]

Add an element.

difference(self, other)[source]

Find the difference set with another set.

Finds a self - other set.

Parameters
otherset, FiniteSet, RegexSet, IntegerSet, EmptySet or UniversalSet
Returns
The difference set
intersection(self, other)[source]

Find the intersection set with another set.

Parameters
otherset, FiniteSet, RegexSet, IntegerSet, EmptySet or UniversalSet
Returns
The intersection set
is_empty(self)[source]

Test if finite set is empty.

is_universal(self)[source]

Test if finite set is universal.

Returns
False, as finite set is never a universal set
issubset(self, other)[source]

Test if subset of another set.

Parameters
otherset, FiniteSet, RegexSet, IntegerSet, EmptySet or UniversalSet
Returns
True is self defines a subset of other, False otherwise
to_json(self)[source]

JSON represenation.

union(self, other)[source]

Find the union with another set.

Parameters
otherset, FiniteSet, RegexSet, IntegerSet, EmptySet or UniversalSet
Returns
The union set
update(self, element)[source]

Update finite set.

class regraph.attribute_sets.IntegerSet(interval_list)[source]

Set of integers defined by a list of disjoint intervals.

Attributes
intervalslist

List of sorted intervals defining an integer set.

Methods

contains(self, num)

Test if provided integer is in integer set.

difference(self, other)

Difference of self with the other.

empty()

Empty integer set.

from_finite_set(s)

Create Integer set object from a finite set.

intersection(self, other)

Intersection of two integer sets.

is_empty(self)

Test if empty.

is_universal(self)

Test universality.

issubset(self, other)

Test set inclusion for intervals of ints.

to_json(self)

JSON represenation of IntegerSet.

union(self, other)

Union of two integer sets.

universal()

Universal integer set.

contains(self, num)[source]

Test if provided integer is in integer set.

difference(self, other)[source]

Difference of self with the other.

classmethod empty()[source]

Empty integer set.

classmethod from_finite_set(s)[source]

Create Integer set object from a finite set.

intersection(self, other)[source]

Intersection of two integer sets.

is_empty(self)[source]

Test if empty.

is_universal(self)[source]

Test universality.

issubset(self, other)[source]

Test set inclusion for intervals of ints.

to_json(self)[source]

JSON represenation of IntegerSet.

union(self, other)[source]

Union of two integer sets.

classmethod universal()[source]

Universal integer set.

class regraph.attribute_sets.RegexSet(regexp)[source]

Class defining a set of strings recognized by a regular expression.

RegexSet is defined by a regular expression, and is morally associated to a set of strings that the regular expression recognizes.

Attributes
patternstr

Regular expression pattern

Methods

difference(self, other)

Find the difference of two regexps.

empty()

Create a RegexSet object not matching any string.

from_finite_set(fset)

Create a regexp from ordinary finite set.

intersection(self, other)

Find the intersection of two regexps.

is_empty(self)

Test if an object is an empty RegexSet.

is_universal(self)

Test if an object is a universal RegexSet.

issubset(self, other)

Test regexp inclusion relation.

match(self, string)

Check if a string is in RegexSet.

to_json(self)

JSON represenation of RegexSet.

union(self, other)

Find the union with another set.

universal()

Create a RegexSet object matching any string.

difference(self, other)[source]

Find the difference of two regexps.

This method uses greenery library to find and reduce the difference pattern between two regex’s.

  • If other is a string, a Python dict or a FiniteSet, it is converted to a regex pattern, after which it is parsed by greenery.lego.parse method and its difference with the pattern of the self is found. See more details here: https://github.com/qntm/greenery

  • If other is an instance of EmpySet, the difference is a copy of self.

  • If other is an instance of UniversalSet, the difference is an instance of EmptySet.

Parameters
otherset, str, re._pattern_type, RegexSet
Returns
resultRegexSet

The union set

classmethod empty()[source]

Create a RegexSet object not matching any string.

classmethod from_finite_set(fset)[source]

Create a regexp from ordinary finite set.

All the elements of the set will be cast to str.

intersection(self, other)[source]

Find the intersection of two regexps.

This method uses greenery library to find and reduce the intersection pattern.

  • If other is a string, a Python dict or a FiniteSet, it is converted to a regex pattern, after which it is parsed by greenery.lego.parse method and its intersection with the pattern of the self is found. The library greenery finds the intersection between two regex’s by constructing corresponding FSM’s (finite state machines) and finding their intersection, after which it is converted back to a regex. See more details here: https://github.com/qntm/greenery

  • If other is an instance of EmpySet, the intersection is a EmpySet object.

  • If other is an instance of UniversalSet, the intersection is a copy of self.

Parameters
otherset, str, re._pattern_type, RegexSet
Returns
resultRegexSet

The union set

is_empty(self)[source]

Test if an object is an empty RegexSet.

is_universal(self)[source]

Test if an object is a universal RegexSet.

issubset(self, other)[source]

Test regexp inclusion relation.

Tests if a set defined by self is a included in a set defined by other.

Parameters
otherset, str, re._pattern_type, RegexSet

Another regex to test inclusion.

Returns
True is self defines a subset of other, False otherwise
Raises
AttributeSetError

If the type other is not recognized.

match(self, string)[source]

Check if a string is in RegexSet.

to_json(self)[source]

JSON represenation of RegexSet.

union(self, other)[source]

Find the union with another set.

The union is found in the following ways:

  • If other is a string, a Python dict or a FiniteSet the result of the union is a simple concatenation of the string representations of the elements of other with the pattern of self.

  • If other is an instance of UniversalSet, the union is a UniversalSet object.

  • If other is an instance of EmptySet, the union is a copy of self.

Parameters
otherset, str, re._pattern_type, RegexSet
Returns
resultRegexSet

The union set

classmethod universal()[source]

Create a RegexSet object matching any string.

class regraph.attribute_sets.UniversalSet(*arg)[source]

Universal attribute set.

Methods

difference(self, other)

Difference with another set.

intersection(self, other)

Intersect with another set.

is_empty(self)

Test if empty.

is_universal(self)

Test if universal.

issubset(self, other)

Test if subset of other set.

to_json(self)

JSON represenation of UniversalSet.

union(self, other)

Find union with another set.

difference(self, other)[source]

Difference with another set.

intersection(self, other)[source]

Intersect with another set.

is_empty(self)[source]

Test if empty.

is_universal(self)[source]

Test if universal.

issubset(self, other)[source]

Test if subset of other set.

to_json(self)[source]

JSON represenation of UniversalSet.

union(self, other)[source]

Find union with another set.