Package com.clarkparsia.pellet.sparqldl.model

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


    kb.addType( a, A );
    kb.addType( b, B );

    kb.addPropertyValue( p, a, b );

    Query q1 = query( TypeAtom( x, A ) );
    Query q2 = query( TypeAtom( x, B ) );
    Query q3 = query( PropertyValueAtom( x, p, y ), TypeAtom( y, B ) );
    Query q4 = query( TypeAtom( x, A ), PropertyValueAtom( x, p, y ), TypeAtom( y, B ) );
    Query q5 = query( TypeAtom( x, C ) );
    Query q6 = query( TypeAtom( x, A ), TypeAtom( x, C ) );

    testABoxQuery( true, q1 );
    testABoxQuery( true, q2 );
    testABoxQuery( true, q3 );
    testABoxQuery( true, q4 );
View Full Code Here


    kb.addSubClass( A, C );
    kb.addSubClass( B, C );

    kb.addType( a, A );

    Query q1 = query( SubClassOfAtom( x, C ), TypeAtom( y, x ) );
    q1.addDistVar( x, VarType.CLASS );
    q1.addResultVar( x );

    QueryResult qr = QueryEngine.exec( q1 );

    List<ATermAppl> results = new ArrayList<ATermAppl>();
    for( ResultBinding result : qr ) {
View Full Code Here

    classes(A, B);
    individuals(a);
   
    kb.addType( a, A );

    Query q1 = query( NotKnownAtom( TypeAtom( a, A ) ) );
    Query q2 = query( NotKnownAtom( TypeAtom( a, B ) ) );
    Query q3 = query( NotKnownAtom( TypeAtom( a, not( A ) ) ) );
    Query q4 = query( NotKnownAtom( TypeAtom( a, not( B ) ) ) );
   
    testQuery( false, q1 );
    testQuery( true, q2 );
    testQuery( true, q3 );
    testQuery( true, q4 );
View Full Code Here

    // 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 );
View Full Code Here

      if( equivalenceSets.size() == 1 )
        return Collections.singletonList( query );

      final Map<ATermAppl, Query> queries = new HashMap<ATermAppl, Query>();
      Query groundQuery = null;
      for( final QueryAtom atom : query.getAtoms() ) {
        ATermAppl representative = null;
        for( final ATermAppl arg : atom.getArguments() ) {
          if( ATermUtils.isVar( arg ) ) {
            representative = disjointSet.find( arg );
            break;
          }
        }

        Query newQuery = null;
        if( representative == null ) {
          if( groundQuery == null ) {
            groundQuery = new QueryImpl( query );
          }
          newQuery = groundQuery;
        }
        else {
          newQuery = queries.get( representative );
          if( newQuery == null ) {
            newQuery = new QueryImpl( query );
            queries.put( representative, newQuery );
          }
          for( final ATermAppl arg : atom.getArguments() ) {
            if( resultVars.contains( arg ) ) {
              newQuery.addResultVar( arg );
            }

            for( final VarType v : VarType.values() ) {
              if( query.getDistVarsForType( v ).contains( arg ) ) {
                newQuery.addDistVar( arg, v );
              }
            }
          }
        }

        newQuery.add( atom );
      }

      final List<Query> list = new ArrayList<Query>( queries.values() );

      if( groundQuery != null ) {
View Full Code Here

  private static void simplify(Query query) {
    domainRangeSimplification( query );
  }

  private static Query preprocess(final Query query) {
    Query q = query;

    Set<ATermAppl> undistVars = q.getUndistVars();

    // SAMEAS
    // replace of SameAs atoms that contain at least one undistinguished
    // or non-result variable.
    boolean boundSameAs = true;
    while( boundSameAs ) {
      boundSameAs = false;
      for( final QueryAtom atom : q.findAtoms( QueryPredicate.SameAs, null, null ) ) {
        final ATermAppl a1 = atom.getArguments().get( 0 );
        final ATermAppl a2 = atom.getArguments().get( 1 );
       
        boolean replaceA1 = false;
        boolean replaceA2 = false;

        if( !a1.equals( a2 ) ) {
          if( undistVars.contains( a1 ) )
            replaceA1 = true;
          else if( undistVars.contains( a2 ) )
            replaceA2 = true;
          else if( ATermUtils.isVar( a1 ) && !q.getResultVars().contains( a1 ) )
            replaceA1 = true;
          else if( ATermUtils.isVar( a2 ) && !q.getResultVars().contains( a2 ) )
            replaceA2 = true;
        }

        if( replaceA1 || replaceA2 ) {
          final ResultBinding b;
          if( replaceA1 ) {
            b = new ResultBindingImpl();
            b.setValue( a1, a2 );
          }
          else {
            b = new ResultBindingImpl();
            b.setValue( a2, a1 );
          }
          q = q.apply( b );
          boundSameAs = true;
          break;
        }
      }
    }
   
    // Remove sameAs statements where:
    // 1) Both arguments are the same
    // 2) Neither is a result variable
    // 3) Removing the atom doesn't result in an empty query
    for( final QueryAtom atom : q.findAtoms( QueryPredicate.SameAs, null, null ) ) {
      final ATermAppl a1 = atom.getArguments().get( 0 );
      final ATermAppl a2 = atom.getArguments().get( 1 );
     
      // Could remove sameAs with result vars if we could guarantee the query still contained an
      // atom containing the variable.
      if( a1.equals( a2 ) && !q.getResultVars().contains( a1 ) && q.getAtoms().size() > 1 ) {
        q.remove( atom );
      }
    }
   

    // Undistinguished variables + CLASS and PROPERTY variables
    // TODO bug : queries Type(_:x,?x) and PropertyValue(_:x, ?x, . ) and
    // PropertyValue(., ?x, _:x) have to be enriched with one more atom
    // evaluating class/property DVs.
    for( final QueryAtom a : new HashSet<QueryAtom>( q.getAtoms() ) ) {
      switch ( a.getPredicate() ) {
      case Type:
      case DirectType:
        final ATermAppl clazz = a.getArguments().get( 1 );

        if( undistVars.contains( clazz ) && undistVars.contains( a.getArguments().get( 0 ) ) ) {
          q.add( QueryAtomFactory.SubClassOfAtom( clazz, clazz ) );
        }
        break;
      case PropertyValue:
        final ATermAppl property = a.getArguments().get( 1 );

        if( undistVars.contains( a.getArguments().get( 0 ) )
            || undistVars.contains( a.getArguments().get( 2 ) )
            && q.getDistVars().contains( property ) ) {
          q.add( QueryAtomFactory.SubPropertyOfAtom( property, property ) );
        }
        break;
      default:
        break;
      }
View Full Code Here

    }

    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);
View Full Code Here

    kb.addDomain( p, C );
   
    ATermAppl pv = var( "pv" );
    ATermAppl cv = var( "cv" );
   
    Query query = query(
        select(pv, cv),
        where(DomainAtom(pv, cv)));
   
    testQuery( query, new ATermAppl[][] {
         {p, TOP}, {q, TOP}, {r, TOP}, {TOP_OBJECT_PROPERTY, TOP}, {TOP_DATA_PROPERTY, TOP}, {BOTTOM_OBJECT_PROPERTY, TOP}, {BOTTOM_DATA_PROPERTY, TOP},
View Full Code Here

    kb.addSubProperty( q, p );
    kb.addDomain( p, C );
   
    ATermAppl cv = var( "cv" );
   
    Query query = query(
        select(cv),
        where(DomainAtom(q, cv)));
   
    testQuery( query, new ATermAppl[][] {
        {TOP},
View Full Code Here

    kb.addSubProperty( q, p );
    kb.addDomain( p, C );
   
    ATermAppl pv = var( "pv" );
   
    Query query = query(
        select(pv),
        where(DomainAtom(pv, C)));
   
    testQuery( query, new ATermAppl[][] { {p}, {q}, {BOTTOM_OBJECT_PROPERTY}, {BOTTOM_DATA_PROPERTY}} );
   
View Full Code Here

TOP

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

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.