public double getDouble() { return getLiteral().getDouble(); }
protected Number toNumber(RDFNode o) { return o.asLiteral().getDouble(); }
public double getDouble() { return getLiteral().getDouble(); }
/** * Return the double value of a literal node. Depending on the backend implementing this method, * the value can be retrieved directly or must be parsed from the string representation. The method can throw * a NumberFormatException or ArithmeticException indicating that the value cannot be represented as double, and an * IllegalArgumentException, indicating that the passed node is not a literal * * @param rdfNode the literal node for which to return the double value * @return double value of the literal node * @throws NumberFormatException in case the literal cannot be represented as double value * @throws ArithmeticException in case the literal cannot be represented as double value * @throws IllegalArgumentException in case the node passed as argument is not a literal */ @Override public Double doubleValue(RDFNode rdfNode) { if(isLiteral(rdfNode)) { return ((Literal)rdfNode).getDouble(); } else { throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value"); } }
@Override public double getDouble() throws ReadDeniedException, AuthenticationRequiredException { checkRead(); return holder.getBaseItem().getDouble(); }
while(set.hasNext()){ QuerySolution qs = set.next(); double value = qs.get("value").asLiteral().getDouble(); csvFile.append(value); csvFile.append(",");
public Double getOrder() { Statement s = shape.getProperty(SH.order); if(s != null && s.getObject().isLiteral()) { return s.getLiteral().getDouble(); } else { return 0.0; } }
public Double getOrder() { Statement s = shape.getProperty(SH.order); if(s != null && s.getObject().isLiteral()) { return s.getLiteral().getDouble(); } else { return 0.0; } }
@Override public Map<OWLIndividual, SortedSet<Double>> getDoubleDatatypeMembersImpl(OWLDataProperty datatypeProperty) { Map<OWLIndividual, SortedSet<Double>> subject2objects = new HashMap<>(); String query = "SELECT ?s ?o WHERE {" + String.format("?s <%s> ?o.", datatypeProperty.toStringID()) + " FILTER(" + datatypeSparqlFilter(OWLAPIUtils.floatDatatypes) + ")}"; ResultSet rs = executeSelectQuery(query); while(rs.hasNext()){ QuerySolution qs = rs.next(); OWLIndividual sub = df.getOWLNamedIndividual(IRI.create(qs.getResource("s").getURI())); Literal val = qs.getLiteral("o").asLiteral(); // Virtuoso bug workaround which returns NAN instead of NaN Double obj = "NAN".equals(val.getLexicalForm()) ? Double.NaN : val.getDouble(); subject2objects.computeIfAbsent(sub, k -> new TreeSet<>()).add(obj); } return subject2objects; }
protected void testDouble( final Model model, final double tv ) { Assert.assertEquals(tv, model.createTypedLiteral(tv).getDouble(), AbstractModelTestBase.dDelta); }
protected void testDouble( final Model model, final double tv ) { Assert.assertEquals(tv, model.createTypedLiteral(tv).getDouble(), AbstractModelTestBase.dDelta); }
private Literal getMax(Set<Literal> literals){ Iterator<Literal> iter = literals.iterator(); Literal max = iter.next(); Literal l; while(iter.hasNext()){ l = iter.next(); if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ max = (l.getInt() > max.getInt()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ max = (l.getDouble() > max.getDouble()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDfloat){ max = (l.getFloat() > max.getFloat()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDdate){ max = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(max.getLexicalForm())) > 0) ? l : max; } } return max; }
private Literal getMin(Set<Literal> literals){ Iterator<Literal> iter = literals.iterator(); Literal min = iter.next(); Literal l; while(iter.hasNext()){ l = iter.next(); if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ min = (l.getInt() < min.getInt()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ min = (l.getDouble() < min.getDouble()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDfloat){ min = (l.getFloat() < min.getFloat()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDdate){ min = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(min.getLexicalForm())) < 0) ? l : min; } } return min; }
private Literal getMax(Set<Literal> literals){ Iterator<Literal> iter = literals.iterator(); Literal max = iter.next(); Literal l; while(iter.hasNext()){ l = iter.next(); if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ max = (l.getInt() > max.getInt()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ max = (l.getDouble() > max.getDouble()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDfloat){ max = (l.getFloat() > max.getFloat()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDdate){ max = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(max.getLexicalForm())) == 1) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDgYear){ max = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(max.getLexicalForm())) == 1) ? l : max; } } return max; }
private Literal getMin(Set<Literal> literals){ Iterator<Literal> iter = literals.iterator(); Literal min = iter.next(); Literal l; while(iter.hasNext()){ l = iter.next(); if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ min = (l.getInt() < min.getInt()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ min = (l.getDouble() < min.getDouble()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDfloat){ min = (l.getFloat() < min.getFloat()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDdate){ min = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(min.getLexicalForm())) == -1) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDgYear){ min = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(min.getLexicalForm())) == -1) ? l : min; } } return min; }
private boolean isLessOrEqual(Literal l1, Literal l2){ if((l1.getDatatype() == XSDDatatype.XSDinteger || l1.getDatatype() == XSDDatatype.XSDint) && (l2.getDatatype() == XSDDatatype.XSDinteger || l2.getDatatype() == XSDDatatype.XSDint)){ return (l1.getInt() <= l2.getInt()); } else if((l1.getDatatype() == XSDDatatype.XSDdouble || l1.getDatatype() == XSDDatatype.XSDdecimal) && (l2.getDatatype() == XSDDatatype.XSDdouble || l2.getDatatype() == XSDDatatype.XSDdecimal)){ return l1.getDouble() <= l2.getDouble(); } else if(l1.getDatatype() == XSDDatatype.XSDfloat && l2.getDatatype() == XSDDatatype.XSDfloat){ return l1.getFloat() <= l2.getFloat(); } else if(l1.getDatatype() == XSDDatatype.XSDdate && l2.getDatatype() == XSDDatatype.XSDdate){ Calendar date1 = DatatypeConverter.parseDate(l1.getLexicalForm()); Calendar date2 = DatatypeConverter.parseDate(l2.getLexicalForm()); int comp = date1.compareTo(date2); return comp <= 0; } return false; }
private static void test(Query query, double expected, DatasetGraph dsg) { try ( QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(dsg)) ) { Literal literal = qExec.execSelect().next().getLiteral("X") ; double result = literal.getDouble() ; assertEquals(expected, result, 0.001); } }
Double value = qualityMD.listObjectsOfProperty(res, DAQ.value).next().asLiteral().getDouble();
private boolean isGreaterOrEqual(Literal l1, Literal l2){ if((l1.getDatatype() == XSDDatatype.XSDinteger || l1.getDatatype() == XSDDatatype.XSDint) && (l2.getDatatype() == XSDDatatype.XSDinteger || l2.getDatatype() == XSDDatatype.XSDint)){ return (l1.getInt() >= l2.getInt()); } else if((l1.getDatatype() == XSDDatatype.XSDdouble || l1.getDatatype() == XSDDatatype.XSDdecimal) && (l2.getDatatype() == XSDDatatype.XSDdouble || l2.getDatatype() == XSDDatatype.XSDdecimal)){ return l1.getDouble() >= l2.getDouble(); } else if(l1.getDatatype() == XSDDatatype.XSDfloat && l2.getDatatype() == XSDDatatype.XSDfloat){ return l1.getFloat() >= l2.getFloat(); } else if(l1.getDatatype() == XSDDatatype.XSDdate && l2.getDatatype() == XSDDatatype.XSDdate){ Calendar date1 = DatatypeConverter.parseDate(l1.getLexicalForm()); Calendar date2 = DatatypeConverter.parseDate(l2.getLexicalForm()); int comp = date1.compareTo(date2); return comp >= 0; } return false; }
/** * Converts the specified hint message into a Match object. * @param wonMessage * @return a match object or null if the message is not a hint message. */ public static Match toMatch(final WonMessage wonMessage) { if (!WONMSG.TYPE_HINT.equals(wonMessage.getMessageType().getResource())){ return null; } Match match = new Match(); match.setFromNeed(wonMessage.getReceiverNeedURI()); Dataset messageContent = wonMessage.getMessageContent(); RDFNode score = findOnePropertyFromResource(messageContent, wonMessage.getMessageURI(), WON.HAS_MATCH_SCORE); if (!score.isLiteral()) return null; match.setScore(score.asLiteral().getDouble()); RDFNode counterpart = findOnePropertyFromResource(messageContent, wonMessage.getMessageURI(), WON.HAS_MATCH_COUNTERPART); if (!counterpart.isResource()) return null; match.setToNeed(URI.create(counterpart.asResource().getURI())); return match; }