Package lupos.rif.model

Examples of lupos.rif.model.RulePredicate


    for (final Rule rule : obj.getRules()) {
      if (rule.isImplication()) {
        for (final IExpression expr : rule.getHeadExpressions()) {
          // Tripel mit variablen Praedikat wird generiert
          if (expr instanceof RulePredicate) {
            final RulePredicate pred = (RulePredicate) expr;
            final BasicOperator pattern = this.generatePattern(pred, arg);
            final KEY key = (pattern instanceof TriplePattern)?
                new KeyTriplePattern((TriplePattern)pattern):
                new KeyPredicatePattern((PredicatePattern)pattern);
            this.tripleProducer.put(key, new LinkedHashSet<BasicOperator>());
View Full Code Here


    return result;
  }

  private BasicOperator onePatternFromConclusion(final IExpression conclusion){
    // Annahme, Conclusion ist Praedikat
    final RulePredicate pred = (RulePredicate) conclusion;
    if (pred.isTriple()) {
      return this.unitermToTriplePattern(pred);
    } else {
      final URILiteral predName = (URILiteral) pred.termName.accept(this,
          null);
      final List<Item> predItems = new ArrayList<Item>();
View Full Code Here

      return n.f0.accept(this, argu);
    else {
      final List<INode> seq = ((List<INode>)((NodeChoice) n.f1.node).choice.accept(this, argu));
      final String operator = (String) seq.get(0).accept(this, null);
      if (operator.equals("#") || operator.equals("##")) {
        final Uniterm term = new RulePredicate(true);
        term.setParent(argu);
        final IExpression leftTerm = (IExpression) n.f0.accept(this, term);
        final IExpression rightTerm = (IExpression) seq.get(1).accept(this, term);
        term.termParams.add(leftTerm);
        term.termParams.add(rightTerm);
        try {
View Full Code Here

      return comp;
    }
  }

  public Object visit(final RIFUniterm n, final IRuleNode argu) {
    final Uniterm term = new RulePredicate(false);
    term.setParent(argu);
    term.termName = (IExpression) n.f0.accept(this, term);
    for (final INode node : (List<INode>) n.f2.accept(this, term)) {
      final NodeChoice choice = (NodeChoice) node;
      if (choice.which == 1)
        term.termParams.add((IExpression) choice.choice.accept(this,
View Full Code Here

  public Object visit(final RIFFrame n, final IRuleNode argu) {
    final List<INode> args = (List<INode>) n.f1.accept(this, argu);
    final AbstractExpressionContainer and = new Conjunction();
    for (final INode node : args) {
      final List<INode> nodeSeq = (List<INode>) node.accept(this, argu);
      final Uniterm term = new RulePredicate(true);
      term.setParent(argu);
      term.termName = (IExpression) nodeSeq.get(0).accept(this, term);
      term.termParams.add((IExpression) ((RIFAtomic)n.getParent().getParent().getParent()).f0.accept(this, term));
      term.termParams
          .add((IExpression) nodeSeq.get(2).accept(this, term));
      if (args.size() == 1)
View Full Code Here

      result.exprs.add((IExpression) expr.accept(this, result));
    return result;
  }

  public IRuleNode visit(RulePredicate obj, IRuleNode arg) throws RIFException {
    final RulePredicate result = new RulePredicate(obj.isTriple());
    result.setParent(arg);
    result.termName = (IExpression) obj.termName.accept(this, result);
    List<IExpression> exprs = new ArrayList<IExpression>(obj.termParams);
    for (IExpression expr : exprs)
      result.termParams.add((IExpression) expr.accept(this, result));
    return result;
View Full Code Here

            if (item instanceof RulePredicate)
              conjunction.addExpr(item);
            else if (item instanceof RuleVariable)
              result = item;
        }
        final RulePredicate item = new RulePredicate(
            new RuleVariable(itVar),
            new Constant(
                LiteralFactory
                    .createURILiteral("<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>"),
                arg), (IExpression) result);
        conjunction.addExpr(item);
        final RulePredicate next = new RulePredicate(
            new RuleVariable(itVar),
            new Constant(
                LiteralFactory
                    .createURILiteral("<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>"),
                arg),
View Full Code Here

    // Conclusion auswerten
    // TODO: erstmal nur ohne Equality, conjunction, disjunction und exists
    PredicateIndexScan conclusionIndex = null;
    if (obj.getConclusion() instanceof RulePredicate) {
      final RulePredicate predicate = (RulePredicate) obj.getConclusion();
      conclusionIndex = new PredicateIndexScan();
      root.addSucceedingOperator(conclusionIndex);
      Predicate toAdd = null;
      if (predicate.isTriple()) {
        final Triple triple = (Triple) predicate.toDataStructure();
        toAdd = new Predicate();
        toAdd.setName(triple.getPredicate());
        toAdd.getParameters().addAll(
            Arrays.asList(triple.getSubject(), triple.getObject()));
      } else
        toAdd = (Predicate) predicate.toDataStructure();
      conclusionIndex.addPredicateFact(toAdd);
    }

    // TODO: nur eine Regel enthalten, welche direkt auf die conclusion
    // passt,
View Full Code Here

  @Override
  public Object visit(Document obj, Object arg) throws RIFException {
    this.rifDoc = obj;
    // 1. Index rules based on predicate names
    for (final Rule rule : obj.getRules()) {
      final RulePredicate pred = (RulePredicate) rule.getHead();
      this.ruleMap.put(pred.termName.toString(), rule);
    }

    // 2. First goal is the conclusion, start recursive processing
    // Determine adornment
View Full Code Here

  public Object visit(Rule obj, Object arg) throws RIFException {
    final Map<RuleVariable, Boolean> boundVariables = new HashMap<RuleVariable, Boolean>();
    for (final RuleVariable var : obj.getDeclaredVariables())
      boundVariables.put(var, false);
    // 1. Determine bound variables
    final RulePredicate head = (RulePredicate) obj.getHead();
    for (int i = 0; i < head.termParams.size(); i++)
      // TODO: Check whether or not constant values appear in the head
      if (arg.toString().charAt(i) == 'b')
        boundVariables.put((RuleVariable) head.termParams.get(i), true);
    final List<IExpression> hornClause = new ArrayList<IExpression>();
    if (obj.getBody() instanceof Conjunction)
      hornClause.addAll(((Conjunction) obj.getBody()).exprs);
    else
      hornClause.add(obj.getBody());
    final List<RulePredicate> predicates = sortInformationPassing(
        hornClause, boundVariables);

    debug("RULE -> " + obj.toString());

    for (final IExpression expr : predicates) {
      // Body contains only a RulePredicate
      // Determine adornment
      final RulePredicate body = (RulePredicate) expr;
      final StringBuilder adornment = new StringBuilder();
      for (final IExpression ex : body.termParams)
        if (ex instanceof Constant
            || (ex instanceof RuleVariable && boundVariables
                .get(ex)))
          adornment.append("b");
        else if (ex instanceof RuleVariable) {
          adornment.append("f");
          boundVariables.put((RuleVariable) ex, true);
        }
      String nextGoal = body.termName.toString() + "_"
          + adornment.toString();
      if(this.goals.contains(nextGoal) && body.isRecursive()){
        // Recursive call -> create magic rule
      }
      body.accept(this, adornment.toString());
    }

    return null;
  }
View Full Code Here

TOP

Related Classes of lupos.rif.model.RulePredicate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.