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


Java QuerySolution.get方法代码示例

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


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

示例1: getProperties

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
private static List<Pair<String, String>> getProperties(String uri) {
    List<Pair<String, String>> results = new ArrayList<>();
    String sparqlQuery = "select ?r ?y where {<" + uri + "> ?r ?y}";
    //System.out.println(sparqlQuery);
    QueryExecution e = QueryExecutionFactory.sparqlService(ENDPOINT, sparqlQuery);
    ResultSet rs = e.execSelect();
    while (rs.hasNext()) {
        QuerySolution nextSolution = rs.nextSolution();
        RDFNode ynode = nextSolution.get("y");
        if (ynode.isResource()) {
            results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getResource("y").getURI()));
        } else {
            results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getLiteral("y").getString().replaceAll("\\n+", " ")));
        }
    }
    e.close();
    return results;
}
 
开发者ID:swapUniba,项目名称:lodrecsys_eswc2017tutorial,代码行数:19,代码来源:DownloadLodProperties.java

示例2: getResultSetAsStringList

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
static List<String> getResultSetAsStringList(ResultSet resultSet, String variableName, boolean literalRequired) {
    List<String> resultStrings = new ArrayList<>();
    RDFNode node;
    if (resultSet != null) {
        while (resultSet.hasNext()) {
            QuerySolution result = resultSet.next();
            if (result != null) {
                node = result.get(variableName);
                if (literalRequired) {
                    String literal = getStringLiteral(node);
                    if (literal != null) {
                        resultStrings.add(literal);
                    }
                } else {
                    if (node != null) {
                        resultStrings.add(node.toString());
                    }
                }
            }
        }
    }
    return resultStrings;
}
 
开发者ID:slidewiki,项目名称:auto-questions-service,代码行数:24,代码来源:QueryUtils.java

示例3: queryData

import org.apache.jena.query.QuerySolution; //导入方法依赖的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: BindingHashMapOverwrite

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
     * Constructs a new binding from a query solution.
     *
     * @param binding -
     */
    public BindingHashMapOverwrite(final QuerySolution binding) {
        var = null;
        node = null;
        if (binding == null) {
            parent = null;
        } else {
            final BindingHashMap p = new BindingHashMap();
            for (Iterator<String> it = binding.varNames(); it.hasNext();) {
                final String varName = it.next();
                if (binding.get(varName) != null) {
                    p.add(Var.alloc(varName), binding.get(varName).asNode());
                }
            }
            parent = p;
        }
//        LOG.trace("New binding #" + System.identityHashCode(this) + " copies " + binding);
    }
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:23,代码来源:BindingHashMapOverwrite.java

示例5: asBinding

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * Turns a QuerySolution into a Binding. 
 * @param map  the input QuerySolution
 * @return a Binding or null if the input is null
 */
public static Binding asBinding(final QuerySolution map) {
	if(map != null) {
		BindingHashMap result = new BindingHashMap();
		Iterator<String> varNames = map.varNames();
		while(varNames.hasNext()) {
			String varName = varNames.next();
			RDFNode node = map.get(varName);
			if(node != null) {
				result.add(Var.alloc(varName), node.asNode());
			}
		}
		return result;
	}
	else {
		return null;
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:23,代码来源:JenaUtil.java

示例6: invokeExpression

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * Calls a SPARQL expression and returns the result, using some initial bindings.
 *
 * @param expression     the expression to execute (must contain absolute URIs)
 * @param initialBinding the initial bindings for the unbound variables
 * @param dataset        the query Dataset or null for default
 * @return the result or null
 */
public static Node invokeExpression(String expression, QuerySolution initialBinding, Dataset dataset) {
    if (dataset == null) {
        dataset = ARQFactory.get().getDataset(ModelFactory.createDefaultModel());
    }
    Query query = ARQFactory.get().createExpressionQuery(expression);
    try(QueryExecution qexec = ARQFactory.get().createQueryExecution(query, dataset, initialBinding)) {
        ResultSet rs = qexec.execSelect();
        Node result = null;
        if (rs.hasNext()) {
            QuerySolution qs = rs.next();
            String firstVarName = rs.getResultVars().get(0);
            RDFNode rdfNode = qs.get(firstVarName);
            if (rdfNode != null) {
                result = rdfNode.asNode();
            }
        }
        return result;
    }
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:28,代码来源:JenaUtil.java

示例7: executeBody

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
@Override
   public NodeValue executeBody(Dataset dataset, Model defaultModel, QuerySolution bindings) {
    try( QueryExecution qexec = createQueryExecution(dataset, defaultModel, bindings) ) {
        if(arqQuery.isAskType()) {
            boolean result = qexec.execAsk();
            return NodeValue.makeBoolean(result);
        }
        else {
            ResultSet rs = qexec.execSelect();
            if(rs.hasNext()) {
                QuerySolution s = rs.nextSolution();
                List<String> resultVars = rs.getResultVars();
                String varName = resultVars.get(0);
                RDFNode resultNode = s.get(varName);
                if(resultNode != null) {
                    return NodeValue.makeNode(resultNode.asNode());
                }
            }
            throw new ExprEvalException("Empty result set for SHACL function");
        }
    }
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:23,代码来源:SHACLSPARQLARQFunction.java

示例8: invokeFunction

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
@Override
public Object invokeFunction(String functionName, QuerySolution bindings) throws javax.script.ScriptException, java.lang.NoSuchMethodException {
	List<String> functionParams = getFunctionParameters(functionName);
	Object[] params = new Object[functionParams.size()];
	Iterator<String> varNames = bindings.varNames();
	while(varNames.hasNext()) {
		String varName = varNames.next();
		int index = functionParams.indexOf(varName);
		if(index < 0) {
			index = functionParams.indexOf("$" + varName);
		}
		if(index >= 0) {
			RDFNode value = bindings.get(varName);
			if(value != null) {
				params[index] = JSFactory.asJSTerm(value.asNode());
			}
		}
	}
	return invokeFunctionOrdered(functionName, params);
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:21,代码来源:NashornScriptEngine.java

示例9: next

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
@Override
public Quad next() {
    QuerySolution solution = results.next();
    Node s = solution.get("s").asNode();
    Node p = solution.get("p").asNode();
    Node o = solution.get("o").asNode();
    Node g = null;
    if (solution.get("g") != null) {
        g = solution.get("g").asNode();
    } else {
        if (graphName != null) {
            g = NodeFactory.createURI(graphName);
        }
    }
    Quad quad = new Quad(g, s, p, o);
    return quad;
}
 
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:18,代码来源:QuadsIterator.java

示例10: execSelect

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
private void execSelect(QueryExecution exec) {
	ResultSet res = exec.execSelect();
	header = res.getResultVars();
	results = new LinkedList<List<String>>();
	while (res.hasNext()) {
		List<String> row = new LinkedList<String>();
		QuerySolution solution = res.next();
		for (String var : header) {
			RDFNode node = solution.get(var);
			if(node.isResource()) {
				row.add("<"+node.toString()+">");
			}
			else {
				row.add(node.asNode().toString(true));
			}
		}
		results.add(row);
	}
	isCD=false;
	isSelect = true;
}
 
开发者ID:dice-group,项目名称:IGUANA,代码行数:22,代码来源:SparqlController.java

示例11: MultiSetScorer

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public MultiSetScorer(ComponentProperty property, Function<RDFNode,Set<String>> f)
{
	super(property);
	ResultSet rs = queryValues();
	while(rs.hasNext())
	{
		QuerySolution qs = rs.next();
		RDFNode node = qs.get("value");
		f.apply(node).forEach(s->
		{
			//				valueToNode.put(s, node);
			values.add(s, qs.get("cnt").asLiteral().getInt());
		});
	}

	Optional<Integer> max = values.elementSet().stream().map(s->values.count(s)).max(Integer::compare);
	if(!max.isPresent())
	{
		log.warn("no values for property "+property+": "+values);
		maxCount=0;
	}
	else
	{
		maxCount = max.get();
	}
}
 
开发者ID:AskNowQA,项目名称:cubeqa,代码行数:27,代码来源:MultiSetScorer.java

示例12: getClasses

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public static List<String> getClasses(Model m){
	List<String> classNames = new ArrayList<String>();
	String sparqlQueryString= "select distinct ?class where {?s a ?class}";
	QueryExecution qexec = QueryExecutionFactory.create(sparqlQueryString, m);
	ResultSet results = qexec.execSelect();
	
	while (results.hasNext()) {
	    QuerySolution row = results.next();
	    RDFNode className = row.get("class");
	    if(!nameSpace.equals("")){
	    	if(!className.toString().startsWith(nameSpace)) continue;
	    }
	    classNames.add(className.toString());
	}
	return classNames;
}
 
开发者ID:dice-group,项目名称:LASSIE,代码行数:17,代码来源:Modifier.java

示例13: getVRankOfResource

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
static float getVRankOfResource(String uri) {
    uri = "<" + uri + ">";
    String var = "v";
    String queryString = Constants.PREFIX_VRANK +
            "SELECT ?" + var + "\n" +
            "FROM <http://dbpedia.org> \n" +
            "FROM <http://people.aifb.kit.edu/ath/#DBpedia_PageRank> \n" +
            "WHERE {\n" +
            uri + " vrank:hasRank/vrank:rankValue ?" + var + ".\n" +
            "}\n";

    try {
        ResultSet results = SPARQLClient.runSelectQuery(queryString, Constants.DBPEDIA_SPARQL_SERVICE);
        if (results != null) {
            while (results.hasNext()) {
                QuerySolution result = results.next();
                RDFNode vRank = result.get(var);
                if (vRank != null && vRank.isLiteral()) {
                    Literal literal = (Literal) vRank;
                    return (literal.getFloat());
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
 
开发者ID:slidewiki,项目名称:auto-questions-service,代码行数:29,代码来源:QueryUtils.java

示例14: getResultSetAsObjectList

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
static List<LinkSUMResultRow> getResultSetAsObjectList(ResultSet resultSet) {
    List<LinkSUMResultRow> rows = new ArrayList<>();
    String subject = "subject";
    String predicate = "pred";
    String object = "object";
    String subLabel = "sublabel";
    String predLabel = "predlabel";
    String obLabel = "oblabel";
    String vRank = "v";

    if (resultSet != null) {
        while (resultSet.hasNext()) {
            QuerySolution result = resultSet.next();
            LinkSUMResultRow.LinkSUMResultRowBuilder builder = LinkSUMResultRow.builder();
            if (result != null) {
                RDFNode subjectNode = result.get(subject);
                RDFNode predicateNode = result.get(predicate);
                RDFNode objectNode = result.get(object);
                builder
                        .subject(subjectNode != null ? subjectNode.toString() : null)
                        .predicate(predicateNode != null ? predicateNode.toString() : null)
                        .object(objectNode != null ? objectNode.toString() : null)
                        .subjectLabel(getStringLiteral(result.get(subLabel)))
                        .predicateLabel(getStringLiteral(result.get(predLabel)))
                        .objectLabel(getStringLiteral(result.get(obLabel)));
                RDFNode vRankNode = result.get(vRank);
                if (vRankNode != null && vRankNode.isLiteral()) {
                    Literal literal = (Literal) vRankNode;
                    builder.vRank(literal.getFloat());
                }
                rows.add(builder.build());
            }
        }
    }
    return rows;
}
 
开发者ID:slidewiki,项目名称:auto-questions-service,代码行数:37,代码来源:QueryUtils.java

示例15: addResultsToList

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
static void addResultsToList(ResultSet results, List<String> resources, String var) {
    if (results != null) {
        while (results.hasNext()) {
            QuerySolution result = results.next();
            if (result != null) {
                RDFNode n = result.get(var);
                String nameLiteral;
                if (n.isLiteral()) {
                    nameLiteral = ((Literal) n).getLexicalForm();
                    resources.add(nameLiteral);
                }
            }
        }
    }
}
 
开发者ID:slidewiki,项目名称:auto-questions-service,代码行数:16,代码来源:QueryUtils.java


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