Running PowerLoom Interactively Practical Artificial Intelligence Programming With Java
|P|PERSON MARK PL-USER |= assert parent-of Ken Mark
|P|PARENT-OF KEN MARK
Now that we have entered two concepts, a test relation, and asserted a few facts, we can look at an example of PowerLoom’s query language:
PL-USER |= retrieve all ?p person ?p There are 2 solutions:
1: ?P=MARK 2: ?P=KEN
PL-USER |= retrieve all ?p parent ?p There is 1 solution:
1: ?P=KEN PL-USER |=
The obvious point to note from this example is that we never specified that Ken was a parent; rather, PowerLoom deduced this from the parent-of relation.
PowerLoom’s command line system prompts you with the string “PL-USER —=“ and you can type any definition or query. Like Lisp, PowerLoom uses a prefix
notation and expressions are contained in parenthesis. PowerLoom supports a mod- ule system for partitioning concepts, relations, functions, and rules into different
sets and as previously mentioned “PL-USER” is the default module. PowerLoom modules can form a hierarchy, inheriting concepts, relations, and rules from parent
modules.
The subdirectory test data contains the demo file business.plm written by Robert MacGregor that is supplied with the full PowerLoom distribution. You can load his
complete example using:
PL-USER |= load ..test_databusiness.plm This is a good example because it demonstrates most of the available functionality
of PowerLoom in a short 200 lines. When you are done reading this chapter, please take a few minutes to read through this example file since I do not list it here. There
are a few things to notice in this example. Here we see a rule used to make the relation “contains” transitive:
defrelation contains ?l1 geographic-location
?l2 geographic-location
50
defrule transitive-contains = and contains ?l1 ?l2
contains ?l2 ?l3 contains ?l1 ?l3
The operator = means that if the first clause is true then so is the second. In English, this rule could be stated “if an instance i1 contains i2 and if instance i2
contains i3 then we can infer that i1 also contains i3.” To see how this rule works in practice, we can switch to the example module “BUSINESS” and find all locations
contained inside another location:
PL-USER |= in-module BUSINESS BUSINESS |= retrieve all
?location1 ?location2 contains ?location1 ?location2
There are 15 solutions: 1: ?LOCATION1=SOUTHERN-US, ?LOCATION2=TEXAS
2: ?LOCATION1=TEXAS, ?LOCATION2=AUSTIN 3: ?LOCATION1=TEXAS, ?LOCATION2=DALLAS
4: ?LOCATION1=UNITED-STATES, ?LOCATION2=SOUTHERN-US 5: ?LOCATION1=GEORGIA, ?LOCATION2=ATLANTA
6: ?LOCATION1=EASTERN-US, ?LOCATION2=GEORGIA 7: ?LOCATION1=UNITED-STATES, ?LOCATION2=EASTERN-US
8: ?LOCATION1=SOUTHERN-US, ?LOCATION2=DALLAS 9: ?LOCATION1=SOUTHERN-US, ?LOCATION2=AUSTIN
10: ?LOCATION1=UNITED-STATES, ?LOCATION2=DALLAS 11: ?LOCATION1=UNITED-STATES, ?LOCATION2=TEXAS
12: ?LOCATION1=UNITED-STATES, ?LOCATION2=AUSTIN 13: ?LOCATION1=EASTERN-US, ?LOCATION2=ATLANTA
14: ?LOCATION1=UNITED-STATES, ?LOCATION2=GEORGIA 15: ?LOCATION1=UNITED-STATES, ?LOCATION2=ATLANTA
BUSINESS |= Here we have fifteen solutions even though there are only seven “contains” relations
asserted in the business.plm file – the other eight solutions were inferred. In addition to the “retrieve” function that finds solutions matching a query you can also use the
“ask” function to determine if a specified relation is true; for example:
BUSINESS |= ask contains UNITED-STATES DALLAS TRUE
BUSINESS |=
51
For complex queries you can use the “why” function to see how PowerLoom solved the last query:
BUSINESS |= ask contains southern-us dallas TRUE
BUSINESS |= why 1 CONTAINS ?location1 ?location2
follows by Modus Ponens with substitution {?l1SOUTHERN-US, ?l3DALLAS,
?l2TEXAS} since 1.1 FORALL ?l1 ?l3
= CONTAINS ?l1 ?l3 EXISTS ?l2
AND CONTAINS ?l1 ?l2 CONTAINS ?l2 ?l3
and 1.2 CONTAINS SOUTHERN-US TEXAS
and 1.3 CONTAINS TEXAS DALLAS
BUSINESS |= By default the explanation facility is turned off because it causes PowerLoom to run
more slowly; it was turned on in the file business.plm using the statement:
set-feature justifications