protected HashSet<String> count(TupleQueryResult res, String given) throws QueryEvaluationException { HashSet<String> emails = new HashSet<String>(); String prefix = null; while(res.hasNext()){ BindingSet bs = res.next(); Value v = bs.getValue(given); prefix = v.stringValue(); if(prefix!=null) prefix.toLowerCase(); prefix = postprocess(prefix,emails); } res.close(); return emails; }
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { String normalized = args[0].stringValue(); URI datatype = ((Literal) args[0]).getDatatype(); return valueFactory.createLiteral(normalized.startsWith("-") ? normalized.substring(1) : normalized, datatype); }
public KiWiNode convert(Value value) { if(value == null) { return null; } if(value instanceof KiWiNode) { return (KiWiNode)value; } if(value instanceof URI) { return (KiWiUriResource)createURI(value.stringValue()); } if(value instanceof BNode) { return (KiWiAnonResource)createBNode(value.stringValue()); } if(value instanceof Literal) { Literal l = (Literal)value; return createLiteral(l.getLabel(),l.getLanguage(), l.getDatatype() != null ? l.getDatatype().stringValue(): null); } throw new IllegalArgumentException("the value passed as argument does not have the correct type"); }
public Set<String> getShardSurnames() throws RepositoryException, MalformedQueryException, QueryEvaluationException{ RepositoryConnection con = repository.getConnection(); String contribQuery = "" + " Select distinct s" + " from" + " {c} <"+RelConstants.RL_IS_PERSON+"> {p}" + " ," + " {c} <"+RelConstants.RL_SURNAME+"> {s}" + " where" + " p!=<http://yadda.icm.edu.pl/person#zbl#->" + ""; TupleQuery query = con.prepareTupleQuery(QueryLanguage.SERQL, contribQuery); TupleQueryResult res = query.evaluate(); HashSet<String> hs = new HashSet<String>(); while(res.hasNext()){ hs.add(res.next().getValue("s").stringValue()); } con.close(); con = null; return hs; }
@Override public String apply(Value input) { return input.stringValue(); } };
private static int calcObjectHash(Value value) { if(value instanceof Literal) { int i = value.stringValue().hashCode(); if(((Literal) value).getLanguage() != null) { i = i*31 + ((Literal) value).getLanguage().hashCode(); } else { i = i*31; } if(((Literal) value).getDatatype() != null) { i = i*31 + ((Literal) value).getDatatype().hashCode(); } else { i = i*31; } return i; } else { return value.hashCode(); } }
@Override public Date dateTimeValue(Value node) { try { XMLGregorianCalendar cal = ((Literal)node).calendarValue(); //TODO: check if we need to deal with timezone and Local here return cal.toGregorianCalendar().getTime(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
private boolean processRow( long row, BindingSet bindingSet, QualifiedIdentityResultCallback callback ) { final Value identifier = bindingSet.getValue( "identity" ); //TODO Shall we throw an exception if there is no binding for identifier = query parser is not right if( identifier == null ) { return true; } final String identity = identifier.stringValue(); final EntityReference entityReference = new EntityReference( identity ); return callback.processRow( row, entityReference ); }
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length < 1) { throw new ValueExprEvaluationException("Incorrect number of arguments"); } if (!(args[0] instanceof Literal)) { throw new ValueExprEvaluationException("First argument must be a string"); } Literal s = (Literal) args[0]; String tmpl = s.getLabel(); Map<String, String> mappings = new HashMap<String, String>(args.length); for (int i=1; i<args.length; i++) { mappings.put(Integer.toString(i), args[i].stringValue()); } String newValue = StrSubstitutor.replace(tmpl, mappings, "{?", "}"); return valueFactory.createLiteral(newValue); } }
@Override public Boolean booleanValue(Value node) { try { return ((Literal)node).booleanValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public String getMimeType(RepositoryConnection connection, URI uri) throws RepositoryException { final RepositoryResult<Statement> formats = connection.getStatements(uri, DCTERMS.format, null, false, ldpContext); try { if (formats.hasNext()) return formats.next().getObject().stringValue(); } finally { formats.close(); } return null; } @Override
@Override public Integer intValue(Value node) { try { return ((Literal)node).intValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public Double doubleValue(Value node) { try { return ((Literal)node).doubleValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public Float floatValue(Value node) { try { return ((Literal)node).floatValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public BigDecimal decimalValue(Value node) { try { return ((Literal)node).decimalValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public Long longValue(Value node) { try { return ((Literal)node).longValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
@Override public BigInteger integerValue(Value node) { try { return ((Literal)node).integerValue(); } catch (ClassCastException e) { throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" + "but of type "+debugType(node)); } }
private void setEnhancementData(Enhancement enhancement, BindingSet result) { if (result.hasBinding("confidence")) { enhancement.setConfidence(Double.parseDouble(result .getBinding("confidence").getValue().stringValue())); } else { enhancement.setConfidence(1.0); // Rupert says this should be the default value... } }
public int compareTo(Object o) { Projection other = (Projection)o; int result = size() - other.size(); if (result == 0) { // Projections have equal size for (int i = 0; i < size() && result == 0; i++) { Value thisValue = get(i); Value otherValue = other.get(i); result = thisValue.compareTo(otherValue); } } return result; }
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { String normalized = args[0].stringValue(); URI datatype = ((Literal)args[0]).getDatatype(); return valueFactory.createLiteral(normalized.startsWith("-") ? normalized.substring(1) : normalized, datatype); } @Override