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


Java ParsedQuery类代码示例

本文整理汇总了Java中org.openrdf.query.parser.ParsedQuery的典型用法代码示例。如果您正苦于以下问题:Java ParsedQuery类的具体用法?Java ParsedQuery怎么用?Java ParsedQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: reformulateSPARQL2

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
public List<SQLWithVarMap> reformulateSPARQL2(String sparqlQuery) throws OWLException, OBDAException, MalformedQueryException {

		QuestQueryProcessor qqueryProcessor = this.getQueryProcessor();

		//parse the given SPARQL query
		ParsedQuery parsedSparql = qqueryProcessor.getParsedQuery(sparqlQuery);
		
		//applying the reformulation algorithm to the parsed SPARQL query, 
		//the resulting reformulated query is in the form of DatalogProgram
		DatalogProgram reformulatedQuery = qqueryProcessor.reformulateSPARQL(parsedSparql);
		List<String> qs = qqueryProcessor.getQuerySignature(parsedSparql);

		
		if(qs == null)
			throw new OBDAException("\nA problem occurred while reformulating the query: \n\n"+
				sparqlQuery+"\n\nthe signature of the reformulated query can't be obtained. Please check the Ontop configuration.\n");
		
		//translate the reformulated query (which is in the form of DatalogProgram) into (a list of) SQL
		return this.sqlGeneratorExt.generateSourceQueries(reformulatedQuery, qs);
	}
 
开发者ID:onprom,项目名称:onprom,代码行数:21,代码来源:QuestOWLReasonerExt.java

示例2: rewrite

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
/**
 * Rewrite a given query to add inference.
 *
 * @param ql the query language used for the query
 * @param query the query to rewrite
 * @param baseuri a base URI to use for the query
 * @return rewritten query that includes inference
 * @throws MalformedQueryException if the query is malformed
 * @throws RepositoryException if there was a problem while rewriting
 */
public Query rewrite(QueryLanguage ql, String query, String baseuri)
		throws MalformedQueryException, RepositoryException {
	// parse query using Sesame
	QueryParserFactory f = QueryParserRegistry.getInstance().get(ql);
	QueryParser parser = f.getParser();
	ParsedQuery parsed = parser.parseQuery(query, baseuri);
	// get SPARQL algebra expression from parsed query
	TupleExpr expr = parsed.getTupleExpr();
	// rewrite query using visitor pattern
	RuleTransformationVisitor visitor
			= new RuleTransformationVisitor(rules);
	expr.visit(visitor);
	// return new query based on rewritten algebra expression
	return getExprQuery(parsed, expr);
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:26,代码来源:QueryRewriter.java

示例3: testReOrderedBasicOptional

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
@Test
	public void testReOrderedBasicOptional() throws MalformedQueryException {

		String query = ""//
				+ "SELECT ?e ?c ?l" //
				+ "{" //
				+ "  ?e a ?c . "//
				+ "  OPTIONAL{?e <uri:talksTo> ?l } . "//
				+ "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
				+ "}";//

		SPARQLParser parser = new SPARQLParser();
		ParsedQuery pq = parser.parseQuery(query, null);
		System.out.println(pq.getTupleExpr());
		List<TupleExpr> joinArgs = getJoinArgs(pq.getTupleExpr(),
				new ArrayList<TupleExpr>());
//		System.out.println(joinArgs);
		FlattenedOptional optional = (FlattenedOptional) joinArgs.get(0);
		TupleExpr sp1 = joinArgs.get(1);
		TupleExpr sp2 = joinArgs.get(2);

		Assert.assertEquals(false, optional.canRemoveTuple(sp1));
		Assert.assertEquals(false, optional.canAddTuple(sp2));


	}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:27,代码来源:FlattenedOptionalTest.java

示例4: evaluate

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
private void evaluate(QueryType type, ParsedQuery query,
		TupleQueryResultHandler handler) {
	if (type.equals(QueryType.SENSOR_OBSERVATION)) {
		evaluate(query, QueryFactory.createSensorObservationQuery(query),
				handler);
		return;
	}
	if (type.equals(QueryType.DATASET_OBSERVATION)) {
		evaluate(query, QueryFactory.createDatasetObservationQuery(query),
				handler);
		return;
	}

	if (log.isLoggable(Level.SEVERE))
		log.severe("Failed to deterine observation query type, sensor or dataset [query = "
				+ query + "]");
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:18,代码来源:Emrooz.java

示例5: testStatementPatternContextVar

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
public void testStatementPatternContextVar() throws Exception {
        String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
                " PREFIX ub: <urn:lubm:rdfts#>\n" +
                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
                " SELECT * WHERE\n" +
                " {\n" +
                " GRAPH ?g {\n" +
                "\t?x rdf:type ub:UndergraduateStudent\n" +
                " }\n" +
                " ?x ub:pred ?g." +
                " }\n" +
                "";
        QueryParser parser = new SPARQLParser();
        ParsedQuery parsedQuery = parser.parseQuery(query, null);

//        System.out.println(parsedQuery);

        SparqlToPigTransformVisitor visitor = new SparqlToPigTransformVisitor();
        visitor.setTablePrefix(tablePrefix);
        visitor.setInstance(instance);
        visitor.setZk(zk);
        visitor.setUser(user);
        visitor.setPassword(password);
        visitor.meet(new QueryRoot(parsedQuery.getTupleExpr()));
//        System.out.println(visitor.getPigScript());
    }
 
开发者ID:apache,项目名称:incubator-rya,代码行数:27,代码来源:SparqlToPigTransformVisitorTest.java

示例6: getQueryTask

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
public QueryTask getQueryTask(QueryDefinition query,
			WriterConfig config, OutputStream out)
			throws MalformedQueryException, RepositoryException {
		QueryParser parser = new SPARQLParserFactory().getParser();
		ParsedQuery parsedQuery = parser.parseQuery(query.getQuery(),
				config.getBaseUri());
		RepositoryConnection conn = cf.getConnection();
		try {
			if (parsedQuery instanceof ParsedTupleQuery) {
				return new TupleQueryTask(conn, query, config, out);
			} else if (parsedQuery instanceof ParsedBooleanQuery) {
				return new AskQueryTask(conn, query, config, out);
			} else if (parsedQuery instanceof ParsedGraphQuery) {
				return new GraphQueryTask(conn, query, config, out);
			}			
		} finally {
//			conn.close();
		}
		throw new MalformedQueryException("Unknown query type: "
				+ ParsedQuery.class.getName());
	}
 
开发者ID:erfgoed-en-locatie,项目名称:artsholland-platform,代码行数:22,代码来源:QueryService.java

示例7: testMutlipleJoins

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
public void testMutlipleJoins() throws Exception {
        String query = "select * where {\n" +
                "?subj <urn:lubm:rdfts#name> 'Department0'.\n" +
                "?subj <urn:lubm:rdfts#subOrganizationOf> <http://www.University0.edu>.\n" +
                "?subj <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <urn:lubm:rdfts#Department>.\n" +
                "}";
//        System.out.println(query);
        QueryParser parser = new SPARQLParser();
        ParsedQuery parsedQuery = parser.parseQuery(query, null);

//        System.out.println(parsedQuery);

        SparqlToPigTransformVisitor visitor = new SparqlToPigTransformVisitor();
        visitor.setTablePrefix(tablePrefix);
        visitor.setInstance(instance);
        visitor.setZk(zk);
        visitor.setUser(user);
        visitor.setPassword(password);
        visitor.meet(new QueryRoot(parsedQuery.getTupleExpr()));
//        System.out.println(visitor.getPigScript());
    }
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:SparqlToPigTransformVisitorTest.java

示例8: testSelectQuery

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
@Test
public void testSelectQuery() throws Exception {
    String text = "PREFIX foaf: <" + FOAF.NAMESPACE + ">\n"
            + "SELECT * WHERE {\n"
            + "  ?x a foaf:Person .\n"
            + "  ?y a foaf:Person .\n"
            + "  ?x foaf:knows ?y .\n"
            + "}";
    ParsedQuery query = new SPARQLParser().parseQuery(text, null);
    AntecedentVisitor visitor = new AntecedentVisitor();
    query.getTupleExpr().visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(
            new StatementPattern(new Var("x"), c(RDF.TYPE), c(FOAF.PERSON)),
            new StatementPattern(new Var("y"), c(RDF.TYPE), c(FOAF.PERSON)),
            new StatementPattern(new Var("x"), c(FOAF.KNOWS), new Var("y")));
    Assert.assertEquals(expected, visitor.getAntecedents());
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:18,代码来源:AntecedentVisitorTest.java

示例9: testPeriodicNodePlacement

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
@Test
public void testPeriodicNodePlacement() throws MalformedQueryException {
     String query = "prefix function: <http://org.apache.rya/function#> " //n
            + "prefix time: <http://www.w3.org/2006/time#> " //n
            + "prefix fn: <http://www.w3.org/2006/fn#> " //n
            + "select ?obs ?time ?lat where {" //n
            + "Filter(function:periodic(?time, 12.0, 6.0,time:hours)) " //n
            + "Filter(fn:test(?lat, 25)) " //n
            + "?obs <uri:hasTime> ?time. " //n
            + "?obs <uri:hasLattitude> ?lat }"; //n
     
     SPARQLParser parser = new SPARQLParser();
     ParsedQuery pq = parser.parseQuery(query, null);
     TupleExpr te = pq.getTupleExpr();
     te.visit(new PeriodicQueryNodeVisitor());
     
     PeriodicNodeCollector collector = new PeriodicNodeCollector();
     te.visit(collector);
     
     PeriodicQueryNode node2 = new PeriodicQueryNode(12*60*60*1000L, 6*3600*1000L, TimeUnit.MILLISECONDS, "time", new Join());

     Assert.assertEquals(true, periodicNodesEqualIgnoreArg(node2, collector.getPeriodicQueryNode()));
     
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:25,代码来源:PeriodicQueryUtilTest.java

示例10: testConstructProjectionBNodes

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
@Test
public void testConstructProjectionBNodes() throws MalformedQueryException {
    String query = "select ?o where { _:b <uri:talksTo> ?o }";
    
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructProjection projection = new ConstructProjection(patterns.get(0));
    
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("o", vf.createURI("uri:Bob"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
    BNode bNode = vf.createBNode();
    Map<String, BNode> bNodeMap = new HashMap<>();
    bNodeMap.put("-anon-1", bNode);
    RyaStatement statement = projection.projectBindingSet(vBs,bNodeMap);
    
    RyaStatement expected = new RyaStatement(RdfToRyaConversions.convertResource(bNode), new RyaURI("uri:talksTo"), new RyaURI("uri:Bob"));
    expected.setTimestamp(statement.getTimestamp());
    expected.setColumnVisibility(new byte[0]);
    
    assertEquals(expected, statement);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:ConstructProjectionTest.java

示例11: testConstructGraph

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
@Test
public void testConstructGraph() throws MalformedQueryException, UnsupportedEncodingException {
    String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }";

    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructGraph graph = new ConstructGraph(patterns);

    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("x", vf.createURI("uri:Joe"));
    bs.addBinding("y", vf.createURI("uri:Bob"));
    bs.addBinding("z", vf.createURI("uri:BurgerShack"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs,"FOUO");
    Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
    
    RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaURI("uri:Bob"));
    RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Bob"), new RyaURI("uri:worksAt"), new RyaURI("uri:BurgerShack"));
    Set<RyaStatement> expected = Sets.newHashSet(Arrays.asList(statement1, statement2));
    expected.forEach(x-> x.setColumnVisibility("FOUO".getBytes()));
    ConstructGraphTestUtils.ryaStatementSetsEqualIgnoresTimestamp(expected, statements);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:23,代码来源:ConstructGraphTest.java

示例12: queryDocIndex

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
public CloseableIteration<BindingSet, QueryEvaluationException> queryDocIndex(final String sparqlQuery,
        final Collection<BindingSet> constraints) throws TableNotFoundException, QueryEvaluationException {

    final SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    try {
        pq1 = parser.parseQuery(sparqlQuery, null);
    } catch (final MalformedQueryException e) {
        e.printStackTrace();
        throw new QueryEvaluationException("Malformed query. query=" + sparqlQuery, e);
    }

    final TupleExpr te1 = pq1.getTupleExpr();
    final List<StatementPattern> spList1 = StatementPatternCollector.process(te1);

    if(StarQuery.isValidStarQuery(spList1)) {
        final StarQuery sq1 = new StarQuery(spList1);
        return queryDocIndex(sq1, constraints);
    } else {
        throw new IllegalArgumentException("Invalid star query!");
    }

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:AccumuloDocIdIndexer.java

示例13: testConstantGraph

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
@Test
public void testConstantGraph() throws Exception {

	SPARQLParser parser1 = new SPARQLParser();
	SPARQLParser parser2 = new SPARQLParser();

	ParsedQuery pq1 = parser1.parseQuery(q20, null);
	ParsedQuery pq2 = parser2.parseQuery(q21, null);

	List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
			pq2.getTupleExpr());

	Assert.assertTrue(normalize.size() == 1);
	for (TupleExpr s : normalize) {
		Assert.assertTrue(tupleEquals(s, pq1.getTupleExpr()));
	}

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:19,代码来源:QueryVariableNormalizerTest.java

示例14: testBasicOptional

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
@Test
	public void testBasicOptional() throws MalformedQueryException {

		String query = ""//
				+ "SELECT ?e ?c ?l" //
				+ "{" //
				+ "  ?e a ?c . "//
				+ "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
				+ "  OPTIONAL{?e <uri:talksTo> ?l } . "//
				+ "}";//

		SPARQLParser parser = new SPARQLParser();
		ParsedQuery pq = parser.parseQuery(query, null);
		List<TupleExpr> joinArgs = getJoinArgs(pq.getTupleExpr(),
				new ArrayList<TupleExpr>());
		FlattenedOptional optional = (FlattenedOptional) joinArgs.get(0);
		TupleExpr sp1 = joinArgs.get(1);
		TupleExpr sp2 = joinArgs.get(2);

		Assert.assertEquals(false, optional.canRemoveTuple(sp2));
		Assert.assertEquals(true, optional.canRemoveTuple(sp1));
//		System.out.println(joinArgs);

	}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:25,代码来源:FlattenedOptionalTest.java

示例15: SesameQueryHandler

import org.openrdf.query.parser.ParsedQuery; //导入依赖的package包/类
public SesameQueryHandler(QueryHandler<Statement> other, ParsedQuery query) {
	if (other == null)
		throw new RuntimeException("[other = null]");
	if (query == null)
		throw new RuntimeException("[query = null]");

	this.other = other;
	this.query = query;

	try {
		this.repo = new SailRepository(new MemoryStore());
		this.repo.initialize();
		this.conn = repo.getConnection();
	} catch (RepositoryException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:18,代码来源:SesameQueryHandler.java


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