Tabnine Logo
SPARQLParser.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
org.openrdf.query.parser.sparql.SPARQLParser
constructor

Best Java code snippets using org.openrdf.query.parser.sparql.SPARQLParser.<init> (Showing top 19 results out of 315)

origin: net.fortytwo.sesametools/linked-data-server

private static ParsedQuery parseQuery(final String query) throws MalformedQueryException {
  SPARQLParser parser = new SPARQLParser();
  return parser.parseQuery(query, BASE_URI);
}
origin: anno4j/anno4j

public SparqlQuery(Reader in, String base) throws IOException,
    MalformedQueryException {
  try {
    StringWriter sw = new StringWriter();
    int read;
    char[] cbuf = new char[1024];
    while ((read = in.read(cbuf)) >= 0) {
      sw.write(cbuf, 0, read);
    }
    sparql = sw.toString();
    this.base = base;
    try {
      query = new SPARQLParser().parseQuery(sparql, base);
    } catch (MalformedQueryException e) {
      try {
        query = new SPARQLParser().parseUpdate(sparql, base);
      } catch (MalformedQueryException u) {
        throw e;
      }
    }
  } catch (MalformedQueryException e) {
    logger.warn(base + " " + e.getMessage(), e);
  }
}
origin: org.apache.rya/rya.pcj.fluo.api

private static String getPrettyPrintSparql(String sparql, int indent) throws Exception {
  SPARQLParser parser = new SPARQLParser();
  ParsedQuery pq = parser.parseQuery(sparql, null);
  SPARQLQueryRenderer render = new SPARQLQueryRenderer();
  String renderedQuery = render.render(pq);
  
  //remove extra quotes generated by query renderer
  String[] splitRender = renderedQuery.split("\"\"\"");
  StringBuilder builder = new StringBuilder();
  for(String s: splitRender) {
    builder.append(s).append("\"");
  }
  builder.replace(builder.length() - 1, builder.length(), "");
  
  //add indent to all lines following newline char
  String[] newLineRender = builder.toString().split("\n");
  builder = new StringBuilder();
  String prefix = getVariableIndent(indent);
  for(int i = 0; i < newLineRender.length; i++) {
    if(i != 0) {
      builder.append(prefix);
    }
    builder.append(newLineRender[i]).append("\n");
  }
  
  return builder.toString();
}
origin: org.apache.rya/rya.pcj.fluo.client

  private String[] prettyFormatSparql(final String sparql) throws Exception {
    final SPARQLParser parser = new SPARQLParser();
    final SPARQLQueryRenderer renderer = new SPARQLQueryRenderer();
    final ParsedQuery pq = parser.parseQuery(sparql, null);
    final String prettySparql = renderer.render(pq);
    final String[] sparqlLines = StringUtils.split(prettySparql, '\n');
    return sparqlLines;
  }
}
origin: org.openrdf.alibaba/alibaba-repository-object

public SPARQLQuery(Reader in, String base) throws IOException,
    MalformedQueryException {
  try {
    StringWriter sw = new StringWriter();
    int read;
    char[] cbuf = new char[1024];
    while ((read = in.read(cbuf)) >= 0) {
      sw.write(cbuf, 0, read);
    }
    sparql = sw.toString();
    this.base = base;
    try {
      query = new SPARQLParser().parseQuery(sparql, base);
    } catch (MalformedQueryException e) {
      try {
        query = new SPARQLParser().parseUpdate(sparql, base);
      } catch (MalformedQueryException u) {
        throw e;
      }
    }
  } catch (MalformedQueryException e) {
    throw new MalformedQueryException(base + " " + e.getMessage(), e);
  } finally {
    in.close();
  }
}
origin: org.apache.rya/rya.test.rdf

/**
 * Fetch the {@link StatementPattern} from a SPARQL string.
 *
 * @param sparql - A SPARQL query that contains only a single Statement Patern. (not nul)
 * @return The {@link StatementPattern} that was in the query, if it could be found. Otherwise {@code null}
 * @throws Exception The statement pattern could not be found in the parsed SPARQL query.
 */
public static @Nullable StatementPattern getSp(final String sparql) throws Exception {
  requireNonNull(sparql);
  final AtomicReference<StatementPattern> statementPattern = new AtomicReference<>();
  final ParsedQuery parsed = new SPARQLParser().parseQuery(sparql, null);
  parsed.getTupleExpr().visitChildren(new QueryModelVisitorBase<Exception>() {
    @Override
    public void meet(final StatementPattern node) throws Exception {
      statementPattern.set(node);
    }
  });
  return statementPattern.get();
}
origin: org.apache.rya/rya.test.rdf

/**
 * Get the first {@link MultiProjection} node from a SPARQL query.
 *
 * @param sparql - The query that contains a single Projection node.
 * @return The first {@link MultiProjection} that is encountered.
 * @throws Exception The query could not be parsed.
 */
public static @Nullable MultiProjection getMultiProjection(final String sparql) throws Exception {
  requireNonNull(sparql);
  final AtomicReference<MultiProjection> multiProjection = new AtomicReference<>();
  final ParsedQuery parsed = new SPARQLParser().parseQuery(sparql, null);
  parsed.getTupleExpr().visit(new QueryModelVisitorBase<Exception>() {
    @Override
    public void meet(final MultiProjection node) throws Exception {
      multiProjection.set(node);
    }
  });
  return multiProjection.get();
}
origin: org.apache.rya/rya.test.rdf

/**
 * Get the first {@link Projection} node from a SPARQL query.
 *
 * @param sparql - The query that contains a single Projection node.
 * @return The first {@link Projection} that is encountered.
 * @throws Exception The query could not be parsed.
 */
public static @Nullable Projection getProjection(final String sparql) throws Exception {
  requireNonNull(sparql);
  final AtomicReference<Projection> projection = new AtomicReference<>();
  final ParsedQuery parsed = new SPARQLParser().parseQuery(sparql, null);
  parsed.getTupleExpr().visit(new QueryModelVisitorBase<Exception>() {
    @Override
    public void meet(final Projection node) throws Exception {
      projection.set(node);
    }
  });
  return projection.get();
}
origin: org.apache.rya/rya.indexing

/**
 * Creates a new {@link MongoPcjQueryNode}.
 *
 * @param sparql - sparql query whose results will be stored in PCJ document. (not empty of null)
 * @param pcjId - name of an existing PCJ. (not empty or null)
 * @param pcjDocs - {@link MongoPcjDocuments} used to maintain PCJs in mongo. (not null)
 *
 * @throws MalformedQueryException - The SPARQL query needs to contain a projection.
 */
public MongoPcjQueryNode(final String sparql, final String pcjId, final MongoPcjDocuments pcjDocs) throws MalformedQueryException {
  checkArgument(!Strings.isNullOrEmpty(sparql));
  checkArgument(!Strings.isNullOrEmpty(pcjId));
  this.pcjDocs = checkNotNull(pcjDocs);
  this.pcjId = pcjId;
  final SPARQLParser sp = new SPARQLParser();
  final ParsedTupleQuery pq = (ParsedTupleQuery) sp.parseQuery(sparql, null);
  final TupleExpr te = pq.getTupleExpr();
  Preconditions.checkArgument(PCJOptimizerUtilities.isPCJValid(te), "TupleExpr is an invalid PCJ.");
  final Optional<Projection> projection = new ParsedQueryUtil().findProjection(pq);
  if (!projection.isPresent()) {
    throw new MalformedQueryException("SPARQL query '" + sparql + "' does not contain a Projection.");
  }
  setProjectionExpr(projection.get());
}
origin: org.apache.rya/rya.test.rdf

  /**
   * Get the first {@link Filter} node from a SPARQL query.
   *
   * @param sparql - The query that contains a single Projection node.
   * @return The first {@link Filter} that is encountered.
   * @throws Exception The query could not be parsed.
   */
  public static @Nullable Filter getFilter(final String sparql) throws Exception {
    requireNonNull(sparql);

    final AtomicReference<Filter> filter = new AtomicReference<>();
    final ParsedQuery parsed = new SPARQLParser().parseQuery(sparql, null);
    parsed.getTupleExpr().visit(new QueryModelVisitorBase<Exception>() {
      @Override
      public void meet(final Filter node) throws Exception {
        filter.set(node);
      }
    });

    return filter.get();
  }
}
origin: org.apache.rya/rya.pcj.fluo.app

public static Optional<PeriodicQueryNode> getPeriodicNode(String sparql) throws MalformedQueryException {
  TupleExpr te = new SPARQLParser().parseQuery(sparql, null).getTupleExpr();
  PeriodicQueryNodeVisitor periodicVisitor = new PeriodicQueryNodeVisitor();
  te.visit(periodicVisitor);
  return periodicVisitor.getPeriodicNode();
}
origin: com.tinkerpop.blueprints/blueprints-sail-graph

try {
  sparqlQuery = getPrefixes() + sparqlQuery;
  final SPARQLParser parser = new SPARQLParser();
  final ParsedQuery query = parser.parseQuery(sparqlQuery, null);
  boolean includeInferred = false;
origin: org.apache.rya/rya.indexing

public CloseableIteration<BindingSet, QueryEvaluationException> queryDocIndex(final String sparqlQuery,
    final Collection<BindingSet> constraints) throws TableNotFoundException, QueryEvaluationException {
  final SPARQLParser parser = new SPARQLParser();
  ParsedQuery pq1 = null;
  try {
    pq1 = parser.parseQuery(sparqlQuery, null);
  } catch (final MalformedQueryException e) {
    e.printStackTrace();
    throw new QueryEvaluationException("Malformed query. query=" + sparqlQuery, e);
  }
  final TupleExpr te1 = pq1.getTupleExpr();
  final List<StatementPattern> spList1 = StatementPatternCollector.process(te1);
  if(StarQuery.isValidStarQuery(spList1)) {
    final StarQuery sq1 = new StarQuery(spList1);
    return queryDocIndex(sq1, constraints);
  } else {
    throw new IllegalArgumentException("Invalid star query!");
  }
}
origin: org.apache.rya/rya.indexing

this.accCon = ConfigUtils.getConnector(conf);
this.auths = getAuthorizations(conf);
final SPARQLParser sp = new SPARQLParser();
final ParsedTupleQuery pq = (ParsedTupleQuery) sp.parseQuery(sparql, null);
final TupleExpr te = pq.getTupleExpr();
origin: org.apache.rya/rya.indexing

final SPARQLParser parser = new SPARQLParser();
final ParsedQuery parsedQuery = parser.parseQuery(sparql, null);
origin: org.apache.rya/rya.pcj.fluo.client

final SPARQLParser parser = new SPARQLParser();
final SPARQLQueryRenderer renderer = new SPARQLQueryRenderer();
final ParsedQuery pq = parser.parseQuery(metadata.getSparql(), null);
origin: org.apache.rya/rya.indexing

this.auths = getAuthorizations(conf);
PcjMetadata meta = pcj.getPcjMetadata(accCon, tablename);
final SPARQLParser sp = new SPARQLParser();
final ParsedTupleQuery pq = (ParsedTupleQuery) sp.parseQuery(meta.getSparql(), null);
origin: joshsh/ripple

@Override
public CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate(final String query)
    throws RippleException {
  ensureOpen();
  SPARQLParser parser = new SPARQLParser();
  boolean useInference = false;
  // FIXME
  String baseIRI = "http://example.org/bogusBaseIRI/";
  ParsedQuery pq;
  try {
    pq = parser.parseQuery(query, baseIRI);
  } catch (MalformedQueryException e) {
    throw new RippleException(e);
  }
  MapBindingSet bindings = new MapBindingSet();
  try {
    return sailConnection.evaluate(pq.getTupleExpr(), pq.getDataset(), bindings, useInference);
  } catch (SailException e) {
    throw new RippleException(e);
  }
}
origin: org.apache.rya/rya.pcj.fluo.app

final SPARQLParser parser = new SPARQLParser();
ParsedQuery pq;
try {
org.openrdf.query.parser.sparqlSPARQLParser<init>

Popular methods of SPARQLParser

  • parseQuery
  • parseUpdate
  • buildQueryModel

Popular in Java

  • Finding current android device location
  • runOnUiThread (Activity)
  • findViewById (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JTextField (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now