Example #1
0
  /**
   * Constructor.
   *
   * @param engine the engine which is calling this interpreter
   * @param goal the query to be satisfied
   * @param clauses the set of code blocks needed to implement this goal
   * @param isTop true if this is a top level call from the outside iterator, false means it is an
   *     internal generator call which means we don't need to insert an tabled call
   */
  public LPInterpreter(
      LPBRuleEngine engine, TriplePattern goal, List<RuleClauseCode> clauses, boolean isTop) {
    this.engine = engine;
    this.goal = goal; // Used for debug only

    // Construct dummy top environemnt which is a call into the clauses for this goal
    if (engine.getDerivationLogging()) {
      envFrame = new EnvironmentFrameWithDerivation(RuleClauseCode.returnCodeBlock);
    } else {
      envFrame = new EnvironmentFrame(RuleClauseCode.returnCodeBlock);
    }
    envFrame.allocate(RuleClauseCode.MAX_PERMANENT_VARS);
    HashMap<Node, Node> mappedVars = new HashMap<>();
    envFrame.pVars[0] = argVars[0] = standardize(goal.getSubject(), mappedVars);
    envFrame.pVars[1] = argVars[1] = standardize(goal.getPredicate(), mappedVars);
    envFrame.pVars[2] = argVars[2] = standardize(goal.getObject(), mappedVars);
    if (engine.getDerivationLogging()) {
      ((EnvironmentFrameWithDerivation) envFrame).initDerivationRecord(argVars);
    }

    if (clauses != null && clauses.size() > 0) {
      if (isTop && engine.getRuleStore().isTabled(goal)) {
        setupTabledCall(0, 0);
        //                setupClauseCall(0, 0, clauses);
      } else {
        setupClauseCall(0, 0, clauses, goal.isGround());
      }
    }

    //        TripleMatchFrame tmFrame = new TripleMatchFrame(this);
    topTMFrame = new TopLevelTripleMatchFrame(this, goal);
    topTMFrame.linkTo(cpFrame);
    topTMFrame.setContinuation(0, 0);
    cpFrame = topTMFrame;
  }
Example #2
0
File: Graph.java Project: AKSW/SINA
 public void addTriple(Entity subject, String predicat, Entity Object) {
   TriplePattern j = new TriplePattern();
   j.setSubject(subject);
   j.setPredicate(predicat);
   j.setObject(Object);
   TripleList.add(j);
 }
Example #3
0
 /**
  * Extended find interface used in situations where the implementator may or may not be able to
  * answer the complete query. It will attempt to answer the pattern but if its answers are not
  * known to be complete then it will also pass the request on to the nested Finder to append more
  * results.
  *
  * @param pattern a TriplePattern to be matched against the data
  * @param continuation either a Finder or a normal Graph which will be asked for additional match
  *     results if the implementor may not have completely satisfied the query.
  */
 @Override
 public ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation) {
   if (graph == null) return new NullIterator<Triple>();
   if (continuation == null) {
     return graph.find(pattern.asTripleMatch());
   } else {
     return graph.find(pattern.asTripleMatch()).andThen(continuation.find(pattern));
   }
 }
Example #4
0
 /** Return a dereferenced copy of a triple. */
 public static Triple deref(TriplePattern t) {
   if (t == null) return null;
   return new Triple(deref(t.getSubject()), deref(t.getPredicate()), deref(t.getObject()));
 }
Example #5
0
 /** Return true if the given pattern occurs somewhere in the find sequence. */
 @Override
 public boolean contains(TriplePattern pattern) {
   return graph.contains(pattern.getSubject(), pattern.getPredicate(), pattern.getObject());
 }
Example #6
0
 /**
  * Basic pattern lookup interface.
  *
  * @param pattern a TriplePattern to be matched against the data
  * @return a ClosableIterator over all Triples in the data set that match the pattern
  */
 @Override
 public ExtendedIterator<Triple> find(TriplePattern pattern) {
   if (graph == null) return new NullIterator<Triple>();
   return graph.find(pattern.asTripleMatch());
 }
Example #7
0
File: Graph.java Project: AKSW/SINA
 public void addTriple(TriplePattern i) {
   TriplePattern j = new TriplePattern();
   j.setSubject(i.getSubject());
   j.setPredicate(i.getPredicate());
   j.setObject(i.getObject());
   j.setPropertySet(i.getPropertySet());
   j.setHasSetOfProperties(i.getHasSetOfProperties());
   TripleList.add(j);
 }