org.apache.jena.sparql.engine.binding.Binding类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中org.apache.jena.sparql.engine.binding.Binding类的一些代码示例,展示了Binding类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binding类的具体详情如下:
包路径:org.apache.jena.sparql.engine.binding.Binding
类名称:Binding

Binding介绍

[英]Interface encapsulating a mapping from a name to a value.
[中]封装从名称到值的映射的接口。

代码示例

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static List<Node> resultSetToList(ResultSet rs, Var v) {
  List<Node> result = new ArrayList<Node>();
  while (rs.hasNext()) {
    Binding binding = rs.nextBinding();
    Node node = binding.get(v);
    result.add(node);
  }
  return result;
}

代码示例来源:origin: apache/jena

public static boolean compatible(Binding bindingLeft, Binding bindingRight)
{
  // Test to see if compatible: Iterate over variables in left
  for ( Iterator<Var> vIter = bindingLeft.vars() ; vIter.hasNext() ; )
  {
    Var v = vIter.next();
    Node nLeft  = bindingLeft.get(v) ; 
    Node nRight = bindingRight.get(v) ;
    
    if ( nRight != null && ! nRight.equals(nLeft) )
      return false ;
  }
  return true ;
}

代码示例来源:origin: apache/jena

@Override
public Binding accept(Binding binding) {
  if ( binding.contains(var) ) {
    if ( mustBeNewVar )
      throw new QueryExecException("Already set: " + var);
    Node n2 = binding.get(var) ;
    if ( ! n2.equals(node) )
      // And filter out.
      return null ;
    else
      // Already in the binding with the value -> nothing to do. 
      return binding ;
  }
  return BindingFactory.binding(binding, var, node) ;
}

代码示例来源:origin: apache/jena

public static boolean disjoint(Binding binding1, Binding binding2)
  {
    Iterator<Var> iterVar1 = binding1.vars() ;
    for ( ; iterVar1.hasNext() ; )
    {
      Var v = iterVar1.next() ; 
      if ( binding2.contains(v) )
        return false ;
    }
    return true ;
  }
}

代码示例来源:origin: apache/jena

public static boolean equals(Binding bind1, Binding bind2) {
    if ( bind1 == bind2 )
      return true;

    // Same variables?

    if ( bind1.size() != bind2.size() )
      return false;

    for ( Iterator<Var> iter1 = bind1.vars() ; iter1.hasNext() ; ) {
      Var var = iter1.next();
      Node node1 = bind1.get(var);
      Node node2 = bind2.get(var);
      if ( !Objects.equals(node1, node2) )
        return false;
    }

    // No need to check the other way round as the sizes matched.
    return true;
  }
}

代码示例来源:origin: apache/jena

public static Iterator<Node> storeGraphNames(Store store)
{
  List<Node> x = new ArrayList<Node>() ;
  String qs = "SELECT ?g { GRAPH ?g { }}" ;
  QueryExecution qExec = QueryExecutionFactory.create(qs, SDBFactory.connectDataset(store)) ;
  ResultSet rs = qExec.execSelect() ;
  Var var_g = Var.alloc("g") ;
  while(rs.hasNext())
  {
    Node n = rs.nextBinding().get(var_g) ;
    x.add(n) ;
  }
  return x.iterator() ;
}

代码示例来源:origin: org.aksw.jena-sparql-api/jena-sparql-api-sparql-ext

org.apache.jena.sparql.engine.ExecutionContext execCtx) {
Node node = subject.isVariable()
    ? binding.get((Var)subject)
    : subject;
if(!object.isVariable()) {
  throw new RuntimeException("Object of json array splitting must be a variable");
  if(node.isURI()) {
    String str = node.getURI();
    Path root = Paths.get(new URI(str));

代码示例来源:origin: at.researchstudio.sat/won-core

if (!result.hasNext()) {
  if (constraint.getProjectVars().stream().noneMatch(var -> "check".equals(var.getVarName()))) {
while (result.hasNext()) {
  Binding binding = result.nextBinding();
  Node node = binding.get(SELECT_VALIDATION_VARIABLE);
  if (node != null) {
    if (node.isLiteral()) {
      String resultString = node.getLiteralValue().toString();
      if (SELECT_VALIDATION_PASSED_VALUE.equals(resultString)) {
        return new ValidationResult();

代码示例来源:origin: apache/jena

private void testErr(String qsAgg, DatasetGraph ds, Syntax syntax) {
  Query query = buildGroupBy(qsAgg, syntax) ;
  try ( QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(ds)) ) {
    ResultSet rs = qExec.execSelect() ;
    assertTrue(rs.getResultVars().contains("X")) ;
    Binding b = rs.nextBinding() ;
    assertFalse(b.contains(Var.alloc("X"))) ;
  }
}

代码示例来源:origin: apache/jena

@Test public void path_38()
{ 
  // Same end points.
  List<Binding> x = eval(graph6, "?x", "(pathN+ :p)", "?x" ) ;
  
  assertEquals(2, x.size()) ;
  Node node1 = x.get(0).get(Var.alloc("x")) ;
  Node node2 = x.get(1).get(Var.alloc("x")) ;
  assertFalse(node1.equals(node2)) ;
  assertTrue(node1.equals(n1) || node1.equals(n2)) ;
  assertTrue(node2.equals(n1) || node2.equals(n2)) ;
}

代码示例来源:origin: apache/jena

@Override
protected RDFNode _get(String varName)
{
  Node n = binding.get(Var.alloc(varName)) ;
  if ( n == null )
    return null;
  return ModelUtils.convertGraphNodeToRDFNode(n, model) ;
}

代码示例来源:origin: apache/jena

private static Node substitute(Node node, Binding binding)
{
  if ( Var.isVar(node) )
  {
    Node x = binding.get(Var.alloc(node)) ;
    if ( x != null )
      return x ;
  }
  return node ;
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

@Override
public void accumulate(Binding binding) {
  Set<Triple> triples = new HashSet<Triple>();
  Map<Node, Node> bNodeMap = new HashMap<Node, Node>();
  template.subst(triples, bNodeMap, binding);
  //Node TRUE = NodeValue.TRUE.asNode();
  Node node = reverse.isVariable()
      ? binding.get((Var)reverse)
      : reverse
      ;
  boolean doReverse = node.isLiteral()
      ? isTrue(node.getLiteralValue())
      : false
      ;
  for(Triple triple : triples) {
    if(doReverse) {
      triple = TripleUtils.swap(triple);
    }
    graph.add(triple);
  }
}

代码示例来源:origin: apache/jena

private ResultSetRewindable convertToStrings(ResultSetRewindable resultsActual)
{
  List<Binding> bindings = new ArrayList<>()  ;
  while(resultsActual.hasNext())
  {
    Binding b = resultsActual.nextBinding() ;
    BindingMap b2 = BindingFactory.create() ;
    
    for ( String vn : resultsActual.getResultVars() )
    {
      Var v = Var.alloc(vn) ;
      Node n = b.get(v) ;
      String s ;
      if ( n == null )
        s = "" ;
      else if ( n.isBlank() )
        s = "_:"+n.getBlankNodeLabel() ;
      else
        s = NodeFunctions.str(n) ;
      b2.add(v, NodeFactory.createLiteral(s)) ;
    }
    bindings.add(b2) ;
  }
  ResultSet rs = new ResultSetStream(resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator())) ;
  return ResultSetFactory.makeRewindable(rs) ;
}

代码示例来源:origin: apache/jena

/** Bound value or null */
private static Node resolve(Binding b, Node n) {
  if ( ! n.isVariable() ) return n ;
  return b.get(Var.alloc(n)) ;
}

代码示例来源:origin: SmartDataAnalytics/Sparqlify

Set<Var> exprVars = expr.getVarsMentioned();
for(Var var : exprVars) {
  if(!binding.contains(var)) {
    allBound = false;
    break;
  if(canonResultValue.isLiteral()) {
    String lex = canonResultValue.getLiteralLexicalForm();
    if(resultValue.isLiteral()) {
      RDFDatatype originalType = resultValue.getLiteralDatatype();

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

if (node.isVariable()) {
  node = binding.get((Var) node);
if (node == null || (i < 3 && node.isLiteral())) {
  result.clear();
  return result;

代码示例来源:origin: SmartDataAnalytics/Sparqlify

public static Pair<List<String>, List<String>> getValues(Binding binding)
{
  List<String> keys = new ArrayList<String>();
  List<String> values = new ArrayList<String>();
  Iterator<Var> it = binding.vars();
  while(it.hasNext()) {
    Var key = it.next();
    keys.add(key.getName());
    values.add(binding.get(key).toString());
  }
  return Pair.create(keys, values);
}

代码示例来源:origin: Galigator/openllet

while (aResults.hasNext())
  final Binding aBinding = aResults.nextBinding();
  final Iterator<?> aVarIter = aBinding.vars();
    aBinding.get(aVar);
while (aResults.hasNext())
  final Binding aBinding = aResults.nextBinding();
  assertFalse(aBinding.vars().hasNext());

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static Map<Var, Node> toMap(Binding binding) {
  Map<Var, Node> result = new HashMap<Var, Node>();
  Iterator<Var> it = binding.vars();
  while(it.hasNext()) {
    Var v = it.next();
    Node n = binding.get(v);
    result.put(v, n);
  }
  return result;
}

相关文章