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


Java BindingSet.getBinding方法代碼示例

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


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

示例1: handleSolution

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
  try {
    xmlWriter.startTag(RESULT_TAG);

    for (String bindingName : bindingNames) {
      Binding binding = bindingSet.getBinding(bindingName);
      if (binding != null) {
        xmlWriter.setAttribute(BINDING_NAME_ATT, binding.getName());
        xmlWriter.startTag(BINDING_TAG);

        writeValue(binding.getValue());

        xmlWriter.endTag(BINDING_TAG);
      }
    }

    xmlWriter.endTag(RESULT_TAG);
  } catch (IOException e) {
    throw new TupleQueryResultHandlerException(e);
  }
}
 
開發者ID:esarbanis,項目名稱:strabon,代碼行數:22,代碼來源:stSPARQLResultsXMLWriter.java

示例2: assertBindingSet

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
private static void assertBindingSet(final Iterator<BindingSet> bindingSetIter, final Iterator<Resource> expectedValues) {
    while (expectedValues.hasNext()) {
        final Resource expectedValue = expectedValues.next();
        assertTrue(bindingSetIter.hasNext());
        final BindingSet bindingSet = bindingSetIter.next();
        assertTrue(bindingSet instanceof QueryBindingSet);
        assertEquals(1, bindingSet.getBindingNames().size());
        final Binding binding = bindingSet.getBinding("s");
        assertNotNull(binding);
        final Value actualValue = binding.getValue();
        assertEquals(expectedValue, actualValue);
    }
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:14,代碼來源:OneOfVisitorTest.java

示例3: keepBindings

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
/**
 * Create a new {@link BindingSet} that only includes the bindings whose names appear within the {@code variableOrder}.
 * If no binding is found for a variable, then that binding is just omitted from the resulting object.
 *
 * @param variableOrder - Defines which bindings will be kept. (not null)
 * @param bindingSet - Contains the source {@link Binding}s. (not null)
 * @return A new {@link BindingSet} containing only the specified bindings.
 */
public static BindingSet keepBindings(final VariableOrder variableOrder, final BindingSet bindingSet) {
    requireNonNull(variableOrder);
    requireNonNull(bindingSet);

    final MapBindingSet result = new MapBindingSet();
    for(final String bindingName : variableOrder) {
        if(bindingSet.hasBinding(bindingName)) {
            final Binding binding = bindingSet.getBinding(bindingName);
            result.addBinding(binding);
        }
    }
    return result;
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:22,代碼來源:BindingSetUtil.java

示例4: enrich

import org.openrdf.query.BindingSet; //導入方法依賴的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

示例5: getTextCsv

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@GET
@Produces("text/csv")
public Response getTextCsv(@QueryParam("sensor") String sensorId,
		@QueryParam("property") String propertyId,
		@QueryParam("feature") String featureId,
		@QueryParam("from") String from, @QueryParam("to") String to) {
	if (from == null)
		return Response.ok("from is null", "text/plain").build();
	if (to == null)
		return Response.ok("to is null", "text/plain").build();
	
	ResultSet<BindingSet> rs = Connection.evaluate(sensorId, propertyId,
			featureId, from, to);

	StringBuffer sb = new StringBuffer();

	sb.append("time,value,sensor,property,feature" + "\n");

	while (rs.hasNext()) {
		BindingSet bs = rs.next();

		sb.append(bs.getBinding("time").getValue().stringValue());
		sb.append("," + bs.getBinding("value").getValue().stringValue());

		Binding b = null;

		b = bs.getBinding("sensorId");

		if (b == null)
			sb.append("," + sensorId);
		else
			sb.append("," + b.getValue().stringValue());

		b = bs.getBinding("propertyId");

		if (b == null)
			sb.append("," + propertyId);
		else
			sb.append("," + b.getValue().stringValue());

		b = bs.getBinding("featureId");

		if (b == null)
			sb.append("," + featureId);
		else
			sb.append("," + b.getValue().stringValue());

		sb.append("\n");
	}

	return Response.ok(sb.toString(), "text/csv").build();
}
 
開發者ID:markusstocker,項目名稱:emrooz,代碼行數:53,代碼來源:ListSensorObservations.java

示例6: handleSolution

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
  try {
    StringBuilder value = new StringBuilder();
    Value boundValue = null;
    String href;

    // if set to FALSE, urls link to web. if set to TRUE, urls are described //
    boolean linkURL = true;
    // /////////////////////////////////////////////////////////////////////////


    xmlWriter.startTag(TABLE_ROW_TAG);
    for (String bindingName : bindingNames) {
      Binding binding = bindingSet.getBinding(bindingName);
      if (binding != null) {
        boundValue = binding.getValue();
        value.append(boundValue.stringValue());

        if (boundValue instanceof BNode) {
          value.insert(0, "_:");
        }

        // If the value is a uri, make it link
        if (boundValue instanceof URI) {
          xmlWriter.setAttribute(STYLE, TABLE_DATA_CLASS);
          xmlWriter.startTag(TABLE_DATA_TAG);

          // select all the triples that contain the boundValue
          if (linkURL) {
            String query =
                "select * " + "where " + "{ " + "?subject ?predicate ?object . "
                    + "FILTER((?subject = <" + boundValue.toString() + ">) || "
                    + "(?predicate = <" + boundValue.toString() + ">)  || " + "(?object = <"
                    + boundValue.toString() + ">)) " + "}";

            // FIXME maybe using URLEncoder.encode() for encoding the query and the "boundValue"
            // is not the proper way to encode the final URL (see related bugs #65 and #49), but
            // I am not 100% sure
            href =
                "Browse?view=HTML&query=" + URLEncoder.encode(query, "UTF-8")
                    + "&format=HTML&resource="
                    + URLEncoder.encode(boundValue.toString(), "UTF-8");

          } else {
            href = boundValue.toString();
          }
          xmlWriter.setAttribute(LINK_REF, href);
          xmlWriter.startTag(LINK);
          xmlWriter.text(boundValue.toString());
          xmlWriter.endTag(LINK);
        } else {
          xmlWriter.setAttribute(STYLE, TABLE_DATA_CLASS + " " + MORE_LINK);
          xmlWriter.startTag(TABLE_DATA_TAG);
          xmlWriter.text(boundValue.toString());
        }
        xmlWriter.endTag(TABLE_DATA_TAG);
      } else {
        xmlWriter.setAttribute(STYLE, TABLE_DATA_CLASS);
        xmlWriter.startTag(TABLE_DATA_TAG);
        xmlWriter.endTag(TABLE_DATA_TAG);
      }
      value.setLength(0);
    }
    xmlWriter.endTag(TABLE_ROW_TAG);

  } catch (IOException e) {
    throw new TupleQueryResultHandlerException(e);
  }
}
 
開發者ID:esarbanis,項目名稱:strabon,代碼行數:71,代碼來源:stSPARQLResultsHTMLWriter.java

示例7: GlobalSecurityValidator

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public GlobalSecurityValidator(final Repository repo) {

	final TupleQueryResult result;
	try {
		
		result = Utils.executeSelectQuery(repo, GRANTED_DOCUMENTS, QueryLanguage.SPARQL);
				
		while(result.hasNext()){
			
			BindingSet bs = result.next();
			
			Binding user = bs.getBinding("user");
			Binding document = bs.getBinding("doc");
								
			if(securityInfo.containsKey(user)){
										
				securityInfo.get(user).add(document.getValue());
				
			}else{
				
				List<Value> docs = new LinkedList<Value>();
				docs.add(document.getValue());
				
				securityInfo.put(user.getValue(), docs);
				
			}
			
		}
	
	} catch (OpenRDFException e) {
		log.error("Security info was not collected", e);
	}
	
	
}
 
開發者ID:blazegraph,項目名稱:blazegraph-samples,代碼行數:36,代碼來源:GlobalSecurityValidator.java

示例8: GlobalSecurityValidator

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public GlobalSecurityValidator(final RemoteRepositoryManager m_repo) throws Exception {
	
		GraphQueryResult repoDescription = m_repo.getRepositoryDescriptions();
		Set<String> namespaces = new HashSet<String>();
		while (repoDescription.hasNext()) {
			Statement stmt = repoDescription.next();
			if (stmt.getPredicate()
					.toString()
					.equals(SD.KB_NAMESPACE.stringValue())) {
				
				namespaces.add(stmt.getObject().stringValue());
			}
	
		}

		TupleQueryResult result;
		
		for (String namespace : namespaces) {
			
			try {
				RemoteRepository repo = m_repo.getRepositoryForNamespace(namespace);
				
				result = repo.prepareTupleQuery(GRANTED_DOCUMENTS).evaluate();
				
				while(result.hasNext()){
					
					BindingSet bs = result.next();
					
					Binding user = bs.getBinding("user");
					Binding document = bs.getBinding("doc");
										
					if(securityInfo.containsKey(user)){
												
						securityInfo.get(user).add(document.getValue());
						
					}else{
						
						List<Value> docs = new LinkedList<Value>();
						docs.add(document.getValue());
						
						securityInfo.put(user.getValue(), docs);
						
					}
					
				}
					
			} catch (Exception e) {
				log.error("Security info was not collected", e);
			}
			
		}
		
}
 
開發者ID:blazegraph,項目名稱:blazegraph-samples,代碼行數:54,代碼來源:GlobalSecurityValidator.java


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