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

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

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

Query.isAskType介绍

暂无

代码示例

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

  1. public WonSparqlValidator(Query constraint, String name) {
  2. if (!constraint.isAskType() && !constraint.isSelectType()) {
  3. throw new IllegalArgumentException("Wrong constraint type!");
  4. }
  5. this.constraint = constraint;
  6. this.name = name;
  7. }

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

  1. public WonSparqlValidator(Query constraint) {
  2. if (!constraint.isAskType() && !constraint.isSelectType()) {
  3. throw new IllegalArgumentException("Wrong constraint type!");
  4. }
  5. this.constraint = constraint;
  6. }

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

  1. @Override
  2. public void visitAskResultForm(Query query1)
  3. {
  4. check("Not both ASK queries", query2.isAskType()) ;
  5. }

代码示例来源:origin: vivo-project/Vitro

  1. private String interpretRequestedFormats(HttpServletRequest req,
  2. String queryString) throws NotAcceptableException {
  3. Query query = SparqlQueryUtils.create(queryString);
  4. String parameterName = (query.isSelectType() || query.isAskType()) ? "resultFormat"
  5. : "rdfResultFormat";
  6. String parameterValue = req.getParameter(parameterName);
  7. if (StringUtils.isBlank(parameterValue)) {
  8. throw new NotAcceptableException("Parameter '" + parameterName
  9. + "' was '" + parameterValue + "'.");
  10. } else {
  11. return parameterValue;
  12. }
  13. }

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

  1. public ValidationResult validate(Dataset input) {
  2. if (logger.isDebugEnabled()) {
  3. logger.debug("validating constraint of WonSparqlValidator '{}'", name);
  4. }
  5. if (constraint.isAskType()) {
  6. return validateAsk(input);
  7. } else if (constraint.isSelectType()) {
  8. return validateSelect(input);
  9. }
  10. return new ValidationResult(false, "Invalid constraint: " + constraint.toString());
  11. }

代码示例来源:origin: com.github.galigator.openllet/openllet-jena

  1. private static QueryType getQueryType(final Query query)
  2. {
  3. if (query.isSelectType())
  4. return QueryType.SELECT;
  5. if (query.isConstructType())
  6. return QueryType.CONSTRUCT;
  7. if (query.isDescribeType())
  8. return QueryType.DESCRIBE;
  9. if (query.isAskType())
  10. return QueryType.ASK;
  11. return null;
  12. }

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

  1. private static QueryType getQueryType(final Query query)
  2. {
  3. if (query.isSelectType())
  4. return QueryType.SELECT;
  5. if (query.isConstructType())
  6. return QueryType.CONSTRUCT;
  7. if (query.isDescribeType())
  8. return QueryType.DESCRIBE;
  9. if (query.isAskType())
  10. return QueryType.ASK;
  11. return null;
  12. }

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

  1. private static QueryType getQueryType(final Query query)
  2. {
  3. if (query.isSelectType())
  4. return QueryType.SELECT;
  5. if (query.isConstructType())
  6. return QueryType.CONSTRUCT;
  7. if (query.isDescribeType())
  8. return QueryType.DESCRIBE;
  9. if (query.isAskType())
  10. return QueryType.ASK;
  11. return null;
  12. }

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

  1. static private String labelForQuery(Query q) {
  2. if ( q.isSelectType() ) return "SELECT" ;
  3. if ( q.isConstructType() ) return "CONSTRUCT" ;
  4. if ( q.isDescribeType() ) return "DESCRIBE" ;
  5. if ( q.isAskType() ) return "ASK" ;
  6. if ( q.isJsonType() ) return "JSON" ;
  7. return "<<unknown>>" ;
  8. }

代码示例来源:origin: TopQuadrant/shacl

  1. /**
  2. * Constructs a new SHACLSPARQLARQFunction based on a given sh:ConstraintComponent
  3. * and a given validator (which must be a value of sh:nodeValidator, sh:propertyValidator etc.
  4. * @param component the constraint component (defining the sh:parameters)
  5. * @param askValidator the sh:SPARQLAskValidator resource
  6. */
  7. public SHACLSPARQLARQFunction(SHConstraintComponent component, Resource askValidator) {
  8. super(null);
  9. try {
  10. queryString = JenaUtil.getStringProperty(askValidator, SH.ask);
  11. arqQuery = ARQFactory.get().createQuery(SPARQLSubstitutions.withPrefixes(queryString, askValidator));
  12. }
  13. catch(Exception ex) {
  14. throw new IllegalArgumentException("Validator " + askValidator + " does not define a valid body", ex);
  15. }
  16. if(!arqQuery.isAskType()) {
  17. throw new ExprEvalException("Body must be ASK query");
  18. }
  19. paramNames.add("value");
  20. addParameters(component);
  21. paramNames.add("shapesGraph");
  22. }

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

  1. private void printQueryResults()
  2. {
  3. if (query.isSelectType())
  4. printSelectQueryResuts();
  5. else
  6. if (query.isConstructType())
  7. printConstructQueryResults();
  8. else
  9. if (query.isAskType())
  10. printAskQueryResult();
  11. }

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

  1. @Override
  2. public boolean execAsk() {
  3. checkNotClosed();
  4. if ( !query.isAskType() )
  5. throw new QueryExecException("Attempt to have boolean from a " + labelForQuery(query) + " query");
  6. startQueryIterator();
  7. boolean r;
  8. try {
  9. // Not has next because setting timeout1 which applies to getting
  10. // the first result, not testing for it.
  11. queryIterator.next();
  12. r = true;
  13. } catch (NoSuchElementException ex) { r = false; }
  14. this.close();
  15. return r;
  16. }

代码示例来源:origin: TopQuadrant/shacl

  1. /**
  2. * Constructs a new SHACLSPARQLARQFunction based on a given sh:Function.
  3. * The shaclFunction must be associated with the Model containing
  4. * the triples of its definition.
  5. * @param shaclFunction the SHACL function
  6. */
  7. public SHACLSPARQLARQFunction(SHSPARQLFunction shaclFunction) {
  8. super(shaclFunction);
  9. try {
  10. queryString = shaclFunction.getSPARQL();
  11. arqQuery = ARQFactory.get().createQuery(SPARQLSubstitutions.withPrefixes(queryString, shaclFunction));
  12. }
  13. catch(Exception ex) {
  14. throw new IllegalArgumentException("Function " + shaclFunction.getURI() + " does not define a valid body", ex);
  15. }
  16. if(!arqQuery.isAskType() && !arqQuery.isSelectType()) {
  17. throw new ExprEvalException("Body must be ASK or SELECT query");
  18. }
  19. addParameters(shaclFunction);
  20. }

代码示例来源:origin: ch.epfl.bluebrain.nexus.org.topbraid/shacl

  1. /**
  2. * Constructs a new SHACLSPARQLARQFunction based on a given sh:Function.
  3. * The shaclFunction must be associated with the Model containing
  4. * the triples of its definition.
  5. * @param shaclFunction the SHACL function
  6. */
  7. public SHACLSPARQLARQFunction(SHSPARQLFunction shaclFunction) {
  8. super(shaclFunction);
  9. try {
  10. queryString = shaclFunction.getSPARQL();
  11. arqQuery = ARQFactory.get().createQuery(SPARQLSubstitutions.withPrefixes(queryString, shaclFunction));
  12. }
  13. catch(Exception ex) {
  14. throw new IllegalArgumentException("Function " + shaclFunction.getURI() + " does not define a valid body", ex);
  15. }
  16. if(!arqQuery.isAskType() && !arqQuery.isSelectType()) {
  17. throw new ExprEvalException("Body must be ASK or SELECT query");
  18. }
  19. addParameters(shaclFunction);
  20. }

代码示例来源:origin: ch.epfl.bluebrain.nexus.org.topbraid/shacl

  1. @Override
  2. public NodeValue executeBody(Dataset dataset, Model defaultModel, QuerySolution bindings) {
  3. try( QueryExecution qexec = createQueryExecution(dataset, defaultModel, bindings) ) {
  4. if(arqQuery.isAskType()) {
  5. boolean result = qexec.execAsk();
  6. return NodeValue.makeBoolean(result);
  7. }
  8. else {
  9. ResultSet rs = qexec.execSelect();
  10. if(rs.hasNext()) {
  11. QuerySolution s = rs.nextSolution();
  12. List<String> resultVars = rs.getResultVars();
  13. String varName = resultVars.get(0);
  14. RDFNode resultNode = s.get(varName);
  15. if(resultNode != null) {
  16. return NodeValue.makeNode(resultNode.asNode());
  17. }
  18. }
  19. throw new ExprEvalException("Empty result set for SHACL function");
  20. }
  21. }
  22. }

代码示例来源:origin: TopQuadrant/shacl

  1. @Override
  2. public NodeValue executeBody(Dataset dataset, Model defaultModel, QuerySolution bindings) {
  3. try( QueryExecution qexec = createQueryExecution(dataset, defaultModel, bindings) ) {
  4. if(arqQuery.isAskType()) {
  5. boolean result = qexec.execAsk();
  6. return NodeValue.makeBoolean(result);
  7. }
  8. else {
  9. ResultSet rs = qexec.execSelect();
  10. if(rs.hasNext()) {
  11. QuerySolution s = rs.nextSolution();
  12. List<String> resultVars = rs.getResultVars();
  13. String varName = resultVars.get(0);
  14. RDFNode resultNode = s.get(varName);
  15. if(resultNode != null) {
  16. return NodeValue.makeNode(resultNode.asNode());
  17. }
  18. }
  19. throw new ExprEvalException("Empty result set for SHACL function");
  20. }
  21. }
  22. }

代码示例来源:origin: tarql/tarql

  1. private void processResults(TarqlQueryExecution ex) throws IOException {
  2. if (testQuery && ex.getFirstQuery().getConstructTemplate() != null) {
  3. IndentedWriter out = new IndentedWriter(System.out);
  4. new FmtTemplate(out, new SerializationContext(ex.getFirstQuery())).format(ex.getFirstQuery().getConstructTemplate());
  5. out.flush();
  6. }
  7. if (ex.getFirstQuery().isSelectType()) {
  8. System.out.println(ResultSetFormatter.asText(ex.execSelect()));
  9. } else if (ex.getFirstQuery().isAskType()) {
  10. System.out.println(ResultSetFormatter.asText(ex.execSelect()));
  11. } else if (ex.getFirstQuery().isConstructType()) {
  12. resultTripleIterator = resultTripleIterator.andThen(ex.execTriples());
  13. } else {
  14. cmdError("Only query forms CONSTRUCT, SELECT and ASK are supported");
  15. }
  16. }

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

  1. private QueryExecution createQueryExecution(Query query, String queryStringToSend) {
  2. QueryExecution qExec = new QueryEngineHTTP(svcQuery, queryStringToSend, httpClient, httpContext);
  3. QueryEngineHTTP qEngine = (QueryEngineHTTP)qExec;
  4. // Set the accept header - use the most specific method.
  5. if ( query != null ) {
  6. if ( query.isSelectType() && acceptSelectResult != null )
  7. qEngine.setAcceptHeader(acceptSelectResult);
  8. if ( query.isAskType() && acceptAskResult != null )
  9. qEngine.setAcceptHeader(acceptAskResult);
  10. if ( ( query.isConstructType() || query.isDescribeType() ) && acceptGraph != null )
  11. qEngine.setAcceptHeader(acceptGraph);
  12. if ( query.isConstructQuad() )
  13. qEngine.setDatasetContentType(acceptDataset);
  14. }
  15. // Use the general one.
  16. if ( qEngine.getAcceptHeader() == null && acceptSparqlResults != null )
  17. qEngine.setAcceptHeader(acceptSparqlResults);
  18. // Make sure it was set somehow.
  19. if ( qEngine.getAcceptHeader() == null )
  20. throw new JenaConnectionException("No Accept header");
  21. return qExec ;
  22. }

代码示例来源:origin: org.apache.jena/jena-rdfconnection

  1. private QueryExecution createQueryExecution(Query query, String queryStringToSend) {
  2. QueryExecution qExec = new QueryEngineHTTP(svcQuery, queryStringToSend, httpClient, httpContext);
  3. QueryEngineHTTP qEngine = (QueryEngineHTTP)qExec;
  4. // Set the accept header - use the most specific method.
  5. if ( query != null ) {
  6. if ( query.isSelectType() && acceptSelectResult != null )
  7. qEngine.setAcceptHeader(acceptSelectResult);
  8. if ( query.isAskType() && acceptAskResult != null )
  9. qEngine.setAcceptHeader(acceptAskResult);
  10. if ( ( query.isConstructType() || query.isDescribeType() ) && acceptGraph != null )
  11. qEngine.setAcceptHeader(acceptGraph);
  12. if ( query.isConstructQuad() )
  13. qEngine.setDatasetContentType(acceptDataset);
  14. }
  15. // Use the general one.
  16. if ( qEngine.getAcceptHeader() == null && acceptSparqlResults != null )
  17. qEngine.setAcceptHeader(acceptSparqlResults);
  18. // Make sure it was set somehow.
  19. if ( qEngine.getAcceptHeader() == null )
  20. throw new JenaConnectionException("No Accept header");
  21. return qExec ;
  22. }

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

  1. public static void executeQuery(Prologue prologue, QueryExecution queryExecution, ResultsFormat outputFormat) {
  2. Query query = queryExecution.getQuery() ;
  3. if ( prologue == null )
  4. prologue = query.getPrologue() ;
  5. if ( prologue == null )
  6. prologue = dftPrologue ;
  7. if ( query.isSelectType() )
  8. doSelectQuery(prologue, queryExecution, outputFormat) ;
  9. else if ( query.isDescribeType() )
  10. doDescribeQuery(prologue, queryExecution, outputFormat) ;
  11. else if ( query.isConstructQuad() )
  12. // Before isConstructType.
  13. doConstructQuadsQuery(prologue, queryExecution, outputFormat) ;
  14. else if ( query.isConstructType() )
  15. doConstructQuery(prologue, queryExecution, outputFormat) ;
  16. else if ( query.isAskType() )
  17. doAskQuery(prologue, queryExecution, outputFormat) ;
  18. else if ( query.isJsonType() )
  19. doJsonQuery(prologue, queryExecution, outputFormat) ;
  20. else
  21. throw new QueryException("Unrecognized query form");
  22. }

相关文章