当前位置: 首页>>代码示例>>Java>>正文


Java QueryResultIO类代码示例

本文整理汇总了Java中org.openrdf.query.resultio.QueryResultIO的典型用法代码示例。如果您正苦于以下问题:Java QueryResultIO类的具体用法?Java QueryResultIO怎么用?Java QueryResultIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


QueryResultIO类属于org.openrdf.query.resultio包,在下文中一共展示了QueryResultIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newSparqlTupleWriter

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
public static TupleQueryResultWriter newSparqlTupleWriter(final TupleQueryResultFormat format,
        final OutputStream stream) {

    final TupleQueryResultWriter writer = QueryResultIO.createWriter(format, stream);

    final WriterConfig config = writer.getWriterConfig();
    if (format.equals(TupleQueryResultFormat.JSON)) {
        config.set(BasicWriterSettings.PRETTY_PRINT, true);
        config.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, true);
        config.set(BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL, true);

    } else if (format.equals(TupleQueryResultFormat.SPARQL)) {
        config.set(BasicWriterSettings.PRETTY_PRINT, true);
        config.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, true);
        config.set(BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL, true);
        config.set(BasicQueryWriterSettings.ADD_SESAME_QNAME, false);
    }

    return writer;
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:21,代码来源:RDFUtil.java

示例2: newSparqlBooleanWriter

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
public static BooleanQueryResultWriter newSparqlBooleanWriter(
        final BooleanQueryResultFormat format, final OutputStream stream) {

    final BooleanQueryResultWriter writer = QueryResultIO.createWriter(format, stream);

    final WriterConfig config = writer.getWriterConfig();
    if (format.equals(BooleanQueryResultFormat.JSON)) {
        config.set(BasicWriterSettings.PRETTY_PRINT, true);
        config.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, true);
        config.set(BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL, true);

    } else if (format.equals(TupleQueryResultFormat.SPARQL)) {
        config.set(BasicWriterSettings.PRETTY_PRINT, true);
        config.set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, true);
        config.set(BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL, true);
        config.set(BasicQueryWriterSettings.ADD_SESAME_QNAME, false);
    }

    return writer;
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:21,代码来源:RDFUtil.java

示例3: testQuery

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
public static void testQuery(String queryFile, String resultsFile, boolean orderOn)
    throws IOException, MalformedQueryException, QueryEvaluationException,
    TupleQueryResultHandlerException, URISyntaxException, QueryResultParseException,
    UnsupportedQueryResultFormatException {
  ByteArrayOutputStream resultsStream = new ByteArrayOutputStream();
  String query =
      FileUtils.readFileToString(new File(Utils.class.getResource(prefixesFile).toURI())) + "\n"
          + FileUtils.readFileToString(new File(Utils.class.getResource(queryFile).toURI()));

  // Pose the query
  strabon.query(query, Format.XML, strabon.getSailRepoConnection(), resultsStream);

  // Check if the results of the query are the expected
  compareResults(queryFile, orderOn, QueryResultIO.parse(
      Utils.class.getResourceAsStream(resultsFile), TupleQueryResultFormat.SPARQL),
      QueryResultIO.parse((new ByteArrayInputStream(resultsStream.toByteArray())),
          TupleQueryResultFormat.SPARQL));
}
 
开发者ID:esarbanis,项目名称:strabon,代码行数:19,代码来源:Utils.java

示例4: validateCount

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
private static void validateCount(MockHttpServletResponse response, int count) throws Exception {

        String rstString = response.getContentAsString();
        TupleQueryResult result = QueryResultIO.parse(new ByteArrayInputStream(rstString.getBytes()), TupleQueryResultFormat.SPARQL);
        
        assertEquals(1, result.getBindingNames().size());
        String binding = result.getBindingNames().get(0);
        
        assertTrue(result.hasNext());
        BindingSet bs = result.next();
        assertEquals(Integer.toString(count), bs.getBinding(binding).getValue().stringValue());
    }
 
开发者ID:apache,项目名称:incubator-rya,代码行数:13,代码来源:RdfControllerAccumuloTest.java

示例5: newSparqlBooleanReader

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
public static BooleanQueryResultParser newSparqlBooleanReader(
        final BooleanQueryResultFormat format) {

    final BooleanQueryResultParser parser = QueryResultIO.createParser(format);
    parser.setValueFactory(Data.getValueFactory());

    return parser;
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:9,代码来源:RDFUtil.java

示例6: executeUpdate

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
/**
 * Executes a given update command both on remote and local model.
 * 
 * @param data the object holding test data (i.e. commands, queries, datafiles).
 * @throws Exception hopefully never otherwise the corresponding test fails.
 */
@SuppressWarnings("deprecation")
void executeUpdate(final MisteryGuest data) throws Exception {
	load(data);
	
	final String updateCommand = readFile(data.query);
	final Update localUpdate = localConnection.prepareUpdate(QueryLanguage.SPARQL, updateCommand);
	final Update cumulusUpdate = cumulusConnection.prepareUpdate(QueryLanguage.SPARQL, updateCommand);
	
	localUpdate.execute();
	cumulusUpdate.execute();
	
	try {
		assertTrue(ModelUtil.equals(
				statements(localConnection.getStatements(null, null, null, false).asList()), 
				statements(cumulusConnection.getStatements(null, null, null, false).asList())));
		
	} catch (final AssertionError exception) {
		final String queryString = "CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
		final GraphQuery localQuery = localConnection.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
		final GraphQuery cumulusQuery = cumulusConnection.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
		
		final GraphQueryResult debugLocalResult = localQuery.evaluate();
		final GraphQueryResult debugCumulusResult = cumulusQuery.evaluate();
			
		System.err.println("***** LOCAL ******");
		QueryResultIO.write(debugLocalResult, RDFFormat.NTRIPLES, System.err);

		System.err.println("***** CRDF ******");
		QueryResultIO.write(debugCumulusResult, RDFFormat.NTRIPLES, System.err);
		
		debugCumulusResult.close();
		debugLocalResult.close();
		throw exception;
	}
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:42,代码来源:LearningSparql_UPDATE_ITCase.java

示例7: constructTest

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
/**
 * Executes a given CONSTRUCT query against a given dataset.
 * 
 * @param data the mistery guest containing test data (query and dataset)
 * @throws Exception never, otherwise the test fails.
 */
protected void constructTest(final MisteryGuest data) throws Exception {
	load(data);
	
	final String queryString = queryString(data.query);
	final GraphQuery localQuery = localConnection.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
	final GraphQuery cumulusQuery = cumulusConnection.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
	
	GraphQueryResult localResult = localQuery.evaluate();
	GraphQueryResult cumulusResult = cumulusQuery.evaluate();
	try {
		assertTrue(
				ModelUtil.equals(
						statements(Iterations.asSet(localResult)), 
						statements(Iterations.asSet(cumulusResult))));			
	} catch (final AssertionError exception) {
		final GraphQueryResult debugLocalResult = localQuery.evaluate();
		final GraphQueryResult debugCumulusResult = cumulusQuery.evaluate();
			
		System.err.println("***** LOCAL ******");
		QueryResultIO.write(debugLocalResult, RDFFormat.NTRIPLES, System.err);

		System.err.println("***** CRDF ******");
		QueryResultIO.write(debugCumulusResult, RDFFormat.NTRIPLES, System.err);
		
		debugCumulusResult.close();
		debugLocalResult.close();
		throw exception;
	}
	
	cumulusResult.close();
	localResult.close();
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:39,代码来源:IntegrationTestSupertypeLayer.java

示例8: selectTest

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
/**
 * Executes a given SELECT query against a given dataset.
 * 
 * @param data the mistery guest containing test data (query and dataset)
 * @throws Exception never, otherwise the test fails.
 */
protected void selectTest(final MisteryGuest data) throws Exception {
	load(data);
	
	final String queryString = queryString(data.query);
	final TupleQuery localQuery = localConnection.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	final TupleQuery cumulusQuery = cumulusConnection.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	
	final TupleQueryResult localResult = localQuery.evaluate();
	final TupleQueryResult cumulusResult = cumulusQuery.evaluate();
	
	try {
		assertTrue(QueryResults.equals(localResult, cumulusResult));
	} catch (final AssertionError exception) {
		final TupleQueryResult debugLocalResult = localQuery.evaluate();
		final TupleQueryResult debugCumulusResult = cumulusQuery.evaluate();
			
		System.err.println("***** LOCAL ******");
		QueryResultIO.write(debugLocalResult, TupleQueryResultFormat.JSON, System.err);

		System.err.println("***** CRDF ******");
		QueryResultIO.write(debugCumulusResult, TupleQueryResultFormat.JSON, System.err);
		
		debugCumulusResult.close();
		debugLocalResult.close();
		throw exception;
	}
	cumulusResult.close();
	localResult.close();
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:36,代码来源:IntegrationTestSupertypeLayer.java

示例9: internalValidAskQueries

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
/**
 * ASK queries with several supported formats.
 * 
 * @param query the ASK queries.
 * @param acceptAsParameter accept as request parameter.
 * @param acceptAsHeader accept as request header.
 * @throws Exception never, otherwise test fails.
 */
private void internalValidAskQueries(
		final String query,
		final String acceptAsParameter,
		final String acceptAsHeader) throws Exception {

	final String accept = acceptAsParameter != null ? acceptAsParameter : acceptAsHeader;
	final File tmp = tmpFile();
	final ServletOutputStream servletOutputStream = new StubServletOutputStream(tmp);

	final HttpServletRequest request = createMockHttpRequest(query, acceptAsParameter, acceptAsHeader, null);
	final HttpServletResponse response = mock(HttpServletResponse.class);
	when(response.getOutputStream()).thenReturn(servletOutputStream);

	_classUnderTest.service(request, response);
	servletOutputStream.close();

	FileInputStream inputStream = null;
	try {
		inputStream = new FileInputStream(tmp);
		assertTrue(
				"query: " + query + ", accept: " + accept,
				QueryResultIO.parse(inputStream, BooleanQueryResultFormat.forMIMEType(accept)));
	} finally {
		// CHECKSTYLE:OFF
		// @formatter:off
		if (inputStream != null) { try { inputStream.close();} catch (final Exception ignore) {}};
		// @formatter:on
		// CHECKSTYLE:ON					
	}
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:39,代码来源:SPARQLServletTest.java

示例10: validSelectQueriesWithAcceptParam

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
/**
 * SELECT queries with several supported formats.
 * 
 * @throws Exception never, otherwise test fails.
 */
@Test
public void validSelectQueriesWithAcceptParam() throws Exception {

	for (final String query : _sparql_select) {

		for (final String accept : _accept_select_header) {

			final File tmp = tmpFile();
			final ServletOutputStream servletOutputStream = new StubServletOutputStream(tmp);

			final HttpServletRequest request = mock(HttpServletRequest.class);
			when(request.getParameter(Parameters.QUERY)).thenReturn(query);
			when(request.getParameter(Parameters.ACCEPT)).thenReturn(accept);
			when(request.getMethod()).thenReturn(Methods.POST);

			final HttpServletResponse response = mock(HttpServletResponse.class);
			when(response.getOutputStream()).thenReturn(servletOutputStream);

			_classUnderTest.service(request, response);
			servletOutputStream.close();

			final TupleQueryResult res = QueryResultIO.parse(new FileInputStream(tmp), TupleQueryResultFormat.forMIMEType(accept));
			assertTrue("query: " + query + ", accept: " + accept, _queries2count.get(query) > 0 ? res.hasNext() : !res.hasNext());
		}
	}
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:32,代码来源:SPARQLServletTest.java

示例11: testGraphQuery

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
/**
 * test get Graph Query.
 * @throws Exception The test would fails if Exception occurs
 */
@Test
public void testGraphQuery() throws Exception {
	//insert some statments first
	for (final String tripleAsString : _data) {
		final Statement triple = parseNX(tripleAsString).iterator().next();
		TRIPLE_STORE.addData(triple);
	}
	//test Graph Query
	String queryString = "SELECT ?x ?y WHERE { ?x ?p ?y } ";
	String uri = BASE_URI + Protocol.REPOSITORIES + "/" + REPO_ID;
	File tmp = WebTestUtils.tmpFile();
	final ServletOutputStream servletOutputStream = new StubServletOutputStream(tmp);
	final HttpServletRequest request = mockHttpRequest(uri, METHOD_POST);
	when(request.getContentType()).thenReturn(MIMETYPE_WWW_FORM);
	when(request.getParameter(Protocol.QUERY_LANGUAGE_PARAM_NAME)).thenReturn(QueryLanguage.SPARQL.toString());
	when(request.getParameter(Protocol.QUERY_PARAM_NAME)).thenReturn(queryString);
	when(request.getParameter(Protocol.ACCEPT_PARAM_NAME)).thenReturn("application/x-binary-rdf-results-table");
	Vector<String> vec = new Vector<String>();
	when(request.getParameterNames()).thenReturn(vec.elements());
	when(request.getCharacterEncoding()).thenReturn(UTF_8);
	final HttpServletResponse response = mock(HttpServletResponse.class);
	when(response.getOutputStream()).thenReturn(servletOutputStream);


	_classUnderTest.service(request, response);
	
	Set<TupleQueryResultFormat> tqrFormats = TupleQueryResultParserRegistry.getInstance().getKeys();
	TupleQueryResultFormat format = TupleQueryResultFormat.matchMIMEType("application/x-binary-rdf-results-table", tqrFormats);
	TupleQueryResultParser parser = QueryResultIO.createParser(format, valueFactory);
	FileInputStream in = new FileInputStream(tmp);
	BackgroundTupleResult tRes = new BackgroundTupleResult(parser, in, null);
	parser.setQueryResultHandler(tRes);
	parser.parseQueryResult(in);
	assertTrue(tRes.hasNext());
	verify(response).setStatus(HttpServletResponse.SC_OK);

	servletOutputStream.close();
}
 
开发者ID:cumulusrdf,项目名称:cumulusrdf,代码行数:43,代码来源:SesameHTTPRepositoryTest.java

示例12: createstSPARQLQueryResultWriter

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
public static TupleQueryResultWriter createstSPARQLQueryResultWriter(Format format,
    OutputStream out) {
  TupleQueryResultWriter writer = null;

  switch (format) {
    case DEFAULT:
      writer = tsv.getWriter(out);
      break;

    case XML:
      writer = xml.getWriter(out);
      break;

    case KML:
      writer = kml.getWriter(out);
      break;

    case KMZ:
      writer = kmz.getWriter(out);
      break;

    case GEOJSON:
      writer = geojson.getWriter(out);
      break;

    case EXP:
      // TODO: add
      break;

    case HTML:
      writer = html.getWriter(out);
      break;

    case TSV:
      writer = tsv.getWriter(out);
      break;

    case SESAME_XML:
      writer = QueryResultIO.createWriter(TupleQueryResultFormat.SPARQL, out);
      break;

    case SESAME_BINARY:
      writer = QueryResultIO.createWriter(TupleQueryResultFormat.BINARY, out);
      break;

    case SESAME_JSON:
      writer = QueryResultIO.createWriter(TupleQueryResultFormat.JSON, out);
      break;

    case SESAME_CSV:
      writer = QueryResultIO.createWriter(TupleQueryResultFormat.CSV, out);
      break;

    case SESAME_TSV:
      writer = QueryResultIO.createWriter(TupleQueryResultFormat.TSV, out);
      break;

    default:
      // return NULL
  }

  return writer;
}
 
开发者ID:esarbanis,项目名称:strabon,代码行数:64,代码来源:stSPARQLQueryResultToFormatAdapter.java

示例13: parse

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
private void parse(InputStream in, TupleQueryResultFormat format, QueryResultHandler handler, ValueFactory valueFactory) throws IOException, QueryResultParseException, QueryResultHandlerException, UnsupportedQueryResultFormatException {
    QueryResultParser parser = QueryResultIO.createParser(format);
    parser.setValueFactory(valueFactory);
    parser.setQueryResultHandler(handler);
    parser.parseQueryResult(in);
}
 
开发者ID:redlink-gmbh,项目名称:redlink-java-sdk,代码行数:7,代码来源:RedLinkDataImpl.java

示例14: testStardogRepositoryManager

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
/**
 * Test method for
 * {@link com.github.ansell.stardog.StardogRepositoryManager#StardogRepositoryManager(com.complexible.stardog.api.admin.AdminConnectionConfiguration, com.complexible.stardog.api.ConnectionConfiguration, java.net.URL)}
 * .
 */
@Test
public void testStardogRepositoryManager() throws Exception
{
    // Specify the server URL
    // String aServerUrl = "http://localhost:5820";
    
    // first create a temporary database to use (if there is one already, drop it first)
    // AdminConnection aAdminConnection =
    // AdminConnectionConfiguration.toEmbeddedServer().credentials("admin", "admin").connect();
    AdminConnection aAdminConnection =
            AdminConnectionConfiguration.toServer(aServerUrl).credentials("admin", "testAdminPassword").connect();
    if(aAdminConnection.list().contains("testSesame"))
    {
        aAdminConnection.drop("testSesame");
    }
    aAdminConnection.createMemory("testSesame");
    aAdminConnection.close();
    
    // Create a Sesame Repository from a Stardog ConnectionConfiguration. The configuration will
    // be used
    // when creating new RepositoryConnections
    Repository aRepo =
            new StardogRepository(ConnectionConfiguration.to("testSesame").server(aServerUrl)
                    .credentials("admin", "testAdminPassword"));
    
    // init the repo
    aRepo.initialize();
    
    // now you can use it like a normal Sesame Repository
    RepositoryConnection aRepoConn = aRepo.getConnection();
    
    // always best to turn off auto commit
    aRepoConn.setAutoCommit(false);
    
    // add some data
    // aRepoConn.add(new FileInputStream("data/sp2b_10k.n3"), "http://sesame.stardog.com/",
    // RDFFormat.N3);
    
    // commit the data to stardog
    aRepoConn.commit();
    
    // we can send queries...
    // we currently only support SPARQL
    TupleQuery aQuery =
            aRepoConn
                    .prepareTupleQuery(QueryLanguage.SPARQL,
                            "select * where { ?s ?p ?o. filter(?s = <http://localhost/publications/articles/Journal1/1940/Article1>).}");
    
    // run the query
    TupleQueryResult aResults = aQuery.evaluate();
    
    // print the results in tabular format
    QueryResultIO.write(aResults, TextTableQueryResultWriter.FORMAT, System.out);
    
    // always close your query results!
    aResults.close();
    
    // always close your connections!
    aRepoConn.close();
    
    // make sure you shut down the repository as well as closing the repository connection as
    // this is what releases the internal Stardog connection
    aRepo.shutDown();
}
 
开发者ID:ansell,项目名称:sesame-stardog-manager,代码行数:70,代码来源:StardogRepositoryManagerTest.java

示例15: handleBoolean

import org.openrdf.query.resultio.QueryResultIO; //导入依赖的package包/类
@Override
public void handleBoolean(boolean value) throws QueryResultHandlerException
{
    try
    {
        // Create a SPARQL/XML representation that will be transformed to HTML using a stylesheet
        ByteArrayOutputStream xmlOut = new ByteArrayOutputStream();
        QueryResultIO.writeBoolean(value, BooleanQueryResultFormat.SPARQL, xmlOut);
        byte[] queryResult = xmlOut.toByteArray();
        
        // get server uri
        String server_uri = CDIContext.getInstance(ConfigurationService.class).getServerUri();
        
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
        
        Source input = new StreamSource(new ByteArrayInputStream(queryResult));
        
        Source s_stylesheet = new StreamSource(SPARQLBooleanHTMLWriter.class.getResourceAsStream("style.xsl"));
        Templates stylesheet = TransformerFactory.newInstance().newTemplates(s_stylesheet);
        Transformer transformer = stylesheet.newTransformer();
        transformer.setParameter("serverurl", server_uri);
        
        JDOMResult result = new JDOMResult();
        transformer.transform(input, result);
        Document output = result.getDocument();
        
        XMLOutputter printer = new XMLOutputter(Format.getPrettyFormat());
        printer.output(output, writer);
        writer.flush();
    }
    catch(TransformerConfigurationException e)
    {
        log.error("could not compile stylesheet for rendering SPARQL results; result display not available!");
        throw new QueryResultHandlerException("could not compile stylesheet for rendering SPARQL results; result display not available!", e);
    }
    catch(Exception ex)
    {
        throw new QueryResultHandlerException("error while transforming XML results to HTML", ex);
    }
    finally
    {
        // writer.close();
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:45,代码来源:SPARQLBooleanHTMLWriter.java


注:本文中的org.openrdf.query.resultio.QueryResultIO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。