Frank Julca-Aguilar

Harold Mouch

Christian Viard-Gaudin
email: christian.viard-gaudin@univ-nantes.fr

Nina S T Hirata

Harold Mouchère
email: harold.mouchere@univ-nantes.fr

A General Framework for the Recognition of Online Handwritten Graphics

Keywords: Graphics recognition, online handwriting recognition, graph parsing, mathematical expression, flowchart. !

We propose a new framework for the recognition of online handwritten graphics. Three main features of the framework are its ability to treat symbol and structural level information in an integrated way, its flexibility with respect to different families of graphics, and means to control the tradeoff between recognition effectiveness and computational cost. We model a graphic as a labeled graph generated from a graph grammar. Non-terminal vertices represent subcomponents, terminal vertices represent symbols, and edges represent relations between subcomponents or symbols. We then model the recognition problem as a graph parsing problem: given an input stroke set, we search for a parse tree that represents the best interpretation of the input. Our graph parsing algorithm generates multiple interpretations (consistent with the grammar) and then we extract an optimal interpretation according to a cost function that takes into consideration the likelihood scores of symbols and structures. The parsing algorithm consists in recursively partitioning the stroke set according to structures defined in the grammar and it does not impose constraints present in some previous works (e.g. stroke ordering). By avoiding such constraints and thanks to the powerful representativeness of graphs, our approach can be adapted to the recognition of different graphic notations. We show applications to the recognition of mathematical expressions and flowcharts. Experimentation shows that our method obtains state-of-the-art accuracy in both applications.

INTRODUCTION

R ECOGNITION of online handwriting aims at finding the best interpretation of a sequence of input strokes [START_REF] Plamondon | On-line and off-line handwriting recognition: A comprehensive survey[END_REF]. Roughly speaking, handwriting data can be divided into two broad categories: text and graphics. In text notation, symbols are usually composed of strokes that are consecutive relative to a time or spatial order; and symbols themselves are also arranged according to a specific order, for example, from left to right. The ordering of symbols defines a single adjacency, or relation type, between consecutive symbols. By contrast, graphics encompass a variety of object types such as mathematical or chemical expressions, diagrams, and tables. Symbols in graphics notation are often composed of strokes that are not consecutive with respect to neither time nor spatial order. Furthermore, a diversified set of relations is possible between arbitrary pairs of symbols. See Figure 1, for instance, where a handwritten mathematical expression illustrates some characteristics of graphics notation.

Due to the linear arrangement of symbols, text recognition can be modeled as a parsing of one-dimensional (1D) data. On the other hand, graphics are intrinsically two-dimensional (2D) data, requiring a structural analysis, and there are no standard parsing methods as in the 1D case. Parsing depends on symbol segmentation (or, stroke grouping), symbol identification, and analysis of structural relationship among constituent elements. Stroke grouping in texts is relatively simpler than in graphics as already mentioned. Identification of segmented symbols include challenges such as the possibly large number of symbol classes, shape similarity between symbols in distinct classes, and shape variability within a same class (e.g. arrows in flowcharts might include arbitrary curves, and be directed towards any orientation). Structural analysis involves the identification of relations between symbols and a coherent integrated interpretation. The large variety of relations arXiv:1709.06389v1 [cs.CV] 19 Sep 2017 might define complex hierarchical structures that increments the difficulty in terms of efficiency and accuracy. There is a strong dependency among the three tasks since symbol segmentation and classification algorithms must often rely on structural or contextual information to solve ambiguities, and structural analysis algorithms depend on symbol identification to build coherent structures.

Although recognition of 2D objects is a subject of study since long ago [START_REF] Marriott | A Survey of Visual Language Specification and Recognition[END_REF], many of the efforts are still focused on solving specific aspects of the recognition process (e.g., detection of constituent parts or classification of components and their relations). A large number of works that tackle the entire recognition problem is clearly emerging, but they are often restricted to specific application domains and have limitations [START_REF] Lin | Table detection in online ink notes[END_REF], [START_REF] Chen | On-line handwritten flowchart recognition based on logical structure and graph grammar[END_REF], [START_REF] Álvaro | An integrated grammar-based approach for mathematical expression recognition[END_REF].

Motivated by the problem of online handwritten mathematical expression recognition, we have examined issues related to the recognition process and identified three features that are desirable. The first feature is multilevel information integration. By multilevel information integration we mean integrating symbol and structural level information to find the best interpretation of a set of strokes. In mathematical expression recognition, methods that seek information integration have already been the concern of several works [START_REF] Awal | Improving online handwritten mathematical expressions recognition with contextual modeling[END_REF], [START_REF] Álvaro | Recognition of printed mathematical expressions using two-dimensional stochastic context-free grammars[END_REF], [START_REF] Maclean | A new approach for recognizing handwritten mathematics using relational grammars and fuzzy sets[END_REF], but it is still one of the most challenging problems. The second feature is related to model generalization. Existing methods often limit the type of expressions to be recognized (for instance, do not include matrices), consider a fixed notation (for instance, it adopts either n i=1 x i or n i=1 x i ), or limit the set of mathematical symbols to be recognized. Any extensions regarding these limitations may require major changes in the recognition algorithms. The third feature is computational complexity management. A general model often results in exponential time algorithms, making its application unfeasible. Existing models handle time complexity issues by adopting constraints that limit the recognizable structures [START_REF] Maclean | A new approach for recognizing handwritten mathematics using relational grammars and fuzzy sets[END_REF], [START_REF] Celik | Probabilistic mathematical formula recognition using a 2D context-free graph grammar[END_REF].

To deal with the issues described above, we have elaborated a general framework for the recognition of online handwritten mathematical expressions and then show its generality by building a flowchart recognition system using the same framework. We model a mathematical expression as a graph, and represent the recognition problem as a graph parsing problem. The recognition process is divided into three stages: (1) hypotheses identification, (2) graph parsing, and (3) optimal interpretation retrieval. The first stage computes a graph, called hypotheses graph, that encodes plausible symbol interpretations and relations between pairs of such symbols. The second stage parses the set of strokes to find all interpretations that are valid according to a predefined graph grammar, using the hypotheses graph to constrain the search space. The parsing method is based on a recursive search of isomorphisms between a labeled graph defined in the graph grammar and the ones derived from the hypotheses graph. The last stage retrieves the most likely interpretation based on a cost function that models symbol segmentation, classification and structural information jointly.

Conceptually, the valid structures are defined through a graph grammar and likely structures in the input stroke set are captured in the hypotheses graph. Thus, the proposed framework enhances independence of the parsing step with respect to specificities of the mathematical notation considered. As a consequence, we have a flexible framework with respect to different mathematical notations. For instance, new expression structures can be included in the family of expressions to be recognized by just including the structures in the grammar rules. Similarly, the class of mathematical symbols to be recognized can be extended by just including new symbol labels in the grammar and in the hypotheses graph building procedure. With respect to graphics in general, among them there is large difference in the set of symbols and relations between symbols. Thus, recognition techniques are often developed for a specific family of graphics, introducing constraints that not only limit their effectiveness, but also their adaptation to recognize different families of graphics. In spite of these differences, graphic notations share common concepts -a set of interrelated symbols spread over a bidimensional space, organized in hierarchical structures that are decisive to the interpretation. We argue that the flexibility of the proposed framework encompasses other families of graphics. This argument is supported by the fact that graphs has already proven adequate to model graphics in general. In addition, there are examples that show that families of graphics can be specified by means of a graph grammar [START_REF] Álvaro | An integrated grammar-based approach for mathematical expression recognition[END_REF], [START_REF] Rekers | Defining and parsing visual languages with layered graph grammars[END_REF], [START_REF] Han | Bottom-up/top-down image parsing by attribute graph grammar[END_REF]. Moreover, hypotheses graphs can be built based on datadriven approaches.

The main contributions of this work are thus twofold. First, we present a general framework in which the parsing process is independent of the family of graphics to be recognized and a control of the computational time is possible by means of a hypotheses graph. Second, we demonstrate an effective application of the framework to the recognition of mathematical expressions and flowcharts.

The remaining of this text is organized as follows. In Section 2 we review some methods and concerns in previous works related to the recognition of mathematical expression and flowcharts, as these types of graphics served as the ground for the development of the method described in this manuscript. We also briefly comment on some works that proposed graph grammars for the recognition of 2D data and influenced our work. In Section 3 we detail the proposed framework. Then in Section 4 we describe how the elements and parameters required by the framework have been defined for the recognition of mathematical expressions and flowcharts. In Section 5 we present and discuss the experimental results for both applications, and in Section 6 the conclusions and future works.

RELATED WORK

In this section, we review some characteristics of the recognition process in previous works, with emphasis on methods for mathematical expression [START_REF] Blostein | Recognition of mathematical notation[END_REF], [START_REF] Chan | Mathematical expression recognition: a survey[END_REF], [START_REF] Zanibbi | Recognition and retrieval of mathematical expressions[END_REF] and flowchart recognition [START_REF] Miyao | On-line handwritten flowchart recognition, beautification and editing system[END_REF], [START_REF] Carton | Fusion of statistical and structural information for flowchart recognition[END_REF], [START_REF] Bresler | Recognition system for on-line sketched diagrams[END_REF].

Early works related to the recognition of mathematical expressions were predominantly based on a sequential recognition process consisting of the symbol segmentation, symbol identification and structural analysis steps [START_REF] Matsakis | Recognition of handwritten mathematical expressions[END_REF], [START_REF] Tapia | Recognition of on-line handwritten mathematical expressions using a minimum spanning tree construction and symbol dominance[END_REF], [START_REF] Zanibbi | Recognizing mathematical expressions using tree transformation[END_REF]. However, a weakness of sequential methods is the fact that errors in early steps are propagated to subsequent steps. For instance, it might be difficult to determine if two handwritten strokes with shape ")" and "(", close to each other, form a single symbol "x", or are the opening and the closing parentheses, respectively. To solve this type of ambiguity, it may be necessary to examine relations of the strokes with other nearby symbols or even with respect to the global structure of the whole expression. This type of observation has motivated more recent works to consider methods that integrate symbol and structural level interpretations into a single process. Most of them are based on parsing methods as described below.

Given an input stroke set, the goal of parsing is to find a parse tree that "explains" the structure of the stroke set, relative to a predefined grammar. From a high-level perspective, parsing-based techniques avoid sequential processing by generating several symbol and relation interpretations, combining them to form multiple interpretations of the whole input stroke set, and selecting the best one according to a score (based on the whole structure).

An important element in parsing based approaches is the grammar. A grammar defines how we model a (graphics) language. For mathematical expressions, most approaches [START_REF] Álvaro | A shape-based layout descriptor for classifying spatial relationships in handwritten math[END_REF], [START_REF] Awal | Towards handwritten mathematical expression recognition[END_REF], [START_REF]A global learning approach for an online handwritten mathematical expression recognition system[END_REF], [START_REF] Yamamoto | Online recognition of handwritten mathematical expressions based on stroke-based stochastic context-free grammar[END_REF], [START_REF] Simistira | Recognition of online handwritten mathematical formulas using probabilistic SVMs and stochastic context free grammars[END_REF] use modifications of context-free string grammars in Chomsky Normal Form 1 (CNF). Such grammars define production rules of the form A r → BC, where r indicates a relation between adjacent elements of the right hand side (RHS) of the rule. For instance, expression 4 2 can be modeled through a rule T ERM superscript → N U M BER N U M BER. However, as such grammars impose the restriction of having at most two elements on the RHS of a rule, structures with more than two components, like 2 + 4, or n i x i , must be modeled as a recursive composition of pairs of components. MacLean et. al. [START_REF] Maclean | A new approach for recognizing handwritten mathematics using relational grammars and fuzzy sets[END_REF] proposed fuzzy relational context free grammars to overcome this limitation. They included production rules of the form: A r → A 1 A 2 . . . A k , where r indicates a relation between adjacent elements of the RHS of the rule. However, the model assumes that the relation can only be of vertical or horizontal types. Celik and Yanikoglu [START_REF] Celik | Probabilistic mathematical formula recognition using a 2D context-free graph grammar[END_REF] use graph grammars with production rules of the form A → B, where both A and B are graphs, and B represents the components of a subexpression as vertices and their relations as edges. Graph grammar models offer more powerful representativeness compared to string grammars. However, the authors limit the grammars to have specific structures (each graph in a rule is either a single vertex graph, or a star graph -a graph with a single central vertex and surrounding vertices that are connected only to the central one), largely restricting the set of recognizable expressions.

With respect to parsing, most algorithms proposed in the literature for mathematical expressions are based on the CYK algorithm [START_REF] Younger | Recognition and parsing of context-free languages in time n 3[END_REF]. The CYK algorithm assumes that the input (in our case) strokes form a sequence and the grammar is in CNF. Those based on bottom-up approaches build a parse tree by first identifying symbols (leaves) from 1. In a CNF, all production rules either have the form A → a, or A → BC, where a is a terminal and A, B, and C are non-terminals single or groups of consecutive strokes, and then combining the symbols recursively to form subcomponents (subtrees), until obtaining a component that covers the whole input set. To adapt the CYK algorithm to the recognition of mathematical expressions, Yamamoto et. al. [START_REF] Yamamoto | Online recognition of handwritten mathematical expressions based on stroke-based stochastic context-free grammar[END_REF] introduced an ordering of the strokes based on the input time. Other approaches avoid the stroke ordering assumption, but introduce different constraints to satisfy the decomposition of the input into pairs of components [START_REF] Álvaro | A shape-based layout descriptor for classifying spatial relationships in handwritten math[END_REF], [START_REF] Awal | Towards handwritten mathematical expression recognition[END_REF], [START_REF]A global learning approach for an online handwritten mathematical expression recognition system[END_REF], [START_REF] Simistira | Recognition of online handwritten mathematical formulas using probabilistic SVMs and stochastic context free grammars[END_REF]. MacLean et. al. [START_REF] Maclean | A new approach for recognizing handwritten mathematics using relational grammars and fuzzy sets[END_REF] proposed a top-down parsing algorithm that does not assume grammars in CNF, but assumes that the input follows either a vertical or horizontal ordering (the fuzzy relational context free grammars mentioned above). Methods that use the CYK algorithm or others borrowed from the context of string grammars must decompose the 2D input into a set of 1D inputs. As there is no guarantee that such decomposition is possible, these methods may present strong limitations with respect to parsable 2D structures and be completely inappropriate for other types of 2D data.

On the other hand, methods that consider graph grammars face computational complexity issues. A key step of any parsing algorithm is the definition of how a stroke set can be partitioned according to the RHS of a rule. Let us consider a set of n strokes. Assuming stroke ordering and a CYK-based algorithm as in [START_REF] Álvaro | A shape-based layout descriptor for classifying spatial relationships in handwritten math[END_REF], [START_REF] Awal | Towards handwritten mathematical expression recognition[END_REF], [START_REF]A global learning approach for an online handwritten mathematical expression recognition system[END_REF], [START_REF] Yamamoto | Online recognition of handwritten mathematical expressions based on stroke-based stochastic context-free grammar[END_REF], [START_REF] Simistira | Recognition of online handwritten mathematical formulas using probabilistic SVMs and stochastic context free grammars[END_REF], rules have at most two components in the RHS and therefore the number of meaningful partitions is O(n) -we can assign the first i strokes to the first component and the rest for the second, with i ∈ {1, . . . , n -1}. On the other hand, if we do not impose CNF, but keep the stroke ordering assumption as in [START_REF] Maclean | A new approach for recognizing handwritten mathematics using relational grammars and fuzzy sets[END_REF], then a rule may have k symbols on its RHS, and the number of meaningful partitions is O n k , corresponding to k -1 split points on the sequence of n strokes. In graph grammars, without any restriction and a rule with k vertices in the RHS, the number of partitions is O(n k ) -any non-empty stroke subset can be mapped to any vertex. Restricting the graph structures in the grammar, for instance to star graph structures as done by Celik and Yanikoglu [START_REF] Celik | Probabilistic mathematical formula recognition using a 2D context-free graph grammar[END_REF], is a way to manage the parsing complexity. Note, however, that in this case the set of recognizable expressions is constrained not only by the parsing algorithm but also by the grammar.

Flowcharts in general have a smaller symbol set than mathematical expressions. However, their structure presents higher variance. For instance, the flowchart in Figure 2 includes two loops, and adjacent symbols can be located at any (vertical, horizontal, or diagonal) position relative to each other, regardless the relation type. In contrast, in mathematical expressions, for a given relation type between two symbols (e.g. superscript) it is expected that one symbol is located at some specific area relative to the other (e.g. topright). Thus, for flowcharts it may be difficult to establish a spatial ordering of the input strokes.

To cope with the structural variance of diagrams, some approaches introduce strong constraints in the input, as requiring all symbols to have only one stroke [START_REF] Yuan | A novel pen-based flowchart recognition system for programming teaching[END_REF], or looplike symbols to be written by consecutive strokes [START_REF] Miyao | On-line handwritten flowchart recognition, beautification and editing system[END_REF]. With respect to symbol recognition, detection of texts (or text box) and arrow symbols are regarded as more difficult, as they do not present a fixed shape. For instance, Carton et. al. [START_REF] Carton | Fusion of statistical and structural information for flowchart recognition[END_REF] determine box symbols (like decision, and data structure) and then select the best interpretations using a deformation metric. Text symbols are recognized only after box symbols. Bresler et. al. [START_REF] Bresler | Recognition system for on-line sketched diagrams[END_REF] also first recognize possible box and arrow symbols, and leave text recognition as a last step. After symbol candidates are identified, the best symbol combination is selected through a max-sum optimization process. An interesting example of graph grammar use is described in [START_REF] Han | Bottom-up/top-down image parsing by attribute graph grammar[END_REF]. The authors propose an attributed graph grammar that allow attributes to be passed from node to node in the grammar, both vertically and horizontally, to describe a scene of man-made objects. Projection of rectangles are used as primitives. However, passage of attributes must be evaluated during parsing, making the parsing algorithm be context-dependent. In [START_REF] Rekers | Defining and parsing visual languages with layered graph grammars[END_REF] entity-relationship diagrams are modeled by a context-sensitive graph grammar with the "left-hand side of every production being lexicographically smaller than its right-hand side". A critical part of the parsing algorithm is to find matchings of the right-hand side of a rule to replace the left-hand-side, making it very complex.

The above review on some characteristics related to the recognition of 2D data illustrates that existing methods present several restrictions and limitations and clearly can not be easily transposed to the recognition of other families of graphics.

In the method proposed in this work, instead a CYKbased algorithm (that assumes a grammar in CNF), we define a graph grammar and use a top-down parsing algorithm, similar to the one of [START_REF] Maclean | A new approach for recognizing handwritten mathematics using relational grammars and fuzzy sets[END_REF], but without assuming any ordering of the input strokes. To avoid context-aware algorithms during parsing, we consider stroke partitions drawn from a previously built hypotheses graph (see Section 3.4) to match the right-hand side of the rules. By doing this, we decouple the parsing algorithm from the particularities of the family of graphics, and achieve independence of the target notation. In addition, it is important to note that target domain knowledge can be fully exploited in the graph grammar definition and hypotheses graph building. This characteristic makes the proposed method general enough to be applied to the recognition of a variety of graphic notations.

THE PROPOSED RECOGNITION FRAMEWORK

The proposed recognition framework is composed of three main parts: (1) hypotheses graph generation, (2) graph parsing, and ( 3) optimal tree extraction. In the first part, stroke groups that are likely to represent symbols, and a set of possible relations between these stroke groups are identified and stored as a graph, called hypotheses graph. In the second part, valid interpretations (potentially multiple of them) are built from the hypotheses graph by parsing it according to a graph grammar. The interpretations found are stored in a parse forest. Then, in the third part an optimal tree is extracted from the parse forest, based on a scoring function.

We first discuss the two main input data of the framework, a handwritten input graphic to be recognized (a set of strokes) and a graph grammar, and then detail the three parts, keeping an abstraction level suitable for the recognition of a variety of graphics in general. Concepts are illustrated using mathematical expressions as examples. Implementation related details regarding the application of the framework to the recognition of mathematical expressions and flowcharts are presented in Section 4.

Stroke set

Online handwriting consists of a set of strokes. Each stroke is, typically, a sequence of point coordinates sampled from the moment a writing device (such as a stylus) touches the screen up to the moment it is released. We assume that each stroke belongs to only one symbol (this assumption is common when dealing with handwritten graphics). Otherwise, a preprocessing step could be applied to split a stroke that is part of two or more symbols. These concepts are illustrated in Figures 3a and3b

Graph grammar model

A graph grammar [START_REF] Pflatz | Web grammars[END_REF] defines a language of graphs. We denote a graph G as a pair (V G , E G ), where V G represents the set of vertices of G and E G represents the set of edges of G. A labeled graph is a graph with labels in its vertices and edges. Hereafter we assume labeled graphs, with labels defined by a function l that assigns symbol labels (in a set SL) to vertices and relation labels (in a set RL) to edges. We define a family of graph grammars, called Graphic grammars, to model graphics as labeled graphs.

Definition 1.

A graphic grammar is a tuple M = (N, T, I, R) where:

• N is a set of non-terminal nodes (or non-terminals);

• T is a set of terminal nodes (or terminals), such that N ∩ T = ∅ (for convenience we denote elements in T using the same names used for the labels in SL);

• I is a non-terminal, called initial node;

• R is a set of production (or rewriting) rules of the form A := B where A is a non-terminal node and

B = (V B , E B ) is a connected graph with label l(v) ∈ N ∪ T for each v ∈ V B , and label l(e) ∈ RL for each e ∈ E B .
Note that M is a context-free graph grammar [START_REF] Pflatz | Web grammars[END_REF]. The language defined by a graphic grammar M = (N, T, I, R) is a (possibly infinite) set of connected labeled graphs and is denoted L(M ). Similarly to string grammars, a labeled graph G belongs to L(M ) if G can be derived (or generated) from the initial non-terminal node I by successively applying production rules in R, until obtaining a graph with only terminal nodes.

Figure 4 shows a graphic grammar that models simple arithmetic and logical expressions. Each production rule defines the replacement of a non-terminal, a single vertex graph G l at the left hand side (LHS) of the rule, with a graph G r at the right hand side (RHS). The definition of how a replacing graph should be linked to a host graph G is called embedding [START_REF] Pflatz | Web grammars[END_REF], and it should be specified for each production rule. Formally, given a production rule G l := G r , its application consists in replacing a subgraph G l of G with G r and the embedding defines how G r will be attached to G\G l . The attachment may be defined by a set of edges that link the replacing graph G r to G \ G l . For instance, Figure 6 shows two different embeddings for The embedding specification depends on the desired language. It is possible to define a same embedding specification for all rules, as we do for mathematical expressions (see Section 4). An embedding can also take spatial information into consideration, for example by including edges only between spatially close vertices. More detailed examples of embeddings are provided in Section 4, through applications to the recognition of mathematical expressions and flowcharts. To ensure that the generated graphs are connected, we assume that every embedding is specified in such a way that its application generates connected graphs.

(r) = {(V, D)|(V, A) ∈ G}∪ {(D, V )|(A, V ) ∈ G} (r) = {(V, E)|(V, A) ∈ G}∪ {(E, V )|(A, V ) ∈ G} A D E w := r:

Hypotheses graph generation

Given a set of strokes S, we define a hypotheses graph as an attributed graph H = (V H , E H ), where V H is a set of symbol hypotheses and E H is a set of relation hypotheses computed from S. Each symbol hypothesis v ∈ V H corresponds to a subset of S, denoted as stk(v), and has as an attribute a list L(v) = {(l i , s i ), i = 1, . . . , k v } of likely interpretations. Each of these interpretations (l i , s i ) consists of a symbol label l i ∈ SL and its respective likelihood score s i ∈ [0, 1]. Note that a stroke may be shared by multiple symbol hypotheses. Relation hypotheses (edges in E H ) are defined over pairs of disjoint symbol hypotheses (i.e., hypotheses such that their stroke sets are disjoint), and also have as an attribute a list of likely relation interpretations denoted L(e). Relation labels are in RL. Figure 7 shows a handwritten mathematical expression and a hypotheses graph calculated from it. To build a hypotheses graph, machine learning methods are effective in identifying groups of strokes that may form symbols and, similarly, relations among them (see application example in Section 4). Since many stroke groups do not correspond to an actual symbol and many pairs of symbols are not directly related each other within a graphic, rather than training classifiers to identify only true hypotheses, those that do not represent any symbol or relation can be included as elements of an additional class, called junk. Training data can be extracted from within the graphic, together with surrounding context, in order to improve rejection of false hypotheses. As will become clear later, hypotheses graphs play an important role to constrain the search space during the parsing process. A high precision and recall in the identification of symbol hypotheses and relations is thus desirable to efficiently constrain the search space.

Label list pruning

To define the labels and respective likelihood scores of symbol and relation hypotheses, we could use the confi-dence scores returned by the respective classifiers. However, to manage complexity, only class labels that present high confidence scores should be kept. Selecting the labels to be kept based on a fixed global confidence threshold value is not adequate since label distributions vary greatly among symbols and relations. An effective method to select the most likely labels for each hypothesis h is described next.

Let {(l i , s i ), i = 1, ..., n h } be the pairs of labels and respective scores initially attributed to h, sorted in descending order according to the likelihood scores s i . Then, given a distribution threshold tr (between 0 an 1), we define the minimum number of k top ranked labels whose confidences sum up to at least tr:

k = arg min x x i=1 s i > tr ( 1
)
Hypothesis h is rejected if it presents highest score for the junk class label and if that score is above the threshold tr. Otherwise, we set L(h) = {(l i , s i ) : i = 1, . . . , k}. We define label pruning thresholds t symb for symbols and t rel for relations.

Graph parsing

The goal of the parsing process is to build a parsing tree that explains the set of input strokes S input , according to a grammar. Since there might be more than one interpretation, multiple trees might be generated, possibly sharing subtrees each other. Thus, they will be stored in a parse forest.

Figure 8 shows a parse forest calculated from the hypotheses graph of Figure 7, using the graph grammar of Figure 4. As can be seen, the root node (top of the figure) corresponds to the starting non-terminal M E. Two branches are generated from rules associated to M E. The left branch is generated by applying rule 2 and the right branch by applying rule 1. Note that, for each rule, any of the resulting partition of the strokes induces a graph that is isomorphic to the RHS graph of the respective rule. The same principle holds for the remaining of the nodes.

The parsing process follows a top-down approach. To understand the parsing process, a key step is to understand how a stroke set is partitioned when a rule is applied. More specifically, given a set of strokes S and a non-terminal N T , for each rule A := B associated to N T , we must find every partition of S that is a valid matching to B. A partition of S is a matching to B if its number of parts is equal to the number of vertices of B, so that each part can be assigned to one vertex in B. A matching is valid if the following two conditions hold: (1) the partition of S induces a graph that is isomorphic to B, and (2) each subset of strokes assigned to a vertex of B must be parsable according to the grammar.

Supposing the number of vertices in B is k and the number of strokes in S is n, without any constraint, the total number of possible stroke partitions to be examined to generate the valid matchings would be O(k n ). Exhaustively examining each of these partitions is not computationally practical.

A main strategy of our method is to constrain the number of partitions to be examined with the aid of the hypotheses graph. We assume that all meaningful interpretations are present in the hypotheses graph as a subgraph. Thus, before starting the parsing process, we build the set of all stroke groups, denoted hereafter as ST K, underlying any valid connected subgraph of H. Note that these stroke groups must not contain repeated strokes, i.e., a valid subgraph is one in which a same stroke is not present twice. Furthermore, not all stroke groups will be necessarily parsable. The relation between two stroke groups is also recorded in STK as being the same between the corresponding subgraphs. Hence, during parsing, the search space of valid matchings will be restricted to those present in ST K. Once a valid matching is found, an instance of B, which we call instantiated graph, will be recursively parsed and will become a parsed graph when each of its vertices is successfully parsed.

The complete algorithm is described next. For the sake of simplification, we will assume that the input grammar contains only two types of rules: terminal and non-terminal. Terminal rules are productions of the form A := b, where the RHS graph b is a single vertex graph, with labels in the terminal set, such as rules from r-7 to r-73 of the grammar of Figure 4. Non-terminal rules are productions of the form A := B, where B is a graph containing one or more vertices, each of them with non-terminal labels, such as rules r-1 to r-6 of the grammar of Figure 4. Thus, Algorithm 1 considers only these two types of rules. Its extension to treat rules that contain both terminals and non-terminals in its right-hand side is a straightforward combination of the previous two cases.

Algorithm 1 receives as inputs a stroke set S = {stk 1 , . . . , stk n } and a non-terminal N T . Initially, the set of strokes is the whole input set S input and the non-terminal is the starting node I. Then, it applies each of the production rules that have N T as the LHS graph and returns a set (parsedG) containing all parsed graphs, together with the respective rules that "generated" them. To avoid recomputation, a global table T BL indexed by pairs (S = {stk 1 , . . . , stk n }, N T ) is used. An entry in TBL is of the form T BL[(S, N T )] = {(G 1 , r 1 ), . . . , (G q , r q )} where G i is a parsed graph and r i is the rule that "generated" G i . At the end of the algorithm, if the pair (S, N T ) is not parsable, the corresponding entry in T BL is empty.

Lines 2-3 verify if the pair (S, N T ) has already been processed. If so, results are retrieved from T BL and returned. Otherwise, lines 5-18 iterate over the rules that have N T in its LHS graph. If the rule is of terminal type (lines 6-10), it suffices to check if the RHS vertex label, l(b), is contained in the set of labels L(S) attributed to the underlying stroke set. This verification is done by checking if the stroke set S corresponds to a vertex in the hypotheses graph and if the label set of the corresponding vertex includes l(b). Then a single vertex graph is built and stored together with the rule in parsedG. If the rule is of non-terminal type (lines 11-17), for each valid matching between S and B (line 12) we verify if the instantiated graph is parsable. The parsing result, either a list of parsed graphs, or an empty list (in case of parsing failure), is added to T BL. As already mentioned, table T BL is used to avoid parsing recomputation of pairs (S, N T ). At the end of the parsing process, the parse forest can be extracted from T BL by traversing it starting from index (S input , I).

Pruning strategies

Besides constraining the partitions to be examined to only those formed by stroke groups that underlie a subgraph of H, there are other strategies that can be used to speed up computation. For example, determining the maximum and minimum size of non-terminal nodes is a strategy that has been previously used in text parsing [START_REF] Grune | Parsing Techniques: A Practical Guide[END_REF]. The sizes, in terms of graphic symbols or strokes, can be computed directly from the grammar. Based on these numbers, during parsing any stroke subsets that are out of the min-max ranges do not need to be evaluated. This information can be calculated when building ST K. Moreover, to find valid matching partitions, the minimum and maximum sizes of the stroke subsets already matched to some vertices can be used to determine the minimum and maximum size of the stroke groups that still can be matched to the rest of the nodes.

Another useful information is to explore the knowledge that a non-terminal can generate only a specific subgroup of the terminals. For instance, in the grammar of Figure 4, non-terminal OP can generate only symbols +, -, <, or >. Thus, stroke subsets that do not contain any hypothesis with one of such labels as terminals are not evaluated during the parsing process. Analogously, stroke groups that correspond to symbol and relation hypotheses with high mean junk score can be disregarded. Specifically, stroke subsets with a certain number (five, for example) symbol hypotheses, having mean junk score, including both symbol and relation labels, above a given junk threshold t junk will not be considered. This pruning is mainly useful when the symbol and relation hypotheses have a large number of labels. High mean junk score indicates that it is unlikely that the underlying group of strokes is parsable.

Optimal parse tree extraction

Once a parse forest is built, the final step consists in traversing it to extract the best tree (interpretation). To characterize what is an optimal tree (best interpretation), we first define a cost function for trees. Roughly stating, an interpretation will be considered of low cost if its corresponding parse tree includes substructures with high confidence scores.

We introduce a few notations that will be helpful. Let x denote a node in the parse forest. Let G x = (V x , E x ) be the graph instantiated at node x. Each vertex v ∈ V x has an underlying set of strokes, stk(v). For each terminal vertex v ∈ V x there will be a pair (label(v), score(v)) ∈ SL × [0, 1] and for each edge e ∈ E x will be a pair (label(e), score(e)) ∈ RL × [0, 1].

The cost of a tree can be computed bottom-up. We first define individual costs relative to symbols and relations, and then define how to combine the two to determine the cost of a tree. Let t be a parse tree and let x be a node in t. Let child(x) denote the child nodes of x. The subtree in t with root at x is denoted t x . We first assign to a node x a symbol cost J s (x):

J s (x) =        -log score(v), if x is terminal, with V x = {v}, y∈child(x) J s (y) if x is non-terminal, (2)
and a relation cost J r (x):

J r (x) = e∈Ex -log score(e) + y∈child(x) J r (y) (3)
Then, the cost of t x is defined as

J(t x ) = α n s J s (x) + 1 -α n r J r (x) (4)
where n s and n r are, respectively, the number of symbols and relations under t x . Parameter α weights both types of costs, and could be adjusted to give more relevance to one or to the other.

An example of a tree is shown in Figure 9. Its root node is x 1 and thus the tree is denoted t x1 . The cost of tree t x1 is given in Eq. 5.

x 1 M E v 1 x 2 OP v 3 T RM v 2 T RM v 4 x 7 < v 10 x 8 CHAR v 11
x 9 1

v 12 x 3 TRM v 5 CHAR v 6
x 4 CHAR v 7

x 5 P v 8

J(t x1 ) = α 4 J s (v 8 ) + J s (v 9 ) + J s (v 10 ) + J s (v 12 ) + 1 -α 3 J r (e 1 ) + J r (e 2 ) + J r (e 3 ) (5)
In order to extract the best tree, the cost of each tree in the parse forest must be computed. Since the trees in the parse forest share subtrees, this fact can be explored to avoid computing the cost of a shared subtree repeatedly. In addition, from an application point of view, being able to efficiently retrieve a number of best parse trees rather than just the best one is often desirable. We borrow ideas from the tree extraction technique, in the context of string grammars, proposed by Boullier et al. [START_REF] Boullier | Constructing parse forests that include exactly the N-best PCFG trees[END_REF]. Given a parse forest, they proposed a method that builds a new parse forest with a fixed number of n-best trees, using a bottomup approach. The resulting parse forest can be further processed to improve the recognition result, for example, by doing a re-ranking of the trees, a processing that could be too expensive to be done in the original parse forest.

Note that there might be multiple subtrees with root at a node x in the parse forest. For instance, in the parse forest of Fig 8, the vertex in the bottom left non-terminal node graph has two possible derivations ("P" or "p"). Whenever there are multiple derivations from a non-terminal vertex, only one of them will be present in a parse tree. Thus, given a node x in the parse forest, let us denote by t

(i)
x , i ∈ I x , the spanned trees from x. The number of possible trees in the forest is combinatorial with respect to the multiple subtrees spanned from the nodes in a path from the root node to a leaf node.

We use a bottom-up approach to compute, for each node x in the forest, a list of subtrees spanned from it. This information is kept as a table in the node, and each row of the table stores information to recover one of the spanned trees (specifically, it stores the partition of the stroke set resulting from the corresponding derivation). After the bottom-up process finishes, individual trees can be extracted by performing a top-down traversal, starting from each row of the table at the root node of the forest. The best tree, according to the specified cost, is the one recovered by starting the traversal from the first row of the table.

However, since there might be a large number of parse trees in the forest, a naive application of the method described above may be computationally prohibitive. To overcome this problem, a pruning strategy can be applied during the bottom-up step to keep table sizes manageable: for each table, spanned trees that have a cost much higher than the best tree are discarded. To compute relative differences of cost, let minJ(x) be the minimum cost tree spanned from x. Then, given t pr ∈ [0, 1], a spanned tree t (i)

x is kept if

|J(t (i) x ) -minJ(x)| < t pr * minJ(x) . ( 6
)
This strategy resembles the one proposed in [START_REF] Boullier | Constructing parse forests that include exactly the N-best PCFG trees[END_REF], but it differs in the sense that while they keep a fixed number of best trees, we keep only the relatively likely ones. The more ambiguous the input, the more parse trees are kept.

The pruning threshold t pr can be empirically estimated.

APPLICATIONS

The application of the framework requires the definition of some key elements. First, a graph grammar that models the family of graphics to be recognized must be defined. A set of labels for the relations (RL) and for the symbols (SL), including junk, must be defined. Second, a hypotheses graph generated from the set of input strokes, with symbol labels in SL and relation labels in RL, must be provided. Terminal nodes of the grammar are named using the labels in SL, while edges in the graphs of the grammar are labeled using labels in RL. For parsing, an embedding method must be defined for each grammar rule. In this section, we detail how these elements as well as important parameter values have been defined for the recognition of mathematical expressions and flowcharts. Results and discussions are presented in the next section. The grammars in xml format are available at www.vision.ime.usp.br/ ∼ frank.aguilar/grammars/. Before applying the recognition method itself, we applied to the set of strokes the smoothing and resampling methods described in [START_REF] Delaye | Hbf49 feature set: A first unified baseline for online symbol recognition[END_REF]. Smoothing removes abrupt trajectory changes in the strokes and resampling makes point distribution uniform -equally spaced -along the strokes. In the evaluating datasets, each stroke belongs to only one symbol; thus no additional preprocessing was needed.

Recognition of mathematical expressions

Dataset and Grammar

We use the CROHME-2014 dataset [START_REF] Mouchère | Competition on recognition of on-line handwritten mathematical expressions (CROHME 2014)[END_REF]. It consists of handwritten expressions divided into training and test sets, with 9, 507 and 986 expressions, respectively. The expressions include 101 symbol classes, and six relation classes (horizontal as in "ab", above as in "

x ", below as in "

x ", superscript as in "a b ", subscript as in "a b ", and inside as in " √ x"). CROHME-2014 dataset provides a string grammar for the corresponding L A T E X expressions. Based on that string grammar, we defined a graph grammar with 205 production rules, including the rules to generate the 101 symbol labels (terminals).

To define the embeddings, we use the concept of baseline. A baseline in a graph is defined as a maximal path whose connecting edges have only the horizontal (h) label (this definition can be seen as a graph version of the baseline definition of [START_REF] Zanibbi | Recognizing mathematical expressions using tree transformation[END_REF]). A baseline is considered nested to a vertex v if it is connected to v by an edge (v, v ), where v is the first vertex of the baseline. A baseline that is nested to no vertex is called dominant baseline. Note that a baseline may consist of a single vertex.

Then, the embedding is defined as follows. Let r : G l := G r be a rule and let v be the leftmost and v be the rightmost vertices of the dominant baseline of G r . Let also G be a graph with an occurrence of G l , identified as a vertex u ∈ V G . The embedding associated to the application of rule r on G replaces u with G r , generating an updated graph G , such that

V G = V G \ {u} ∪ V Gr and E G = [E G \ ({(u , u) : u ∈ V G } ∪ {(u, u ) : u ∈ V G })] ∪ where = {(u , v ) : (u , u) ∈ E G } ∪ {(v , u ) : (u, u ) ∈ E G }. (7)
In other words, all edges that were incident on u will be made incident to v and all edges that were originated from u will be made originating from v .

Hypotheses graph building

To generate the hypotheses graph, we used the symbol segmentation and classification methods described in [START_REF] Julca-Aguilar | Progress in Pattern Recognition, Image Analysis[END_REF], [START_REF] Julca-Aguilar | Mathematical symbol hypothesis recognition with rejection option[END_REF], along with the spatial relation classification methods described in [START_REF] Julca-Aguilar | Subexpression and dominant symbol histograms for spatial relation classification in mathematical expressions[END_REF]. They are based on multilayer neural networks with shape context descriptor [START_REF] Belongie | Shape matching and object recognition using shape contexts[END_REF], and images created from symbols and relations, including neighboring strokes to be used as contextual information. The networks use a softmax output which is then converted to a cost measure (applying the negative logarithm to the output) in order to be used in the cost function defined in Eq. 4.

An important parameter to build the hypotheses graph is the symbol and relation label pruning thresholds, t symb and t rel (see Eq. 1). These threshold values determine how many and which labels will be attached to each vertex and edge. Since during the parsing process the partitions of the stroke set and labels are constrained by the hypotheses graph, the achievable maximum recognition rates are bounded by possibilities encoded in the hypotheses graph.

From the training set, we randomly selected 950 expressions (about 10%) to serve as a validation set and used the rest for training. Using the trained symbol and relation classifiers, we evaluated the effect of varying values of t symb and t rel on the validation set. For each threshold value we computed the symbol, relation and complete expression recalls, that is, how many of each of these components were present in the hypotheses graph.

Figure 10 shows the results relative to this evaluation, over t symb in the range [0.4 -1] (for values less than 0.4, the performance was similar to the case of 0.4) and t rel in the range [0.1 -1]. Note that this evaluation is concerned with verifying how many of the elements of interest are, in fact, present in the hypotheses graph; it is not related with parsing. We can see in Figure 10 that even for the lowest threshold values the recall of symbols and relation is about 90%. For complete expressions (i.e. all symbols and relations of the expressions are in the hypothesis graph), however, the recall for the lowest threshold values is 40%. If symbol classification threshold is set to 1, 99, 75% of the symbols are correctly included. Since in this case no stroke group is rejected, 99, 75% is also the percentage of symbols identified by the stroke grouping method. If, in addition, we also set the relation classification threshold to 1, almost all relations and expressions are included (99, 45% and 98.11%, respectively).

Graph parsing and tree extraction

We also analyzed the effect of different values of t symb and t rel on the recall after parsing. We set the maximum value for t symb to 0.98 and for t rel to 0.85, as parsing large expressions with thresholds larger than those takes much time to be considered in a real application. In this evaluation, for optimal tree extraction we set α = 0.5 (same weight for the symbol and relation costs, see Eq. 4) and t pr = 0.1 (tree pruning threshold, see Eq. 6). Figure 11 shows the expression recall obtained by the parsing method and the corresponding recall obtained by the hypotheses graph generation step (note that the second indicates the maximum achievable recall). Although for values above t symb = 0.9 and t rel = 0.8 no considerable improvements are observed in the parsing recall, the gap between hypotheses graph recall and parsing recall increases up to about 40%. Thus, we chose t symb = 0.98 and t rel = 0.85, as these values allow to keep more hypotheses and can be useful during parsing of unseen expressions (better generalization).

Using t symb = 0.98 and t rel = 0.85, we have also evaluated the effect of different values of t pr (tree pruning threshold) and α (weighting in the cost function) on tree extraction on validation set. Through this evaluation, we set t pr = 0.1 and α = 0.4 (this choice was based on the best expression recall).

Recognition of flowcharts

Dataset and grammar

We use the flowchart dataset described in [START_REF] Awal | First experiments on a new online handwritten flowchart database[END_REF]. The dataset includes 7 symbol classes (arrow, connection, data, decision, process, terminator, and text), and three relation classes (Src, Targ, and AssTxt). An example was presented in Section 2 (Fig. 2), with strokes colored according to the symbol type they belong to. In this dataset, relations in each flowchart are established between "adjacent" symbols. For instance, in the flowchart of Figure 2, Src and Targ relations are defined between the top arrow and a terminal and data, respectively. In the same way, an AssTxt relation is defined between the top terminal and the text inside it. The flowcharts have been written by 36 people, and the dataset is divided into a train set with 248 and a test set with 171 flowcharts. The total number of symbols is about 9, 000.

As described in Section 2, text symbols have different characteristics than other flowchart symbols, and they are usually recognized through specific methods. Since flowchart recognition is addressed in this work with the aim of illustrating the application of the proposed framework, we are not specially concerned with recognition performance. Thus, we have opted on removing strokes corresponding to text symbols, as well as the respective relations (AssTxt) from the flowcharts. Symbol class text and relation class AssTxt were not considered. We note, however, that it would be equally possible to parse the integral flowchart without any changes in the parsing and tree extraction steps once adequate symbol and relation classifiers are developed for texts.

In contrast to the CROHME-2014 dataset, we found no grammar defined for the flowchart dataset. Thus, we defined a grammar with 16 production rules, where six of them generate the terminal symbols. The embedding is defined in a similar way to the one defined for mathematical expressions, except for the set of edges to be added. Let u denote the vertex to be replaced in G and v i ∈ V Gr the vertices in the replacing graph. The edges to be added are defined by:

={(u , v) | (u , u) ∈ E G and v = arg min vi cost r (u , v i )} ∪ {(v, u ) | (u, u ) ∈ E G and v = arg min vi cost r (v i , u )}
where cost r (u, v) is the minimum relation cost among relations between a symbol hypothesis under u and a symbol hypothesis under v.

Parameter adjustment

For symbol segmentation and classification we used the same method used for mathematical expressions. Symbol and relation classifier thresholds, t symb and t rel , were set both to 0.95, following the same scheme as done with mathematical expressions.

An important performance difference between the two applications is the relative low accuracy of the flowchart relation classifier compared to the mathematical expression relation classifier. This difference is due to the fact that arrows in flowcharts present a high shape variance and the classifiers we used, which are mainly based on shape histograms of the symbols [START_REF] Julca-Aguilar | Subexpression and dominant symbol histograms for spatial relation classification in mathematical expressions[END_REF], do not generalize well. We alleviate this deficiency by setting t rel = 0.95 (in mathematical expressions, we set t rel = 0.85), in order to keep more labels. We also applied the pruning method based on the mean junk score of groups with five or more symbols hypotheses, with t junk = 0.25 (see Section 3.4.1) to cope with the large number valid partitions. For tree extraction, best validation results were achieved with α = 0.8, placing more weight to symbol classifier scores than to relation classifier scores, and tree pruning threshold t pr = 0.1 (same value as in the case of mathematical expressions).

RESULTS AND DISCUSSIONS

Using the datasets, grammars and parameters as described in the previous section, we applied the recognizers on the test set of the respective applications. Here we present and discuss the results.

Recognition of mathematical expressions

Table 1 shows expression level recognition rates including those reported in the CROHME-2014 competition [START_REF] Mouchère | Competition on recognition of on-line handwritten mathematical expressions (CROHME 2014)[END_REF]. The competing systems are identified as I, . . ., VII, as reported in the competition results. The four error columns indicate recognition rates considering recognition with up to 0, 1, 2 and 3 errors, respectively, Our method recognized 33.98% of the expressions completely. We note, however, that 78.40% of the generated hypotheses graph include the complete expressions. Thus, we conclude that the tree extraction process is failing in retrieving the correct interpretation. This observation is also consistent with the evaluation performed on the validation set and described in the previous section.

The two best systems, I and III, include statistical models [START_REF] Mouchère | Competition on recognition of on-line handwritten mathematical expressions (CROHME 2014)[END_REF]. In particular, system III corresponds to the commercial system MyScript 2 , which has been optimized over hundreds of thousands of equations that are not publicly available. The statistical information used by both systems could explain, at some extent, their better performance. Nevertheless, our method is very close in performance to system I, the best one among those trained exclusively with CROHME-2014 dataset.

We also note that about 15% of the expressions were not correctly recognized due to up to 3 errors. Figure 12 shows some of the expressions that fall in this case. For instance, in the first example, the last term b 0 was recognized as b0. In the last example, a 9 is mistaken as g. Thus, we hypothesize that several of the errors could be eliminated by improving the symbol and relation classifiers. However, some cases are difficult to solve even for humans. For instance, in the second example, the relation between p and -1 is interpreted as horizontal and recognized as p -1, when the true relation is subscript (p -1 ).

(a) 2 2 b 2 + 2b 1 + b 0 → 2 2 b 2 + 2b 1 + b0 (b) n -n 1 -. . . -np -1 → n - n 1 -. . . -n p-1 (c) bag 1 → bay1
(d) a 0 +3a 1 +9a 2 +27a 3 = 0 → a 0 +3a 1 +ga 2 +27a 3 = 0 Fig. 12. Expressions recognized with a few errors. For each expression, its ground truth and the system's output is shown as: ground truth → system's output.

Figure 13 shows examples of correctly recognized expressions. Our method is able to correctly recognize some ambiguous symbols as well as relations. For instance, in spite of the relation between the subexpressions " 1 2 " and "sin 2 (1)" of Figure 13c had received higher score as superscript, the optimal parse tree interpreted it correctly as a horizontal relation.

We also analyzed the most common symbol-to-symbol relation classification errors on test set. A classification was considered an error if either the relation or one of the symbols were wrongly identified. Table 2 shows the ten most frequent errors. Some of the structures are particularly difficult due to the ambiguity at symbol level. For instance, our system often missrecognizes "×" as "x" and the trigonometric function "sin" as tree symbols (like "s", "i" and "n") related by horizontal relation.

In mathematical expressions, the probability of certain symbols or structures be present in particular subexpressions might help solving ambiguities that can not be solved based only on shapes, relations or time related information. For instance, the above common errors of missrecognizing symbol "×" as "x" or the trigonometric function "sin" as tree separated symbols are examples that could be adequately handled with a statistical model. In the first case, symbol "×" probably appears more frequently between a pair of numbers (or letters) and probably almost never without two arguments (one at its left side and another at its right side); in the second case, the three symbols would probably appear more often as the trigonometric function "sin", rather than for instance, representing the product of three variables s, i and n. Hence, statistical information calculated from training data could be associated to the production rules of the grammar and then rule probabilities could be considered when ranking the parse trees, by including a new term in the cost function. When a true symbol or a true relation is not in the hypotheses graph, the parsing process will fail to recognize the graphic. Figure 15 shows an example of spatial relation and another of a symbol that were not recognized during the hypotheses graph generation. However, since 67% of the flowcharts were fully represented in the hypotheses graphs, there is a gap of 33% between the achieved rate and the potentially achievable one. Our explanation for this gap is the fact that although a relatively large number of symbols are correctly recognized (Table 3), many of the true labels in the hypotheses graph presented lower likelihood scores than the false ones, leading to a wrong choice of a tree. Regarding this issue, it is worth to mention that most of the compared methods used specific techniques to identify flowchart symbols, while we used a generic method.

Recognition of flowcharts

The results indicate, nonetheless, that our method can be applied to flowchart recognition as well. To improve recognition performance, the current bottleneck seems to be in the hypotheses graph generation step. By improving symbol and relation classifiers, a considerable improvement would be possible.

CONCLUSIONS

We have proposed a general framework for the recognition of online handwritten graphics that is flexible with respect to the family of graphics, offers possibilities to control processing time, and integrates symbol and structural level information in the parsing process. We model graphics as labeled graphs, and the recognition problem as a graph parsing problem by a graph grammar. The first step of the framework builds a hypotheses graph that encodes symbol and relation hypotheses computed from the input strokes. The second step parses the set of strokes according to a graph grammar. Rule application is modeled as graph matching between graphs in the rule and graphs induced by partitions of the stroke set. The parsing step typically generates multiple interpretations and thus the third step is for selecting an optimal interpretation. The recognition process is modeled as a bottom-up/top-down approach, where the hypotheses graph relates to the bottom-up part that deals with symbol level information and the graph grammar relates to the top-down part that deals with structural information.

Flexibility with respect to application domains is achieved by encoding all domain specific information in the hypotheses graph and in the grammar, making the parsing method be independent of a particular application. We presented applications of the framework to the recognition of mathematical expressions and flowcharts. Recognition performance are on par with many state-of-theart methods. Moreover, our evaluations show that there is room for significative improvement. Specifically, in mathematical expression recognition we verified that although 78% of the test expressions were fully represented in the hypotheses graph, only 33.98% of the expressions were fully recognized, corresponding to a gap of almost 45%. Since the parsing algorithm generates all interpretations that are consistent with the grammar, we conclude that the tree extraction step is failing in choosing the correct interpretation. With respect to flowcharts, in many cases the true symbol and relation labels presented very low likelihood or were not even included in the hypotheses graph (it should be noted that no specialized symbol or relation classifier was developed for this application). These evaluations suggest that an immediate improvement would be possible by just improving symbol and relation classifiers. With respect to optimal tree selection, improvement of symbol and hypotheses likelihood scores will naturally lead to better cost estimation. However, a second improvement could be possible by incorporating in the cost computation a term that captures statistical information with respect to structure occurrence.

Another important feature of our framework is the possibility of managing computational cost. Hypotheses graph is the main tool to reduce the space of partitions to be examined when applying a rule. Only partitions that are present in the hypotheses graph are considered. In addition, there is a set of parameters to control the amount of possibilities to be encoded in the hypotheses graph (symbol and relation label pruning), as well as the number of tree (interpretation) costs to be evaluated (tree pruning). These parameters can be adjusted according to each application particularities.

As future works, we would like to experiment deep neural networks as tools to improve symbol and relation classification in both applications and verify how far recognition rate can be pushed. We would like also to extend the applications to other families of graphics or 2D structures.

Fig. 1 .

 1 Fig. 1. Handwritten mathematical expression example. Top: A sequence of strokes where the order (indicated by numbers in blue) is given by the input time. Symbols and z are composed of non-consecutive strokes. Bottom: The expression is composed of symbols and several types of spatial relations between them.

Fig. 2 .

 2 Fig. 2. Flowchart example. Strokes are colored according to the symbol type they belong to.

  .

Fig. 3 .

 3 Fig. 3. Handwritten expressions representing

Fig. 4 .

 4 Fig. 4. Graph grammar that models basic mathematical expressions. The grammar is defined by non-terminals N = {M E, T RM, OP, CHAR}, relation labels RL = {sp, sb, h}, terminals T = {+, -, <, >, a, . . . , z, A, . . . , Z, 0, . . . , 9}, rules R = {r-1, . . . , r-73}, and M E at the left hand side graph of rule r -1 is the initial node. Abbreviations: M E = mathematical expression, sp = superscript, sb = subscript, h = horizontal, T RM = term, OP = operator, CHAR = character.

Figure 5

 5 Figure5shows a graph generation process using the grammar of Figure4. Rules are applied sequentially, starting with non-terminal M E, until all elements in the generated graph are terminals. Dashed arrows correspond to edges that link the replacing graphs with the host graph.The definition of how a replacing graph should be linked to a host graph G is called embedding[START_REF] Pflatz | Web grammars[END_REF], and it should be specified for each production rule. Formally, given a production rule G l := G r , its application consists in replacing a subgraph G l of G with G r and the embedding defines how G r will be attached to G\G l . The attachment may be defined by a set of edges that link the replacing graph G r to G \ G l . For instance, Figure6shows two different embeddings for

Fig. 5 .

 5 Fig. 5. Generation of a graph that represents the expression a b + c d . At each rule application, the replacing graph nodes are depicted in dark gray. Edges that link the replacing graph with the host graph are depicted with dashed arrows. Rule applications after the fourth one are not shown.

Fig. 6 .

 6 Fig. 6. Graph transformation with two different embeddings. The top graph is transformed through rule r. Each embedding defines edges between vertices that are linked to vertex A of the top graph with vertex D (left hand side embedding) or E (right hand side embedding) of the replacing graph. Dashed arrows represent the edges defined by each embedding.

Fig. 7 .

 7 Fig. 7. Hypotheses graph example. Vertices represent symbol hypotheses and edges represent relations between symbols. The labels associated to symbols and relations indicate their most likely interpretations.

Fig. 8 .

 8 Fig. 8. A parse forest representing multiple interpretations of a mathematical expression. Labels on arrows refer to grammar rules of Figure 4. Red arrows represent a parse tree that corresponds to the interpretation "P b 4".

Algorithm 1 :

 1 parseGraphic(S,N T ) Parses a set of strokes S from a non-terminal N T Input: (S, N T ) Output: parsedG = {(G 1 , r 1 ), . . . , (G q , r q )} 1: parsedG ← ∅ 2: if parsed[(S, N T )] then 3: parsedG ← T BL[(S, N T )] 4: else 5: for all rule in rulesWithLHS(N T ) do 6: if rule is A → b then 7: if l(b) ∈ L(S) then 8: G ← buildGraph(S, l(b)) 9: parsedG ← parsedG ∪ {(G, rule)} for all G in validMatchingInstances(S, B = RHS(rule)) do 13: if ∀ v ∈ V G , parseGraphic(stk(v), l(v)) = ∅ then 14: parsedG ← parsedG ∪ {(G, rule)} (S, N T )] ← parsedG 20: parsed[(S, N T )] ← T rue 21: end if 22: return parsedG 1

Fig. 9 .

 9 Fig. 9. Parse tree of expression P b < 1, extracted from the parse forest of Figure 8. Nodes are indexed as x i , i = 1, . . . , 9. Similarly, vertices and edges of the instantiated graphs are respectively indexed as v j , for j = 1, . . . , 12, and e k , for k = 1, . . . , 3. Nodes with terminal symbols are depicted with double line borders.

2 .Fig. 13 .

 213 Fig. 13. Examples of expressions containing potentially ambiguous interpretations that have been correctly recognized by our system.

  the flowchart in the right side of Figure14a, or very short ones, or yet curvy ones, are correctly identified.

Fig. 14 .

 14 Fig. 14. Examples of flowcharts that have been correctly recognized by our method.

Fig. 15 .

 15 Fig. 15. Parts of flowcharts with missing components in the hypotheses graph. (a) Relation between the top arrow and data symbols has not been identified; (b) the top-center arrow has not been identified.

  Fig. 10. Symbol, relation and expression level recall of the hypotheses graph generation step. For each symbol classification threshold t symb in the range [0.4 -1.0], relation classification threshold t rel is varied in the range [0.1 -1.0].

	Recall (%)
	3	0.5	0.7	0.9	0.1	0.3	0.5	0.7	0.9	0.1	0.3	0.5	0.7	0.9	0.1	0.3	0.5	0.7	0.9	0.1	0.3	0.5	0.7	0.9	0.1	0.3	0.5	0.7	0.9	0.1	0.3	0.5	0.7	0.9
		0.4					0.5					0.6					0.7					0.8					0.9					1
				Symbol (below) and rela>on (above) classifier thresholds
									Symbol		Rela>on		Expression

TABLE 1

 1 Expression level recognition rates on the test set of CROHME-2014 competition: competing systems and our method

	System	0	# errors ≤ 1 ≤ 2	≤ 3
	I	37.22 44.22 47.26 50.20
	II	15.01 22.31 26.57 27.69
	III	62.68 72.31 75.15 76.88
	IV	18.97 28.19 32.35 33.37
	V	18.97 26.37 30.83 32.96
	VI	25.66 33.16 35.90 37.32
	VII	26.06 33.87 38.54 39.96
	Ours	33.98 43.10 47.56 49.29

TABLE 2

 2 Most frequently misclassified spatial relation between symbols on test set. Relation identity is implicitly indicated by the relative positions of the symbols.

	Relation # errors # samples % errors
	x×	24	24	100
	×x √ -	24 19	24 29	100 65.52
	n sin(	18 20	37 42	48.65 47.62
	= -	26	91	28.57
	2 x+	19 26	81 120	23.46 21.67
	1	28	133	21.05
	(x	21	108	19.44

Table 3

 3

shows the parsing results regarding stroke and symbol labeling accuracy w.r.t. the flowchart test set. It should be noted, however, that we as well as Bresler et al.

[START_REF] Bresler | Modeling flowchart structure recognition as a max-sum problem[END_REF]

did not consider text symbols.

Concerning flowcharts as a whole, our method fully recognized 34% of the flowcharts in the test set. Three examples are shown in Figure

14

. They include linear as well as (nested) loop structures. It is interesting to note that varying shapes of arrows such as the one that extends over a

TABLE 3

 3 Comparison of our method and four state-of-the-art methods, w.r.t. stroke and symbol labeling accuracy (%)

	System	Stroke labeling Symbol labeling
	Include text recognition:
	Lemaitre et al. [39]	91.1	72.4
	Carton et al. [16]	92.4	75.0
	Bresler et al. [17]	95.2	82.8
	Wang et al. [40]	95.8	84.3
	Without text recognition:
	Bresler et al.

ACKNOWLEDGMENTS

This work has received support from CNPq, Brazil (grant 484572/2013-0). F. Julca-Aguilar thanks FAPESP, Brazil, for the financial support (2012/08389-1 and 2013/13535-0). N.S.T. Hirata is partially supported by CNPq (grant 305055/2015-1).

Christian Viard-Gaudin is a Full Professor at the Electrical and Electronic Engineering Department of University of Nantes. He is a leading researcher in the field of document image processing and handwriting recognition. He has been involved in many projects concerning automatic mail sorting systems, offline and online handwriting recognition. Currently, he is working on mathematical expression recognition, writer identification and document categorization.

Nina S. T. Hirata holds a PhD degree in Computer Science. She is currently an associate professor at the Department of Computer Science, Institute of Mathematics and Statistics of University of S ão Paulo. Her research interests include pattern recognition and image/signal analysis, using approaches based on machine learning, graphs, mathematical morphology, and other tools, with applications in a variety of problems such as document image analysis, graphics recognition, astronomical and plankton image classification, image segmentation, object detection in images, among others.