Package org.mindswap.pellet

Examples of org.mindswap.pellet.DependencySet


    public void visit(SameIndividualAtom atom) {
      Pair<ATermAppl, DependencySet> arg1 = translateAtomObject(atom
          .getArgument1());
      Pair<ATermAppl, DependencySet> arg2 = translateAtomObject(atom
          .getArgument2());
      DependencySet mergedDS = ds;
      if (arg1.second != DependencySet.INDEPENDENT)
        mergedDS = ds.union(arg1.second, abox.doExplanation());
      if (arg2.second != DependencySet.INDEPENDENT)
        mergedDS = ds.union(arg2.second, abox.doExplanation());
View Full Code Here


   * </ul>
   *
   */
  public com.clarkparsia.pellet.rules.rete.Rule transformRule( Rule rule ) {
    ATermAppl ruleID = getRuleID( rule );
    DependencySet ds = DependencySet.INDEPENDENT; // TODO Make DS for the rule.
   
   
    Collection<ATermAppl> vars = new TreeSet<ATermAppl>( Comparators.termComparator );
   
    List<TermTuple> body = new ArrayList<TermTuple>();
View Full Code Here

      log.log( Level.WARNING,  "Fact with no elements, create clash" );
      return;
    }

    if( fact.getElements().size() == 3 ) {
      DependencySet ds = fact.getDependencySet();
     
      if( log.isLoggable( Level.FINE ) )
        log.fine( "RULE: " + fact + " " + ds );

      ATermAppl pred = fact.getElements().get( Compiler.PRED );
      Individual subj = abox.getIndividual( fact.getElements().get( Compiler.SUBJ ) );
      if( subj.isMerged() ) {
        ds = ds.union( subj.getMergeDependency( true ), abox.doExplanation() );
        subj = subj.getSame();
      }

      ATermAppl objTerm = fact.getElements().get( Compiler.OBJ );
View Full Code Here

  private int createDisjunctionsFromBinding(VariableBinding binding, Rule rule, DependencySet ds) {
    List<RuleAtom> atoms = new ArrayList<RuleAtom>();

    for( RuleAtom atom : rule.getBody() ) {
      DependencySet atomDS = atomTester.isAtomTrue( atom, binding );
      if( atomDS != null ) {
        ds = ds.union( atomDS, abox.doExplanation() );
      }
      else {
        atoms.add( atom );
      }
    }
   
    // all the atoms in the body are true
    if( atoms.isEmpty() ) {
      if( rule.getHead().isEmpty() ) {
        if( log.isLoggable( Level.FINE ) )
          log.fine( "Empty head for rule " + rule );
        abox.setClash( Clash.unexplained( null, ds ) );       
      }
      else {
        for( RuleAtom atom : rule.getHead() ) {
          ruleAtomAsserter.assertAtom( atom, binding, ds, false, abox, this );
        }
      }
      return -1;
    }
   
    int bodyAtomCount = atoms.size();

    for( RuleAtom atom : rule.getHead() ) {
      DependencySet atomDS = atomTester.isAtomTrue( atom, binding );
      if( atomDS == null ) {
        atoms.add( atom );
      }
    }
   
View Full Code Here

      ATermAppl[] factParts = new ATermAppl[permutation.length];
      for( int i = 0; i < permutation.length; i++ )
        factParts[permutation[i]] = constants.get( i );

      DependencySet ds = match.first.getDependencySet();
      ds = ds.union( match.second.getDependencySet(), doExplanation );

      List<ATermAppl> orderedConstants = Arrays.asList( factParts );
      Fact fact = new Fact( ds, orderedConstants );
      facts.add( fact );
      index.add( orderedConstants, fact );
View Full Code Here

        if( ATermUtils.isVar(term))
          constants.add( getVar( term, f.getElements() ) );
        else
          constants.add( term );
      }
      DependencySet ds = f.getDependencySet();
      ds = ds.union( rhs.getDependencySet(), doExplanation );
      if( rule != null && rule.explain != null )
        ds = ds.union( rule.explain, doExplanation );
      results.add( new Fact( ds, constants ) );
    }
    return results;
  }
View Full Code Here

  public boolean addFact(Edge edge) {
    final Individual from = edge.getFrom();
    final org.mindswap.pellet.Node to = edge.getTo().getSame();
    if( !to.isRootNominal() || to.isPruned() )
      return false;
    final DependencySet ds = edge.getDepends();
    Role role = edge.getRole();
   
    boolean added = addFact( role, from, to, ds );

    if( role.isObjectRole() ) {
View Full Code Here

     
      /*
       * Collect the data range and its dependency set
       */
      Collection<ATermAppl> existing = dataranges.get( r );
      DependencySet ds = x.getDepends( allDesc );
      if (existing == null) {
        existing = new ArrayList<ATermAppl>();
        dataranges.put( r, existing );
      } else {
        ds = ds.union( rangeDepends.get( r ), strategy.getABox().doExplanation() );
      }
      existing.add( (ATermAppl) allDesc.getArgument(1) );
      rangeDepends.put( r, ds );

    }

    /*
     * Get the ranges of any data properties that have min cardinality restrictions
     */
    for (ATermAppl minDesc : x.getTypes( Node.MIN )) {
      /*
       * TODO: Verify that minDesc will never have a property chain
       */
      final ATermAppl r = (ATermAppl)minDesc.getArgument( 0 );
      final Role role = strategy.getABox().getRole( r );
     
      /*
       * Skip any roles that are not datatype properties
       */
      if (!role.isDatatypeRole())
        continue;

      final Set<ATermAppl> ranges = role.getRanges();
      if( !ranges.isEmpty() ) {
        Collection<ATermAppl> existing = dataranges.get( r );
        DependencySet ds;
        if( existing == null ) {
          existing = new ArrayList<ATermAppl>();
          dataranges.put( r, existing );
          ds = DependencySet.EMPTY;
        } else
          ds = rangeDepends.get( r );

        for( ATermAppl dataRange : role.getRanges() ) {
          /*
           * TODO: Verify the dependency set handling here. The old
           * implementation just used independent (thus could avoid
           * this loop and call addAll)
           */
          existing.add( dataRange );
          ds = ds.union( role.getExplainRange( dataRange ), strategy.getABox().doExplanation() );
          rangeDepends.put( r, ds );
        }
      }
    }

    /*
     * For each of the min cardinality restrictions, verify that the data range is large enough
     */
    for (ATermAppl minDesc : x.getTypes( Node.MIN )) {
      final ATermAppl r = (ATermAppl)minDesc.getArgument( 0 );
      final Role role = strategy.getABox().getRole( r );

      Set<ATermAppl> drs = new HashSet<ATermAppl>();
      Collection<ATermAppl> direct = dataranges.get( r );
      DependencySet ds;
      if (direct != null) {
        drs.addAll(direct);
        ds = rangeDepends.get( r );
      } else
        ds = DependencySet.EMPTY;

      for (Role superRole : role.getSuperRoles()) {
        final ATermAppl s = superRole.getName();
        Collection<ATermAppl> inherited = dataranges.get( s );
        if( inherited != null ) {
          drs.addAll( inherited );
          ds = ds.union( rangeDepends.get( s ), strategy.getABox().doExplanation() ).union(
              role.getExplainSuper( s ), strategy.getABox().doExplanation() );
        }
      }

      if( !drs.isEmpty() ) {
View Full Code Here

      abox.getCompletionQueue().add( qElement, NodeSelector.MAX_NUMBER );
      abox.getCompletionQueue().add( qElement, NodeSelector.CHOOSE );
    }
   
   
    DependencySet ds = getTermDepends();     
    for(; getTryNext() < getTryCount(); tryNext++) {   
      this.abox.getKB().timers.mainTimer.check();
      if(PelletOptions.USE_SEMANTIC_BRANCHING) {
        for(int m = 0; m < getTryNext(); m++) {
          NodeMerge nm = mergePairs.get(m);     
          Node y = abox.getNode(nm.getSource()).getSame();
          Node z = abox.getNode(nm.getTarget()).getSame();
          y.setDifferent( z, prevDS[m]);
          //strategy.addType( y, ATermUtils.makeNot( ATermUtils.makeValue( z.getName() ) ), prevDS[m] );
        }
      }
     
      NodeMerge nm = mergePairs.get(getTryNext());     
      Node y = abox.getNode(nm.getSource()).getSame();
      Node z = abox.getNode(nm.getTarget()).getSame();
           
      if( log.isLoggable( Level.FINE ) )
                log.fine(
            "MAX : (" + (getTryNext()+1) + "/" + mergePairs.size() +
            ") at branch (" + getBranch() + ") to  " + ind +
            " for prop " + r + " qualification " + qualification +
            " merge " + y + " -> " + z + " " + ds);           
     
      ds = ds.union(new DependencySet(getBranch()), abox.doExplanation());
     
      // max cardinality merge also depends on all the edges
      // between the individual that has the cardinality and
      // nodes that are going to be merged
      EdgeList rNeighbors = ind.getRNeighborEdges(r);
      boolean yEdge = false, zEdge = false;
      for( Edge edge : rNeighbors ) {
        Node neighbor = edge.getNeighbor( ind );
       
        if( neighbor.equals( y ) ) {
          ds = ds.union( edge.getDepends(), abox.doExplanation() );
          yEdge = true;
        }
        else if( neighbor.equals( z ) ) {
          ds = ds.union( edge.getDepends(), abox.doExplanation() );
          zEdge = true;
        }
      }
     
      // if there is no edge coming into the node that is
      // going to be merged then it is not possible that
      // they are affected by the cardinality restriction
      // just die instead of possibly unsound results
      if(!yEdge || !zEdge)
          throw new InternalReasonerException(
              "An error occurred related to the max cardinality restriction about "  + r);
     
      // if the neighbor nodes did not have the qualification
      // in their type list they would have not been affected
      // by the cardinality restriction. so this merges depends
      // on their types
      ds = ds.union( y.getDepends( qualification ), abox.doExplanation() );
      ds = ds.union( z.getDepends( qualification ), abox.doExplanation() );
     
            // if there were other merges based on the exact same cardinality
      // restriction then this merge depends on them, too (we wouldn't
      // have to merge these two nodes if the previous merge did not
      // eliminate some other possibilities)
          for( int b = abox.getBranches().size() -2; b >=0; b-- ) {
            Branch branch = abox.getBranches().get( b );
            if( branch instanceof MaxBranch ) {
              MaxBranch prevBranch = (MaxBranch) branch;
              if( prevBranch.ind.equals( ind )
                && prevBranch.r.equals( r )
                && prevBranch.qualification.equals( qualification ) ) {
                ds.add( prevBranch.getBranch() );
              }
              else {
                break;
              }
            }
            else
              break;
          }
     
      strategy.mergeTo(y, z, ds);

//      abox.validate();
     
      boolean earlyClash = abox.isClosed();
      if(earlyClash) {
        if( log.isLoggable( Level.FINE ) )
                    log.fine("CLASH: Branch " + getBranch() + " " + abox.getClash() + "!");

        DependencySet clashDepends = abox.getClash().getDepends();
       
        if(clashDepends.contains(getBranch())) {
          // we need a global restore here because the merge operation modified three
          // different nodes and possibly other global variables
          strategy.restore(this);
         
          // global restore sets the branch number to previous value so we need to
View Full Code Here

      }
    }
  }

  void applyFunctionality(Individual subj, Role pred, Node obj) {
    DependencySet maxCardDS = pred.isFunctional() ? pred.getExplainFunctional() : subj.hasMax1(pred);

    if (maxCardDS != null) {
      maxRule.applyFunctionalMaxRule(subj, pred, ATermUtils.getTop(pred), maxCardDS);
    }
View Full Code Here

TOP

Related Classes of org.mindswap.pellet.DependencySet

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.