{'fraction_non_alphanumeric': 0.05320062018937926, 'fraction_numerical': 0.008001550473448141, 'mean_word_length': 3.6451675133431936, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 47, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
On the complexity of finding set repairs for data-graphs

In the deeply interconnected world we live in, pieces of information link domains all around us. As graph databases embrace effectively relationships among data and allow processing and querying these connections efficiently, they are rapidly becoming a popular platform for storage that supports a wide range of domains and applications. As in the relational case, it is expected that data preserves a set of integrity constraints that define the semantic structure of the world it represents. When a database does not satisfy its integrity constraints, a possible approach is to search for a 'similar' database that does satisfy the constraints, also known as a repair. In this work, we study the problem of computing subset and superset repairs for graph databases with data values using a notion of consistency based on a set of Reg-GXPath expressions as integrity constraints. We show that for positive fragments of Reg-GXPath these problems admit a polynomial-time algorithm, while the full expressive power of the language renders them intractable.


Introduction
The availability of high volumes of interconnected data allows the possibility of developing applications that go well beyond semantic indexing and search and involve advance reasoning tasks on top of existing data. Alternative data models such as graph databases are becoming popular as they allow to effectively represent and access this type of data. Graph databases are specially useful for applications where the topology of the data is as important as the data itself, such as social networks analysis (Fan, 2012), data provenance (Anand, Bowers, & Ludäscher, 2010), and the Semantic Web (Arenas & Pérez, 2011). The structure of the database is commonly queried through navigational languages such as regular path queries or RPQs (Barceló Baeza, 2013) that can capture pairs of nodes connected by some specific kind of path. These query languages can be extended to add more expressiveness, while usually adding extra complexity in the evaluation as well. For example, C2RPQs are a natural extension of RPQs defined by adding to the language the capability of traversing edges backwards and closing the expressions under conjunction (similar to relational CQs).
RPQs and its most common extensions (C2RPQs and NREs (Barceló, Pérez, & Reutter, 2012)) can only act upon the edges of the graph, leaving behind any possible interaction with data values in the nodes. This led to the design of query languages for the case of data-graphs (i.e. graph databases where data lies both in the paths and in the nodes themselves), such as REMs and Reg-GXPath (Libkin, Martens, & Vrgoč, 2016).
Advanced computational reasoning tasks usually require the management of inconsistent information. Reasoning with or in the presence of inconsistent knowledge bases has been the focus of a vast amount of research in Artificial Intelligence and theory of relational databases for over 30 years. However, in the last years, the area has flourished focusing on logical knowledge bases and ontologies (Lembo, Lenzerini, Rosati, Ruzzi, & Savo, 2010;Bienvenu, Bourgaux, & Goasdoué, 2019;Lukasiewicz, Malizia, Martinez, Molinaro, Pieris, & Simari, 2022) As in the relational case, consistency is related to the notion of integrity constraints that express some of the semantic structure the data intends to represent. In the context of graph databases, these constraints can be expressed in graph databases through path constraints (Abiteboul & Vianu, 1999;Buneman, Fan, & Weinstein, 2000). When a database does not satisfy its integrity constraints, a possible approach is to compute a 'similar' database that does satisfy the constraints. In the literature, such a database is called a repair (Arenas, Bertossi, & Chomicki, 1999), and in order to define it properly one has to precisely determine the meaning of 'similar'.
Consider for example the data-graph in Figure 1: here the nodes represent people, and the edges model different kinds of relationships between them, such as brothership or parentship. Observe that in this data-graph, every pair of nodes (x, y) connected with a sibling of edge directed from x to y is also connected with a sibling of edge directed from y to x. This property seems reasonable, since the brothership relation is symmetric. In addition, the nodes (Mauro, Julieta) are connected through a nibling of edge directed to Julieta, which it is also a property we would expect to find considering that Mauro's dad, Diego, is the brother of Julieta.  The structure that this particular data-graph has to preserve in order to properly capture our notions of sibling of and nibling of can be stated through path expressions that capture those pairs of nodes that satisfy the semantic constraints. In particular, the pair (María, Julieta) does not satisfy the semantics of the nibling of relation, since Diego is also María's parent but there is no edge nibling of from María to Julieta. This could be 'fixed' by adding the nibling of edge from Maria to Julieta, or by rather deleting the edge child of directed from María to Diego. Naturally, we want to preserve as much data as possible from our original data-graph.
There are different notions of repairs in the literature, among others, set-based repairs (Ten Cate, Fontaine, & Kolaitis, 2012), attribute-based repairs (Wijsen, 2002), and cardinality based repairs (Lopatenko & Bertossi, 2007). In this work, we study two restrictions of the problem of finding a set-based repair G ′ of a graph database G under a set of Reg-GXPath expressions R considered as path constraints: when G ′ is a subgraph of G and when G ′ is a super-graph of G. These kinds of repairs are usually called subset and superset repairs, respectively (Ten Cate et al., 2012;Barceló & Fontaine, 2017). Since repairs may not be unique, it is possible to impose an order over the set of repairs and look for an 'optimum' repair over such order (Flesca, Furfaro, & Parisi, 2007;Staworko, Chomicki, & Marcinkowski, 2012).
The specific contributions of this work are the following: • We define a model for graph databases with data values and introduce a notion of consistency over this model, based on a set of Reg-GXPath expressions that capture a significant group of common integrity constraints that appear in the literature.
• Given a graph database G and a set of constraints R, we study the problem of computing a subset repair (respectively, a superset repair) G ′ of G.
• We show that depending on the expressiveness of the restrictions (whether they use the full power of Reg-GXPath or only the fragment without negation known as Reg-GXPath pos ), these problems admit a polynomial-time algorithm or rather turn out to be intractable, even undecidable.
The rest of this work is organized as follows. In Section 2 we introduce the necessary preliminaries and notation for the syntax and semantics for our data-graph model as well as the definitions of consistency and different types of repairs. We also show, by means of examples, that the proposed language can capture a group of integrity constraints that are common in the database literature. In Section 3 we study the complexity of the repair computing problem for both subset and superset. Finally, in Section 4 and Section 5 we discuss related work and conclusions, respectively.

Definitions
Fix a finite set of edge labels Σ e and a countable (either finite or infinite enumerable) set of data values Σ n , sometimes referred to as data labels, both of which we assume non-empty, and such that Σ e ∩ Σ n = ∅. A data-graph G is a tuple (V, L e , D) where V is a set of nodes, L e is a mapping from V × V to P(Σ e ) defining the edges of the graph, and D is a function mapping the nodes from V to data values from Σ n .
Path expressions of Reg-GXPath are given by: where a iterates over every label of from Σ e and ϕ is a node expression defined by the following grammar: where α and β are path expressions (i.e. path and node expressions are defined by mutual recursion) and c iterates over Σ n . If we only allow the Kleene star to be applied to labels and their inverses (the production a − ), then we obtain a subset of Reg-GXPath called Core-GXPath. The semantics of these languages are defined in (Libkin et al., 2016) in a similar fashion as the usual regular languages for navigating graphs (Barceló Baeza, 2013), while adding some extra capabilities such as the complement of a path expression α and data tests. The α operator is the usual one for nested regular expressions (NREs) used in (Barceló et al., 2012). Given a data-graph G = (V, L, D), the semantics of Reg-GXPath expressions are: Notice that we are using the standard composition of relations in the definition of α.β G and α n,m G . More precisely, given two binary relations R 1 , R 2 over V G , we define R 1 R 2 as {(x, z) : ∃y ∈ (x, y) ∈ R 1 , (y, z) ∈ R 2 }, and R k+1 ≡ R k R.
We denote with α ⇛ β the path expression β∪α, and with ϕ ⇒ ψ the node expression ψ∨¬ϕ. We also note a label a as ↓ a in order to easily distinguish the 'path' fragment from the expressions. For example, the expression child of [Maria = ] sister of will be noted as ↓ child of [Maria = ] ↓ sister of . Naturally, the expression α ∩ β can be rewritten as α ∪ β while preserving the semantics, and something similar happens with the operators ∧ and ∨ for the case of node expressions using the ¬ operator. However, we still include the definitions of all these operators for this grammar, since we will be interested in the sequel in a fragment of Reg-GXPath called Reg-GXPath pos . This fragment shares the same grammar with the exception of the α and ¬ϕ productions. Thus, we will not be able to 'simulate' the ∩ operator in Reg-GXPath pos unless it is present in the original Reg-GXPath grammar.
Example 1. Using Core-GXPath, we could write an expression capturing every 'transitive friend' in a social network using α =↓ + friend of . This is a common example of regular expressions, and it does not require most of Core-GXPath capacities. We can enhance our example by asking for an expression that captures those pairs of nodes who are 'transitive friends' and also follow some other specific node x.
In this case, we are already using the data tests and the nest operator. Another interesting difference between most regular languages and Core-GXPath is that we can easily obtain the complement of a path expression. Since regular languages are closed under complement, most navigation languages can express the complement of any expression, but this is not generally built into the grammar.
Example 2. Given a social database where we have family links, we can capture those nodes that do not have any ancestor node with the same name. We do so by using the following node expression: Note that this cannot be expressed by most navigational languages, since they do not have a way of comparing data values.
Consistency Given a specific database, we may want a node or path expression to capture all the nodes from the data-graph, since it could represent some structure we expect to find in our data. This kind of Core-GXPath or Reg-GXPath expression would work as an integrity constraint defining semantic relations among our data. A data-graph in which an expression α, used as a constraint, does not capture all nodes, may be called inconsistent with respect to α. In general, we define the notion of consistency in the following way: Definition 3 (Consistency). Let G be a data-graph and R = P ∪ N a finite set of restrictions, where P and N consist of path and node expressions, respectively. We say that (G, R) is consistent with respect to R, noted as G |= R, if the following conditions hold: • ∀x ∈ V G and ϕ ∈ N , we have that x ∈ ϕ • ∀x, y ∈ V G and α ∈ P , we have that (x, y) ∈ α Otherwise we say that G is inconsistent w.r.t. R.
In the remainder of this work we will simply say that G is (in)consistent, whenever R is clear from the context.
Example 4. Consider a film database (see figure 2), where some nodes represent people from the film industry such as actors or directors, and others represent movies or documentaries. If we want to make a cut from that graph that preserves only actors who have worked with Philip Seymour Hoffman in a film from Paul Thomas Anderson, then we want the following formula to be satisfied: In this data-graph ϕ is satisfied, since both Phoenix and Moore have worked with Hoffman in a film from Anderson (respectively through 'The Master' and 'Magnolia'). Note that the restriction also applies to Hoffman, so it is required that he participates in any film from Anderson in order to satisfy the constraint.
Example 5. All Regular Path Constraints (RPCs) considered in (Barceló & Fontaine, 2017) can be written as Reg-GXPath expressions, since the language is capable to express implications of the form 'α 1 ⇛ α 2 ' where α i is a 2RPQ for i ∈ {1, 2}. In particular, the constraints from Example 1 of (Barceló & Fontaine, 2017) can be written as Core-GXPath expressions in a straightforward way: the symmetry of the sibling of relation can be stated as α =↓ sibling of ⇛ ↓ − sibling of , and the nibling condition as β =↓ child of ↓ sibling of ⇛↓ nibling of . These are exactly the constraints we wanted to express in figure 1. Now we can formally state that the data-graph is inconsistent, since (María, Julieta) / ∈ β . Meanwhile, every pair (x, y) belongs to α . Deleting the edge (María, child of, Diego) would make the graph consistent, since María would no longer be Julieta's nibling and thus β would be satisfied. On the other hand, deleting the edge (Diego, sibling of, Julieta) would also fix β, but it would cause α to not be satisfied anymore, since the brothership relation would not be symmetric. Note that adding the edge (Maria, nibling of, Julieta) would also make the data-graph consistent.
Example 6. We can express restrictions that are similar to foreign keys using Core-GXPath, relating data values from different entities. Consider a database where we have information about citizens and cities. We may like to ensure that a person's nationality coincides with the country of the city he was born in. This could be captured with the expression: Example 7. NREs ⊆ Reg-GXPath (Libkin et al., 2016) can express restrictions that take into account typing and inheritance properties common to the Resource Description Framework (RDF), such as those considered in (Pérez, Arenas, & Gutierrez, 2010).
Repairs When a graph database G is inconsistent with respect to a set of restrictions R (i.e. there is a path expression or node expression in R that is not satisfied) we would like to compute a new graph database G ′ consistent with respect to R and that differs minimally from G. This new database G ′ is usually called a repair of G with respect to R following some formal definition for the semantics of 'minimal difference'.
We consider set repairs, in which the notion of minimality is based on the difference between the sets of nodes and edges. While we could provide a notion of distance between arbitrary datagraphs via an adequate definition of symmetric difference, it has been the case that the complexity of finding such repairs is quite high. Thus, it is common to consider only those set repairs in which one graph is obtained from the other by only adding or only deleting information (Barceló & Fontaine, 2017;Lukasiewicz, Martinez, & Simari, 2013;Ten Cate et al., 2012). This gives raise to subset and superset repairs.
We say that a data-graph G = (V, L e , D) is a subset of a data-graph In this case, we also say that G ′ is a superset of G.
Definition 8 (Subset and superset repairs). Let R be a set of restrictions and G a data-graph. We say that G ′ is a subset repair (respectively, superset repair) or ⊆-repair (respectively, ⊇-repair) of G if: We denote the set of subset repairs of G with respect to R as ⊆-Rep(G, R) (respectively, the set of superset repairs as ⊇-Rep(G, R)).
Example 9. In Example 1, deleting the edge (Maria, child of, Diego) results in a ⊆-repair, while adding the edge (Maria, nibling of, Diego) results in a ⊇-repair. Deleting both (Diego, sibling of, Julieta) and (Julieta, sibling of, Diego) also creates a ⊆-repair, since this new graph database is consistent with respect to R and is also maximal.

Computing repairs
In this Section, we study the computational complexity of the repair computing problem for a given data-graph and a set of constraints. We start by mentioning a useful fact from (Libkin et al., 2016) related to Reg-GXPath expressions that we use later in this section.
Theorem 10. Given a Reg-GXPath expression α and a data-graph G it is possible to compute the set α G in polynomial time in the size of G and α.
It follows from this result that, given a set of Reg-GXPath expressions R where |R| = Σ α∈R |α| and a data-graph G, it is possible to check if G is consistent with respect to R in polynomial time.
In the sequel, we study the complexity of the subset and superset repair-computing problems, which naturally depend on the fragment of Reg-GXPath used to express the constraints. For some results we consider R fixed, which is a common simplification of the repair-computing problem usually called the data complexity of the problem. We obtain bounds for both the combined and data complexity of the problems (Vardi, 1982).

Subset repairs
Let us consider the empty graph defined as G = (∅, L, D), from now on denoted by ∅. Since the empty graph satisfies every set of restrictions, we conclude that every graph G has a subset repair given any set R of restrictions. In order to understand the complexity of finding such repairs, we define the following decision problem: Problem: ∃SUBSET-REPAIR Input: A data-graph G and a set R of expressions from L. Output: Decide if G has a subset repair G ′ = ∅ with respect to R.
The difficulty of this problem depends on the set of expressions L. Throughout this work, we will assume that L is always a set of expressions included in Reg-GXPath. Observe that this problem can be reduced to the problem of finding a subset repair of G with respect to R and, therefore, by studying it we can derive lower bounds for the problem of computing subset repairs.
∃SUBSET-REPAIR L is in NP, since we can ask a non-empty subset of G that satisfies R as a positive certificate. In what follows, we prove that this problem is NP-complete even if considering only path expressions from Reg-GXPath pos .
Theorem 11. There exists a set R of Reg-GXPath pos path expressions such that the problem ∃SUBSET-REPAIR is NP-complete.
Proof. We reduce 3-SAT to ∃SUBSET-REPAIR, considering a fixed set R of restrictions. Given a 3CNF formula φ of n variables x 1 , . . . , x n and m clauses c 1 , . . . , c m we want to construct a datagraph G = (V, L, D) of Reg-GXPath pos expressions such that G has a non-trivial subset repair with respect to R if and only if φ is satisfiable. We give a description of R once we outline the structure of the data-graph G.
First, let us define the nodes of the graph. We have two 'boolean nodes' for each variable, representing each possible assignment. In addition, we have one node for every clause.
In a valid subset repair, only one of the nodes ⊥ i or ⊤ i will remain, and that will implicitly define a truth assignment on the variable x i of φ.
We encode the information of the formula φ into the edges of our data-graph. For every clause node c j there is an edge to a boolean node ⊥ i (respectively, ⊤ i ) if and only if the literal ¬x i appears in c j (respectively without ¬). For this, we consider Σ e ⊇ {needs, exists, unique} and define: In a valid subset repair, we want every clause c j to keep at least one of these edges, since that would imply that c j is satisfied.
However, a technical problem arises from this approach: it could be the case that not every node is present in a repair, and thus this might result in the corresponding clause node c j to be removed. To avoid this scenario, we add some edges to our graph and a path expression to R that will force every node to be present in case the repair is non-trivial. To do this, we define a cyclic structure with exist edges: We add exists edges to L(c m , ⊤ 1 ), L(c m , ⊥ 1 ), L(⊤ n , c 1 ) and L(⊥ n , c 1 ) Using these edges and the following constraint: we ensure that every clause node and at least one ⋆ i node is present for ⋆ ∈ {⊥, ⊤}, 1 ≤ i ≤ n.
We also add unique edges to every pair of nodes but those of the form (⊤ i , ⊥ i ). In other words, Observe that every pair of nodes except for those of the form (⊤ i , ⊥ i ) belongs to the unique relation, and if R contains the constraint: then every non-trivial repair will not contain both ⊤ i and ⊥ i nodes for each i. Hence, every non-trivial repair will implicitly define an assignment on the variables of φ.
Finally, we need to ensure that the assignment defined by any non-trivial repair satisfies φ. To do this, we add more edges: we add a valid edge between every pair of nodes v and v ′ such that (v, v ′ ) = (c j , ⋆ i ) for every j, i and ⋆ ∈ {⊥, ⊤}; and consider the following constraint: Every pair of nodes belongs to the valid relation, except for those of the form (c j , ⋆ i ), where ⋆ ∈ {⊥, ⊤}. Moreover, those pairs of nodes will satisfy path expression 3 only if at least one of the needs edges remains for every c j . This means that in a non-trivial repair, every clause c j must have a needs edge directed to one of its variables valuations that evaluates c j to ⊤. Thus, the valuation implicitly defined by the ⊥ i ,⊤ i nodes that remain in the repair will be a satisfying one.
Intuitively, if there is a non-trivial repair of G with respect to R = {β 1 , β 2 , β 3 }, then such a repair consists of a selection of boolean nodes for each i such that every clause node keeps a needs edge. Notice that R is independent of φ.
Let us prove that φ is satisfiable if and only if G has a non-trivial repair with respect to R. =⇒ ) If φ is satisfiable then there is an assignment f of its variables such that φ evaluates to true. Consider the graph G, and delete from G every node Since we deleted only one boolean node for each i, the path expression 1 is satisfied. The expression 2 is satisfied, since there is no i for which both ⊤ i and ⊥ i remain in the graph. Finally, since f is a valid assignment, we know that for every clause node c j one of its needs edges remains, hence the expression 3 is satisfied.
This implies that the subgraph satisfies R, which means that there exists a non-trivial subset repair of G with respect to R.
⇐= ) Let G ′ be a non-trivial repair of G with respect to R. Since both expressions 1 and 2 are satisfied, we know that, for every i, one of the boolean nodes belongs to G ′ . Hence, we define an assignment f on the variables x i as f (x i ) = ⊤ ⇐⇒ ⊤ i ∈ V G ′ . Since the expression 3 is satisfied, at least one variable from each clause evaluates to true (or false, if the variable is negated in the clause). It follows that f is an assignment that evaluates φ to true.
The problem is also NP-hard when considering only node expressions from Reg-GXPath: Theorem 12. The problem ∃SUBSET-REPAIR is NP-complete for a fixed set of Reg-GXPath node expressions.
Proof. We reduce 3-SAT to ∃SUBSET-REPAIR, considering a fixed set R of node expressions from Reg-GXPath. Given a 3CNF formula φ of n variables x 1 , . . . , x n and m clauses c 1 , . . . , c m , we will construct a data-graph G = (V, L, D) of Reg-GXPath expressions such that G has a non-trivial subset repair with respect to R if and only if φ is satisfiable. We give a description of R once we outline the structure of the data-graph G. For our reduction we require that |Σ e | ≥ 4 and |Σ n | ≥ 4, and in particular we will assume that we have edge labels {assign, needs true, needs false, h} ⊆ Σ e and data values {var, clause, ⊤, ⊥} ⊆ Σ n .
The data-graph G = (V, L, D) is defined as Given an ordering p 1 . . . p |V | of the |V | nodes of the data-graph, we add the edge labels ↓ h to L(p k , p k+1 mod |V | ) for k = 1, . . . , |V |. The set of node expressions R = {ψ 1 , ψ 2 , ψ 3 } is defined as: The data-graph G is a representation of the input formula φ, where each variable is assigned to both boolean values ⊥ and ⊤. A subset repair of G with respect to R will represent a proper assignment, where each variable node x i has a unique outgoing edge of label assign. This condition is imposed by ψ 2 , since it forbids the case in which a node with data value var has two outgoing edges to nodes having different data value.
Observe that ψ 3 implies that in a valid repair every clause will either contain a literal that is a negation of a variable that is assigned to ⊥, or a non-negated literal assigned to ⊤. Finally, ψ 1 forces the repair to either preserve all nodes or none of them: if a proper subset of the nodes is deleted then at least one node will not have an outgoing edge of label h, and therefore R will not be satisfied. Now, we prove that φ is satisfiable if and only if G has a non-trivial subset repair with respect to R.
=⇒ ) Let f : {x i } 1≤i≤n → {⊤, ⊥} be an assignment that satisfies φ. Hence, we can define a sub data-graph G ′ of G by removing the edges (x i , assign, ¬f (x i )). Since every node is present and every var node has an unique outgoing edge of label assign, ψ 1 and ψ 2 are satisfied in this data-graph. Moreover, ψ 3 is also satisfied: given a clause node c j , there is a literal x i or ¬x i in c j that is satisfied through f , and the data-graph G ′ contains the edges of the form (x i , assign, f (x i )). Therefore, from every clause node there will be a path with the proper edge labels to either ⊥ or ⊤. Since G ′ satisfies R and G ′ ⊂ G, there must be a non-trivial subset repair G ′′ ⊇ G ′ of G with respect to R.
⇐= ) Given a non-trivial subset repair G ′ of G with respect to R, we build a satisfying assignment of φ. Since ψ 1 is satisfied by G ′ , every node from G is present in G ′ . We define the following assignment f : . We claim that this assignment satisfies φ.
Given a clause c j from φ, the node c j in G ′ satisfies ψ 3 . This means that, there is either a path ↓ needs true ↓ assign [⊤] or a path ↓ needs false ↓ assign [⊥] starting at the node c j . Assume without loss of generality that the path is of the form ↓ needs false ↓ assign [⊥] (the other case follows analogously), and that the intermediate node is x i . By construction, we know that ¬x i is a literal in c j . Due to constraint ψ 2 , the node x i has at most one outgoing edge of label assign, and therefore assign ∈ L(x i , ⊥) implies that assign / ∈ L(x i , ⊤), which by definition of f also implies that f (x i ) = ⊥. We conclude that c j is satisfied.
Since computing a repair seems unfeasible when using path constraints from Reg-GXPath pos or node constraints from Reg-GXPath, we now study the ∃SUBSET-REPAIR problem when L contains only node expressions from Reg-GXPath pos .
First, we prove that the positive fragment of Reg-GXPath pos satisfies a certain property of monotony: Lemma 13 (Monotony of Reg-GXPath pos ). Let G be a data-graph, α a Reg-GXPath pos path expression, ϕ a Reg-GXPath pos node expression, and G ′ a data-graph such that G ⊆ G ′ . Then: Proof. Intuitively, if a pair of nodes satisfies (v, w) ∈ α G where α is a positive expression, then there is a certain subgraph H of G that is a witness of that fact. For example, if (v, w) ∈ ↓ l [c = ] ↓ l G then there is a node z such that D(z) = c and a path vzw made by edges with label l. The subgraph composed by these three nodes and two edges is enough for the pair (v, w) to satisfy the positive path expression α, and therefore in every superset G ′ of G it will be the case that (v, w) ∈ α G . See the appendix 6 for the proper proof.
This fact allows us to define an efficient procedure for finding a subset repair, based on the following observation: if a node v in G does not satisfy a positive node expression ϕ, then there is no subset repair G ′ such that v is a node from G ′ . More generally, we have the following result.
Theorem 14. Let G be a data-graph, R a set of Reg-GXPath pos restrictions and v a node from G which violates a node expression. Then where G V is the sub data-graph of G induced by the nodes V ⊆ V G Proof. For the ⊆ direction: let H ∈ Rep(G, R) be a subset repair of G with respect to R. Due to Lemma 13 and the fact that there is a node expression ϕ ∈ R such that v / ∈ ϕ G we conclude that v is not a node from H. This implies that H ⊆ G V G \{v} , and since H is a maximal consistent subset of G with respect to R, it also is a maximal consistent subset from G V G \{v} .
For the other direction: let H ∈ Rep(G V G \{v} , R). Since H is consistent with respect to R and H ⊆ G we only need to prove that it is maximal with respect to G. Toward a contradiction, suppose there exists a data-graph H ′ such that H ⊂ H ′ ⊆ G and H ′ satisfies R. Since v is not a node from H ′ , it follows that H ′ ⊆ G V G \{v} , which then implies that H is not a repair of G V G \{v} . This results in a contradiction, and hence we proved that H is a subset repair of G with respect to R.
Furthermore, given two data-graphs G 1 and G 2 satisfying a Reg-GXPath pos node expression ϕ it can be shown that G 1 ∪ G 2 satisfies ϕ as well (this follows from Lemma 13). Then, if R only contains Reg-GXPath pos node expressions we can conclude that there is a unique subset repair of G with respect to R.
Given all these facts, we define an algorithm that computes the unique subset repair of a datagraph given a set of Reg-GXPath pos node expressions: Algorithm 1 SubsetRepair(G, R) Require: G is a data-graph and R a set of Reg-GXPath pos node expressions.
This method is correct since Theorem 14 implies that Rep(G, R) = Rep(G V G \V ⊥ , R). It also terminates, since (∅, R) is consistent. The set V ⊥ can be computed in polynomial time, and since there are at most |V G | iterations we conclude the following: Theorem 15. Given a data-graph G and a set of Reg-GXPath pos node expressions R, it is possible to compute the unique subset repair of G with respect to R in polynomial time.
Note that Theorem 11 readily implies that the problem ∃SUBSET-REPAIR is NP-hard for L = Reg-GXPath pos if we allow both node and path expressions, even when considering the data complexity of the problem.
We conclude this section by noticing that even though the problem of finding subset repairs turns out to be NP-complete for a fragment of quite simple path expressions, node expressions on the other hand have substantial expressive power, as we show in our examples. These examples actually use node expression negation for building the 'implications', but they can be rewritten to avoid this by taking into account some extra assumptions on the database.
The examples use node expression negation to make 'typed restrictions' over the data-graph. It would be reasonable to assume that a constraint of the form ↓ type will be present in the database, and we could exploit this one to modify the other restrictions: instead of writing type(α) =⇒ restriction we could define β =α type(β) ∪ restriction (supposing that Σ n is finite), which, given the previous 'type' constraint, will retain the original semantics of the implication. Also, since the set of node labels is fixed, this will only increment the expression length by a constant factor.
Finally, we remark that the algorithm for Reg-GXPath pos node expressions will work as long as the expressions satisfy monotony. This means that we could add more monotone tools to the language and the procedure would still be correct and run in polynomial type, assuming of course that the expressions from the new language can be evaluated in polynomial time given the length of the expressions and the data-graph.

Superset repairs
We start this section by noticing that, in contrast with the subset repair problem, not every datagraph G admits a superset repair with respect to a set of Reg-GXPath expressions: Remark 16. There exists a data-graph G and a set R of Reg-GXPath pos expressions such that there is no superset repair of G with respect to R.
In order to study the complexity of finding superset repairs, we define the following decision problem: Problem: ∃SUPERSET-REPAIR Input: A data-graph G and a set R of L expressions. Output: Does G have a superset repair with respect to R?
When fixing R the problem remains intractable in general.
Theorem 17. There is a set of labels Σ e such that ∃SUPERSET-REPAIR is undecidable for a fixed set R of path expressions from Reg-GXPath.
Proof. To prove undecidability, we reduce the superset-CQA problem (Barceló & Fontaine, 2017, Theorem 4) to our problem. Since the problem is undecidable, so will be ours.
In (Barceló & Fontaine, 2017, Theorem 4), the following CQA problem is proven to be undecidable for a particular choice of Σ, q, Γ: given a finite alphabet Σ, a non-recursive RPQ query q, a set of word constraints Γ, a graph G, and a tuple (x, y) of nodes of G, decide whether (x, y) ∈ q G ′ for every G ′ ∈⊇-Rep(G, Γ) (i.e., there is a q-labeled path from x to y in all supersets of G satisfying the constraints Γ).
For ease of reference, we now provide the required definitions. Given an alphabet Σ, regular path queries over Σ, noted RPQ, are defined by the following grammar: We say that an RPQ is non-recursive if it does not mention the Kleene-star. The semantics for RPQ formulas over a graph G with edges labeled in Σ is as follows: belongs to the reflexive-transitive closure of η G } A word constraint is defined as a formula α 1 ⊆ α 2 where α i is a word formula for i ∈ {1, 2}; that is, a finite conjunction of labels. Intuitively, a graph G satisfies a word constraint α 1 ⊆ α 2 if α 1 G ⊆ α 2 G .
We note that a word constraint α = a 1 . . . a m ⊆ a ′ 1 . . . a ′ n is equivalent to a Reg-GXPath formula . For a non-recursive RPQ q there is also a straightforward translation to an equivalent Reg-GXPath formula q T that preserves its semantics, since a non-recursive RPQ is a finite union of word formulas. We We consider the set of edge labels Σ e = {↓ a | a ∈ Σ} ⊔ {↓ x }. Given (G, (x, y)), letĜ be the graph G with edges a transformed into ↓ a , and augmented with an edge ↓ x such that x is connected with y via ↓ x . Thus, it follows that: Notice that this proof actually shows something stronger: Observation 18. The problem is undecidable even when only considering restrictions from the fragment of Reg-GXPath that has no node expressions and whose path expressions are of the form: As for the particular case of ∃SUPERSET-REPAIR that considers restriction sets only consisting of node-expressions, we have the following result: Theorem 19. There is a set of labels Σ e such that ∃SUPERSET-REPAIR is undecidable, even when R is a set of node expressions (but it isn't fixed).
Proof. We reduce the problem Finite 2RPQ Entailment from ALCOIF KBs to our problem. First, we give some background and the required definitions.
Let N C , N R and N I be countably infinite disjoint sets representing concept names (unary relations), role names (binary relations) and individual names (constants), respectively. An assertion is an expression of the form C(a) or r(a, b), where a, b are individual names, C is a concept name, and r is a role name. A concept is any of the following expressions: where C ∈ N C , r ∈ N R and a ∈ N I . A concept of the form {a} is called a nominal.
An ALCOIF axiom is a concept inclusion A ⊑ B or a functionality restriction F un(r) with r a role concept. A knowledge base (KB from now on) is a pair K = (T , A) where T (the TBox ) is a finite set of ALCOIF axioms and A (the ABox ) is a finite set of assertions. We denote CN (K) to the set of concept names in K, ind(K) to the set of individuals in K and nom(K) to the set of nominals in K.
An interpretation is a pair I = (∆ I , · I ) where ∆ I is a non-empty set called the domain of I, and · I is a mapping called the interpretation function, that assigns as follows: • C I ⊆ ∆ I for every concept name C; • r I ⊆ ∆ I × ∆ I for every role name r; • a I ∈ ∆ I for every individual name a.
We say that I is a finite interpretation if ∆ I is finite. For convenience, we assume ∆ I ∩ N I = ∅ for every I. The semantics for the remaining concepts can be extended as follows: A) if all of the following assertions hold: • a I ∈ C I for every assertion C(a) in A; • (a I , b I ) ∈ r I for every assertion r(a, b) in A.
The signature of any KB structure can be extended with new unary symbols to obtain a normal form for the concept inclusions (Gogacz, Ibáñez-García, & Murlak, 2018), hence we assume without loss of generality that the TBox only contains concept inclusions of the form where A i , B j , A, B are concept names and {a} is a nominal.
A 2RPQ is defined analogously as in (4), with the difference that we also allow to traverse edges backwards, i.e., we add r − to the syntax.
The problem Finite 2RPQ Entailment from ALCOIF KBs asks, given a KB K and a 2RPQ q, whether I |= ∃x.q(x, x) is true for every finite model I of K, or not. Notice that this problem is quite similar to superset-CQA, with the exception that the underlying structure given by the ABox is not just a graph database, but is a graph that allows multiple labels on edges and nodes, and the set of restrictions is now given by the TBox. In other words, we ask if the query is valid on any model that "repairs" the KB, seen as a partial representation of a graph-like model. Finite 2RPQ Entailment from ALCOIF KBs is undecidable (Rudolph, 2016), even for a finite set Σ of role names, which is the particular case of the problem we consider from now on.
For every KB K and 2RPQ q we will construct a data-graph G(K) and a set of node constraints R(K, q) such that G(K) has a superset-repair with respect to R(K, q) if and only if there is a finite counter-model for K and ∃x.q(x, x), that is, a finite model of K that does not satisfy the query.
We fix the set of edge labels to be Σ e = {↓ r : r ∈ Σ} ∪ {↓ total }, and define the set of data values for G(K) as Σ n = {P I : I ⊆ CN (K) ∪ nom(K)} ∪ {T I : I ⊆ CN (K) ∪ nom(K)}. Intuitively, we will use the data values P I as a preliminary description of the concepts used in the ABox of K, and the data values T I as a total description of the concepts used in a model of K. We call partial node to a node having data value P I , and total node to a node having data value T I . In general, we assume that the indices I, J vary in CN (K) ∪ nom(K). We say that a node contains a concept name A if A lies in the set I that corresponds to the index of its data value. For K = (T , A) let us consider G(K) = (V, L, D) where: We now present the formulas in R(K, q), together with a short description of the restriction we want to model in each case: (i) The conjunction of the following formulas We denote this conjunction by ψ 1 . This formula states that every partial node must be connected to precisely one total node through the relation ↓ total , and every total edge in the data-graph must be an outgoing edge from a partial node. Furthermore, the middle part of the formula asserts that partial nodes cannot have more than one outgoing total edge. A total node connected to a partial node through the relation ↓ total is called the total counterpart of that partial node.
(ii) For every i A i ⊑ j B j in T consider: which states that the data value of every total node must contain all the concept-name information to describe a model of K.
(iii) For every A ⊑ ∀r.B in T consider: which states that, for every total node containing the concept name A such that either it has an outgoing edge ↓ r or the node itself is the total counterpart of a partial node having an outgoing edge ↓ r , is not possible that the total node meets another total node that does not contain the concept B through a path in (ǫ ∪ ↓ − total ) ↓ r (ǫ ∪ ↓ total ). One way to intuitively interpret this, is to think of every outgoing edge from a partial node also as an outgoing edge from its total counterpart, and vice versa. From now on, "outgoing edge" will have this interpretation.
(iv) For every A ⊑ ∃r.B in T consider: which states that every total node containing the concept name A must have an outgoing edge ↓ r joining it with another total node containing concept B.
(v) For every A ≡ {a} in T , we consider the conjunction of the following formulas: which states that a total node contains concept A if and only if such node is the total counterpart of a partial node containing the nominal {a}.
(vi) For every F un(r) in T , we consider the conjunction of the following formulas: Notice that these three formulas could be unified into a single one. However, for simplicity we write them separately to help us clarify which patterns (and how) we wish to avoid in a valid repair, which are depicted in Figure 3. In the upper boxes, the patterns we do not wish to appear in a repair as specified by the constraints. In the lower boxes, how to fix each problem by merging the problematic node with a node. The nodes are represented as follows: undesired total nodes, total nodes, partial nodes, any kind of nodes. The unlabeled edges represent total edges, thus the or node is the total counterpart of the incident node. The case (a) is handled by ψ 7 , cases (b) and (c) by ψ 8 , and cases (d) and (e) by ψ 9 .
(vii) Finally, we should add a restriction that ensures the non-satisfiability of the query. But first, we show how to translate a 2RPQ α to obtain the path expression α S that we need. The translation is as follows: We add the formula ψ 10 = ǫ ∩ q S to R(K, q). Notice that if we delete every appearance of the symbol ↓ total in a word ω from α S we obtain a word from α T , where α T is the translation of α as defined in the proof of Theorem 17.
We now proceed to prove that there is a finite counter-model for K and ∃x.q(x, x) if and only if there is a superset-repair for G(K) and R(K, q).
=⇒ ) Let I = (∆ I , · I ) be a counter-model for K and ∃x.q(x, x). We define the data-graph Notice that if r(a, b) is an assertion, then ↓ r ∈ L ′ (a, b) ∩ L ′ (a I , b I ), and if {a} is a nominal in K, then {a}∈I P = I G ′ = {a}. This is relevant to simplify the proof below. We show that the graph G ′ satisfies each of the formulas in R(K, q). It follows by definition that formula in item (i) is satisfied.
For item (ii), suppose that i A i ⊑ j B j is in T and u ∈ V ′ belongs to T = I G ′ where A i ∈ I for every i. This implies by definition that u ∈ ∆ I and u ∈ A I i for every i. Since I |= T , we have that u ∈ B I k for some k, hence B k ∈ I. For item (iii), suppose that A ⊑ ∀r.B is in T and let u ∈ V ′ . If u does not contain the concept A, then u is in ψ 3 G ′ . On the other hand, if D ′ (u) = T I for A ∈ I, and (u, v) ∈ r I for some v ∈ ∆ I , then we have that v ∈ B I since I |= T , and thus D ′ (v) = T J for some B ∈ J. It follows that u is in ψ 3 G ′ .
For item (iv), suppose A ⊑ ∃r.B is in T and u ∈ V ′ is a total node that contains the concept A. This implies by definition that u ∈ ∆ I and u ∈ A I . Since I |= T , there is v ∈ ∆ I such that (u, v) ∈ r I and v ∈ B I . Thus, u ∈ ψ 4 G ′ .
For item (v), suppose A ≡ {a} is in T and let u = a I . Since I |= T , it follows that u ∈ A I . This implies that a ∈ ψ 5 G ′ . Now, if v ∈ V ′ is a total node containing the concept A, then v ∈ A I , thus by hypothesis, v = u. It follows that A∈J T = J G ′ = {u} and hence ψ 6 G ′ = V ′ . For item (vi), suppose F un(r) is in T . We will only show that ψ 9 G ′ = V ′ , since a similar argument holds for the remaining formulas of the conjunction. If u ∈ ind(K) or u = b I for every b ∈ ind(K), then it is straightforward that u ∈ ψ 9 G ′ . If instead u = b I for b ∈ ind(K), and r(a, b), r(a, c) are assertions in K, then we assert that b I = c I since I is a model of K. This implies u ∈ ψ 9 G ′ .
For item (vii) we will prove that, if ψ 10 G ′ = V ′ , then I satisfies the query, i.e. there is a cycle in I reading a word from the language q. First, notice that for every 2RPQ α, a ∈ V and u ∈ V ′ , the pair (a, u) ∈ α S if and only if (a I , u) ∈ α S , and the pair (u, a) ∈ α S if and only if (u, a I ) ∈ α S . Since ↓ r ∈ L ′ (a, b) ∩ L ′ (a I , b I ) for every assertion r(a, b) in K, we conclude that, if u, v ∈ ∆ I and (u, v) ∈ α S , then (u, v) ∈ α T . In other words, if u and v are connected by a path with label in α S , then u and v are also connected by a path that has no edge ↓ total . This statement can be easily proved by induction on the structure of α. Suppose now that ψ 10 G ′ = V ′ , and let u ∈ V ′ be a node for which the constraint ψ 10 is not valid. By definition, this occurs when (u, u) ∈ q S G ′ . We may assume that u ∈ ∆ I , thus (u, u) ∈ q T G ′ , which implies that I has a cycle reading a word from q that contains the node u.
Therefore, G ′ is a finite data-graph that contains G(K) and satisfies R(K, q), hence it contains a superset-repair of G(K).
⇐= ) Let G ′ = (V ′ , L ′ , D ′ ) be a superset-repair of G(K) with respect to R(K, q). We will obtain a counter-model for K and ∃x.q(x, x) by applying an equivalence relation on V ′ . Let ∼ be the relation on V ′ defined as: We use the Kleene star to guarantee that the relation is transitive and reflexive, and the symmetry is a direct consequence of the definition. In essence, we are collapsing every node having data value P I with its total counterpart, which we know exists since (i) is satisfied. For every u ∈ V ′ , we denote by [u] to its equivalence class. Let us consider I = (∆ I , · I ), where I = V ′ / ∼ and · I is defined over the signature of K as follows: : ∃I, ∃u ′ ∼ u. D ′ (u ′ ) = T I and C ∈ I} for every concept name C; Notice that every class [u] contains exactly one total node, and it may contain several (or no) elements from ind(K) and other partial nodes. We denote by [u] T to the total node of the class [u].
We will now show that I is a counter-model for K = (T , A) and ∃x.q(x, x). It follows from the definition that a I ∈ C I for every assertion C(a) in A, and (a I , b I ) ∈ r I for every assertion r(a, b) in A.
Suppose that i A i ⊑ j B j is in T , and let [u] ∈ ∆ I such that [u] ∈ A I i for every i. For the element u ′ = [u] T , we know that D ′ (u ′ ) = T I with A i ∈ I for every i. Since G ′ satisfies the constraint ψ 2 from item (ii), it follows that B k ∈ I for some k, which implies that [u] T , it follows that v ′ = w ′ from the satisfaction of formula ψ 7 from item (vi). For the remaining cases, consider that every node that is different from its total counterpart is connected to it by a total edge. As a consequence of this fact and the satisfaction of formulas ψ 8 and ψ 9 , we obtain that the statement holds for the remaining cases.
Finally, we have to check that I does not satisfy the query. Toward a contradiction, let [u] ∈ ∆ I such that, for a cycle in I containing [u], the label of the path starting and finishing in [u] reads a word on the language q. We will prove that there is a cycle in G ′ reading a word from the language q S . Moreover, this cycle contains [u] T and the read word starts in this node. Suppose the cycle in and ω = r 1 r 2 · · · r n ∈ q. The triplet (v, α, w) means (v, w) ∈ α I . Then, is a cycle in G ′ . Since any word in r S 1 r S 2 · · · r S n is also a word in q S we obtain that G ′ cannot satisfy As pointed out in Remark 16, simple data tests may prevent the existence of superset repairs. Observe that in the absence of them, any data-graph G has a superset repair if we consider only the positive fragment of Reg-GXPath: add every possible edge label l ∈ Σ e to every pair of nodes v, v ′ ∈ V G and the resulting graph will satisfy any expression. The proof of this fact follows quite straightforward by induction in the expression's structure.
Before proceeding, we define some concepts related to data values: Definition 20. Let η be a Reg-GXPath expression. We define the set of data values present in η as the set of all those c ∈ Σ n such that the subexpression [c = ] or [c = ] is used in η. We denote it as Σ η n .
Analogously, we define the set of data values used by a set of Reg-GXPath expressions R as We also denote the set of data values used in a graph G as Σ G n .
Even though Σ n may be infinite, when considering only Reg-GXPath pos expressions we obtain the following lemma: Lemma 21. Let G be a data-graph and R a set of Reg-GXPath pos expressions. If there is a superset repair G ′ of G with respect to the constraints R, then there is another superset repair H that only uses data values from Σ R n ∪ Σ G n plus at most two extra data values not mentioned in R.
Proof. Intuitively, values that are not mentioned in R are not neccessary to satisfy R, and therefore, if there exists a repair, there must be one with only data values from R and the original data values from G. Nonetheless, it could be the case that every data value mentioned in R is in an expression of the form [c = ], and in that case we might need an extra data value (for example, consider the for D a set of data values). Actually, we might need two fresh data values to satisfy some expression of the form α = β (replace α = β = γ). See the Appendix 6 for the detailed proof.
The following observation is a consequence of the previous lemma: Observation 22. If there is a superset repair G with respect to R, then there exists a superset repair with a number of different data values that linearly depends on |G| + |R|.
Notice that this observation does not imply that there must be a superset repair with linear size on |G| + |R|: it could be the case that there is an exponential number of nodes having the same data value. However, we could somehow 'merge' all those nodes with the same data value while preserving some edges, such that the resulting graph will still satisfy all those Reg-GXPath pos expressions that were satisfied in the original graph: Lemma 23. Let G be a data-graph that satisfies a Reg-GXPath pos restriction η. Let V d be a set of nodes from G having the same data value d. If we define a new data-graph H where Then, H satisfies η.
Proof. Expressions from Reg-GXPath pos can only interact with data values and edge labels, ignoring the actual identity of the nodes 1 . Then, observe that in the data-graph just defined the neighbourhoods of all nodes are the same as in data-graph G, except that we might have collapsed some set of nodes. But for those nodes collapsed, we created a new one with the same data value and the same (or even bigger) neighbourhood. Finally, the positive expression of Reg-GXPath pos cannot really distinguish this new node from the previous ones. See the Appendix 6 for the actual proof.
As it was mentioned previously, when we define the graph H the set of nodes V d is collapsed into a unique node v d while preserving all the edges that were incident to the set V d . This operation is usually called vertex contraction. Using Lemmas 21 and 23, we prove the following very useful fact: Theorem 24. Let G be a data-graph and R a set of Reg-GXPath pos expressions. If there is a superset repair of G with respect to R, then there is a superset repair of G with respect to R of polynomial size depending on |G| + |R|.
Proof. We define a data-graph H such that G ⊆ H, H |= R, and the size of H polynomially depends on |G| + |R|. This will suffice to prove the theorem.
Let G ′ be a superset repair of G with respect to R that uses a number of data values that linearly depends on |G| + |R|. Such a superset repair exists as a consequence of Lemma 21 and the hypothesis. Thus, for every data value c ∈ Σ G ′ n \ Σ G n , we contract all the nodes having data value c to a unique node. Let H ′ be the graph obtained once those nodes were contracted. Notice that H ′ satisfies R due to Lemma 23.
We contract every other node v ∈ V G ′ \ V G in H ′ that has a data value from Σ G n with a node from G having the same data value. The resulting graph is indeed the H we are looking for, since once again due to Lemma 23, H satisfies R and |H| is exactly |V G | + |Σ G ′ n \ Σ G n |. Moreover, |H| linearly depends on |G| + |R|. Therefore, the size of H is at most quadratic on |G| + |R|.
This last theorem shows that the problem ∃SUPERSET-REPAIR lies in NP for Reg-GXPath pos expressions, since we can use the repair itself as a witness for a positive instance. Moreover, we can use the same proof to define a polynomial-time algorithm that computes a superset repair of a data-graph G. If there exists a superset repair of G with respect to R, then there is a 'small' graph H such that H |= R and H has a very precise structure: the only nodes that are added to G in order to obtain H have a one-to-one correspondence with those new data values that were not present in G. From now on we will refer to this structure as the standard form of a superset repair. Hence, we may find a minimal -with respect to node inclusion-data-graph H ′ that satisfies H ′ |= R and G ⊆ H ′ as follows: Iterate over every possible subset S of (Σ R n ∪ {c, d}) \ Σ G n , where c and d are the 'fresh' data values mentioned in Lemma 21. Then, add one node to G for each data value in S and every possible edge between any pair of nodes. Finally, check if the resulting data-graph satisfies R.
If none of these data-graphs satisfies R, then it follows from Theorem 24 that there is no superset repair. Otherwise, after computing the minimal -with respect to node inclusion-data-graph H ′ , we may find a repair by deleting edges from H ′ : if once we delete an edge e from H ′ we notice that R is not satisfied anymore, then it follows from Lemma 13 that there is no subset H ′′ of H ′ that does not contain the edge e such that H ′′ satisfies R and such that H ′′ is a data-graph that still contains G. This allows us to assert that e will belong to the final repair.
Considering all the previous discussions, we design the algorithm 2. The first for will be executed at most 2 Σ R n +2 times. If Σ n is finite, then this number of executions is constant. Otherwise, it can depend exponentially on |R|. Everything inside the loop can be computed in polynomial time thanks to Theorem 10. The second loop will run at most (|V G | + Σ R n ) 2 times, which is quadratic in respect to the input size. Since the procedure is correct, we obtain the final result: Algorithm 2 SupersetRepair(G, R) Require: G is a data-graph and R a set of Reg-GXPath pos expressions. return 'There is no superset repair' 9: end if 10: end if 14: end for 15: return H ′ Theorem 25. Given a data-graph G and a set of Reg-GXPath pos expressions, there is an algorithm that computes a superset repair of G with respect to R in polynomial time, if Σ n is finite.
If Σ n is infinite, then we can still compute a superset repair in polynomial time if R is fixed.
Note that if R only contains positive node expressions then we can use a similar procedure as in algorithm 1: we start by building the data-graph H = buildGraph(G, S) where S = Σ R n ∪ {c, d}\Σ G n and then we iteratively remove vertices that do not satisfy some node expression φ ∈ R. By theorem 24 we know that if there exists a superset repair, then there must exist some superset repair G ′ such that G ⊆ G ′ ⊆ H. Also, if v / ∈ φ H for some v then v / ∈ G ′ . Therefore, in at most |V H \V G | ≤ |R|+2 iterations we will find a data-graph that contains the same set of nodes as some superset repair of G with respect to R. Then, we only need to remove the edges to reach the minimality condition. This yields the following result: Theorem 26. The ∃SUPERSET-REPAIR problem can be solved in polynomial-time in combined complexity if R only contains node expressions from Reg-GXPath pos .
If we do not impose any of these restrictions the problem is once again intractable in general: Theorem 27. If the set of Reg-GXPath pos expressions R is not fixed and Σ n is allowed to be infinite, then the problem ∃SUPERSET-REPAIR is NP-complete in general.
Proof. We reduce 3-SAT to an instance of ∃SUPERSET-REPAIR, where |R| depends on the input formula of 3-SAT and Σ n is infinite. We take Σ e ⊇ {down} and Σ n ⊇ Given the 3-CNF formula φ with n variables and m clauses we define the data-graph G = (V, L, D) where: We would like that every superset repair of G represents a valuation (or at least a partial valuation) on the variables x i . Intuitively, given a superset repair G ′ , a variable x i will evaluate to ⊤ if there is a node in G ′ with data value x i , and will evaluate to ⊥ if there is a node in G ′ with data value ¬x i .
In order to obtain valid valuations, we need to avoid the scenario where both data values x i and ¬x i are present in a repair. To do this, we define the following constraints: where i iterates over 1 ≤ i ≤ n. The expressions defined by 6 cannot be satisfied by any graph that has both nodes with data values x i and ¬x i for some i. This follows from the fact that, for any of the three subexpressions, the path cannot begin and end in nodes having data values x i and ¬x i respectively.
Then, we add the following constraint to ensure that, for every repair, the defined valuation evaluates the clauses to true: where j iterates over 1 ≤ j ≤ m and c j k represents the kth literal appearing in c j , either x i or ¬x i , for some i. Any repair of G will satisfy all the expressions from 7, which implies that in any repair there must be at least one variable from every clause that evaluates to true.
In summary, we defined R = {α i | 1 ≤ i ≤ n} ∪ {β j | 1 ≤ j ≤ m}. Now we show that φ is satisfiable if and only if G has a superset repair with respect to R.
=⇒ ) Let f be a valuation of the variables of φ that evaluates φ to true. We define the data-graph H = (V H , L H , D H ) as: Every expression α i is satisfied, since there are no pairs of nodes with 'opposite' data values and the graph is fully connected. The expressions β j are also satisfied given that for every clause c j , at least one of the variables that evaluates the clause to true is present in H. Since G ⊆ H and H |= R there exists a superset repair G ′ of G with respect to R.
⇐= ) Let G ′ be a superset repair of G with respect to R. We define a valuation on the variables of φ by considering the data values present in G ′ . If the data value x i is present then f (x i ) = ⊤, and we define f (x i ) = ⊥ otherwise. Observe that since α i is satisfied for every i this is a valid valuation. Moreover, notice that since β j is satisfied for every j, this valuation makes every clause evaluate to true. Let us consider an arbitrary clause c j . Since β j is satisfied in G ′ , one of the literals x j k for k ∈ {1, 2, 3} has to appear as data value in G ′ . If one of those literals that appear is positive (i.e. without negation) then it evaluates to true by f , and thus c j is satisfied. Otherwise, there is a literal with negation from c j as data value in G ′ , and it evaluates to true through f , and thus c j evaluates to true. This shows that φ is satisfiable.
Reg-GXPath is a query language developed for graph databases with data values in the nodes (Libkin et al., 2016) largely inspired by XPath (Benedikt & Koch, 2009), a language for traversing data trees (i.e. XML documents). Reg-GXPath expressiveness is quite understood in relation to other query languages (Libkin et al., 2016), but there are still some open problems related to it, such as query containment and query equivalence. Two other candidates for this work were the RQMs and RDQs (Libkin & Vrgoč, 2012), the first is more expressive than Reg-GXPath, but its evaluation belongs to PSpace, while the other one is less expressive than Reg-GXPath and therefore its complexity is lower. The main advantage of Reg-GXPath in comparison with other query languages is its great balance between expressiveness and complexity of evaluation (being polynomial on the graph and query size), as well as the fact that it can interact with the topology of the graph and at the same time reason about the data that it contains. Different types of integrity and path constraints have been defined and studied in this context (Buneman et al., 2000;Abiteboul & Vianu, 1999;Barceló & Fontaine, 2017). There is not yet a standard definition of consistency for a graph database over some constraints, and therefore we developed our own based on a set of typical examples found in the literature. Other type of graph database constraints can be expressed through graph patterns and graph dependencies (Fan, 2019).
The notion of database repair and the repair computing problem, as well as the Consistent Query Answering (CQA) problem, were first introduced in the relational context (Arenas et al., 1999). Since then CQA has received much attention from the research community in data management, developing techniques and efficient algorithms under different notions of repairs and considering all kinds of combinations of classes of integrity constraints and queries (Bertossi, 2011(Bertossi, , 2019. These concepts were successfully extended to diverse data models such as XML or description logics (Bertossi, 2006;Ten Cate et al., 2012;Lukasiewicz, Martinez, Pieris, & Simari, 2015;Wijsen, 2005). In the case of graph databases there has been some work concerning CQA over graphs without data values (Barceló & Fontaine, 2017), but, to the best of our knowledge, no previous work studies the problem of computing repairs neither the case when the graphs have data values in their nodes.
When studying CQA and repair problems in contexts such as description logics, it seems more natural to focus on subset repairs, as the DL semantics is open world in nature. This means that the non presence of a fact in the database (explicitly or implicitly) is not enough to derive the negation of the fact. In the case of graph databases, some applications can respond either to closed or open world semantics, and therefore both types of set-based repairs could be meaningful. In this work, we have considered both types of set-based repairs, but we note that we left for future work the study of symmetric difference-based repairs, which were actually studied in (Barceló & Fontaine, 2017). Usually reasoning on symmetric difference repairs is much harder, and in the case of graphs with data the definition of symmetric difference is not as direct to formalize as it is in the models defined in (Barceló & Fontaine, 2017).

Conclusions
In this work, we presented a graph database model along with a notion of consistency based upon path constraints defined by the Reg-GXPath language. We proved many results concerning the complexity of computing subset and superset repairs of data-graphs given a set of restrictions (which can be summarized in Table 1). We proved that, depending on the semantics of the repair and the syntactic conditions imposed on the set of constraints, the problem ranges from polynomial-time solvable to undecidable.
When restricting the language to the positive fragment of Reg-GXPath, which we denote Reg-GXPath pos , we obtained polynomial-time algorithms (on data complexity) for superset-repair computing, and when considering only node expressions from Reg-GXPath pos we found a polynomialtime algorithm for computing subset repair. We note that the algorithm for subset repairs runs in polynomial time on both the size of the graph G and the size of the restriction set R (in other words, we consider combined complexity of the problem). Furthermore, for every intractable case studied, we also obtained tight bounds on the combined and data complexity of the problem.
Some questions regarding repair computing in this context remain open. For example, if the ∃SUPERSET-REPAIR problem remains undecidable when considering only a fixed set of node expressions from Reg-GXPath. It does not seem direct to extend the same proofs and techniques used for the case of path expressions or node expressions (under unfixed constraints).
Another venue of future research we are interested in is the development of preference criteria over repairs. In the problems we studied, we were concerned in finding any repair of a data-graph given a set of constraints. This assumes no prior information about the domain semantics. However, in many contexts we might have a preference criterion that may yield an ordering over all possible repairs.
The complexity of CQA under this context has not been studied yet. Taking into account the results from (Ten Cate, Fontaine, & Kolaitis, 2015) and (Barceló & Fontaine, 2017) it is plausible that reasoning over superset repairs will turn out to be harder than in subset repairs, but meanwhile the complexity of the problem remains unknown. Nevertheless, we note that the CQA problem turns out to be trivial in some cases based on the facts developed through this work concerning Reg-GXPath and Reg-GXPath pos ; for example, when considering subset repairs and Reg-GXPath pos there is a unique repair which is computable in polynomial time, and therefore the CQA problem is easy to solve.

Acknowledgements
We thank Ricardo Oscar Rodriguez (Departamento de Computación, Universidad de Buenos Aires) for his helpful comments and suggestions during the development of this work.

Appendix
Proof of Lemma 13. We will prove it by induction over the structure of the expressions. Let us note G = (V G , L e , D) and In the base case of a path expression α, it must be of the form ǫ, , a or a − . In all of these cases the property holds: since G ⊆ G ′ , we have that For the base case of a node expression ϕ, it can only be of the form c = or c = , and it is easy to see that the property also holds.
• The case ϕ = ψ 1 ∨ ψ 2 can be treated in the same way.
And since we also have that D(z i ) = D ′ (z i ) (since the z i are in V G ), we obtain that v ∈ β 1 ⋆ β 2 G ′ , as we wanted.
Proof of Lemma 21. In order to prove this Lemma we need to first prove another property of Reg-GXPath pos expressions: • α = β 1 .β 2 : for the statement 1, let v, w ∈ V K satisfy its hypothesis ((v, w) ∈ α K , v = w, D(w) / ∈ Σ α n ), and let x be a node such that (v, x) ∈ β 1 K and (x, w) ∈ β 2 K . Then if x = w we know by the inductive hypothesis that (x, z) ∈ β 2 K for every z ∈ V K with D K (z) / ∈ Σ β 2 n (which is a superset of those nodes y such that D K (y) / ∈ Σ β 1 .β 2 n ), and then we can conclude that (v, z) ∈ β 1 .β 2 K . If w = x the result follows by considering that (v, z) ∈ β 1 K and then (z, z) ∈ β 2 K by the statement 3. The statement 2 can be proved the same way. Now for statement 3 let v be a node from K that satisfies its hypothesis ((v, v) ∈ α K and D K (z) / ∈ Σ α n ) and let x be the 'intermediate' node. Let z be a node such that D K (z) / ∈ Σ β 1 .β 2 n . If x = v it follows by using statement 3 as inductive hypothesis that (z, z) ∈ β 1 .β 2 K . Otherwise (i.e. x = v) by using statement 1 and 2 as inductive hypothesis we can obtain the same result.
• The case α = β 1 ∩ β 2 can be treated in a similar way.
• α = β * : if (v, w) ∈ β * K then either (v, w) ∈ ǫ K or (v, w) ∈ β n K for some n > 0. The first scenario has already been proved, while the second one follows from what we have seen in the concatenation case.
• If α = β n,m : the result follows with the same argument used in the β * case since (v, w) ∈ β n,m ⇐⇒ (v, w) ∈ β k for some n ≤ k ≤ m.
• ϕ = β : let v ∈ V K satisfy the hypothesis of statement 4. Then (v, x) ∈ β K for some x.
Thanks to statement 2 we can deduce that if x = v then (z, x) ∈ β K for every z such that D K (z) / ∈ Σ β n . If x = v we use statement 3.
• ϕ = β 1 = β 2 : let v ∈ V K satisfy the hypothesis of statement 4, x 1 and x 2 be nodes such that (v, x i ) ∈ β i K for i ∈ {1, 2} and D K (x 1 ) = D K (x 2 ), and z ∈ V K other node such that D K (z) / ∈ Σ ϕ n . If both x i are different from v then (z, x i ) ∈ β i K thanks to statement 2. Otherwise, suppose x 1 = v without loss of generality, which then implies that (z, z) ∈ β 1 K due to statement 3. Since D K (x 2 ) = D K (x 1 ) = D K (v) / ∈ Σ ϕ n we can guarantee that (z, z) ∈ β 2 K : if x 2 = v then this follows due to statement 3, and if x 2 = v then due to statement 2 we know that (x 2 , x 2 ) ∈ β 2 K and then that (z, z) ∈ β 2 K through statement 3.
• ϕ = β 1 = β 2 : let v ∈ V K satisfy the hypothesis of statement 4, x 1 and x 2 be nodes such that (v, x i ) ∈ β i K for i ∈ {1, 2} and D K (x 1 ) = D K (x 2 ), and z ∈ V K other node such that D K (z) / ∈ Σ ϕ n . If v = x i for i ∈ {1, 2} then the result follows by statement 2. Otherwise, consider that x 1 = v, which then implies that (z, z) ∈ β 1 K by statement 3. If x 2 = v then by statement 2 we can conclude that (z, x 2 ) ∈ β 2 K . If D K (x 2 ) = D K (z) we have finished, and if not, knowing that D K (x 2 ) / ∈ Σ ϕ n (this follows from D K (x 2 ) = D K (z)), we can consider that (z, v) ∈ β 2 K by statement 1 and that D K (x 2 ) = D K (x 1 ) = D K (v). The case x 2 = v cannot happen, since we are assuming that x 1 = v and D K (x 1 ) = D K (x 2 ). Now we continue with the Lemma 21. Let G ′ be a superset repair of G with respect to R. If Σ G ′ n ⊆ Σ G n ∪ Σ R n ∪ {c, d} for some c, d ∈ Σ n \ Σ R n , c = d, then G ′ is already the witness we want for this lemma. Otherwise, take c, d ∈ Σ G ′ n \ (Σ G n ∪ Σ R n ), c = d. We define the graph H = (V H , L H , D H ) where: where Σ G ′ e is the set of all edge labels mentioned in G ′ (i.e. Σ G ′ e = {l ∈ Σ e | ∃v, w ∈ V G ′ such that l ∈ L G ′ (v, w)}).
Intuitively, we have changed all data values that were not in Σ G n ∪ Σ R n ∪ {c, d} into c, and we also added every possible edge considering those labels already present in G ′ . Note that Σ H n ⊆ Σ G n ∪ Σ R n ∪ {c, d}, so showing that H |= R is enough to prove the lemma. We will show by induction in the expressions' structure that if a pair v, w ∈ V G ′ satisfies (v, w) ∈ α G ′ then (v, w) ∈ α H , and that if v ∈ ϕ G ′ then v ∈ ϕ H (where the expressions considered only use data values from Σ R n ). For the base cases: • α = : if some pair (v, w) is in G ′ then Σ G ′ e = ∅, and (v, w) ∈ G ′ .
• α = a and α = a − : if (v, w) ∈ a G ′ then clearly a ∈ Σ G ′ e and a ∈ L H (v, w).
Since e ∈ Σ R n the data value was preserved in H (D H (v) = e) and thus v ∈ e = H .
• The case α = β n,m follows with the same argument used in the . * case.
• ϕ = β 1 = β 2 : this is the most interesting case. Note that the paths used in G to satisfy the expression could now lead to nodes with the same data value. If v ∈ β 1 = β 2 G ′ then there exist nodes z 1 , z 2 ∈ V G ′ such that (v, z 1 ) ∈ β 1 G ′ , (v, z 2 ) ∈ β 2 G ′ and D G ′ (z 1 ) = D G ′ (z 2 ). If D H (z 1 ) = D H (z 2 ) then we can conclude using the inductive hypothesis that v ∈ β 1 = β 2 H . If this is not the case, then both nodes had in G ′ as data value either c or one of those we changed (i.e. one from Σ G ′ n \ (Σ G n ∪ Σ R n ∪ {c, d}). Note that since D G ′ (z 1 ) = D G ′ (z 2 ), it must hold that either z 1 = v or z 2 = v; without loss of generality we can assume that z 1 = v. Let v d be a node from H that has data value d (by construction there must be at least one such node). Since (v, z 1 ) ∈ β 1 H , v = z 1 , D H (z 1 ) / ∈ Σ R n and H is a 'complete graph' under edge labels form Σ G ′ e we can deduce using statement 1 of Lemma 28 that (v, v d ) ∈ β 1 H . Then we can conclude that v ∈ β 1 = β 2 H taking into account that (v, z 2 ) ∈ β 2 H due to the inductive hypothesis.
We can then conclude, since G ′ |= R, that H |= R holds.
Proof of Lemma 23. Let f : V G → V H be a mapping between the nodes of G and H such that f (v) = v if v ∈ V G \ V d , and f (v) = v d otherwise. Now we show, by induction over the formula's structure, that if a pair of nodes v, w ∈ V G satisfies (v, w) ∈ α G , then (f (v), f (w)) ∈ α H , and that if v ∈ ϕ G then f (v) ∈ ϕ H . This is enough to prove the lemma.
For the base cases: • α = : if both v and w were not in V d then their edges were preserved. If w ∈ V d and v / ∈ V d then by construction L G (v, w) ⊆ L H (v, v d ). The case when v ∈ V d is analogous. If both v and w are in V d we use the fact that L G (v, w) ⊆ L H (v d , v d ).