org.apache.jena.query.Query.getResultVars()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(199)

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

Query.getResultVars介绍

[英]Return a list of the variables requested (SELECT)
[中]返回所请求变量的列表(选择)

代码示例

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

final List<String> vars = query.getResultVars();
if (!query.isQueryResultStar() && !query.hasGroupBy()) {
  final String[] all = new String[vars.size()];

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

@Override
public void visitDescribeResultForm(Query query)
{
  x ^= query.getResultVars().hashCode() ;
  x ^= query.getResultURIs().hashCode() ;
}

代码示例来源:origin: org.aksw.rdfunit/rdfunit-model

private Optional<ResultAnnotation> getFocusNodeAnnotation() {
  if (query.getResultVars().contains("focusNode")) {
    return Optional.of(
        createVariableAnnotation(SHACL.focusNode, "focusNode"));
  } else {
    return Optional.of(
        createVariableAnnotation(SHACL.focusNode, "this"));
  }
}

代码示例来源:origin: AKSW/RDFUnit

private Optional<ResultAnnotation> getFocusNodeAnnotation() {
  if (query.getResultVars().contains("focusNode")) {
    return Optional.of(
        createVariableAnnotation(SHACL.focusNode, "focusNode"));
  } else {
    return Optional.of(
        createVariableAnnotation(SHACL.focusNode, "this"));
  }
}

代码示例来源:origin: org.aksw.rdfunit/rdfunit-model

private Optional<ResultAnnotation> getMessageAnnotation() {
  if (query.getResultVars().contains("message")) {
    return Optional.of(
        createVariableAnnotation(SHACL.resultMessage, "message"));
  } else {
    return ImmutableList.of(shape.getMessage(),validator.getDefaultMessage()).stream()
        .filter(Optional::isPresent)
        .map(Optional::get)
        .findFirst()
        .map(message -> createValueAnnotation(SHACL.resultMessage, message));
  }
}

代码示例来源:origin: AKSW/RDFUnit

private Optional<ResultAnnotation> getMessageAnnotation() {
  if (query.getResultVars().contains("message")) {
    return Optional.of(
        createVariableAnnotation(SHACL.resultMessage, "message"));
  } else {
    return ImmutableList.of(shape.getMessage(),validator.getDefaultMessage()).stream()
        .filter(Optional::isPresent)
        .map(Optional::get)
        .findFirst()
        .map(message -> createValueAnnotation(SHACL.resultMessage, message));
  }
}

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

/**
 * Execute a query, expecting the result to be one row, one column. Return
 * that one RDFNode
 */
public static RDFNode getExactlyOne(String qs, Dataset ds) {
  Query q = QueryFactory.create(qs) ;
  if ( q.getResultVars().size() != 1 )
    throw new ARQException("getExactlyOne: Must have exactly one result columns") ;
  String varname = q.getResultVars().get(0) ;
  try ( QueryExecution qExec = QueryExecutionFactory.create(q, ds) ) {
    return getExactlyOne(qExec, varname) ;
  }
}

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

@Bean
  @StepScope
  @Autowired
  public LineAggregator<Binding> lineAggregator(Query query) {
    List<String> varNames = query.getResultVars();
    LineAggregator<Binding> result = new LineAggregatorBindingToXml(varNames);

    return result;
//        return new LineAggregator<Binding>() {
//            @Override
//            public String aggregate(Binding item) {
//                return item.toString();
//            }
//        };
  }

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

public static Node extractDescribeNode(Query query) {
  if (!query.isDescribeType()) {
    throw new RuntimeException("DESCRIBE query expected. Got: ["
        + query.toString() + "]");
  }
  // TODO Right now we only support describe with a single constant.
  //Element queryPattern = query.getQueryPattern();
  if(query.getQueryPattern() != null || !query.getResultVars().isEmpty() || query.getResultURIs().size() > 1) {
    throw new RuntimeException("Sorry, DESCRIBE is only implemented for a single resource argument");
  }
  Node result = query.getResultURIs().get(0);
  return result;
}

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

@Override
public void visitDescribeResultForm(Query query1)
{
  check("Not both DESCRIBE queries", query2.isDescribeType()) ;
  check("Result variables", 
     query1.getResultVars(), query2.getResultVars() ) ;
  check("Result URIs", 
     query1.getResultURIs(), query2.getResultURIs() ) ;
  
}

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

private ResultSet asResultSet(QueryIterator qIter) {
  Model model = null ;
  if ( dataset != null )
    model = dataset.getDefaultModel() ;
  else
    model = ModelFactory.createDefaultModel() ;
  
  ResultSetStream rStream = new ResultSetStream(query.getResultVars(), model, qIter) ;
  return rStream ;
}

代码示例来源:origin: org.aksw.rdfunit/rdfunit-model

private Optional<ResultAnnotation> getPathAnnotation() {
  if (query.getResultVars().contains("path")) {
    List<Var> vars = query.getProjectVars();
    VarExprList vel = query.getProject();
    return Optional.of(
      createVariableAnnotation(SHACL.resultPath, "path"));
  } else {
    if (shape.getPath().isPresent()) {
      return Optional.of(
        createValueAnnotation(SHACL.resultPath, shape.getPath().get().getPathAsRdf()));
    }
  }
  return Optional.empty();
}

代码示例来源:origin: AKSW/RDFUnit

private Optional<ResultAnnotation> getPathAnnotation() {
  if (query.getResultVars().contains("path")) {
    List<Var> vars = query.getProjectVars();
    VarExprList vel = query.getProject();
    return Optional.of(
      createVariableAnnotation(SHACL.resultPath, "path"));
  } else {
    if (shape.getPath().isPresent()) {
      return Optional.of(
        createValueAnnotation(SHACL.resultPath, shape.getPath().get().getPathAsRdf()));
    }
  }
  return Optional.empty();
}

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

@Override
public void visitDescribeResultForm(Query query)
{
  out.print("DESCRIBE ") ;
  
  if ( query.isQueryResultStar() )
    out.print("*") ;
  else
  {
    appendVarList(query, out, query.getResultVars()) ;
    if ( query.getResultVars().size() > 0 &&
       query.getResultURIs().size() > 0 )
      out.print(" ") ;
    appendURIList(query, out, query.getResultURIs()) ;
  }
  out.newline() ;
}

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

@Test
public void testDoubleCount() {
  Query[] result = test_roundTripQuery("select (count(?s) as ?sc) (count(?p) as ?pc) { ?s ?p ?o }") ;
  assertEquals(2, result[1].getResultVars().size());
  assertTrue(result[1].getResultVars().contains("sc"));
  assertTrue(result[1].getResultVars().contains("pc"));
}

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

@Test
public void testProject2() {
  Query[] result = test_roundTripQuery("SELECT (?x + 1 AS ?c) ?d {}");
  assertEquals(2, result[1].getResultVars().size());
  assertTrue(result[1].getResultVars().contains("c"));
  assertTrue(result[1].getResultVars().contains("d"));
}

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

/** Find the variables needed out of this query.
 * If we don't do sorting in-DB, then we need the ORDER BY variables as well. 
 * @param query
 */
public static List<Var> queryOutVars(Query query)
{
  // If part query, need all variables. 
  
  // Project variables
  List<Var> vars = toList(map(query.getResultVars().iterator(), Var::alloc)) ;
  
  // Add the ORDER BY variables
  List<SortCondition> orderConditions = query.getOrderBy() ;
  if ( orderConditions != null )
  {
    for ( SortCondition sc : orderConditions )
    {
      Set<Var> x = sc.getExpression().getVarsMentioned() ;
      for ( Var v :  x )
      {
        if ( ! vars.contains(v) )
          vars.add(v) ;
      }
    }
  }
  return vars ;
}

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

/**
 *
 *
 * @param pattern
 *            a pattern of a where-clause
 * @param resultVar
 *            an optional result variable (used for describe queries)
 * @return
 */
public static Query elementToQuery(Element pattern, String resultVar) {
  if (pattern == null)
    return null;
  Query query = new Query();
  query.setQueryPattern(pattern);
  query.setQuerySelectType();
  if (resultVar == null) {
    query.setQueryResultStar(true);
  }
  query.setResultVars();
  if (resultVar != null) {
    query.getResultVars().add(resultVar);
  }
  return query;
}

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

@Override
public Iterator<JsonObject> execJsonItems() 
{
  checkNotClosed() ;
  if ( ! query.isJsonType() )
    throw new QueryExecException("Attempt to get a JSON result from a " + labelForQuery(query)+" query") ;
  startQueryIterator() ;
  return new JsonIterator(queryIterator, query.getResultVars()) ;
}

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

@Override
public JsonArray execJson()
{
  checkNotClosed() ;
  if ( ! query.isJsonType() )
    throw new QueryExecException("Attempt to get a JSON result from a " + labelForQuery(query)+" query") ;
  startQueryIterator() ;
  JsonArray jsonArray = new JsonArray() ;
  List<String> resultVars = query.getResultVars() ;
  while (queryIterator.hasNext())
  {
    Binding binding = queryIterator.next() ;
    JsonObject jsonObject = new JsonObject() ; 
    for (String resultVar : resultVars) {
      Node n = binding.get(Var.alloc(resultVar)) ;
      JsonValue value = RDFTerm2Json.fromNode(n) ;
      jsonObject.put(resultVar, value) ;
    }
    jsonArray.add(jsonObject) ;
  }
  return jsonArray ;
}

相关文章