當前位置: 首頁>>代碼示例>>Java>>正文


Java TupleQuery.setBinding方法代碼示例

本文整理匯總了Java中org.openrdf.query.TupleQuery.setBinding方法的典型用法代碼示例。如果您正苦於以下問題:Java TupleQuery.setBinding方法的具體用法?Java TupleQuery.setBinding怎麽用?Java TupleQuery.setBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openrdf.query.TupleQuery的用法示例。


在下文中一共展示了TupleQuery.setBinding方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testEvaluateMultiLine

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testEvaluateMultiLine() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    URI uri1 = vf.createURI(litdupsNS, "uri1");
    URI pred2 = vf.createURI(litdupsNS, "pred2");
    URI uri2 = vf.createURI(litdupsNS, "uri2");
    conn.add(cpu, loadPerc, uri1);
    conn.add(cpu, pred2, uri2);
    conn.commit();

    String query = "select * where {" +
            "?x <" + loadPerc.stringValue() + "> ?o1." +
            "?x <" + pred2.stringValue() + "> ?o2." +
            "}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERYPLAN_FLAG, RdfCloudTripleStoreConstants.VALUE_FACTORY.createLiteral(true));
    CountTupleHandler cth = new CountTupleHandler();
    tupleQuery.evaluate(cth);
    conn.close();
    assertEquals(cth.getCount(), 1);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:22,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例2: createBlockQuery

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
private TupleQuery createBlockQuery(int b) throws RepositoryException {
	StringBuilder sb = new StringBuilder();
	sb.append("SELECT ?pred ?value ?value_class\n");
	sb.append("WHERE { $self ?pred ?value\n");
	sb.append("OPTIONAL { ?value a ?value_class }\n");
	sb.append("FILTER (");
	for (int i = b * BSIZE, n = b * BSIZE + BSIZE; i < n; i++) {
		sb.append("?pred = <");
		sb.append(RDF.NAMESPACE);
		sb.append("_");
		sb.append((i + 1));
		sb.append(">");
		if (i + 1 < n) {
			sb.append(" || ");
		}
	}
	sb.append(")}\n");
	ObjectConnection con = getObjectConnection();
	try {
		TupleQuery query = con.prepareTupleQuery(SPARQL, sb.toString());
		query.setBinding("self", getResource());
		return query;
	} catch (MalformedQueryException e) {
		throw new RepositoryException(e);
	}
}
 
開發者ID:anno4j,項目名稱:anno4j,代碼行數:27,代碼來源:RDFSContainer.java

示例3: testReadAccess

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testReadAccess() throws Exception {
	ValueFactory vf = con.getValueFactory();
	URI graph = vf.createURI("urn:test:graph");
	con.setAddContexts(graph);
	Company c = new Company();
	c = (Company) con.getObject(con.addObject(c));
	c.setName("My Company");
	assertEquals("My Company", c.getName());
	TupleQuery query = con.prepareTupleQuery("SELECT ?g WHERE {GRAPH ?g {?o <urn:test:name> ?name}}");
	query.setBinding("name", vf.createLiteral("My Company"));
	TupleQueryResult results = query.evaluate();
	Value g = results.next().getValue("g");
	results.close();
	assertEquals(graph, g);
	con.setAddContexts();
	assertEquals("My Company", c.getName());
	query = con.prepareTupleQuery("SELECT ?g WHERE {GRAPH ?g {?o <urn:test:name> ?name}}");
	query.setBinding("name", vf.createLiteral("My Company"));
	results = query.evaluate();
	g = results.next().getValue("g");
	results.close();
	assertEquals(graph, g);
}
 
開發者ID:anno4j,項目名稱:anno4j,代碼行數:24,代碼來源:FieldPredicateTest.java

示例4: findTargetByLastResolved

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
private TupleQueryResult findTargetByLastResolved(XMLGregorianCalendar xgc,
		int limit) throws OpenRDFException {
	String qry = TARGET_BY_DATE + "\nLIMIT " + limit;
	ObjectConnection con = getObjectConnection();
	ValueFactory vf = con.getValueFactory();
	TupleQuery query = con.prepareTupleQuery(qry);
	query.setBinding("this", getResource());
	query.setBinding("date", vf.createLiteral(xgc));
	return query.evaluate();
}
 
開發者ID:mowjoothfm,項目名稱:persistenturls,代碼行數:11,代碼來源:ValidatingDomainSupport.java

示例5: findUnresolvedTarget

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
private TupleQueryResult findUnresolvedTarget(int limit)
		throws OpenRDFException {
	String qry = TARGET_WITHOUT_DATE + "\nLIMIT " + limit;
	ObjectConnection con = getObjectConnection();
	TupleQuery query = con.prepareTupleQuery(qry);
	query.setBinding("this", getResource());
	return query.evaluate();
}
 
開發者ID:mowjoothfm,項目名稱:persistenturls,代碼行數:9,代碼來源:ValidatingDomainSupport.java

示例6: findResolvedTargetBefore

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
private TupleQueryResult findResolvedTargetBefore(XMLGregorianCalendar xgc,
		int limit) throws OpenRDFException {
	String qry = TARGET_BEFORE_DATE + "\nLIMIT " + limit;
	ObjectConnection con = getObjectConnection();
	ValueFactory vf = con.getValueFactory();
	TupleQuery query = con.prepareTupleQuery(qry);
	query.setBinding("this", getResource());
	query.setBinding("date", vf.createLiteral(xgc));
	return query.evaluate();
}
 
開發者ID:mowjoothfm,項目名稱:persistenturls,代碼行數:11,代碼來源:ValidatingDomainSupport.java

示例7: performSelect

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
protected Object performSelect(final String query, final String auth, final Boolean infer) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException {
    final TupleQuery tupleQuery = connection.prepareTupleQuery(
            QueryLanguage.SPARQL, query);
    if (auth != null && auth.length() > 0) {
        tupleQuery.setBinding(CONF_QUERY_AUTH, valueFactory.createLiteral(auth));
    }
    if (infer != null) {
        tupleQuery.setBinding(CONF_INFER, valueFactory.createLiteral(infer));
    }
    if (CbSailEndpoint.CbSailOutput.BINARY.equals(queryOutput)) {
        final List listOutput = new ArrayList();
        final TupleQueryResultHandlerBase handler = new TupleQueryResultHandlerBase() {
            @Override
            public void handleSolution(final BindingSet bindingSet) throws TupleQueryResultHandlerException {
                final Map<String, String> map = new HashMap<String, String>();
                for (final String s : bindingSet.getBindingNames()) {
                    map.put(s, bindingSet.getBinding(s).getValue().stringValue());
                }
                listOutput.add(map);
            }
        };
        tupleQuery.evaluate(handler);
        return listOutput;
    } else if (CbSailEndpoint.CbSailOutput.XML.equals(queryOutput)) {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final SPARQLResultsXMLWriter sparqlWriter = new SPARQLResultsXMLWriter(baos);
        tupleQuery.evaluate(sparqlWriter);
        return new String(baos.toByteArray(), StandardCharsets.UTF_8);
    } else {
        throw new IllegalArgumentException("Query Output[" + queryOutput + "] is not recognized");
    }
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:33,代碼來源:CbSailProducer.java

示例8: testTupleQueryBinding

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testTupleQueryBinding() throws Exception {
	Person jamie = con.addDesignation(con.getObjectFactory().createObject(),
			Person.class);
	jamie.getFoafNames().add("Jamie");
	jamie.getFoafFamily_names().add("Leigh");
	String q = PREFIX + "Select ?name where { ?person foaf:name ?name }";
	TupleQuery query = con.prepareTupleQuery(q);
	query.setBinding("person", ((RDFObject)jamie).getResource());
	TupleQueryResult result = query.evaluate();
	assertTrue(result.hasNext());
	assertEquals("Jamie", result.next().getValue("name").stringValue());
	result.close();
}
 
開發者ID:anno4j,項目名稱:anno4j,代碼行數:14,代碼來源:ObjectQueryTest.java

示例9: testUpdateWAuthOnConfig

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testUpdateWAuthOnConfig() throws Exception {
        String sparqlUpdate = getSparqlUpdate();

        RdfCloudTripleStore tstore = new MockRdfCloudStore();
        NamespaceManager nm = new NamespaceManager(tstore.getRyaDAO(), tstore.getConf());
        tstore.setNamespaceManager(nm);
        SailRepository repo = new SailRepository(tstore);
        tstore.getRyaDAO().getConf().setCv("1|2");
        repo.initialize();

        RepositoryConnection conn = repo.getConnection();
        Update u = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlUpdate);
        u.execute();

        String query =
                "PREFIX  ex:  <http://www.example.org/exampleDocument#>\n" +
                "PREFIX  voc:  <http://www.example.org/vocabulary#>\n" +
                "PREFIX  foaf:  <http://xmlns.com/foaf/0.1/>\n" +
                "PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-schema#>\n" +
                "\n" +
                "SELECT * \n" +
//              "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
                "WHERE\n" +
                "{\n" +
                "  GRAPH ex:G1\n" +
                "  {\n" +
                "    ?m voc:name ?name ;\n" +
                "           voc:homepage ?hp .\n" +
                "  } .\n" +
                " GRAPH ex:G2\n" +
                "  {\n" +
                "    ?m voc:hasSkill ?skill .\n" +
                "  } .\n" +
                "}";
        TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
        tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
        CountTupleHandler tupleHandler = new CountTupleHandler();
        tupleQuery.evaluate(tupleHandler);
        assertEquals(1, tupleHandler.getCount());

        tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); //no auth
        tupleHandler = new CountTupleHandler();
        tupleQuery.evaluate(tupleHandler);
        assertEquals(0, tupleHandler.getCount());

        conn.close();

        repo.shutDown();
    }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:50,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例10: testNamedGraphLoadWAuth

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testNamedGraphLoadWAuth() throws Exception {
        InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
        assertNotNull(stream);

        RdfCloudTripleStore tstore = new MockRdfCloudStore();
        NamespaceManager nm = new NamespaceManager(tstore.getRyaDAO(), tstore.getConf());
        tstore.setNamespaceManager(nm);
        SailRepository repo = new SailRepository(tstore);
        tstore.getRyaDAO().getConf().setCv("1|2");
        repo.initialize();

        RepositoryConnection conn = repo.getConnection();
        conn.add(stream, "", RDFFormat.TRIG);
        conn.commit();

        String query = "PREFIX  ex:  <http://www.example.org/exampleDocument#>\n" +
                "PREFIX  voc:  <http://www.example.org/vocabulary#>\n" +
                "PREFIX  foaf:  <http://xmlns.com/foaf/0.1/>\n" +
                "PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-schema#>\n" +
                "\n" +
                "SELECT * \n" +
//                "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
                "WHERE\n" +
                "{\n" +
                "  GRAPH ex:G1\n" +
                "  {\n" +
                "    ?m voc:name ?name ;\n" +
                "           voc:homepage ?hp .\n" +
                "  } .\n" +
                " GRAPH ex:G2\n" +
                "  {\n" +
                "    ?m voc:hasSkill ?skill .\n" +
                "  } .\n" +
                "}";
        TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
        tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
        CountTupleHandler tupleHandler = new CountTupleHandler();
        tupleQuery.evaluate(tupleHandler);
        assertEquals(1, tupleHandler.getCount());

        tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); //no auth
        tupleHandler = new CountTupleHandler();
        tupleQuery.evaluate(tupleHandler);
        assertEquals(0, tupleHandler.getCount());

        conn.close();

        repo.shutDown();
    }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:50,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例11: testPrepareTupleQuerywithBidings

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
@Test
public void testPrepareTupleQuerywithBidings() throws Exception{
	
	Statement st1 = vf.createStatement(john, fname, johnfname, dirgraph);
	Statement st2 = vf.createStatement(john, lname, johnlname, dirgraph);
	Statement st3 = vf.createStatement(john, homeTel, johnhomeTel, dirgraph);
	Statement st4 = vf.createStatement(john, email, johnemail, dirgraph);
	Statement st5 = vf.createStatement(micah, fname, micahfname, dirgraph);
	Statement st6 = vf.createStatement(micah, lname, micahlname, dirgraph);
	Statement st7 = vf.createStatement(micah, homeTel, micahhomeTel, dirgraph);
	Statement st8 = vf.createStatement(fei, fname, feifname, dirgraph);
	Statement st9 = vf.createStatement(fei, lname, feilname, dirgraph);
	Statement st10 = vf.createStatement(fei, email, feiemail, dirgraph);
	
	testAdminCon.add(st1);
	testAdminCon.add(st2);
	testAdminCon.add(st3);
	testAdminCon.add(st4);
	testAdminCon.add(st5);
	testAdminCon.add(st6);
	testAdminCon.add(st7);
	testAdminCon.add(st8);
	testAdminCon.add(st9);
	testAdminCon.add(st10);
	
			
	try{
		Assert.assertEquals(10, testAdminCon.size(dirgraph));
	}
	catch(Exception ex){
		logger.error("Failed :", ex);
	}
		
	
	StringBuilder queryBuilder = new StringBuilder(64);
	
	queryBuilder.append(" SELECT ?person ?firstname ?lastname ?phonenumber");
	queryBuilder.append(" FROM <").append(dirgraph.stringValue()).append(">");
	queryBuilder.append(" WHERE");
	queryBuilder.append(" { ");
	queryBuilder.append("   ?person <#firstName> ?firstname ;");
	queryBuilder.append("           <#lastName> ?lastname ; ");
	queryBuilder.append("           <#homeTel> ?phonenumber .} ");
	queryBuilder.append(" ORDER BY ?lastname");
	
	TupleQuery query = testAdminCon.prepareTupleQuery(queryBuilder.toString(),"http://marklogicsparql.com/addressbook");
	query.setBinding("firstname", vf.createLiteral("Micah"));
	
	TupleQueryResult result = query.evaluate();
	
	String [] epectedPersonresult = {"http://marklogicsparql.com/id#2222"};
	String [] expectedLnameresult = {"Dubinko"};
	String [] expectedFnameresult = {"Micah"};
	int i = 0;
	try {
		assertThat(result, is(notNullValue()));
		Assert.assertTrue(result.hasNext());
		while (result.hasNext()) {
			BindingSet solution = result.next();
			assertThat(solution.hasBinding("person"), is(equalTo(true)));
			assertThat(solution.hasBinding("lastname"), is(equalTo(true)));
			Value personResult = solution.getValue("person");
			Value lnameResult = solution.getValue("lastname");
			Value fnameResult = solution.getValue("firstname");
			Literal phoneResult = (Literal) solution.getValue("phonenumber");		
			Assert.assertEquals(epectedPersonresult[i], personResult.stringValue());
			Assert.assertEquals(expectedLnameresult[i], lnameResult.stringValue());
			Assert.assertEquals(expectedFnameresult[i], fnameResult.stringValue());
			assertThat(phoneResult.doubleValue(),  is(equalTo(new  Double(22222222D))));
			i++;
		}
	}
	finally {
		result.close();
	}

}
 
開發者ID:marklogic,項目名稱:marklogic-sesame,代碼行數:78,代碼來源:MarkLogicRepositoryConnectionTest.java

示例12: enrich

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
@Override
public List<Statement> enrich(EnricherConfig config, NamedGraph graph) {
	List<Statement> statements = new ArrayList<Statement>();
	ValueFactory vf = graph.getValueFactory();
	RepositoryConnection conn = config.getConnection();
	try {
		
		String classUri = platformConfig.getString("platform.classUri");						
		String homepageStr = GraphUtil.getOptionalObjectResource(graph, null, vf.createURI("http://xmlns.com/foaf/0.1/homepage")).toString();
		
		String sparql = 
				"SELECT ?dbpedia WHERE { " +
				"		SERVICE <http://dbpedia.org/sparql> { " +
				"			?dbpedia <http://xmlns.com/foaf/0.1/homepage> ?homepage . " +
				"		}" +
				"}";

		List<URI> homepages = new ArrayList<URI>();  
	  Collections.addAll(homepages, vf.createURI(homepageStr), vf.createURI(homepageStr + "/")); 
		
	  for (URI homepage : homepages) {
	  	TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparql);
			query.setBinding("homepage", homepage);
			
			TupleQueryResult queryResult = query.evaluate();
			
			while (queryResult.hasNext()) {
				BindingSet bindingSet = queryResult.next();
				Binding dbpedia = bindingSet.getBinding("dbpedia");
				
				statements.add(
					vf.createStatement(graph.getGraphUri(), 
					vf.createURI(classUri + "dbpedia"), 
					vf.createURI(dbpedia.getValue().stringValue())));				
			}
	  }						
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return statements;
}
 
開發者ID:erfgoed-en-locatie,項目名稱:artsholland-platform,代碼行數:43,代碼來源:DBpediaEnricher.java

示例13: testSPARQLQueryBindings

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
@Test
public void testSPARQLQueryBindings()
        throws Exception {

    String queryString = "select ?s ?p ?o { ?s ?p ?o . filter (?s = ?b) filter (?p = ?c) }";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);

    tupleQuery.setBinding("b", ValueFactoryImpl.getInstance().createURI("http://semanticbible.org/ns/2006/NTNames#Jim"));
    tupleQuery.setBinding("c", ValueFactoryImpl.getInstance().createURI("http://semanticbible.org/ns/2006/NTNames#parentOf"));

    tupleQuery.removeBinding("c");

    // TBD -  Assert. for confirmation of removal

    Assert.assertEquals(null, tupleQuery.getBindings().getBinding("c"));

    tupleQuery.clearBindings();

    Assert.assertEquals(null, tupleQuery.getBindings().getBinding("b"));

    tupleQuery.setBinding("b", ValueFactoryImpl.getInstance().createURI("http://semanticbible.org/ns/2006/NTNames#Jotham"));
    tupleQuery.setBinding("c", ValueFactoryImpl.getInstance().createURI("http://semanticbible.org/ns/2006/NTNames#parentOf"));

    TupleQueryResult results = tupleQuery.evaluate();

    Assert.assertEquals(results.getBindingNames().get(0), "s");
    Assert.assertEquals(results.getBindingNames().get(1), "p");
    Assert.assertEquals(results.getBindingNames().get(2), "o");

    logger.info(results.getBindingNames().toString());

    Assert.assertTrue(results.hasNext());
    BindingSet bindingSet = results.next();

    Value sV = bindingSet.getValue("s");
    Value pV = bindingSet.getValue("p");
    Value oV = bindingSet.getValue("o");

    Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#Jotham", sV.stringValue());
    Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#parentOf", pV.stringValue());
    Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#Ahaz", oV.stringValue());
    results.close();
}
 
開發者ID:marklogic,項目名稱:marklogic-sesame,代碼行數:44,代碼來源:MarkLogicTupleQueryTest.java


注:本文中的org.openrdf.query.TupleQuery.setBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。