Using the PowerLoom APIs in Java Programs

• PowerLoomUtils – constructor initializes the Java PowerLoom runtime sys- tem. • loadString fpath – load a source .plm file. • changeModuleString workingModule – set the current PowerLoom working module “PL-USER” is the default module. • assertPropositionString proposition – asserts a new proposition; for exam- ple: ”and company c3 company-name c3 \”Moms Grocery\””. Note that quotation marks are escaped with a backslash character. You can also use single quote characters like: ”and company c3 company-name c3 ’Moms Grocery’” because I convert single quotes in my wrapper code. • createRelationString relation, int arity – create a new relation with a speci- fied arity number of “arguments”. For example you could create a relation “owns” with arity 2 and then assert “owns Elaine ’Moms Grocery’” – I usu- ally do not use this API since I prefer to place relations with rules in a source code file ending in the extention .plm. • doQueryString query – returns a list of results from a query. Each result in the list is itself a list. You will always want to work in an interactive PowerLoom console for writing and debugging PowerLoom models. I built the model in test.plm in the subdirectory test data interactively and we will use it here in an embedded Java example: PowerLoomUtils plu = new PowerLoomUtils; plu.loadtest_datatest.plm; plu.changeModuleBUSINESS; plu.assertProposition and company c1 + company-name c1 \Moms Grocery\; plu.assertProposition and company c2 + company-name c2 \IBM\; plu.assertProposition and company c3 + company-name c3 \Apple\; List answers = plu.doQueryall ?x company ?x; System.out.printlnanswers; answers: [[C3], [C2], [C1]] answers = plu.doQuery all ?x ?name + and + company ?x + 53 company-name ?x ?name; System.out.printlnanswers; answers: [[C3, Apple], [C2, IBM], [C1, Moms Grocery]] plu.createRelationCEO, 2; plu.assertProposition CEO \Apple\ \SteveJobs\; answers = plu.doQuery all ?x ?name ?ceo + and + company-name ?x ?name + CEO ?name ?ceo; System.out.printlnanswers; answers: [[C3, Apple, SteveJobs]] I have added the program output produced by printing the value of the list variable “answers” as comments after each System.out.println call. In the wrapper API calls that take a string argument, I broke long strings over several lines for formatting to the width of a page; you would not do this in your own programs because of the cost of the extra string concatenation. We will not look at the implementation of the P owerLoomU tils class – you can read the code if you are interested. That said, I will make a few commments on the Java PowerLoom APIs. The class P LI contains static methods for initializing the system, loading PowerLoom source files. Here are a few examples: PLI.initialize; PLI.loadtest.plm, null; PLI.sChangeModuleBUSINESS, null;

3.5 Suggestions for Further Study

This chapter has provided a brief introduction to PowerLoom, one of my favorite AI tools. I also showed you how to go about embedding the PowerLoom knowledge representation and reasoning systems in your Java programs. Assuming that you see benefit to further study I recommend reading through the PowerLoom manual and the presentations PDF files on the PowerLoom web site. As you read through this material it is best to have an interactive PowerLoom session open to try the examples as you read them. 54 Knowledge Representation and Logic are huge subjects and I will close out this chapter by recommending a few books that have been the most helpful to me: • Knowledge Representation by John Sowa. This has always been my favorite reference for knowledge representation, logic, and ontologies. • Artificial Intelligence, A Modern Approach by Stuart Russell and Peter Norvig. A very good theoretical treatment of logic and knowledge representation. • The Art of Prolog by Leon Sterling and Ehud Shapiro. Prolog implements a form of predicate logic that is less expressive than the descriptive logics supported by PowerLoom and OWL Chapter 4. That said, Prolog is very efficient and fairly easy to learn and so is sometimes a better choice. This book is one of my favorite general Prolog references. The Prolog language is a powerful AI development tool. Both the open source SWI- Prolog and the commercial Amzi Prolog systems have good Java interfaces. I don’t cover Prolog in this book but there are several very good tutorials on the web if you decide to experiment with Prolog. We will continue Chapter 4 with our study of logic-based reasoning systems in the context of the Semantic Web. 55