Example #1
0
 @Override
 public IExtendedIterator<IStatement> match(
     IReference subject,
     IReference predicate,
     IValue object,
     boolean includeInferred,
     IReference... contexts) {
   String query;
   if (contexts.length > 0 && !includeInferred) {
     query = "SELECT DISTINCT ?s ?p ?o ?g WHERE { GRAPH ?g { ?s ?p ?o } }";
   } else {
     query = "SELECT DISTINCT ?s ?p ?o WHERE { ?s ?p ?o }";
   }
   IDataManagerQuery<?> dmQuery = createQuery(query, null, includeInferred, contexts);
   setParameters(dmQuery, subject, predicate, object);
   return dmQuery
       .evaluate()
       .mapWith(
           new IMap<Object, IStatement>() {
             @Override
             public IStatement map(Object value) {
               IBindings<?> bindings = (IBindings<?>) value;
               return new Statement(
                   (IReference) bindings.get("s"),
                   (IReference) bindings.get("p"),
                   bindings.get("o"),
                   (IReference) bindings.get("g"));
             }
           });
 }
Example #2
0
 protected void setParameters(
     IDataManagerQuery<?> query, IReference subject, IReference predicate, IValue object) {
   if (subject != null) {
     query.setParameter("s", subject);
   }
   if (predicate != null) {
     query.setParameter("p", predicate);
   }
   if (object != null) {
     query.setParameter("o", object);
   }
 }
Example #3
0
 @Override
 public boolean hasMatch(
     IReference subject,
     IReference predicate,
     IValue object,
     boolean includeInferred,
     IReference... contexts) {
   String query;
   if (contexts.length > 0 && !includeInferred) {
     query = "ASK { GRAPH ?g { ?s ?p ?o } }";
   } else {
     query = "ASK { ?s ?p ?o }";
   }
   IDataManagerQuery<?> dmQuery = createQuery(query, null, includeInferred, contexts);
   setParameters(dmQuery, subject, predicate, object);
   Object result = dmQuery.evaluate().next();
   return Boolean.TRUE.equals(result);
 }