Introducing the pxindex-builder gem

require 'pxindex-builder'


s = "
How are you?
What's today's date?
Is it going to rain tomorrow?
Track my location
what's Tom's mobile number?
What's Sally's mobile number?
Open the door
How are you?
Switch the bedroom light on
Switch the bedroom light off
Switch the livingroom light on
How are you?
Switch the bedroom light on
Switch the bedroom light off
Switch the livingroom light off
Open the door
"
s = PhraseLookup.new(s.strip).master.to_h.to_yaml

xml = PxIndexBuilder.new(s, ignore: %w(is it the are you to)).to_xml
puts xml

The pxindex-builder gem is intended to create a Polyrex Index document for populating a dynamic tree list on a web page which can either be expanded or collapsed. On average it would take the user 3 clicks to select any of the above statements. To open the door the use would click on the letter o, followed by click on the word open and then click on the open the door statement.

Output (extract):

<?xml version='1.0' encoding='UTF-8'?>
<items>
  <summary>
    <recordx_type>polyrex</recordx_type>
    <schema>items/entry[title]/entry[title]/entry[title]</schema>
  </summary>
  <records>
    <entry>
      <summary>
        <title>a</title>
        <schema>entry[title]</schema>
      </summary>
      <records>
        <entry>
          <summary>
            <title>are</title>
            <schema>entry[title]</schema>
          </summary>
          <records>
            <entry>
              <summary>
                <title>how are you</title>
                <schema>entry[title]</schema>
              </summary>
            </entry>
          </records>
        </entry>
      </records>
    </entry>
    <entry>
      <summary>
        <title>b</title>
        <schema>entry[title]</schema>
      </summary>
      <records>
        <entry>
          <summary>
            <title>bedroom</title>
            <schema>entry[title]</schema>
          </summary>
          <records>
            <entry>
              <summary>
                <title>switch the bedroom light on</title>
                <schema>entry[title]</schema>
              </summary>
            </entry>
            <entry>
              <summary>
                <title>switch the bedroom light off</title>
                <schema>entry[title]</schema>
              </summary>
            </entry>
          </records>
        </entry>
      </records>
    </entry>
    <entry>
      <summary>
        <title>d</title>
        <schema>entry[title]</schema>
      </summary>
      <records>
        <entry>
          <summary>
            <title>door</title>
            <schema>entry[title]</schema>
          </summary>
          <records>
            <entry>
              <summary>
                <title>open the door</title>
                <schema>entry[title]</schema>
              </summary>
            </entry>
          </records>
        </entry>
        <entry>
          <summary>
            <title>date</title>
            <schema>entry[title]</schema>
          </summary>
          <records>
            <entry>
              <summary>
                <title>what's today's date</title>
                <schema>entry[title]</schema>
              </summary>
            </entry>
          </records>
        </entry>
      </records>
    </entry>
...

Notes:

Resource