Package com.clarkparsia.pellet.sparqldl.model

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


    return result;
  }

  public static QueryResult exec(final Query query) {
    if( query.getAtoms().isEmpty() ) {
      final QueryResultImpl results = new QueryResultImpl( query );
      results.add( new ResultBindingImpl() );
      return results;
    }
    query.getKB().ensureConsistency();

    // PREPROCESSING
    if( log.isLoggable( Level.FINE ) ) {
      log.fine( "Preprocessing:\n" + query );
    }
    Query preprocessed = preprocess( query );

    // SIMPLIFICATION
    if( PelletOptions.SIMPLIFY_QUERY ) {
      if( log.isLoggable( Level.FINE ) ) {
        log.fine( "Simplifying:\n" + preprocessed );
      }

      simplify( preprocessed );
    }

    // SPLITTING
    if( log.isLoggable( Level.FINE ) ) {
      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 ) );
    }
    else {
      final List<QueryResult> results = new ArrayList<QueryResult>( queries.size() );
      for( final Query q : queries ) {
        results.add( execSingleQuery( q ) );
      }

      r = new MultiQueryResults( query.getResultVars(), results );
    }
   
View Full Code Here


    return hasUndefinedTerm( query.getAtoms(), query.getKB() );
  }

  private static QueryResult execSingleQuery(Query query) {
    if( hasUndefinedTerm( query ) ) {
      return new QueryResultImpl( query );
    }

    // if (PelletOptions.SAMPLING_RATIO > 0) {
    // if (log.isLoggable( Level.FINE ))
    // log.fine("Reorder\n" + query);
View Full Code Here

    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);
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
  public QueryResult execABoxQuery(final Query q) {
    results = new QueryResultImpl(q);

    this.kb = q.getKB();

    long satCount = kb.getABox().stats.satisfiabilityCount;
    long consCount = kb.getABox().stats.consistencyCount;
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

    this.kb = query.getKB();
    if( kb == null ) {
      throw new RuntimeException( "No input data set is given for query!" );
    }

    this.result = new QueryResultImpl( query );

    this.oldQuery = query;
    this.query = setupCores( query );

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

TOP

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

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.