/** * Gets the label of the supplied literal. The fallback value is returned in case the supplied literal is * <tt>null</tt>. * * @param l * The literal to get the label for. * @param fallback * The value to fall back to in case the supplied literal is <tt>null</tt>. * @return Either the literal's label, or the fallback value. */ public static String getLabel(Literal l, String fallback) { return l != null ? l.getLabel() : fallback; }
/** * Gets the label of the supplied literal. The fallback value is returned in case the supplied literal is * <tt>null</tt>. * * @param l * The literal to get the label for. * @param fallback * The value to fall back to in case the supplied literal is <tt>null</tt>. * @return Either the literal's label, or the fallback value. */ public static String getLabel(Literal l, String fallback) { return l != null ? l.getLabel() : fallback; }
public static String getLiteralPropertyValueAsString(Statement statement) { Value object = statement.getObject(); if (object instanceof Literal) { return ((Literal)object).getLabel(); } else { return null; } }
public static Optional<Boolean> getBooleanValue(Model theGraph, Resource theSubj, IRI thePred) { Optional<Literal> aLitOpt = getLiteral(theGraph, theSubj, thePred); if (!aLitOpt.isPresent()) { return Optional.empty(); } else { Literal aLiteral = (Literal)aLitOpt.get(); return (aLiteral.getDatatype() == null || !aLiteral.getDatatype().equals(XMLSchema.BOOLEAN)) && !aLiteral.getLabel().equalsIgnoreCase("true") && !aLiteral.getLabel().equalsIgnoreCase("false") ? Optional.empty() : Optional.of(Boolean.valueOf(aLiteral.getLabel())); } }
protected static void addBindings(Query query, Value... args) throws ValueExprEvaluationException { for (int i = 1; i < args.length; i += 2) { if (!(args[i] instanceof Literal)) { throw new ValueExprEvaluationException("Argument " + i + " must be a literal"); } query.setBinding(((Literal)args[i]).getLabel(), args[i + 1]); } } }
public void parse(Model model, Resource resource) throws RepositoryConfigException { Models.objectLiteral(model.filter(resource, REPOSITORYTYPE, null)).ifPresent( typeLit -> setType(typeLit.getLabel())); }
@Override public void parse(Model model, Resource resource) throws RepositoryConfigException { Models.objectLiteral(model.filter(resource, REPOSITORYTYPE, null)).ifPresent( typeLit -> setType(typeLit.getLabel())); }
public static Set<String> getRepositoryIDs(Model model) throws RepositoryException { Set<String> idSet = new LinkedHashSet<String>(); model.filter(null, REPOSITORYID, null).forEach(idStatement -> { if (idStatement.getObject() instanceof Literal) { Literal idLiteral = (Literal)idStatement.getObject(); idSet.add(idLiteral.getLabel()); } }); return idSet; }
public static Set<String> getRepositoryIDs(Model model) throws RepositoryException { Set<String> idSet = new LinkedHashSet<>(); model.filter(null, REPOSITORYID, null).forEach(idStatement -> { if (idStatement.getObject() instanceof Literal) { Literal idLiteral = (Literal)idStatement.getObject(); idSet.add(idLiteral.getLabel()); } }); return idSet; }
private long convertPeriodToMillis(Literal literal, IRI unit) { String stringVal = literal.getLabel(); IRI dataType = literal.getDatatype(); checkArgument(dataType.equals(XMLSchema.INTEGER) || dataType.equals(XMLSchema.INT), String .format("Invalid data type for period duration. Data Type must be of type %s or %s .", XMLSchema.INTEGER, XMLSchema.INT)); checkArgument(XMLDatatypeUtil.isValidInteger(stringVal) || XMLDatatypeUtil.isValidInt(stringVal), "Invalid duration value."); return convertToMillis(Integer.parseInt(stringVal), unit); }
private byte[] literal2data(Literal literal, boolean create) throws IOException { return literal2data(literal.getLabel(), literal.getLanguage(), literal.getDatatype(), create); }
private Instant convertToInstant(Literal literal) { String stringVal = literal.getLabel(); IRI dataType = literal.getDatatype(); checkArgument(dataType.equals(XMLSchema.DATETIME) || dataType.equals(XMLSchema.DATE), String.format("Invalid data type for date time. Data Type must be of type %s or %s .", XMLSchema.DATETIME, XMLSchema.DATE)); checkArgument(XMLDatatypeUtil.isValidDateTime(stringVal) || XMLDatatypeUtil.isValidDate(stringVal), "Invalid date time value."); return literal.calendarValue().toGregorianCalendar().toInstant(); }
private Binding getBinding(Resource bindingNode) throws GraphUtilException { Literal name = GraphUtil.getUniqueObjectLiteral(graph, bindingNode, VARIABLE); Value value = GraphUtil.getUniqueObject(graph, bindingNode, VALUE); return new SimpleBinding(name.getLabel(), value); } }
private Binding getBinding(Resource bindingNode) throws GraphUtilException { Literal name = GraphUtil.getUniqueObjectLiteral(graph, bindingNode, VARIABLE); Value value = GraphUtil.getUniqueObject(graph, bindingNode, VALUE); return new SimpleBinding(name.getLabel(), value); } }
private Binding getBinding(Resource bindingNode) throws GraphUtilException { Literal name = GraphUtil.getUniqueObjectLiteral(graph, bindingNode, VARIABLE); Value value = GraphUtil.getUniqueObject(graph, bindingNode, VALUE); return new SimpleBinding(name.getLabel(), value); } }
private byte[] literal2data(Literal literal, boolean create) throws IOException { return literal2data(literal.getLabel(), literal.getLanguage(), literal.getDatatype(), create); }
private byte[] literal2legacy(Literal literal) throws IOException { IRI dt = literal.getDatatype(); if (XMLSchema.STRING.equals(dt) || RDF.LANGSTRING.equals(dt)) return literal2data(literal.getLabel(), literal.getLanguage(), null, false); return literal2data(literal.getLabel(), literal.getLanguage(), dt, false); }
private byte[] literal2legacy(Literal literal) throws IOException { IRI dt = literal.getDatatype(); if (XMLSchema.STRING.equals(dt) || RDF.LANGSTRING.equals(dt)) return literal2data(literal.getLabel(), literal.getLanguage(), null, false); return literal2data(literal.getLabel(), literal.getLanguage(), dt, false); }
private static double parseTemporalDuration(ValueConstant valConst) { Value val = valConst.getValue(); Preconditions.checkArgument(val instanceof Literal); Literal literal = (Literal) val; String stringVal = literal.getLabel(); IRI dataType = literal.getDatatype(); Preconditions.checkArgument(dataType.equals(XMLSchema.DECIMAL) || dataType.equals(XMLSchema.DOUBLE) || dataType.equals(XMLSchema.FLOAT) || dataType.equals(XMLSchema.INTEGER) || dataType.equals(XMLSchema.INT)); return Double.parseDouble(stringVal); }
@Test public void testConvertLiteral_normalString() { final String expectedData = "Hello"; final RyaType ryaType = new RyaType(XMLSchema.STRING, expectedData); final Literal literal = RyaToRdfConversions.convertLiteral(ryaType); assertEquals(XMLSchema.STRING, literal.getDatatype()); assertEquals(expectedData, literal.getLabel()); assertFalse(literal.getLanguage().isPresent()); final Literal expectedLiteral = VF.createLiteral(expectedData); assertEquals(expectedLiteral, literal); } }