Programming by Example Using Least General Generalizations for Rich Document Formatting
Abstract
Automating repetitive formatting tasks in richly formatted documents like Microsoft Word or PowerPoint is challenging due to the complexity of underlying XML structures. This paper presents a Programming by Example (PBE) framework that treats these tasks as XML tree transformations. By employing the concept of Least General Generalizations (LGG) from inductive logic programming, the system efficiently synthesizes complex structural programs from a few user examples, bypassing the scalability limitations of traditional version space approaches.
Introduction
Modern office suites store documents as massive, hierarchical XML trees. While PBE tools like Excel's Flash Fill excel at simple string manipulation, extending this to rich formatting requires handling structural complexity and selection criteria. Traditional PBE methods often struggle with scalability, as the search space for potential programs grows exponentially with the size of the XML tree. This paper introduces a novel approach that shifts the focus from searching for all possible programs to finding the most specific program that covers the user's examples.
The LGG Framework
The core of the proposed system is a Domain Specific Language (DSL) designed for transformations on ordered trees. This DSL supports variables, functional transformations (e.g., relative font size changes), and loop iterators to handle varying numbers of child nodes, such as rows in a table or paragraphs in a text box.
Instead of an exhaustive search, the algorithm uses "syntactic anti-unification" to find the Least General Generalization (LGG). By defining a subsumption ordering—where one program is considered more general than another—the synthesis task becomes a lattice problem. Finding the "least" program in this lattice is computationally efficient and naturally incorporates selection criteria. For instance, if a user provides examples of modifying only red shapes, the LGG will automatically include the "color=red" attribute in its selection filter.
Evaluation and Results
The system, implemented as a PowerPoint add-in called FlashFormat, was evaluated on 20 real-world tasks sourced from online help forums. These tasks involved complex formatting of shapes, charts, tables, and styles.
The evaluation demonstrated high efficiency and performance:
- Minimal Examples: The system required an average of only 4.17 examples per task.
- Real-time Performance: Execution times were typically under 1 second, making the tool suitable for interactive use.
- High Precision: In 75% of the tasks, the system generated a single correct program. The remaining tasks required partitioning examples into disjunctions (if-else logic), which the framework also supports.
Conclusion
By leveraging LGG, this framework provides a scalable and efficient solution for automating rich document formatting. Future work includes extending the DSL to support more complex boolean logic and integrating natural language processing to further simplify the user experience.
Summary updated