 Download Download Presentation 1. Extraction Operators

# 1. Extraction Operators

Télécharger la présentation ## 1. Extraction Operators

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. 1. Extraction Operators • Projection • Selection • Unorder • Join • Cartesian Product • Union • Difference • Intersection set-like operators (commutativity) ADC 2002 (Extra)

2. Projection [type, name](e: expression) =follows the edges of a given type and name from the input collection of vertices. The result is the collection of target vertices of the followed edges. The order of the output collection depends on the order of the input collection. type = E, A, R, D or disjunctions (|) of these name = regular expression over strings Example.[E, (P|p)ainter[s]#)](e) produces all the target vertices of element containment edges that have names starting with Painter, painter, Painters, or painters, and that originate from the vertices in e. ADC 2002 (Extra)

3. Selection [condition](e: expression) = selects input collection vertices fulfilling the given condition. The order of the output collection depends on the order of the input collection. • In condition one can use projection operator, comparison operators (=, <, > etc.), and logical operators (and, or, not). Example.[[A, name]=“Dali”](e: expression) selects all the vertices that have an attribute called name with the value “Dali”. ADC 2002 (Extra)

4. Unorder (e: expression) = unorders an input collection. • Unordering collections enables the definition of set-like (commutative) operators. • ⋈,, , , and  are considering the order of the input collections in building the result. Unordering input collections enables the usage of their set-like variants (order is not important). • Two vertices are equal if they have the same value. ADC 2002 (Extra)

5. Join (x: expression) ⋈[condition] (y: expression) = [condition](x  y) = the cartesian product is defined as two loops: the external loop traverses the left input collection and the internal loop traverses the right input collection. The pairs that fulfill the join condition form virtual vertices that have as outgoing edges, first the outgoing edges of the vertex from the left input collection and then the outgoing edges of the vertex from the right input collection preserving the original edge order. ADC 2002 (Extra)

6. Join (ctn’d) Example. (x: [E, person](people)) ⋈[[A, id](x) = [A, name](y)] (y: [E, painter](painters))pairs person and painter vertices in virtual vertices based on the equality of the id attribute value of a person and the name attribute value of a painter. • Cartesian Product (x: expression)  (y: expression) = join without condition. ADC 2002 (Extra)

7. Difference (x: expression)  (y:expression) = the result is a collection containing vertices that exist in first collection but not in second one preserving the original vertex order of the left input collection. • Intersection (x: expression)  (y:expression) = the result is a collection containing vertices that exist in both input collections preserving the original vertex order of the left input collection. ADC 2002 (Extra)

8. Union (x: expression)  (y:expression) = the result is a collection that contains first the left input collection, then the right input collection preserving the original vertex order. • It can be easily generalized to an n-ary operator. • Flexibility ensured by the fact that the input collections do not have to be “union compatible” as it was the case in relational algebra. ADC 2002 (Extra)

9. 2. Meta-operators • Map map[f](e: expression) = applies a given function f to each element of the input collection. The function results are concatenated in the output collection. • All unary extraction operators have an inherent map operator associated to them. In the construction phase, the map operator is used explicitly to iterate not just over collection of vertices but also collection of edges. ADC 2002 (Extra)

10. Kleene Star [f](e: expression) = repeats a given function f possibly infinite times starting with the given input collection. At each iteration the results of the function are added to the next function input. The order of the result collection depends on the order of the input collection and the recursion order. • Compared with the map operator it includes in the result the input collection. • When a fix point is reached (output = input) the repetition stops. ADC 2002 (Extra)

11. 3. Construction Operators • Create vertex vertex[type](value) = adds a new vertex with the given type and value to the graph. Example.v1: vertex[element](null) creates a vertex of type element which has a new value (id) given by the system (by a skolem function) and v2:vertex[string](“Dali”) creates a vertex of type string and value “Dali”. ADC 2002 (Extra)

12. Create edge edge[type, name, parent](child) = adds a new edge with a given type, name, parent, and child vertex to the graph. • Before inserting a new edge of type E, the resulting graph is checked for presence of loops among element containment edges. If such a loop is formed the operation is unsuccessful. Example.edge[E, painter, v1](v2) creates an edge of type E with name painter between two vertices (the vertices from the previous example). ADC 2002 (Extra)

13. Examples • Example.Copying a vertex v means creating a new vertex with the type and value of the original vertex: vertex[type(v)](value(v)). • Example. Copying an edge e, involves copying also the parent and children vertices: edge[type(e), name(e), vp](vc) where vp = vertex[type(parent(e))](value(parent(e)), and vc = vertex[type(child(e))](value(child(e))). ADC 2002 (Extra)

14. Example. Copying a complete graph starting from the vertex v can be done by copying all the graph edges and their associated vertices: map[edge[type(e), name(e), vertex[type(parent(e))](value(parent(e))) ](vertex[type(child(e))](value(child(e)))) ](e) where e = *[parentedge([E|A|D, #](child(x)))] (x: parentedge([E|A|D, #](v))) e represents all the edges in the original graph. For each original vertex a unique new vertex is created using a skolem function. ADC 2002 (Extra)