Package com.clarkparsia.pellet.datatypes

Examples of com.clarkparsia.pellet.datatypes.DatatypeReasoner


  @Test
  public void testBuiltinDatatypesWithCardinalityRestriction() {
    String ns = "urn:test:";

    DatatypeReasoner dtReasoner = new DatatypeReasonerImpl();
    for( ATermAppl uri : dtReasoner.listDataRanges() ) {
      OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );
      DatatypeProperty prop = model.createDatatypeProperty( ns + "prop" );
      Resource datatype = model.createResource( uri.getName() );
      prop.addRange( datatype );
      OntClass C = model.createClass( ns + "C" );
View Full Code Here


      if( !ATermUtils.isLiteral( l ) ) {
        return false;
      }

      final DatatypeReasoner dtReasoner = kb.getDatatypeReasoner();
      try {
        final Object value = dtReasoner.getValue( l );
        return dtReasoner.isSatisfiable( Collections.singleton( d ), value );
      } catch( DatatypeReasonerException e ) {
        final String msg = format(
            "Unexpected datatype reasoner exception while checking if literal (%s) is in datarange (%s): %s ",
            l, d, e.getMessage() );
        log.severe( msg );
View Full Code Here

        promoter.accept(visitor);

        return comparesWell( visitor.getComparison() );
      }

      final DatatypeReasoner dtr = l1.getABox().getDatatypeReasoner();
      final ATermAppl term1 = l1.getTerm();
      final ATermAppl type1 = (ATermAppl) term1.getArgument( ATermUtils.LIT_URI_INDEX );
      final ATermAppl type2 = (ATermAppl) l2.getTerm().getArgument( ATermUtils.LIT_URI_INDEX );
      try {
        /*
         * First check if the literals' datatypes are comparable. If so,
         * compile the comparison into a datatype reasoner
         * satisfiability check.
         */
        if( dtr.isSatisfiable( Arrays.asList( type1, type2 ) ) ) {
          Facet f = lt
            ? inclusive
              ? Facet.XSD.MIN_INCLUSIVE
              : Facet.XSD.MIN_EXCLUSIVE
            : inclusive
              ? Facet.XSD.MAX_INCLUSIVE
              : Facet.XSD.MAX_EXCLUSIVE;
          final ATermAppl canon1 = dtr.getCanonicalRepresentation( term1 );
          final ATermAppl baseType = (ATermAppl) canon1
              .getArgument( ATermUtils.LIT_URI_INDEX );
          final ATermAppl dr = ATermUtils
              .makeRestrictedDatatype( baseType, new ATermAppl[] { ATermUtils
                  .makeFacetRestriction( f.getName(), canon1 ) } );
          if( dtr.isSatisfiable( Collections.singleton( dr ), l2val ) )
            return true;
          else
            return false;
        }
        else
View Full Code Here

  @Test
  public void testBuiltinDatatypesWithCardinalityRestriction() {
    String ns = "urn:test:";

    DatatypeReasoner dtReasoner = new DatatypeReasonerImpl();
    for( ATermAppl uri : dtReasoner.listDataRanges() ) {
      OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );
      DatatypeProperty prop = model.createDatatypeProperty( ns + "prop" );
      Resource datatype = model.createResource( uri.getName() );
      prop.addRange( datatype );
      OntClass C = model.createClass( ns + "C" );
View Full Code Here

            }
      return;
    }

    final Set<ATermAppl> types = getTypes();
    final DatatypeReasoner dtReasoner = abox.getDatatypeReasoner();

    try {
      if( hasValue ) {

        if( !dtReasoner.isSatisfiable( types, value ) ) {
          ArrayList<ATermAppl> primitives = new ArrayList<ATermAppl>();
          for( ATermAppl t : types ) {
            if( ATermUtils.TOP_LIT.equals( t ) ) {
                          continue;
                        }
                        else {
                          primitives.add( t );
                        }
          }

          final ATermAppl dt[] = primitives
              .toArray( new ATermAppl[primitives.size() - 1] );

          DependencySet ds = DependencySet.EMPTY;
          for( int i = 0; i < dt.length; i++ ) {
            ds = ds.union( getDepends( dt[i] ), abox.doExplanation() );
            if (abox.doExplanation()) {
              ATermAppl dtName = ATermUtils.isNot(dt[i]) ? (ATermAppl) dt[i].getArgument(0) : dt[i];
              ATermAppl definition = dtReasoner.getDefinition(dtName);
              if (definition != null) {
                              ds = ds.union(Collections.singleton(ATermUtils.makeDatatypeDefinition(dtName, definition)), true);
                            }
            }
          }

          reportClash( Clash.valueDatatype( this, ds, (ATermAppl) atermValue.getArgument(0), dt[0] ) );
        }
      }
      else {
        if( dtReasoner.isSatisfiable( types ) ) {
          if ( !dtReasoner.containsAtLeast( 2, types ) ) {
            /*
             * This literal is a variable, but given current ranges can only
             * take on a single value.  Merge with that value.
             */
            final Object value = dtReasoner.valueIterator( types ).next();
            final ATermAppl valueTerm = dtReasoner.getLiteral( value );
            Literal valueLiteral = abox.getLiteral( valueTerm );
            if (valueLiteral == null) {
              /*
               * No dependency set is used here because omitting it prevents the
               * constant literal from being removed during backtrack
               */
              valueLiteral = abox.addLiteral( valueTerm );
            }
            DependencySet mergeDs = DependencySet.INDEPENDENT;
            for ( DependencySet ds : depends.values() ) {
                          mergeDs = mergeDs.union( ds, abox.doExplanation() );
                        }
            merge = new NodeMerge( this, valueLiteral, mergeDs );
          }
        } else {
          ArrayList<ATermAppl> primitives = new ArrayList<ATermAppl>();
          for( ATermAppl t : types ) {
            if( ATermUtils.TOP_LIT.equals( t ) ) {
                          continue;
                        }
                        else {
                          primitives.add( t );
                        }
          }

          final ATermAppl dt[] = primitives
              .toArray( new ATermAppl[primitives.size() - 1] );

          DependencySet ds = DependencySet.EMPTY;
          for( int i = 0; i < dt.length; i++ ) {
                      ds = ds.union( getDepends( dt[i] ), abox.doExplanation() );
              if (abox.doExplanation()) {
              ATermAppl definition = dtReasoner.getDefinition(dt[i]);
              if (definition != null) {
                              ds = ds.union(Collections.singleton(ATermUtils.makeDatatypeDefinition(dt[i], definition)), true);
                            }
            }
                    }
View Full Code Here

TOP

Related Classes of com.clarkparsia.pellet.datatypes.DatatypeReasoner

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.