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


Java TupleQuery.setBinding方法代码示例

本文整理汇总了Java中org.eclipse.rdf4j.query.TupleQuery.setBinding方法的典型用法代码示例。如果您正苦于以下问题:Java TupleQuery.setBinding方法的具体用法?Java TupleQuery.setBinding怎么用?Java TupleQuery.setBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.rdf4j.query.TupleQuery的用法示例。


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

示例1: select

import org.eclipse.rdf4j.query.TupleQuery; //导入方法依赖的package包/类
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri) throws QueryEvaluationException {
	RepositoryConnection conn = endpoint.getConn();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, service.getSelectQueryString(projectionVars), baseUri);
		Iterator<Binding> bIter = bindings.iterator();
		while (bIter.hasNext()) {
			Binding b = bIter.next();
			if (service.getServiceVars().contains(b.getName()))
				query.setBinding(b.getName(), b.getValue());
		}
		TupleQueryResult qRes = query.evaluate();
		return new InsertBindingsIteration(qRes, bindings);
	} catch(Throwable e) {
		throw new QueryEvaluationException(e);
	} finally {
		conn.close();
	}
}
 
开发者ID:dice-group,项目名称:CostFed,代码行数:20,代码来源:SAILFederatedService.java

示例2: findLineageProgenitor

import org.eclipse.rdf4j.query.TupleQuery; //导入方法依赖的package包/类
/**
 * Find the lineage progenitor for the given disco.
 *
 * @param disco URI of the disco
 * @param triplestore
 * @return URI of the progenitor, null if not present;
 */
static URI findLineageProgenitor(URI disco, Rdf4jTriplestore ts) {
    final RepositoryConnection c = ts.getConnection();

    final TupleQuery q = c.prepareTupleQuery(QUERY_LINEAGE_SEARCH);

    q.setBinding(BINDING_RESOURCE, c.getValueFactory().createIRI(disco.toString()));

    try (TupleQueryResult result = q.evaluate()) {
        if (result.hasNext()) {
            final URI found = URI.create(result.next().getBinding(BINDING_LINEAGE).getValue().toString());
            if (result.hasNext()) {
                throw new RuntimeException(String.format("Two lineages found for resource <>: <> and <>",
                        disco, found, result.next().getBinding(BINDING_LINEAGE).toString()));
            }
            return found;
        }
    }

    return null;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:28,代码来源:ORMapQueriesLineage.java

示例3: findDerivativesfrom

import org.eclipse.rdf4j.query.TupleQuery; //导入方法依赖的package包/类
static Set<URI> findDerivativesfrom(URI disco, Rdf4jTriplestore ts) {

        final Set<URI> derivatives = new HashSet<>();
        final RepositoryConnection c = ts.getConnection();
        final TupleQuery q = c.prepareTupleQuery(QUERY_FIND_DERIVATIVES);

        q.setBinding(BINDING_LINEAGE, c.getValueFactory().createIRI(disco.toString()));

        try (TupleQueryResult result = q.evaluate()) {
            while (result.hasNext()) {
                derivatives.add(URI.create(result.next().getBinding(BINDING_RESOURCE).getValue().toString()));
            }
        }

        return derivatives;
    }
 
开发者ID:rmap-project,项目名称:rmap,代码行数:17,代码来源:ORMapQueriesLineage.java

示例4: getLineageMembersWithDates

import org.eclipse.rdf4j.query.TupleQuery; //导入方法依赖的package包/类
static Map<Date, URI> getLineageMembersWithDates(URI progenitor, Rdf4jTriplestore ts) {

        final Map<Date, URI> members = new TreeMap<>();

        final RepositoryConnection c = ts.getConnection();
        final TupleQuery q = c.prepareTupleQuery(QUERY_GET_LINEAGE_MEMBERS);

        q.setBinding(BINDING_LINEAGE, c.getValueFactory().createIRI(progenitor.toString()));

        try (TupleQueryResult result = q.evaluate()) {
            while (result.hasNext()) {
                final BindingSet val = result.next();

                final Date date = new Date(((Literal) val.getValue(BINDING_DATE)).calendarValue()
                        .toGregorianCalendar()
                        .getTimeInMillis());

                members.put(date, URI.create(val.getValue(BINDING_RESOURCE).toString()));
            }
        }

        return members;
    }
 
开发者ID:rmap-project,项目名称:rmap,代码行数:24,代码来源:ORMapQueriesLineage.java

示例5: testPrepareTupleQuerywithBidings

import org.eclipse.rdf4j.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-rdf4j,代码行数:75,代码来源:MarkLogicRepositoryConnectionTest.java

示例6: testSPARQLQueryBindings

import org.eclipse.rdf4j.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", SimpleValueFactory.getInstance().createIRI("http://semanticbible.org/ns/2006/NTNames#Jim"));
    tupleQuery.setBinding("c", SimpleValueFactory.getInstance().createIRI("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", SimpleValueFactory.getInstance().createIRI("http://semanticbible.org/ns/2006/NTNames#Jotham"));
    tupleQuery.setBinding("c", SimpleValueFactory.getInstance().createIRI("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-rdf4j,代码行数:44,代码来源:MarkLogicTupleQueryTest.java


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