Re: Using Stella Functions in PowerLoom

Hans Chalupsky <[email protected]> Wed, 5 Dec 2012 11:30:22 -0800
Newsgroups gmane.comp.ai.powerloom
Message-ID <[email protected]>
Sebastian,

you can call STELLA functions in PowerLoom, however, they have to conform to
certain restrictions regarding their signature.  For example, the simpler
choice are what we call "computations", which take a number of bound input
arguments and compute a resulting value from that.  For this to work
generically, all arguments of the function and its return value must be
subtypes of OBJECT (the STELLA version of OBJECT).  For this reason, functions
in the STELLA string library can generally not be called directly, since they
take literal types such as STRING and INTEGER as their input and return types.
Also PowerLoom versions of strings and numbers are special, since they can
have additional indexing information, even thought that's most of the time
transparent to the computation function developer.

Various computation functions in specialists.ste and arithmetic.ste are
PowerLoom wrappers that perform these type conversions, plus they are
additionally more tolerant to handle incorrect types and various error
conditions without throwing exceptions.  For example, look at
"string-match-computation" in the file powerloom/sources/logic/arithmetic.ste
(not quite sure why it's in arithmetic...)

Additionally, computed predicates have to be registered in the logic by
associating a PowerLoom relation with a computation function.  For example,
string-match is defined like this in pl-kernel.ste:

(deffunction string-match ((?pattern STRING) (?object THING)
                           (?start INTEGER) (?end INTEGER))
  :-> (?match-position INTEGER)
  :documentation "Match ?pattern against ?object between ?start and ?end (zero-based),
and return the position of the first match or fail if no match exists.  Supplying -1 for
?end indicates the end of ?object, -2 is one character from the end, etc.  ?object can be
a named logic object or a string.  ?pattern will eventually allow support regular expressions,
currently it only handles string literals.  Apart from doing to-string coercion on ?object
this is somewhat redundant, since `substring' can generate ?start/?end pairs if its string
and substring arguments are bound."
  :axioms (and (computed string-match)
               (relation-computation string-match string-match-computation)
               (relation-specialist string-match computation-specialist)))

The three axioms tell the inference engine that this is a computed predicate,
and how to compute it.

There is a more complex computed predicate interface called "specialists"
which additionally can generate multiple bindings for unbound inputs.
However, to use those correctly requires a bit more knowledge of the inference
engine, so I won't go into that here.

Now back to your original problem: The PowerLoom string and math libraries are
incomplete, I am running into this myself on occasion.  Unfortunately, I'm
often under time pressure when this arises, and so my solutions and
work-arounds don't always make it back into the released version.

If you let me know what additional string operations you'd like to see, I can
see to add them to the next PowerLoom snapshot.

Hans

>>>>> Sebastian Herold <[email protected]> writes:

> Hi there,
> I'm currently facing the problem that I'd like to use the more 
> exhaustive Stella functions for dealing with strings in PowerLoom (e.g., 
> string-compare). But whatever I do, I get only "Unknown 
> predicate/function" messages.

> Do I have to include the Stella module explicitly, or is it possible at all?

> Thanks,
> Sebastian
> _______________________________________________
> powerloom-forum mailing list
> [email protected]
> http://mailman.isi.edu/mailman/listinfo/powerloom-forum