University of Arkansas – CSCE Department CSCE 4613 Artificial Intelligence – Final Report – Fall 2013 Querying XML Workflow Logs Xiangzhe Li, David Carman Abstract The problem of our project is to extract elements out of recipes, which can be viewed as workflows that are represented in XML. More precisely, we want to examine the XML generated by other class projects to get the information we need. The objective of this project is to query the XML recipes given user's inputs and return the information requested. Our approach is to master both SAX parsing and XPath querying, communicate with the Workflow via Avatarbots group and Smart Objects group and to develop queries for information that they need. We were able to complete a prototype of different user inquiry cases that will be passed on to both of these groups to meet their needs. 1. Introduction 1.1 Problem The Workflow via Avatarbots team will generate a representation of the workflow so the computer can understand. It is up to our group to communicate with them in order to Understand the capability of SAX and XPath so they can make necessary adjustment to their XML format. Understand the limit and restriction of their XML generated format so we can construct the necessary SAX and/or XPath queries. Communicate with the Smart Objects team that will provide users an interface that handles the construction of queries or commands. Our group has communicate with this group to Understand the hypothesis grammar of the querying language the Smart Objects group is trying to construct so we can make necessary construction of our XPath queries Understand the limitation of XPath and make suggestions on possible grammars for their language construction. 1.2 Objective The objective of our project is to query XML representations of recipes given user's inputs and return the information requested. In order to successfully meet users’ inquires, it is critical to 1 understand how XPath is integrated with Java and set up the environment to test different query cases. 1.3 Context Our Human Workflows project was focused, in part, on querying and commanding avatars and workflows in a kitchen-recipe-cooking domain. The Communicating with Smart Objects team recognizes natural language inputs and translates them into XPath queries or workflow commands. Our project’s job is to provide the semantics of how to execute the XPath queries. 2. Related Work 2.1 Related Class Projects Our projects on X relates to these other class projects: Workflow via Avatarbots team: we are connected to Workflow via Avatarbot in the sense that their team is generating a representation of data workflow such as XML so we could query against it. Communicate with Smart Objects team: this project will interact with user to construct appropriate sentence to obtain the information they need. It is up to our team to provide the translated XPath expression based on Smart Objects group’s inquiry. 3. Architecture 3.1 Requirements or Use Cases A user can add a recipe to the recipe book. A user can remove a recipe from the recipe book. A user can search the recipe book for all recipes with a certain ingredient. A user can search a specific recipe for all items (nodes) of a specific type. A user can search a specific recipe for the cook (author) and date of that recipe. A user can search the recipe book for the quantity of a specific ingredient in a specific recipe. 3.2 Design 1 The project was split up into three main functions, a class for the functions, and a main class to call the functions. The xmlHandler class contains a private variable for the recipe book file. Almost all of our functions take advantage of this private class except the ones searching only a single recipe. Three of the functions used the Document class (and related classes) while the other three used the XPath class ( and related classes). The functions that use the Document class are using DOM to query the XML while the functions using the XPath class are using XPath to query the XML. Since each function is contained to itself and because of how closely DOM resembles XPath, using different classes like this was not a problem. The “main” class was then 1 NOTE on locating XPath in the code: Located in the XMLHandler file. You can search for FindItemRecipe, FindCookAndDate, and FindQtyXInY to see the functions that used Xpath expression to generate results. 2 used to create the user interface to access the functions. This one done by using command line arguments denoted by a “-” when the Java command is given in the console/terminal. A series of if states then checks to see which functions need to be called. Inside of each if statement, there is a check to make sure the necessary parameters have been set using the arguments. Since this is a series of if statements, you could possibly call every single function in one run of the program. This can be done safely with most functions, but might result in errors if you say remove a recipe and then try to search something in it. 3.3. Tasks David Carman He started by writing the add recipe to recipe book, remove recipe from recipe book, and find recipes that have a specified ingredient functions. Once this was complete, he worked on making these functions generic so that any parameter could be put in them (aka any recipe could be input into the add recipe to recipe book instead of hard coding a path to a recipe). The next piece of the project was to create a command line interface where these functions could be called from. Once this was created, it was tested to make sure the functions were still working. The final piece of the project was to merge the code that Xiangzhe Li had created so that it was compatible with the command line interface. Once finished, more testing was done to make sure all of his functions were still working under the command line interface. Screenshots of functions made: Add recipe to recipe book function 3 Remove recipe from recipe book Find recipes with specified ingredient Xiangzhe Li He started by learning the usability of XPath and how it is set up with java environment and XML to handle user’s inquiries. He first started by testing the specific questions that was recommended by Dr. Thompson. They were : Find the quantity of ingredient chicken in the recipe for chicken soup Find steps in the recipe for chicken soup Find the cook and date for cooking events using recipe chicken soup Then he went and made those tasks functional and generic for any item or recipe that are in the recipe log. Here are the screenshot for the tasks above: 4 Find the cook and the date of this recipe Find all the ingredient chicken in the recipe chicken and Rice Soup 5 Find all the steps of preparation for every recipe in the recipe log 3.4 Testing We tested our project by first input static variables that we need should work. Then we moved on to more dynamic variables such as those in a single recipe. Next we added all of the recipes together into one recipe book and testing our functions with all of the recipes there except for the ones that only used a single recipe. 6 4. Conclusions 4.1 Potential Impact Our work is the middle man between the avatar bots team and the communications with smart objects team. Once the communication between our program and their programs is worked out, then we would be providing an essential link between those two teams. It would allow the Communications team to use the avatar bots data in a format their program could understand. 4.2 Future Work Creating outputs that other teams could use more effectively (not just printing to the console) Creating more functions to better cover the range of what can be queried. Working with the avatar bots team to better create a standard XML output format that would better suit both teams. Creating interfaces that could directly connect to the avatar bots team and communication team (as in programing interfaces). 4.3 Project Value We learned how to use XML and DOM to query XML. We also learned part of how a workflow can be built and how little pieces of a workflow can come together to form a (semi) working larger workflow. Bios David Carman – Carman is a senior student Computer Science major Mathematics minor at the University of Arkansas. He has completed many required courses for Computer Science including Programming I & II, Programming Paradigms, Algorithms, Digital Design, Computer Organization, and Database Management, all required classes for his Mathematics minor including Calculus I-III, Differential Equations, Linear Algebra, Discrete, and Advanced Applied. He has had two co-op tours with IBM at their RTP, NC and Austin, TX sites. He will be working with IBM WebSphere when he graduates in May 2014. Xiangzhe (Shawn) Li – Li is a senior Computer Science/Computer Engineering major in the Computer Science and Computer Engineering Department at the University of Arkansas. He has completed Programming foundations I, II, Digital Design, Computer Organization, Programming Paradigms, Algorithms, Software Engineering, Operating System, Formal Language, Database Management, Smartphone programming, and Artificial intelligence in the CSCE department. Shawn had interned at MasterCard worldwide as a software engineer in the summer of 2013 and JB Hunt transportation service as an IT developer in spring 2013 and fall 2013. His primary tasks at MasterCard were developing window front-end application with C# .NET environment on. Some of his primary tasks at JB Hunt Transportation were to work with Microsoft Sharepoint designer and web application development using the Spring framework and java. Shawn Li will be responsible for the collaborative role of researching on the feasible tools to be used for the architecture of the web application, the necessary API and libraries to be used for the 7 development process, and implementing the interface or prototype so users can access the different tools on a centralized application that can store shared information throughout the platform. Dr. Craig Thompson, Mentor – Thompson is a professor in the Computer Science and Computer Engineering Department. He leads the Everything is Alive research project that is currently focusing on how to simulate pervasive computing using 3D virtual worlds. See http://vw.ddns.uark.edu. References http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/DocumentBuilder.html http://stackoverflow.com/questions/6604876/parsing-xml-with-nodelist-and-documentbuilder http://docs.oracle.com/javase/7/docs/api/javax/xml/XPath/package-summary.html http://docs.oracle.com/javase/tutorial/jaxp/xslt/XPath.html Appendix A – Deliverables Manifest There is a README document attached with the .zip file that summarize the essential of what we have done and quick overview of this project as well as direction on how to execute. 8