Package com.clarkparsia.pellet.sparqldl.model

Examples of com.clarkparsia.pellet.sparqldl.model.QueryResult


      log.fine( "Splitting:\n" + preprocessed );
    }
   
    final List<Query> queries = split( preprocessed );

    QueryResult r = null;
    if( queries.isEmpty() ) {
      throw new InternalReasonerException( "Splitting query returned no results!" );
    }
    else if( queries.size() == 1 ) {
      r = execSingleQuery( queries.get( 0 ) );
View Full Code Here


      log.fine("Executing query " + query.getAtoms());
    }

    partitionQuery(query);

    QueryResult newResult;

    boolean shouldHaveBinding;
    final QueryResult result;

    if (schemaQuery.getAtoms().isEmpty()) {
      shouldHaveBinding = false;
      result = new QueryResultImpl(query);
      result.add(new ResultBindingImpl());
    } else {
      if (log.isLoggable( Level.FINE )) {
        log.fine("Executing TBox query: " + schemaQuery);
      }
      result = distCombinedQueryExec.exec(schemaQuery);

      shouldHaveBinding = org.mindswap.pellet.utils.SetUtils.intersects(
          query.getDistVarsForType(VarType.CLASS), query
              .getResultVars())
          || org.mindswap.pellet.utils.SetUtils.intersects(query
              .getDistVarsForType(VarType.PROPERTY), query
              .getResultVars());
    }
    if (shouldHaveBinding && result.isEmpty()) {
      return result;
    }

    if (log.isLoggable( Level.FINE )) {
      log.fine("Partial binding after schema query : " + result);
    }

    if (aboxQuery.getAtoms().size() > 0) {
      newResult = new QueryResultImpl(query);
      for (ResultBinding binding : result) {
        final Query query2 = aboxQuery.apply(binding);

        if (log.isLoggable( Level.FINE )) {
          log.fine("Executing ABox query: " + query2);
        }
        final QueryResult aboxResult = execABoxQuery(query2);

        for (ResultBinding newBinding : aboxResult) {
          for (final ATermAppl var : binding.getAllVariables()) {
            newBinding.setValue(var, binding.getValue(var));
          }
View Full Code Here

    return true; // TODO
  }

  @Override
  public QueryResult execABoxQuery(final Query q) {
    final QueryResult results = new QueryResultImpl(q);
    final KnowledgeBase kb = q.getKB();

    long satCount = kb.getABox().stats.satisfiabilityCount;
    long consCount = kb.getABox().stats.consistencyCount;

    if (q.getDistVars().isEmpty()) {
      if (QueryEngine.execBooleanABoxQuery(q)) {
        results.add(new ResultBindingImpl());
      }
    } else {
      final Map<ATermAppl, Set<ATermAppl>> varBindings = new HashMap<ATermAppl, Set<ATermAppl>>();

      for (final ATermAppl currVar : q
          .getDistVarsForType(VarType.INDIVIDUAL)) {
        ATermAppl rolledUpClass = q.rollUpTo(currVar,
            Collections.EMPTY_SET, false);

        if (log.isLoggable( Level.FINER ))
          log.finer("Rolled up class " + rolledUpClass);
        Set<ATermAppl> inst = kb.getInstances(rolledUpClass);
        varBindings.put(currVar, inst);
      }

      if (log.isLoggable( Level.FINER ))
        log.finer("Var bindings: " + varBindings);

      final Iterator<ResultBinding> i = new BindingIterator(varBindings);

      final Set<ATermAppl> literalVars = q
          .getDistVarsForType(VarType.LITERAL);
      final Set<ATermAppl> individualVars = q
          .getDistVarsForType(VarType.INDIVIDUAL);

      boolean hasLiterals = !individualVars.containsAll(literalVars);

      if (hasLiterals) {
        while (i.hasNext()) {
          final ResultBinding b = i.next();

          final Iterator<ResultBinding> l = new LiteralIterator(q, b);
          while (l.hasNext()) {
            ResultBinding mappy = l.next();
            boolean queryTrue = QueryEngine.execBooleanABoxQuery(q
                .apply(mappy));
            if (queryTrue)
              results.add(mappy);
          }
        }
      } else {
        while (i.hasNext()) {
          final ResultBinding b = i.next();
          boolean queryTrue = (q.getDistVarsForType(
              VarType.INDIVIDUAL).size() == 1)
              || QueryEngine.execBooleanABoxQuery(q.apply(b));
          if (queryTrue)
            results.add(b);
        }
      }
    }

    if (log.isLoggable( Level.FINE )) {
View Full Code Here

     */
    @Override
    protected QueryIterator nextStage(Binding binding) {
      Query newQuery = query.apply( convertBinding( binding ) );

      QueryResult results = QueryEngine.exec( newQuery );

      SparqlDLResultSet resultSet = new SparqlDLResultSet( results, null, binding );

      QueryIteratorResultSet iter = new QueryIteratorResultSet( resultSet );

View Full Code Here

        }
       
        kb.isConsistent();
       
        sup.setKB( kb );
        QueryResult results = QueryEngine.exec( sup );
        sup.setKB( sup.getKB() );
       
        return results;
    }
View Full Code Here

    return true; // TODO
  }

  @Override
  public QueryResult execABoxQuery(final Query q) {
    final QueryResult results = new QueryResultImpl(q);
    final KnowledgeBase kb = q.getKB();

    long satCount = kb.getABox().stats.satisfiabilityCount;
    long consCount = kb.getABox().stats.consistencyCount;

    if (q.getDistVars().isEmpty()) {
      if (QueryEngine.execBooleanABoxQuery(q)) {
        results.add(new ResultBindingImpl());
      }
    } else {
      final Map<ATermAppl, Set<ATermAppl>> varBindings = new HashMap<ATermAppl, Set<ATermAppl>>();

      for (final ATermAppl currVar : q
          .getDistVarsForType(VarType.INDIVIDUAL)) {
        ATermAppl rolledUpClass = q.rollUpTo(currVar,
            Collections.EMPTY_SET, false);

        if (log.isLoggable( Level.FINER ))
          log.finer("Rolled up class " + rolledUpClass);
        varBindings.put(currVar, kb.getInstances(rolledUpClass));
      }

      if (log.isLoggable( Level.FINER ))
        log.finer("Var bindings: " + varBindings);

      final List<ATermAppl> varList = new ArrayList<ATermAppl>(
          varBindings.keySet()); // TODO

      final Map<ATermAppl, Collection<ResultBinding>> goodLists = new HashMap<ATermAppl, Collection<ResultBinding>>();

      final ATermAppl first = varList.get(0);
      final Collection<ResultBinding> c = new HashSet<ResultBinding>();

      for (final ATermAppl a : varBindings.get(first)) {
        final ResultBinding bind = new ResultBindingImpl();
        bind.setValue(first, a);
        c.add(bind);
      }

      goodLists.put(first, c);

      Collection<ResultBinding> previous = goodLists.get(first);
      for (int i = 1; i < varList.size(); i++) {
        final ATermAppl next = varList.get(i);

        final Collection<ResultBinding> newBindings = new HashSet<ResultBinding>();

        for (final ResultBinding binding : previous) {
          for (final ATermAppl testBind : varBindings.get(next)) {
            final ResultBinding bindingCandidate = binding.duplicate();

            bindingCandidate.setValue(next, testBind);

            boolean queryTrue = QueryEngine.execBooleanABoxQuery(q
                .apply(bindingCandidate));
            if (queryTrue) {
              newBindings.add(bindingCandidate);
              if (log.isLoggable( Level.FINER )) {
                log.finer("Accepted binding: "
                    + bindingCandidate);
              }
            } else {
              if (log.isLoggable( Level.FINER )) {
                log.finer("Rejected binding: "
                    + bindingCandidate);
              }
            }
          }
        }

        previous = newBindings;
      }

      // no var. should be marked as both INDIVIDUAL and LITERAL in an
      // ABox query.
      boolean hasLiterals = !q.getDistVarsForType(VarType.LITERAL)
          .isEmpty();

      if (hasLiterals) {
        for (final ResultBinding b : previous) {
          for (final Iterator<ResultBinding> i = new LiteralIterator(
              q, b); i.hasNext();) {
            results.add(i.next());
          }
        }
      } else {
        for (final ResultBinding b : previous) {
          results.add(b);
        }
      }
      if (log.isLoggable( Level.FINE )) {
        log.fine("Results: "
            + results);
View Full Code Here

   
    return q;
  }

  protected void testQuery(Query query, boolean expected) {
    QueryResult result = QueryEngine.exec( query );

    assertEquals( expected, !result.isEmpty() );
  }
View Full Code Here

        answers.put( answer, count + 1 );
      }

    }

    QueryResult result = QueryEngine.exec( query );
    for( ResultBinding binding : result ) {
      List<ATermAppl> list = new ArrayList<ATermAppl>( resultVars.size() );
      for( ATermAppl var : resultVars ) {
        list.add( binding.getValue( var ) );
      }
View Full Code Here

          newQuery.addResultVar( var );
        }
       
        QueryExec newEngine = new CombinedQueryEngine();
       
        QueryResult newResult = newEngine.exec( newQuery )
        for( ResultBinding newBinding : newResult ) {
          newBinding.setValues( binding );
          exec( newBinding );
        }
      }
View Full Code Here

TOP

Related Classes of com.clarkparsia.pellet.sparqldl.model.QueryResult

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.