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


Java Query类代码示例

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


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

示例1: getLabel

import org.apache.jena.query.Query; //导入依赖的package包/类
/**
 * Return the label for this object in the selected language
 * @param language - the language for which the label is requested
 * @return - the label in the requested language.
 * @throws ModelException - thrown if there are multiple labels present for this object in this language
 */
public Label getLabel(Language language) throws ModelException {
	String sparql = "SELECT ?label WHERE { ?objectURI rdfs:label ?label . FILTER(LANG(?label) = STR(?labelLanguage)) }";
	ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
	parameterizedSparql.setCommandText(sparql);
	parameterizedSparql.setParam("objectURI", resource);
	parameterizedSparql.setParam("labelLanguage", model.createLiteral(language.getCode(), ""));
	
	Query query = QueryFactory.create(parameterizedSparql.asQuery());

	QueryExecution qexec = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = qexec.execSelect();
	
	if (!resultSet.hasNext()) return null;
	
	QuerySolution querySolution = resultSet.next();
	Label label = new Label(querySolution.getLiteral("label"));
	
	if (!resultSet.hasNext()) return label;
	
	throw new ModelException("%s has more than one label in language '%s'", resource.getURI(), language.getCode());
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:28,代码来源:ObjectWithURI.java

示例2: getCount

import org.apache.jena.query.Query; //导入依赖的package包/类
public static int getCount(String q, Model m) {
    Query query = QueryFactory.create(q);
    QueryExecution queryExec = QueryExecutionFactory.create(query, m);
    ResultSet rs = queryExec.execSelect();
    String vName = "";
    for (String v: rs.getResultVars()) {
        if (v.contains("count")) {
            vName = v;
            break;
        }
    }
    
    while (rs.hasNext()) {
        QuerySolution s = rs.nextSolution();
        Literal c = s.getLiteral(vName);
        queryExec.close();
        return c.getInt();
    }   
    queryExec.close();
    return 0;
}
 
开发者ID:albangaignard,项目名称:EDAMetrics,代码行数:22,代码来源:Queries.java

示例3: queryData

import org.apache.jena.query.Query; //导入依赖的package包/类
public static List<String> queryData(String query){
	Dataset db = TDBFactory.createDataset("temp/dataset");
	db.begin(ReadWrite.READ);
    Model model = db.getDefaultModel();
    Query q = QueryFactory.create(query);
    QueryExecution qexec = QueryExecutionFactory.create(query, model);
    ResultSet results = qexec.execSelect();
    List<String> answer = new ArrayList<String>();
    while(results.hasNext()){
    	QuerySolution t = results.nextSolution();
    	RDFNode x  = t.get("x");
    	String s = x.toString();
	System.out.println(s);
    	answer.add(s.substring(7));
    }
    qexec.close();
    db.close();
    return answer;
}
 
开发者ID:kunal15595,项目名称:smart-question-answering-nlp,代码行数:20,代码来源:Database.java

示例4: getQ

import org.apache.jena.query.Query; //导入依赖的package包/类
public Query getQ() {
    String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
            + "PREFIX owl: <http://www.w3.org/2002/07/owl#>"
            + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
            + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
            + "PREFIX iot: <http://IBCNServices.github.io/Accio-Ontology/SSNiot#>"
            + "PREFIX ssn: <http://IBCNServices.github.io/Accio-Ontology/ontologies/ssn#>"
            + "PREFIX dul: <http://IBCNServices.github.io/Accio-Ontology/ontologies/DUL.owl#>"
            + " SELECT * "
            + "	WHERE {"
            + "		?location a dul:Place."
            + "		?location dul:hasDataValue ?dataval."
            + "	}";
    Query query = org.apache.jena.query.QueryFactory.create(queryString);
    return query;
}
 
开发者ID:IBCNServices,项目名称:OBEP,代码行数:17,代码来源:OBEPQueryAbstracterTest.java

示例5: LocationMapperAccept

import org.apache.jena.query.Query; //导入依赖的package包/类
public LocationMapperAccept(final Model configurationModel) {
    Query q = QueryFactory.create("PREFIX lm: <http://jena.hpl.hp.com/2004/08/location-mapping#>"
            + "SELECT * WHERE {"
            + "[] lm:mapping ?e ."
            + "?e lm:name ?name ; lm:altName ?alt ."
            + "OPTIONAL { ?e lm:media ?media . } "
            + "}");
    QueryExecutionFactory.create(q, configurationModel).execSelect().forEachRemaining((result) -> {
        String name = null, altName = null, media = null;
        try {
            name = result.getLiteral("name").getString();
            altName = result.getLiteral("alt").getString();
            media = (result.getLiteral("media") == null ? null : result.getLiteral("media").getString());
            altLocations.put(new LookUpRequest(name, media), new LookUpRequest(altName, media));
        } catch (Exception ex) {
            log.warn("Error while reading mapping in configuration model for name " + name + ", alt " + altName + ", media " + media,ex);
        }
    });
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:20,代码来源:LocationMapperAccept.java

示例6: visitSelectResultForm

import org.apache.jena.query.Query; //导入依赖的package包/类
@Override
public void visitSelectResultForm(Query query) {
    if(query.isQueryResultStar()) {
        return;
    }
    final VarExprList project = query.getProject();
    final VarExprList newProject = new VarExprList();
    final ExprNormalizer enzer = new ExprNormalizer();
    project.getVars().forEach((var) -> {
        if(project.hasExpr(var)) {
            final Expr nzed = enzer.normalize(project.getExpr(var));
            newProject.add(var, nzed);
        } else {
            newProject.add(var);
        }
    });
    project.clear();
    project.addAll(newProject);
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:20,代码来源:QueryNormalizer.java

示例7: visitGroupBy

import org.apache.jena.query.Query; //导入依赖的package包/类
@Override
public void visitGroupBy(Query query) {
    if (query.hasGroupBy() && !query.getGroupBy().isEmpty()) {
        // Can have an empty GROUP BY list if the grouping is implicit
        // by use of an aggregate in the SELECT clause.
        final VarExprList namedExprs = query.getGroupBy();
        final VarExprList newNamedExprs = new VarExprList();
        final ExprNormalizer enzer = new ExprNormalizer();
        for (Var var : namedExprs.getVars()) {
            if(namedExprs.hasExpr(var)) {
                final Expr nzed = enzer.normalize(namedExprs.getExpr(var));
                newNamedExprs.add(var, nzed);
            } else {
                newNamedExprs.add(var);
            }
        }
        namedExprs.clear();
        namedExprs.addAll(newNamedExprs);
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:21,代码来源:QueryNormalizer.java

示例8: visitSelectResultForm

import org.apache.jena.query.Query; //导入依赖的package包/类
@Override
public void visitSelectResultForm(Query query) {
    out.print("SELECT ");
    if (query.isDistinct()) {
        out.print("DISTINCT ");
    }
    if (query.isReduced()) {
        out.print("REDUCED ");
    }
    out.print(" "); //Padding

    if (query.isQueryResultStar()) {
        out.print("*");
    } else {
        appendNamedExprList(query, out, query.getProject());
    }
    out.newline();
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:19,代码来源:SPARQLGenerateQuerySerializer.java

示例9: visitConstructResultForm

import org.apache.jena.query.Query; //导入依赖的package包/类
@Override
    public void visitConstructResultForm(Query query) {
        out.print("CONSTRUCT ");
//        if ( query.isQueryResultStar() )
//        {
//            out.print("*") ;
//            out.newline() ;
//        }
//        else
        {
            out.incIndent(BLOCK_INDENT);
            out.newline();
            Template t = query.getConstructTemplate();
            fmtTemplate.format(t);
            out.decIndent(BLOCK_INDENT);
        }
    }
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:18,代码来源:SPARQLGenerateQuerySerializer.java

示例10: visitDescribeResultForm

import org.apache.jena.query.Query; //导入依赖的package包/类
@Override
public void visitDescribeResultForm(Query query) {
    out.print("DESCRIBE ");

    if (query.isQueryResultStar()) {
        out.print("*");
    } else {
        appendVarList(query, out, query.getResultVars());
        if (query.getResultVars().size() > 0
                && query.getResultURIs().size() > 0) {
            out.print(" ");
        }
        appendURIList(query, out, query.getResultURIs());
    }
    out.newline();
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:17,代码来源:SPARQLGenerateQuerySerializer.java

示例11: SPARQLGenerateQuery

import org.apache.jena.query.Query; //导入依赖的package包/类
/**
 * Parses the query.
 * @param query
 * @param queryString
 * @return 
 */
@Override
protected Query parse$(final Query query, String queryString) {

    SPARQLGenerateQuery q = new SPARQLGenerateQuery();
    q.setSyntax(query.getSyntax());
    q.setResolver(query.getResolver());

    Action action = new Action() {
        @Override
        public void exec(SPARQLGenerateParser parser) throws Exception {
            parser.GenerateUnit();
        }
    };

    perform(q, queryString, action);
    validateParsedQuery(q);
    return q;
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:25,代码来源:ParserSPARQLGenerate.java

示例12: main

import org.apache.jena.query.Query; //导入依赖的package包/类
public static void main(String[] args) {
    String[] inputFileNames = args;

    Model model = loadRDF(inputFileNames);
    model.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");

    //read file into stream, try-with-resources
    try (Stream<String> prioryStream = Files.lines(Paths.get("./np.txt")); Stream<String> ignoreStream = Files.lines(Paths.get("./ignore.txt"))) {
        priories = prioryStream.collect(Collectors.toList());
        ignore = ignoreStream.collect(Collectors.toList());

        Set<Resource> roots = getRoots(model);

        roots.stream()
                .forEach((res) -> {
                    System.out.println("Generating query from " + res);
                    varId = 0;
                    Query query = randomWalk(model, res);
                    QueryDressing.countDistinctAll(query);
                    System.out.println(query);
                });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:xgfd,项目名称:ASPG,代码行数:26,代码来源:QueryGen.java

示例13: randomWalk

import org.apache.jena.query.Query; //导入依赖的package包/类
private static Query randomWalk(Model model, Resource node) {

//        Resource node = model.getResource(root);
        Set<Statement> numP = new HashSet();
        Set<Statement> nonNumP = new HashSet();

        System.out.println("Selecting statements...");
        walkNode(node, numP, nonNumP);

        System.out.println(numP);
        System.out.println(nonNumP);

        System.out.println("Converting to query...");
        Query query = toQuery(numP, nonNumP);
        return query;
    }
 
开发者ID:xgfd,项目名称:ASPG,代码行数:17,代码来源:QueryGen.java

示例14: createQueryExecution

import org.apache.jena.query.Query; //导入依赖的package包/类
public QueryExecution createQueryExecution(Query query, Dataset dataset, QuerySolution initialBinding) {
		if(!query.getGraphURIs().isEmpty() || !query.getNamedGraphURIs().isEmpty()) {
			dataset = new FromDataset(dataset, query);
		}
		
		if ( LOG_QUERIES ) {
		    // And the data - can be long.
//    		System.err.println("~~ ~~");
//    		RDFDataMgr.write(System.err, dataset.getDefaultModel(), Lang.TTL);
    		System.err.println("~~ ~~");
    		System.err.println(initialBinding);
    		System.err.println(query);
		}
		
		QueryExecution qexec = QueryExecutionFactoryFilter.get().create(query, dataset, initialBinding);
		adjustQueryExecution(qexec);
		return qexec;
	}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:19,代码来源:ARQFactory.java

示例15: createRemoteQueryExecution

import org.apache.jena.query.Query; //导入依赖的package包/类
public QueryEngineHTTP createRemoteQueryExecution(
		String service,
		Query query, 
		List<String> defaultGraphURIs, 
		List<String> namedGraphURIs, 
		String user, 
		String password) {
    HttpClient httpClient = buildHttpClient(service, user, password);
	QueryEngineHTTP qexec = (QueryEngineHTTP) QueryExecutionFactoryFilter.get().sparqlService(service, query, httpClient);
	if( defaultGraphURIs.size() > 0 ) {
		qexec.setDefaultGraphURIs(defaultGraphURIs);
	}
	if( namedGraphURIs.size() > 0 ) {
		qexec.setNamedGraphURIs(namedGraphURIs);
	}
	return qexec;
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:18,代码来源:ARQFactory.java


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