Package com.clarkparsia.pellet.sparqldl.model

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


   * Simple query subsumption similar to standard concept subsumption. Every
   * Male is a Person so query 1 is subsumed by query 2. The converse is
   * obviously not true.
   */
  public void example1() {
    Query q1 = query( "?x a family:Male ." );
    Query q2 = query( "?x a family:Person ." );

    System.out.println( "Example 1" );
    System.out.println( "=========" );
    System.out.println( "Query 1: " + q1.toString());
    System.out.println( "Query 2: " + q2.toString() );
    System.out.println();
    System.out
        .println( "Query 1 is subsumed by query 2: " + QuerySubsumption.isSubsumedBy( q1, q2 ) );
    System.out
        .println( "Query 2 is subsumed by query 1: " + QuerySubsumption.isSubsumedBy( q2, q1 ) );
View Full Code Here


   * Another example of subsumption. First query asks for all people married
   * to Male individuals which is subsumed by the second query which asks for
   * all Females.
   */
  public void example2() {
    Query q3 = query( "?x family:isMarriedTo ?y . ?y rdf:type family:Male" );
    Query q4 = query( "?x a family:Female ." );

    System.out.println( "Example 2" );
    System.out.println( "=========" );
    System.out.println( "Query 3: " + q3.toString() );
    System.out.println( "Query 4: " + q4.toString() );
    System.out.println();
    System.out
        .println( "Query 3 is subsumed by query 4: " + QuerySubsumption.isSubsumedBy( q3, q4 ) );
    System.out
        .println( "Query 4 is subsumed by query 3: " + QuerySubsumption.isSubsumedBy( q4, q3 ) );
View Full Code Here

   * hasFather and hasParent properties would normally establish subsumption
   * in one way but due to cardinality restrictions defined in the ontology
   * two queries end up being equivalent,
   */
  public void example3() {
    Query q5 = query( "?x family:hasFather ?y . " );
    Query q6 = query( "?x family:hasParent ?y . ?y a family:Male ." );

    System.out.println( "Example 3" );
    System.out.println( "=========" );
    System.out.println( "Query 5: " + q5.toString() );
    System.out.println( "Query 6: " + q6.toString() );
    System.out.println();
    System.out
        .println( "Query 5 is subsumed by query 6: " + QuerySubsumption.isSubsumedBy( q5, q6 ) );
    System.out
        .println( "Query 6 is subsumed by query 5: " + QuerySubsumption.isSubsumedBy( q5, q6 ) );
View Full Code Here

   * variable name ?z instead of the the variable name ?y used in the first
   * query. The query subsumption algorithm finds the mapping between query
   * variables.
   */
  public void example4() {
    Query q7 = query( "?x a family:Female; family:hasBrother ?y . " );
    Query q8 = query( "?x a family:Female; family:hasSibling ?z ." );

    System.out.println( "Example 4" );
    System.out.println( "=========" );
    System.out.println( "Query 7: " + q7.toString() );
    System.out.println( "Query 8: " + q8.toString() );
    System.out.println();
    System.out
        .println( "Query 7 is subsumed by query 8: " + QuerySubsumption.isSubsumedBy( q7, q8 ) );

    System.out.print( "Subsumption mappings: " );
    QueryResult mappings = QuerySubsumption.getSubsumptionMappings( q7, q8 );
    for( Iterator<ResultBinding> i = mappings.iterator(); i.hasNext(); ) {
      ResultBinding mapping = i.next();
      for( Iterator<?> j = q8.getVars().iterator(); j.hasNext(); ) {
        ATermAppl var = (ATermAppl) j.next();
        System.out.print( var.getArgument( 0 ) + " -> " + mapping.getValue( var )); //I get var(x) as opposed to x
        if( j.hasNext() )
          System.out.print( ", " );
      }
View Full Code Here

public class TestBooleanQueries extends AbstractKBTests {
  private static final ATermAppl  x  = ATermUtils.makeVar( "x" );
  private static final ATermAppl  y  = ATermUtils.makeVar( "y" );

  private Query query(QueryAtom... atoms) {
    Query q = new QueryImpl( kb, true );
    for( QueryAtom atom : atoms ) {
      q.add( atom );
    }
    return q;
  }
View Full Code Here

    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

  protected Query ask(QueryAtom... atoms) {
    return query( new ATermAppl[0], atoms );
  }

  protected Query query(ATermAppl[] vars, QueryAtom[] atoms) {
    Query q = new QueryImpl( kb, true );
    for( ATermAppl var : vars ) {     
      q.addResultVar( var );
    }
   
    for( QueryAtom atom : atoms ) {
      q.add( atom );
    }
   
    for( ATermAppl var : q.getUndistVars() ) {
      q.addDistVar( var, VarType.INDIVIDUAL );
    }
   
    return q;
  }
View Full Code Here

public class TestBooleanQueries extends AbstractKBTests {
  private static final ATermAppl  x  = ATermUtils.makeVar( "x" );
  private static final ATermAppl  y  = ATermUtils.makeVar( "y" );

  private Query query(QueryAtom... atoms) {
    Query q = new QueryImpl( kb, true );
    for( QueryAtom atom : atoms ) {
      q.add( atom );
    }
    return q;
  }
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.