Class InterpreterEngine

java.lang.Object
tools.refinery.interpreter.api.InterpreterEngine
Direct Known Subclasses:
AdvancedInterpreterEngine

public abstract class InterpreterEngine extends Object
A Viatra Query (incremental) evaluation engine, attached to a model such as an EMF resource. The engine hosts pattern matchers, and will listen on model update notifications stemming from the given model in order to maintain live results.

By default, ViatraQueryEngines do not need to be separately disposed; they will be garbage collected along with the model. Advanced users: see AdvancedInterpreterEngine if you want fine control over the lifecycle of an engine.

Pattern matchers within this engine may be instantiated in the following ways:

  • Recommended: instantiate the specific matcher class generated for the pattern by e.g. MyPatternMatcher.on(engine).
  • Use getMatcher(IQuerySpecification) if the pattern-specific generated matcher API is not available.
  • Advanced: use the query specification associated with the generated matcher class to achieve the same.
Additionally, a group of patterns (see IQueryGroup) can be initialized together before usage; this may improve the performance of pattern matcher construction by trying to gather all necessary information from the model in one go. Note that no such improvement is to be expected if the engine is specifically constructed in wildcard mode, an option available in some scope implementations (see
invalid reference
EMFScope#EMFScope(Notifier, BaseIndexOptions)
and
invalid reference
BaseIndexOptions#withWildcardMode(boolean)
).
  • Constructor Details

    • InterpreterEngine

      public InterpreterEngine()
  • Method Details

    • getBaseIndex

      public abstract IBaseIndex getBaseIndex()
      Provides access to the internal base index component of the engine, responsible for keeping track of basic contents of the model.

      If using an

      invalid reference
      EMFScope
      , consider
      invalid reference
      EMFScope#extractUnderlyingEMFIndex(InterpreterEngine)
      instead to access EMF-specific details.
      Returns:
      the baseIndex the NavigationHelper maintaining the base index
      Throws:
      InterpreterRuntimeException - if the base index could not be constructed
    • getMatcher

      public abstract <Matcher extends InterpreterMatcher<? extends IPatternMatch>> Matcher getMatcher(IQuerySpecification<Matcher> querySpecification)
      Access a pattern matcher based on a IQuerySpecification. Multiple calls will return the same matcher.
      Parameters:
      querySpecification - a IQuerySpecification that describes a Refinery Interpreter query specification
      Returns:
      a pattern matcher corresponding to the specification
      Throws:
      InterpreterRuntimeException - if the matcher could not be initialized
    • getMatcher

      public abstract InterpreterMatcher<? extends IPatternMatch> getMatcher(String patternFQN)
      Access a pattern matcher for the graph pattern with the given fully qualified name. Will succeed only if a query specification for this fully qualified name has been generated and registered. Multiple calls will return the same matcher unless the registered specification changes.
      Parameters:
      patternFQN - the fully qualified name of a Refinery Interpreter query specification
      Returns:
      a pattern matcher corresponding to the specification
      Throws:
      InterpreterRuntimeException - if the matcher could not be initialized
    • getExistingMatcher

      public abstract <Matcher extends InterpreterMatcher<? extends IPatternMatch>> Matcher getExistingMatcher(IQuerySpecification<Matcher> querySpecification)
      Access an existing pattern matcher based on a IQuerySpecification.
      Parameters:
      querySpecification - a IQuerySpecification that describes a Refinery Interpreter query specification
      Returns:
      a pattern matcher corresponding to the specification, null if a matcher does not exist yet.
    • getCurrentMatchers

      public abstract Set<? extends InterpreterMatcher<? extends IPatternMatch>> getCurrentMatchers()
      Access a copy of available InterpreterMatcher pattern matchers.
      Returns:
      a copy of the set of currently available pattern matchers registered on this engine instance
    • getRegisteredQuerySpecifications

      public Set<IQuerySpecification<? extends InterpreterMatcher<? extends IPatternMatch>>> getRegisteredQuerySpecifications()
    • getScope

      public abstract QueryScope getScope()
      Returns:
      the scope of query evaluation; the definition of the set of model elements that this engine is operates on.
    • flushChanges

      public abstract void flushChanges()
    • withFlushingChanges

      public abstract <T> T withFlushingChanges(Supplier<T> supplier)