<?xml version="1.0" encoding="windows-1252"?>
<node id="318378" title="Re: Being Forced to Fork with Nested Regular Expressions" created="2004-01-02 13:00:51" updated="2005-05-18 08:56:50">
<type id="11">
note</type>
<author id="6562">
paulbort</author>
<data>
<field name="doctext">
I know that it really doesn't address your topic, but I think the reason that you're running into the problem is that it's the wrong approach. An impressive (ab)use of regular expressions, though.&lt;BR&gt;&lt;BR&gt;
What I've seen of predicate systems leads me to a database approach rather than regular expressions. Given the right data structure, you need to write two parsers: one to convert $facts into rows in tables, and one to convert your queries into SQL. With the right data structure, this is straightforward. &lt;BR&gt;&lt;BR&gt;
Most of this can be done with three tables: One to contain people, things and attributes (Merlyn, Ovid, Kudra, books, gold, valuable), one to contain verbs ( owns, is ), and one to contain tuples of person/thing/attribute, verb, person/thing/attribute. This leads to something like:
&lt;CODE&gt;
SELECT actor 
  FROM relations 
  WHERE verb = 'owns' 
    AND acted_on IN ( 
      SELECT actor 
        FROM relations 
        WHERE verb = 'is' 
          AND acted_on = 'valuable' 
      );
&lt;/CODE&gt;
This query, with proper data, can answer the question of 'who owns something valuable' in a very reasonable amount of time. You still do code generation, but now it's SQL instead of RE. &lt;BR&gt;&lt;BR&gt;
HTH, &lt;BR&gt;
Paul
&lt;div class="pmsig"&gt;&lt;div class="pmsig-6562"&gt;
&lt;br&gt;--&lt;br&gt;Spring: Forces, Coiled Again!

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
318350</field>
<field name="parent_node">
318350</field>
</data>
</node>
