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


Java BindingSet類代碼示例

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


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

示例1: runQuery

import org.openrdf.query.BindingSet; //導入依賴的package包/類
private QueryResult runQuery()
		throws IOException, QueryEvaluationException,
		       QueryResultParseException, TupleQueryResultHandlerException,
			   QueryResultHandlerException {
	TestResultHandler noninf = new TestResultHandler();
	TestResultHandler actual = new TestResultHandler();
	TestResultHandler expect = new TestResultHandler();
	parser.setQueryResultHandler(expect);
	parser.parseQueryResult(getResource(expected));
	nonInfQuery.evaluate(noninf);
	query.evaluate(actual);
	Multiset<BindingSet> noninfset = noninf.getSolutions();
	Multiset<BindingSet> expectset = expect.getSolutions();
	Multiset<BindingSet> actualset = actual.getSolutions();
	return new QueryResult(expectset, actualset, noninfset);
}
 
開發者ID:lszeremeta,項目名稱:neo4j-sparql-extension-yars,代碼行數:17,代碼來源:SPARQLInferenceTest.java

示例2: runSPARQL

import org.openrdf.query.BindingSet; //導入依賴的package包/類
/**
 * Execute a SELECT SPARQL query against the graph
 * 
 * @param qs
 *            SELECT SPARQL query
 * @return list of solutions, each containing a hashmap of bindings
 */
public List runSPARQL(String qs) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			TupleQuery query = con.prepareTupleQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
			TupleQueryResult qres = query.evaluate();
			ArrayList reslist = new ArrayList();
			while (qres.hasNext()) {
				BindingSet b = qres.next();
				Set names = b.getBindingNames();
				HashMap hm = new HashMap();
				for (Object n : names) {
					hm.put((String) n, b.getValue((String) n));
				}
				reslist.add(hm);
			}
			return reslist;
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:33,代碼來源:SimpleGraph.java

示例3: vertexPropertyId

import org.openrdf.query.BindingSet; //導入依賴的package包/類
/**
 * Binding set to vertex property (for Vertex elements).
 */
private final <V> Function<BindingSet, VertexProperty<V>> 
vertexProperty(final BlazeVertex v) {
    return bs -> {

        log.debug(() -> bs);
        final Literal val = (Literal) bs.getValue("val");
        final BigdataBNode sid = (BigdataBNode) bs.getValue("vp");
        final BigdataStatement stmt = sid.getStatement();
        final URI key = stmt.getPredicate();
        final String vpId = vertexPropertyId(stmt);
        final BlazeProperty<V> prop = 
                new BlazeProperty<>(BlazeGraph.this, v, key, val);
        final BlazeVertexProperty<V> bvp = 
                new BlazeVertexProperty<>(prop, vpId, sid);
        return bvp;

    };
}
 
開發者ID:blazegraph,項目名稱:tinkerpop3,代碼行數:22,代碼來源:BlazeGraph.java

示例4: _select

import org.openrdf.query.BindingSet; //導入依賴的package包/類
/**
 * {@inheritDoc}
 * 
 * Logs the query at INFO and logs the optimized AST at TRACE.
 */
@Override
protected Stream<BindingSet> _select( 
        final String queryStr, final String extQueryId) {

    logQuery(queryStr);
    return Code.wrapThrow(() -> {
        final BigdataSailTupleQuery query = (BigdataSailTupleQuery) 
                cxn().prepareTupleQuery(QueryLanguage.SPARQL, queryStr);
        setMaxQueryTime(query);
        final UUID queryId = setupQuery(query.getASTContainer(), 
                                        QueryType.SELECT, extQueryId);
        
        sparqlLog.trace(() -> "optimized AST:\n"+query.optimize());
        
        /*
         * Result is closed automatically by GraphStreamer.
         */
        final TupleQueryResult result = query.evaluate();
        final Optional<Runnable> onClose = 
                Optional.of(() -> finalizeQuery(queryId));
        return new GraphStreamer<>(result, onClose).stream();
    });
    
}
 
開發者ID:blazegraph,項目名稱:tinkerpop3,代碼行數:30,代碼來源:BlazeGraphEmbedded.java

示例5: handleTuple

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@Override
public void handleTuple( BindingSet set, ValueFactory fac ) {
	URI pred = fac.createURI( set.getValue( "p" ).stringValue() );
	Value val = set.getValue( "o" );

	// for baseuri, we need the subject, not the object
	// and also, we use the VOID_DS as the key elsewhere in the code
	if ( RDF.TYPE.equals( pred ) ) {
		pred = SEMTOOL.Database;
		val = set.getValue( "db" );
	}
	else if ( pred.getNamespace().equals( DC.NAMESPACE ) ) {
		// silently handle the old DC namespace (ignore our DC-specific URIs)
		if ( !( MetadataConstants.DCT_CREATED.equals( pred )
				|| MetadataConstants.DCT_MODIFIED.equals( pred ) ) ) {
			pred = fac.createURI( DCTERMS.NAMESPACE, pred.getLocalName() );
		}
	}

	result.put( pred, val );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:22,代碼來源:MetadataQuery.java

示例6: rebuildConceptProps

import org.openrdf.query.BindingSet; //導入依賴的package包/類
private Model rebuildConceptProps( List<URI> concepts ) {
	String cimplosion = Utility.implode( concepts );

	// now see what properties are on concepts and edges
	String query = "SELECT DISTINCT ?type ?prop WHERE {\n"
			+ "  ?s ?prop ?propval . FILTER ( isLiteral( ?propval ) )\n"
			+ "  ?s a|rdfs:subClassOf+ ?type .\n"
			+ "  FILTER ( ?prop != rdfs:label ) .\n"
			+ "} VALUES ?type { " + cimplosion + " }";

	ModelQueryAdapter mqa = new ModelQueryAdapter( query ) {

		@Override
		public void handleTuple( BindingSet set, ValueFactory fac ) {
			URI type = URI.class.cast( set.getValue( "type" ) );
			URI prop = URI.class.cast( set.getValue( "prop" ) );
			result.add( type, prop, Constants.ANYNODE );
		}
	};

	return engine.queryNoEx( mqa );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:23,代碼來源:SemtoolStructureManagerImpl.java

示例7: testSailStrategy

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@Test
public void testSailStrategy() throws Exception {
    insertDataFile(Resources.getResource("data.ttl"), "http://example.org#");
    insertDataFile(Resources.getResource("university.ttl"), "http://example.org#");
    insertDataFile(Resources.getResource("owlrl.ttl"), "http://example.org#");
    Set<BindingSet> solutions = executeQuery(Resources.getResource("query.sparql"));
    Set<BindingSet> expected = new HashSet<>();
    Assert.assertEquals(expected, solutions);
    conf.setUseAggregationPipeline(false);
    ForwardChainSpinTool tool = new ForwardChainSpinTool();
    ToolRunner.run(conf, tool, new String[] {});
    solutions = executeQuery(Resources.getResource("query.sparql"));
    expected.add(new ListBindingSet(Arrays.asList("X", "Y"),
        VF.createURI(EX, "Alice"), VF.createURI(EX, "Department1")));
    Assert.assertEquals(expected, solutions);
    Assert.assertEquals(24, tool.getNumInferences());
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:18,代碼來源:MongoSpinIT.java

示例8: evaluate

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@Override
    public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr expr, BindingSet bindings) throws QueryEvaluationException {
        if (expr instanceof QueryRoot) {
            if (displayQueryPlan) {
//                System.out.println("Tables: ");
//                System.out.println("--SPO: \t" + RdfCloudTripleStoreConstants.TBL_SPO);
//                System.out.println("--PO: \t" + RdfCloudTripleStoreConstants.TBL_PO);
//                System.out.println("--OSP: \t" + RdfCloudTripleStoreConstants.TBL_OSP);
                logger.info("=================== Rya Query ===================");
                for (String str : expr.toString().split("\\r?\\n")) {
                    logger.info(str);
                }
                logger.info("================= End Rya Query =================");
            }
        }
        return super.evaluate(expr, bindings);
    }
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:18,代碼來源:ParallelEvaluationStrategyImpl.java

示例9: getBindingSetsFromKafka

import org.openrdf.query.BindingSet; //導入依賴的package包/類
private Set<BindingSet> getBindingSetsFromKafka(final String topicName) {
    KafkaConsumer<String, BindingSet> consumer = null;

    try {
        consumer = makeBindingSetConsumer(topicName);
        final ConsumerRecords<String, BindingSet> records = consumer.poll(20000);  // Wait up to 20 seconds for a result to be published.

        final Set<BindingSet> bindingSets = new HashSet<>();
        records.forEach(x -> bindingSets.add(x.value()));

        return bindingSets;

    } catch (final Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (consumer != null) {
            consumer.close();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:21,代碼來源:PeriodicNotificationExporterIT.java

示例10: accept

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@Override
protected boolean accept(BindingSet bindings) throws QueryEvaluationException {
  try {
    // Limit the bindings to the ones that are in scope for this filter
    QueryBindingSet scopeBindings = new QueryBindingSet(bindings);

    // FIXME J1 scopeBindingNames should include bindings from superquery if the filter
    // is part of a subquery. This is a workaround: we should fix the settings of
    // scopeBindingNames,
    // rather than skipping the limiting of bindings.
    if (!(filter.getParentNode() instanceof SubQueryValueOperator)) {
      scopeBindings.retainAll(scopeBindingNames);
    }

    return strategy.isTrue(filter.getCondition(), scopeBindings);
  } catch (ValueExprEvaluationException e) {
    // failed to evaluate condition
    return false;
  }
}
 
開發者ID:esarbanis,項目名稱:strabon,代碼行數:21,代碼來源:StSPARQLFilterIterator.java

示例11: printTupleQueryResult

import org.openrdf.query.BindingSet; //導入依賴的package包/類
/***
 * Prints the query results of result.
 * @param result
 * @throws QueryEvaluationException
 */
public static void printTupleQueryResult(TupleQueryResult result) throws QueryEvaluationException 
{
	while (result.hasNext()) 
	{ /*
									 * iterate over the result and print the
									 * bindings.
									 */
		BindingSet bindingSet = result.next();
		Value valueOfX = bindingSet.getValue("x");
		Value valueOfY = bindingSet.getValue("y");
		System.out.print("value of ?x " + valueOfX + " ++++++ ");
		System.out.println("value of ?y " + valueOfY);
	}
	
}
 
開發者ID:matanso,項目名稱:OASSIS,代碼行數:21,代碼來源:SPARQLQueryManager.java

示例12: doSparql

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected <T> Stream<T> doSparql(@Nullable final Long timeout, final Class<T> type,
        final String expression, final Set<URI> defaultGraphs, final Set<URI> namedGraphs)
        throws Exception {

    final String path = Protocol.PATH_SPARQL;
    final String query = query(//
            Protocol.PARAMETER_QUERY, expression, //
            Protocol.PARAMETER_DEFAULT_GRAPH, defaultGraphs, //
            Protocol.PARAMETER_NAMED_GRAPH, namedGraphs);
    GenericType<?> responseType;
    if (type == Statement.class) {
        responseType = Protocol.STREAM_OF_STATEMENTS;
    } else if (type == BindingSet.class) {
        responseType = Protocol.STREAM_OF_TUPLES;
    } else if (type == Boolean.class) {
        responseType = Protocol.STREAM_OF_BOOLEANS;
    } else {
        throw new Error("Unexpected result type: " + type);
    }
    return (Stream<T>) invoke(HttpMethod.GET, path, query, null, null, responseType,
            timeout);
}
 
開發者ID:dkmfbk,項目名稱:knowledgestore,代碼行數:25,代碼來源:Client.java

示例13: doEvaluate

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@Override
void doEvaluate(final Session session, final BindingSet input,
        final MapBindingSet output) throws Throwable {

    final URI id = (URI) Statements.parseValue(this.id.instantiate(input),
            Namespaces.DEFAULT);

    long numTriples = 0L;
    try {
        final Stream<Record> stream = session.retrieve(this.layer).ids(id)
                .properties(this.properties).exec();
        numTriples = Record.encode(stream, ImmutableList.of(this.layer)).count();
        if (numTriples == 0) {
            LOGGER.warn("No results for LOOKUP request, layer "
                    + TestUtil.format(this.layer) + ", id " + id);
        }

    } catch (final Throwable ex) {
        throw new RuntimeException("Failed LOOKUP " + TestUtil.format(this.layer)
                + ", id " + TestUtil.format(id) + ", properties " + this.properties,
                ex);
    } finally {
        output.addBinding("size", FACTORY.createLiteral(numTriples));
    }
}
 
開發者ID:dkmfbk,項目名稱:knowledgestore,代碼行數:26,代碼來源:TestDriver.java

示例14: convert

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@Override
public String convert(final BindingSet bindingSet, final VariableOrder varOrder) {
    requireNonNull(bindingSet);
    requireNonNull(varOrder);

    // Convert each Binding to a String.
    final List<String> bindingStrings = new ArrayList<>();
    for(final String varName : varOrder) {
        if(bindingSet.hasBinding(varName)) {
            // Add a value to the binding set.
            final Value value = bindingSet.getBinding(varName).getValue();
            final RyaType ryaValue = RdfToRyaConversions.convertValue(value);
            final String bindingString = ryaValue.getData() + TYPE_DELIM + ryaValue.getDataType();
            bindingStrings.add(bindingString);
        } else {
            // Add a null value to the binding set.
            bindingStrings.add(NULL_VALUE_STRING);
        }
    }

    // Join the bindings using the binding delim.
    return Joiner.on(BINDING_DELIM).join(bindingStrings);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:24,代碼來源:BindingSetStringConverter.java

示例15: testMultiConstruct

import org.openrdf.query.BindingSet; //導入依賴的package包/類
@Test
public void testMultiConstruct() throws Exception {
    // Insert data
    URI alice = VF.createURI("urn:Alice");
    URI bob = VF.createURI("urn:Bob");
    URI eve = VF.createURI("urn:Eve");
    URI friend = VF.createURI("urn:friend");
    URI knows = VF.createURI("urn:knows");
    URI person = VF.createURI("urn:Person");
    insert(alice, friend, bob);
    insert(bob, knows, eve);
    insert(eve, knows, alice);
    // Define query and expected results
    final String query = "CONSTRUCT {\n"
            + "    ?x rdf:type owl:Thing .\n"
            + "    ?x rdf:type <urn:Person> .\n"
            + "} WHERE { ?x <urn:knows> ?y }";
    final Multiset<BindingSet> expected = HashMultiset.create();
    List<String> varNames = Arrays.asList("subject", "predicate", "object");
    expected.add(new ListBindingSet(varNames, bob, RDF.TYPE, OWL.THING));
    expected.add(new ListBindingSet(varNames, bob, RDF.TYPE, person));
    expected.add(new ListBindingSet(varNames, eve, RDF.TYPE, OWL.THING));
    expected.add(new ListBindingSet(varNames, eve, RDF.TYPE, person));
    // Test query
    testPipelineQuery(query, expected);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:27,代碼來源:PipelineQueryIT.java


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