Integrating

Once your ruleset is written and trained, your application can run a DOM tree through it:

// Tell the ruleset which DOM to run against, yielding a factbase about the
// document:
const facts = rules.against(document);

Then you can pull answers out of the factbase. In the case of the Example Ruleset, we want the node representing the highest-scoring overlay, which the ruleset conveniently stores under the “overlay” output key:

const bestOverlayFnode = facts.get('overlay');

If you’re using a third-party ruleset that doesn’t anticipate the output you want, you can ask for it more explicitly by passing a query, in the form of a full LHS, to get(). For example, if you simply want all the overlay-typed things so you can do further computation on them…

const allOverlayFnodes = facts.get(type('overlay'));

Or if you have a reference to a DOM element from elsewhere in your program, you can look up the scores, types, and notes Fathom attached to it:

const fnode = facts.get(dom.getElementById('someOverlay'));

Remember, once you have a Fnode(), you can access the wrapped element from its element property.