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


Java Query.setBinding方法代码示例

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


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

示例1: testPrepareQuery4

import org.openrdf.query.Query; //导入方法依赖的package包/类
@Test
public void testPrepareQuery4() throws Exception{
	
	URL url = MarkLogicRepositoryConnectionTest.class.getResource(TEST_DIR_PREFIX+"tigers.ttl");
	testAdminCon.add(url, "", RDFFormat.TURTLE);
	Assert.assertEquals(107L, testAdminCon.size());
		
	String query1 = "ASK "+
			"WHERE"+ 
			"{"+
			" ?s <#position> ?o."+
			 "}";

	Query bq = testAdminCon.prepareQuery(query1, "http://marklogic.com/baseball/players");
	bq.setBinding("o", vf.createLiteral("pitcher"));
	boolean result1	= ((BooleanQuery)bq).evaluate();
	Assert.assertTrue(result1);	
	
}
 
开发者ID:marklogic,项目名称:marklogic-sesame,代码行数:20,代码来源:MarkLogicRepositoryConnectionTest.java

示例2: testPrepareQuery2

import org.openrdf.query.Query; //导入方法依赖的package包/类
@Test
public void testPrepareQuery2() throws Exception{
	
	Reader ir = new BufferedReader(new InputStreamReader(MarkLogicRepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "property-paths.ttl")));
	testAdminCon.add(ir, "", RDFFormat.TURTLE, null);
	
	StringBuilder queryBuilder = new StringBuilder(128);
	queryBuilder.append(" prefix : <http://learningsparql.com/ns/papers#> ");
	queryBuilder.append(" prefix c: <http://learningsparql.com/ns/citations#>");
	queryBuilder.append(" SELECT ?s");
	queryBuilder.append(" WHERE {  ");
	queryBuilder.append(" ?s ^c:cites :paperK2 . ");
	queryBuilder.append(" FILTER (?s != :paperK2)");
	queryBuilder.append(" } ");
	queryBuilder.append(" ORDER BY ?s ");
	
	Query query = testAdminCon.prepareQuery(queryBuilder.toString());
	query.setBinding("whatcode", vf.createLiteral("33333"));
	TupleQueryResult result = null;
       if (query instanceof TupleQuery) {
           result = ((TupleQuery) query).evaluate();
       
       }
	
	try {
		assertThat(result, is(notNullValue()));
	
		while (result.hasNext()) {
			BindingSet solution = result.next();
			assertThat(solution.hasBinding("s"), is(equalTo(true)));
			Value totalResult = solution.getValue("s");
			Assert.assertEquals(vf.createURI("http://learningsparql.com/ns/papers#paperJ"),totalResult);
			
		}
	}
	finally {
		result.close();
	}
}
 
开发者ID:marklogic,项目名称:marklogic-sesame,代码行数:40,代码来源:MarkLogicRepositoryConnectionTest.java

示例3: performNodeBindings

import org.openrdf.query.Query; //导入方法依赖的package包/类
private void performNodeBindings(final Map<String, Node> bindings, final Query query) {
    ValueFactory valueFactory = ValueFactoryImpl.getInstance();
    for (String i : bindings.keySet()) {
        Node n = bindings.get(i);
        if (n != null) {
            query.setBinding(i, getSesameValue(n, valueFactory));
        }
    }
}
 
开发者ID:discoverygarden,项目名称:trippi-sail,代码行数:10,代码来源:AbstractSesameSession.java

示例4: testPrepareQuery1

import org.openrdf.query.Query; //导入方法依赖的package包/类
@Test
public void testPrepareQuery1() throws Exception {
	testAdminCon.add(MarkLogicRepositoryConnectionTest.class.getResourceAsStream(TEST_DIR_PREFIX + "companies_100.ttl"), "",
			RDFFormat.TURTLE, null);
	Assert.assertEquals(testAdminCon.size(), 1600L);
	
	StringBuilder queryBuilder = new StringBuilder(128);
	queryBuilder.append("PREFIX demor: <http://demo/resource#>");
	queryBuilder.append(" PREFIX demov: <http://demo/verb#>");
	queryBuilder.append(" PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>");
	queryBuilder.append(" SELECT (COUNT(?company) AS ?total)");
	queryBuilder.append(" WHERE { ");
	queryBuilder.append("  ?company a vcard:Organization .");
	queryBuilder.append("  ?company demov:industry ?industry .");
	queryBuilder.append("  ?company vcard:hasAddress/vcard:postal-code ?zip .");
	queryBuilder.append("  ?company vcard:hasAddress/vcard:postal-code ?whatcode ");
	queryBuilder.append(" } ");
	

	Query query = testAdminCon.prepareQuery(QueryLanguage.SPARQL, queryBuilder.toString());
	query.setBinding("whatcode", vf.createLiteral("33333"));
	TupleQueryResult result = null;
       if (query instanceof TupleQuery) {
           result = ((TupleQuery) query).evaluate();
       
       }
	
	try {
		assertThat(result, is(notNullValue()));
	
		while (result.hasNext()) {
			BindingSet solution = result.next();
			assertThat(solution.hasBinding("total"), is(equalTo(true)));
			Value totalResult = solution.getValue("total");
			Assert.assertEquals(vf.createLiteral("12",XMLSchema.UNSIGNED_LONG),totalResult);
			
		}
	}
	finally {
		result.close();
	}
}
 
开发者ID:marklogic,项目名称:marklogic-sesame,代码行数:43,代码来源:MarkLogicRepositoryConnectionTest.java


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