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


Java TupleQueryResult類代碼示例

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


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

示例1: getDistinctObj

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
/**
 * Get total number of distinct objects for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static long getDistinctObj(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objs) " + // 
			"WHERE " +
			"{" +
       		"?s <" + pred + "> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objs").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例2: getDistinctSbj

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
/**
 * Get total number of distinct objects for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static long getDistinctSbj(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?s) AS ?subjs) " + // 
			"WHERE " +
			"{" +
       		"?s <" + pred + "> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("subjs").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例3: getSubjectCount

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
/**
 * Get total number of distinct subjects of a dataset
 * @return count 
 */
public static long getSubjectCount(String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?s) AS ?sbjts) " + // 
			"WHERE " +
			"{" +
       		"?s ?p ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("sbjts").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:23,代碼來源:SemagrowSummariesGenerator.java

示例4: getObjectCount

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
/**
 * Get total number of distinct objects of a dataset
 * @return count
 */
public static long getObjectCount(String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objts) " + // 
			"WHERE " +
			"{" +
       		"?s ?p ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objts").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:23,代碼來源:SemagrowSummariesGenerator.java

示例5: getTripleCount

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
/**
 * Get total number of triple for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static Long getTripleCount(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(?s) AS ?triples) " + // 
			"WHERE " +
			"{" +
       		"?s <"+pred+"> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("triples").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例6: getPredicates

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
/**
 * Get Predicate List
 * @param endPointUrl SPARQL endPoint Url
 * @param graph Named graph
 * @return  predLst Predicates List
 */
private static List<String> getPredicates(String endPointUrl, String graph) throws Exception
{
	List<String>  predLst = new ArrayList<String>();
	String strQuery = getPredQuery(graph);
	SPARQLRepository repo = new SPARQLRepository(endPointUrl);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult res = query.evaluate();
		while (res.hasNext()) 
		{
			String pred = res.next().getValue("p").toString();
			predLst.add(pred);	  		
		}
	} finally {
		conn.close();
		repo.shutDown();
	}
	return predLst;
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:28,代碼來源:SemagrowSummariesGenerator.java

示例7: runSPARQL

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

示例8: _select

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

示例9: getSelect

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
public static final <T> T getSelect( QueryExecutor<T> query,
		RepositoryConnection rc, boolean dobindings ) throws RepositoryException,
		MalformedQueryException, QueryEvaluationException {

	String sparql = processNamespaces( dobindings ? query.getSparql()
			: query.bindAndGetSparql(), query.getNamespaces() );

	ValueFactory vfac = new ValueFactoryImpl();
	TupleQuery tq = rc.prepareTupleQuery( QueryLanguage.SPARQL, sparql );

	if ( null != query.getContext() ) {
		DatasetImpl dataset = new DatasetImpl();
		dataset.addDefaultGraph( query.getContext() );
		tq.setDataset( dataset );
	}

	if ( dobindings ) {
		tq.setIncludeInferred( query.usesInferred() );
		query.setBindings( tq, vfac );
	}

	TupleQueryResult rslt = tq.evaluate();
	query.start( rslt.getBindingNames() );
	while ( rslt.hasNext() ) {
		query.handleTuple( rslt.next(), vfac );
	}
	query.done();
	rslt.close();
	return query.getResults();
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:31,代碼來源:AbstractSesameEngine.java

示例10: testSorensenDice

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
@Test
public void testSorensenDice() throws Exception {
    final Connection aConn = ConnectionConfiguration.to(DB)
            .credentials("admin", "admin")
            .connect();

    try {

        final String aQuery = "prefix ss: <" + StringSimilarityVocab.NAMESPACE + "> " +
                "select ?dist where { bind(ss:sorensenDice(\"ABCDE\", \"ABCDFG\", 2) as ?dist) }";

        final TupleQueryResult aResult = aConn.select(aQuery).execute();

        try {
            assertTrue("Should have a result", aResult.hasNext());

            final String aValue = aResult.next().getValue("dist").stringValue();

            assertEquals(0.3333, Double.parseDouble(aValue), 0.0001);

            assertFalse("Should have no more results", aResult.hasNext());
        }
        finally {
            aResult.close();
        }
    }
    finally {
        aConn.close();
    }
}
 
開發者ID:semantalytics,項目名稱:stardog-plugin-string-similarity,代碼行數:31,代碼來源:TestSorensenDice.java

示例11: testSorensenDiceTooManyArgs

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

    final Connection aConn = ConnectionConfiguration.to(DB)
            .credentials("admin", "admin")
            .connect();

    try {
        final String aQuery = "prefix ss: <" + StringSimilarityVocab.NAMESPACE + "> " +
                "select ?str where { bind(ss:sorensenDice(\"one\", \"two\", \"three\", \"four\") as ?str) }";

        final TupleQueryResult aResult = aConn.select(aQuery).execute();
        try {
            // there should be a result because implicit in the query is the singleton set, so because the bind
            // should fail due to the value error, we expect a single empty binding
            assertTrue("Should have a result", aResult.hasNext());

            final BindingSet aBindingSet = aResult.next();

            assertTrue("Should have no bindings", aBindingSet.getBindingNames().isEmpty());

            assertFalse("Should have no more results", aResult.hasNext());
        }
        finally {
            aResult.close();
        }
    }
    finally {
        aConn.close();
    }
}
 
開發者ID:semantalytics,項目名稱:stardog-plugin-string-similarity,代碼行數:32,代碼來源:TestSorensenDice.java

示例12: testSorensenDiceWrongType

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
@Test
public void testSorensenDiceWrongType() throws Exception {
    final Connection aConn = ConnectionConfiguration.to(DB)
            .credentials("admin", "admin")
            .connect();

    try {

        final String aQuery = "prefix ss: <" + StringSimilarityVocab.NAMESPACE + "> " +
                "select ?str where { bind(ss:sorensenDice(7) as ?str) }";

        final TupleQueryResult aResult = aConn.select(aQuery).execute();
        try {
            // there should be a result because implicit in the query is the singleton set, so because the bind
            // should fail due to the value error, we expect a single empty binding
            assertTrue("Should have a result", aResult.hasNext());

            final BindingSet aBindingSet = aResult.next();

            assertTrue("Should have no bindings", aBindingSet.getBindingNames().isEmpty());

            assertFalse("Should have no more results", aResult.hasNext());
        }
        finally {
            aResult.close();
        }
    }
    finally {
        aConn.close();
    }
}
 
開發者ID:semantalytics,項目名稱:stardog-plugin-string-similarity,代碼行數:32,代碼來源:TestSorensenDice.java

示例13: testLevenshtein

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
@Test
public void testLevenshtein() throws Exception {
    final Connection aConn = ConnectionConfiguration.to(DB)
            .credentials("admin", "admin")
            .connect();

    try {

        final String aQuery = "prefix ss: <" + StringSimilarityVocab.NAMESPACE + "> " +
                "select ?dist where { bind(ss:levenshtein(\"My string\", \"My tring\") as ?dist) }";

        final TupleQueryResult aResult = aConn.select(aQuery).execute();

        try {
            assertTrue("Should have a result", aResult.hasNext());

            final String aValue = aResult.next().getValue("dist").stringValue();

            assertEquals(1.0, Double.parseDouble(aValue), 0.0);

            assertFalse("Should have no more results", aResult.hasNext());
        }
        finally {
            aResult.close();
        }
    }
    finally {
        aConn.close();
    }
}
 
開發者ID:semantalytics,項目名稱:stardog-plugin-string-similarity,代碼行數:31,代碼來源:TestLevenshtein.java

示例14: testLevenstheinTooManyArgs

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

    final Connection aConn = ConnectionConfiguration.to(DB)
            .credentials("admin", "admin")
            .connect();

    try {
        final String aQuery = "prefix ss: <" + StringSimilarityVocab.NAMESPACE + "> " +
                "select ?str where { bind(ss:levenshtein(\"one\", \"two\", \"three\") as ?str) }";

        final TupleQueryResult aResult = aConn.select(aQuery).execute();
        try {
            // there should be a result because implicit in the query is the singleton set, so because the bind
            // should fail due to the value error, we expect a single empty binding
            assertTrue("Should have a result", aResult.hasNext());

            final BindingSet aBindingSet = aResult.next();

            assertTrue("Should have no bindings", aBindingSet.getBindingNames().isEmpty());

            assertFalse("Should have no more results", aResult.hasNext());
        }
        finally {
            aResult.close();
        }
    }
    finally {
        aConn.close();
    }
}
 
開發者ID:semantalytics,項目名稱:stardog-plugin-string-similarity,代碼行數:32,代碼來源:TestLevenshtein.java

示例15: testLevenshteinWrongType

import org.openrdf.query.TupleQueryResult; //導入依賴的package包/類
@Test
public void testLevenshteinWrongType() throws Exception {
    final Connection aConn = ConnectionConfiguration.to(DB)
            .credentials("admin", "admin")
            .connect();

    try {

        final String aQuery = "prefix ss: <" + StringSimilarityVocab.NAMESPACE + "> " +
                "select ?str where { bind(ss:levenshtein(7) as ?str) }";

        final TupleQueryResult aResult = aConn.select(aQuery).execute();
        try {
            // there should be a result because implicit in the query is the singleton set, so because the bind
            // should fail due to the value error, we expect a single empty binding
            assertTrue("Should have a result", aResult.hasNext());

            final BindingSet aBindingSet = aResult.next();

            assertTrue("Should have no bindings", aBindingSet.getBindingNames().isEmpty());

            assertFalse("Should have no more results", aResult.hasNext());
        }
        finally {
            aResult.close();
        }
    }
    finally {
        aConn.close();
    }
}
 
開發者ID:semantalytics,項目名稱:stardog-plugin-string-similarity,代碼行數:32,代碼來源:TestLevenshtein.java


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