@Override
 public OWLLiteral getOWLLiteral(String lexicalValue, OWLDatatype datatype) {
   OWLLiteral literal;
   if (datatype.isRDFPlainLiteral()) {
     int sep = lexicalValue.lastIndexOf('@');
     if (sep != -1) {
       String lex = lexicalValue.substring(0, sep);
       String lang = lexicalValue.substring(sep + 1);
       literal = getBasicLiteral(lex, lang, getRDFPlainLiteral());
     } else {
       literal = getBasicLiteral(lexicalValue, datatype);
     }
   } else {
     // check the four special cases
     try {
       if (datatype.isBoolean()) {
         literal = getOWLLiteral(isBooleanTrueValue(lexicalValue.trim()));
       } else if (datatype.isFloat()) {
         if (lexicalValue.trim().equals("-0.0")) {
           // according to some W3C test, this needs to be
           // different from 0.0; Java floats disagree
           if (negativeFloatZero == null) {
             negativeFloatZero = getBasicLiteral("-0.0", XSD_FLOAT);
           }
           literal = negativeFloatZero;
         } else {
           try {
             float f = Float.parseFloat(lexicalValue);
             literal = getOWLLiteral(f);
           } catch (NumberFormatException e) {
             literal = getBasicLiteral(lexicalValue, datatype);
           }
         }
       } else if (datatype.isDouble()) {
         literal = getOWLLiteral(Double.parseDouble(lexicalValue));
       } else if (datatype.isInteger()) {
         // again, some W3C tests require padding zeroes to make
         // literals different
         if (lexicalValue.trim().charAt(0) == '0') {
           literal = getBasicLiteral(lexicalValue, getIntegerOWLDatatype());
         } else {
           try {
             // this is fine for values that can be parsed as
             // ints - not all values are
             literal = getOWLLiteral(Integer.parseInt(lexicalValue));
           } catch (NumberFormatException ex) {
             // try as a big decimal
             literal = getBasicLiteral(lexicalValue, datatype);
           }
         }
       } else {
         literal = getBasicLiteral(lexicalValue, datatype);
       }
     } catch (NumberFormatException e) {
       // some literal is malformed, i.e., wrong format
       literal = getBasicLiteral(lexicalValue, datatype);
     }
   }
   return literal;
 }
 protected boolean isNonNegativeIntegerStrict(IRI mainNode, OWLRDFVocabulary predicate) {
   OWLLiteral literal = consumer.getLiteralObject(mainNode, predicate, false);
   if (literal == null) {
     return false;
   }
   OWLDatatype datatype = literal.getDatatype();
   OWL2Datatype nni = OWL2Datatype.XSD_NON_NEGATIVE_INTEGER;
   return datatype.getIRI().equals(nni.getIRI()) && nni.isInLexicalSpace(literal.getLiteral());
 }
 @Override
 public boolean equals(Object obj) {
   if (super.equals(obj)) {
     if (obj instanceof OWLLiteralImplBoolean) {
       OWLLiteralImplBoolean other = (OWLLiteralImplBoolean) obj;
       return literal == other.literal && datatype.equals(other.getDatatype());
     }
     if (obj instanceof OWLLiteral) {
       return datatype.equals(((OWLLiteral) obj).getDatatype())
           && getLiteral().equals(((OWLLiteral) obj).getLiteral());
     }
   }
   return false;
 }
 public Object visit(OWLDatatype node) {
   if (!allowedDatatypes.contains(node.getIRI())) {
     profileViolations.add(
         new UseOfIllegalDataRange(getCurrentOntology(), getCurrentAxiom(), node));
   }
   return null;
 }
 protected PropertyType getPropertyType(OWLOntology o, OWLDataProperty dataTypeProperty) {
   Set<OWLDataRange> ranges = dataTypeProperty.getRanges(o);
   if (ranges.size() == 0) {
     return null;
   }
   if (ranges.size() > 1) {
     throw new LumifyException(
         "Unexpected number of ranges on data property " + dataTypeProperty.getIRI().toString());
   }
   for (OWLDataRange range : ranges) {
     if (range instanceof OWLDatatype) {
       OWLDatatype datatype = (OWLDatatype) range;
       return getPropertyType(datatype.getIRI().toString());
     }
   }
   throw new LumifyException(
       "Could not find range on data property " + dataTypeProperty.getIRI().toString());
 }
 @Override
 protected int compareObjectOfSameType(OWLObject object) {
   OWLDatatypeRestriction other = (OWLDatatypeRestriction) object;
   int diff = datatype.compareTo(other.getDatatype());
   if (diff != 0) {
     return diff;
   }
   return compareSets(facetRestrictions, other.getFacetRestrictions());
 }
 @Override
 protected int compareObjectOfSameType(OWLObject object) {
   OWLLiteral other = (OWLLiteral) object;
   int diff = getLiteral().compareTo(other.getLiteral());
   if (diff != 0) {
     return diff;
   }
   return datatype.compareTo(other.getDatatype());
 }
Beispiel #8
0
 public boolean equals(Object obj) {
   if (super.equals(obj)) {
     if (!(obj instanceof OWLLiteral)) {
       return false;
     }
     OWLLiteral other = (OWLLiteral) obj;
     return literal.equals(other.getLiteral())
         && datatype.equals(other.getDatatype())
         && lang.equals(other.getLang());
   }
   return false;
 }
 @Override
 public OWLLiteral getOWLLiteral(String lexicalValue, OWLDatatype datatype) {
   OWLLiteral literal = super.getOWLLiteral(lexicalValue, datatype);
   // no caches for booleans, they are singleton in owldatafactory
   if (datatype.isBoolean()) {
     return literal;
   }
   if (literal instanceof OWLLiteralImplFloat) {
     return floatCache.cache(((OWLLiteralImplFloat) literal).parseFloat(), literal);
   }
   if (literal instanceof OWLLiteralImplDouble) {
     return doubleCache.cache(((OWLLiteralImplDouble) literal).parseDouble(), literal);
   }
   if (literal instanceof OWLLiteralImplInteger) {
     return intCache.cache(((OWLLiteralImplInteger) literal).parseInteger(), literal);
   }
   if (datatype.isString()) {
     return stringCache.cache(literal.getLiteral(), literal);
   }
   return litCache.cache(literal);
 }
 @Override
 public boolean equals(Object obj) {
   if (super.equals(obj)) {
     // superclass is responsible for null, identity, owlaxiom type and annotations
     if (!(obj instanceof OWLDatatypeDefinitionAxiom)) {
       return false;
     }
     OWLDatatypeDefinitionAxiom other = (OWLDatatypeDefinitionAxiom) obj;
     return datatype.equals(other.getDatatype()) && dataRange.equals(other.getDataRange());
   }
   return false;
 }
Beispiel #11
0
 public boolean isRDFPlainLiteral() {
   return datatype.equals(getOWLDataFactory().getRDFPlainLiteral());
 }
Beispiel #12
0
 public boolean isFloat() {
   return datatype.equals(getOWLDataFactory().getFloatOWLDatatype());
 }
Beispiel #13
0
 public boolean isDouble() {
   return datatype.equals(getOWLDataFactory().getDoubleOWLDatatype());
 }
 @Override
 protected void writeDatatypeComment(OWLDatatype datatype) {
   writeComment(datatype.getIRI().toString());
 }
 @Override
 public void visit(OWLDatatype datatype) {
   handleObject(datatype);
   datatype.getIRI().accept(this);
 }
 @Override
 public void visit(OWLDatatype node) {
   write("Datatype");
   write(node.getIRI());
 }
Beispiel #17
0
 public boolean isInteger() {
   return datatype.equals(getOWLDataFactory().getIntegerOWLDatatype());
 }
Beispiel #18
0
  private OWLOntology parseWithReasoner(OWLOntologyManager manager, OWLOntology ontology) {
    try {
      PelletOptions.load(new URL("http://" + cssLocation + "pellet.properties"));
      PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(ontology);
      reasoner.getKB().prepare();
      List<InferredAxiomGenerator<? extends OWLAxiom>> generators =
          new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
      generators.add(new InferredSubClassAxiomGenerator());
      generators.add(new InferredClassAssertionAxiomGenerator());
      generators.add(new InferredDisjointClassesAxiomGenerator());
      generators.add(new InferredEquivalentClassAxiomGenerator());
      generators.add(new InferredEquivalentDataPropertiesAxiomGenerator());
      generators.add(new InferredEquivalentObjectPropertyAxiomGenerator());
      generators.add(new InferredInverseObjectPropertiesAxiomGenerator());
      generators.add(new InferredPropertyAssertionGenerator());
      generators.add(new InferredSubDataPropertyAxiomGenerator());
      generators.add(new InferredSubObjectPropertyAxiomGenerator());

      InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, generators);

      OWLOntologyID id = ontology.getOntologyID();
      Set<OWLImportsDeclaration> declarations = ontology.getImportsDeclarations();
      Set<OWLAnnotation> annotations = ontology.getAnnotations();

      Map<OWLEntity, Set<OWLAnnotationAssertionAxiom>> entityAnnotations =
          new HashMap<OWLEntity, Set<OWLAnnotationAssertionAxiom>>();
      for (OWLClass aEntity : ontology.getClassesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLObjectProperty aEntity : ontology.getObjectPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLDataProperty aEntity : ontology.getDataPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLNamedIndividual aEntity : ontology.getIndividualsInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLAnnotationProperty aEntity : ontology.getAnnotationPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLDatatype aEntity : ontology.getDatatypesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }

      manager.removeOntology(ontology);
      OWLOntology inferred = manager.createOntology(id);
      iog.fillOntology(manager, inferred);

      for (OWLImportsDeclaration decl : declarations) {
        manager.applyChange(new AddImport(inferred, decl));
      }
      for (OWLAnnotation ann : annotations) {
        manager.applyChange(new AddOntologyAnnotation(inferred, ann));
      }
      for (OWLClass aEntity : inferred.getClassesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLObjectProperty aEntity : inferred.getObjectPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLDataProperty aEntity : inferred.getDataPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLNamedIndividual aEntity : inferred.getIndividualsInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLAnnotationProperty aEntity : inferred.getAnnotationPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLDatatype aEntity : inferred.getDatatypesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }

      return inferred;
    } catch (FileNotFoundException e1) {
      return ontology;
    } catch (MalformedURLException e1) {
      return ontology;
    } catch (IOException e1) {
      return ontology;
    } catch (OWLOntologyCreationException e) {
      return ontology;
    }
  }
Beispiel #19
0
 public boolean isBoolean() {
   return datatype.equals(getOWLDataFactory().getBooleanOWLDatatype());
 }
Beispiel #20
0
  // OWLAPI3TranslatorDLLiteA only
  @Deprecated
  public static Predicate.COL_TYPE getType(OWLDatatype owlDatatype) throws TranslationException {
    if (owlDatatype == null) return COL_TYPE.LITERAL;

    return getType(owlDatatype.getBuiltInDatatype());
  }