本文整理汇总了Java中org.apache.jena.sparql.core.Var.alloc方法的典型用法代码示例。如果您正苦于以下问题:Java Var.alloc方法的具体用法?Java Var.alloc怎么用?Java Var.alloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.sparql.core.Var
的用法示例。
在下文中一共展示了Var.alloc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solutions
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private static Solution solutions(Rel rel, Solution input, Rel match) {
Solution soln = new Solution(input);
int N = rel.getTuple().len();
for(int i = 0 ; i < N ;i++ ) {
Node x = rel.getTuple().get(i);
Node z = match.getTuple().get(i);
if ( Var.isVar(x) ) {
Var v = Var.alloc(x);
if ( soln.containsKey(v) ) {
// Binding exists
Node node = soln.get(v);
if ( !Objects.equals(x, z) )
// kill
return null ;
// else leave as-is
} else
soln.put(v, match.getTuple().get(i));
}
}
return soln;
}
示例2: getStringAttributeQuery
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
public static String getStringAttributeQuery(StringAttribute name, UMLClass relatedClass, Set<DiagramShape> casePath) {
try {
//create select builder
SelectBuilder builder = new SelectBuilder();
//builder.setDistinct(true);
final Var classVar = Var.alloc(relatedClass.getCleanName());
final String classIRI = "<" + relatedClass.getLongName() + ">";
final Var nameVar = Var.alloc("n");
// add class variable
builder.addVar(classVar);
if (casePath != null) {
addJoin(builder, casePath);
} else {
builder.addWhere(classVar, "a", classIRI);
}
if (name.getAttribute() == null) {
//add name variable
builder.addVar("\"" + name.getValue() + "\"", nameVar);
return builder.toString();
} else {
//add name variable
builder.addVar(nameVar);
// add path to the name
addJoin(builder, name.getPath());
//add attribute
builder.addWhere("?" + name.getUmlClass().getCleanName(), "<" + name.getAttribute().getLongName() + ">", nameVar);
//we only add filter if it is a dynamic value
if (name.getFilterClause() != null && !name.getFilterClause().isEmpty()) {
//add filter clause to the query
builder.addFilter(name.getFilterClause().replaceAll("%1", "?n"));
}
return builder.toString();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
InformationDialog.display(e.toString());
return "ERROR: QUERY IS NOT GENERATED (" + e.getMessage() + ")";
}
}
示例3: getAttributeQuery
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private static AnnotationQuery getAttributeQuery(AnnotationAttribute attribute) {
//TODO IS-A relationships?
try {
SelectBuilder builder = new SelectBuilder();
//builder.setDistinct(true);
//definitions
final StringAttribute value = attribute.getValue();
final UMLClass valueClass = value.getUmlClass();
final Var classVar = Var.alloc(valueClass.getCleanName());
//answer variables
final Var nameVar = Var.alloc("n");
final Var valueVar = Var.alloc("v");
builder.addVar("\"" + attribute.getName() + "\"", nameVar);
builder.addVar(valueVar);
//where clauses
builder.addWhere(classVar, "a", "<" + valueClass.getLongName() + ">");
// add path of the value
addJoin(builder, value.getPath());
//add attribute
builder.addWhere(classVar, "<" + value.getAttribute().getLongName() + ">", valueVar);
//we only add filter if it is a dynamic value
if (value.getFilterClause() != null && !value.getFilterClause().isEmpty()) {
//add filter clause to the query
builder.addFilter(value.getFilterClause().replaceAll("%1", "?v"));
}
return new AnnotationQuery(builder.toString(), "n", "v");
} catch (Exception e) {
logger.error(e.getMessage(), e);
InformationDialog.display(e.toString());
return new AnnotationQuery("ERROR: QUERY IS NOT GENERATED (" + e.getMessage() + ")", "n", "v");
}
}
示例4: visit
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
@Override
public void visit(ExprVar nv) {
String s = nv.getVarName();
if (Var.isBlankNodeVarName(s)) {
// Return to a bNode via the bNode mapping of a variable.
Var v = Var.alloc(s);
out.print(context.getBNodeMap().asString(v));
} else {
// Print in variable form or as an aggregator expression
out.print(nv.asSparqlExpr());
}
}
示例5: appendVarList
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
void appendVarList(Query query, IndentedWriter sb, List<String> vars) {
boolean first = true;
for (String varName : vars) {
Var var = Var.alloc(varName);
if (!first) {
sb.print(" ");
}
sb.print(var.toString());
first = false;
}
}
示例6: resToNode
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private static Node resToNode(Resource r, boolean toVar) {
Node n;
if (toVar) {
String name = r.getLocalName();
if (r.getURI().contains(xsd)) {
name += varId++;
}
n = Var.alloc(name);
} else {
n = NodeFactory.createURI(r.getURI());
}
return n;
}
示例7: evidencesForFacts
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
/**
* Given a set of triples extracted/generated from the result/answer of query gpad-basic.rq, we find matching evidence subgraphs.
* In other words, if there are no matching evidence (i.e. no bindings for evidence_type), we discard (basic) GPAD instance.
*
* The parameter "facts" consists of triples <?subject, ?predicate, ?object> constructed from a binding of ?pr, ?rel, ?target in gpad_basic.rq.
* (The codes that constructing these triples are executed right before this method is called).
*
* These triples are then decomposed into values used as the parameters/bindings for objects of the following patterns.
* ?axiom owl:annotatedSource ?subject (i.e. ?pr in gpad_basic.rq)
* ?axiom owl:annotatedProperty ?predicate (i.e., ?rel in gpad_basic.rq, which denotes qualifier in GPAD)
* ?axiom owl:annotatedTarget ?object (i.e., ?target in gpad_basic.rq)
*
* If we find the bindings of ?axioms and the values of these bindings have some rdf:type triples, we proceed. (If not, we discard).
* The bindings of the query gpad-relation-evidence-multiple.rq are then used for filling up fields in GPAD records/tuples.
*/
private Map<Triple, Set<GPADEvidence>> evidencesForFacts(Set<Triple> facts, Model model, String modelID) {
Query query = QueryFactory.create(multipleEvidenceQuery);
Var subject = Var.alloc("subject");
Var predicate = Var.alloc("predicate");
Var object = Var.alloc("object");
List<Var> variables = new ArrayList<>();
variables.add(subject);
variables.add(predicate);
variables.add(object);
Stream<Binding> bindings = facts.stream().map(f -> createBinding(Pair.of(subject, f.getSubject()), Pair.of(predicate, f.getPredicate()), Pair.of(object, f.getObject())));
query.setValuesDataBlock(variables, bindings.collect(Collectors.toList()));
QueryExecution evidenceExecution = QueryExecutionFactory.create(query, model);
ResultSet evidenceResults = evidenceExecution.execSelect();
Map<Triple, Set<GPADEvidence>> allEvidences = facts.stream().collect(Collectors.toMap(Function.identity(), f -> new HashSet<GPADEvidence>()));
while (evidenceResults.hasNext()) {
QuerySolution eqs = evidenceResults.next();
if (eqs.get("evidence_type") != null) {
Triple statement = Triple.create(eqs.getResource("subject").asNode(), eqs.getResource("predicate").asNode(), eqs.getResource("object").asNode());
IRI evidenceType = IRI.create(eqs.getResource("evidence_type").getURI());
Optional<String> with = Optional.ofNullable(eqs.getLiteral("with")).map(l -> l.getLexicalForm());
Set<Pair<String, String>> annotationAnnotations = new HashSet<>();
annotationAnnotations.add(Pair.of("noctua-model-id", modelID));
annotationAnnotations.addAll(getContributors(eqs).stream().map(c -> Pair.of("contributor", c)).collect(Collectors.toSet()));
String date = eqs.getLiteral("date").getLexicalForm();
String reference = eqs.getLiteral("source").getLexicalForm();
allEvidences.get(statement).add(new GPADEvidence(evidenceType, reference, with, date, "GO_Noctua", annotationAnnotations, Optional.empty()));
}
}
evidenceExecution.close();
return allEvidences;
}
示例8: toVar
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private Var toVar(String s) {
if (s == null)
return null;
s = s.trim().replace(" ", "_").replace("-", "_").replace("?", "_").replace("%", "_").replace("(", "_").replace(")", "_");
if ("".equals(s))
return null;
// FIXME: Handle other characters not allowed in Vars
return Var.alloc(s);
}
示例9: getVar
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private Var getVar(int column) {
if (vars.size() < column) {
getVar(column - 1);
}
if (vars.size() == column) {
Var var = Var.alloc(getColumnName(column));
while (vars.contains(var)) {
var = Var.alloc("_" + var.getName());
}
vars.add(var);
}
return vars.get(column);
}
示例10: execVarVar
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private QueryIterator execVarVar(Binding binding, Table table, Node subject, Node object,ExecutionContext execCxt) {
Iterator<Entry<Node,Node>> iter = table.subj2obj.entries().iterator() ;
return new QueryIterExtendByVar2(binding, Var.alloc(subject), Var.alloc(object), iter, execCxt) ;
}
示例11: execVarTerm
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private QueryIterator execVarTerm(Binding binding, Table table, Node subject, Node object,ExecutionContext execCxt) {
Collection<Node> x = table.obj2subj.get(object) ;
return new QueryIterExtendByVar(binding, Var.alloc(subject), x.iterator(), execCxt) ;
}
示例12: execTermVar
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private QueryIterator execTermVar(Binding binding, Table table, Node subject, Node object,ExecutionContext execCxt) {
Collection<Node> x = table.subj2obj.get(subject) ;
return new QueryIterExtendByVar(binding, Var.alloc(object), x.iterator(), execCxt) ;
}
示例13: main
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
public static void main (String[] argv)
{
String BASE = "http://example/" ;
BasicPattern bp = new BasicPattern() ;
Var var_x = Var.alloc("x") ;
Var var_z = Var.alloc("z") ;
// ---- Build expression
bp.add(new Triple(var_x, NodeFactory.createURI(BASE+"p"), var_z)) ;
Op op = new OpBGP(bp) ;
//Expr expr = ExprUtils.parse("?z < 2 ") ;
Expr expr = new E_LessThan(new ExprVar(var_z), NodeValue.makeNodeInteger(2)) ;
op = OpFilter.filter(expr, op) ;
// ---- Example setup
Model m = makeModel() ;
m.write(System.out, "TTL") ;
System.out.println("--------------") ;
System.out.print(op) ;
System.out.println("--------------") ;
// ---- Execute expression
QueryIterator qIter = Algebra.exec(op, m.getGraph()) ;
// -------- Either read the query iterator directly ...
if ( false )
{
for ( ; qIter.hasNext() ; )
{
Binding b = qIter.nextBinding() ;
Node n = b.get(var_x) ;
System.out.println(NodeFmtLib.displayStr(n)) ;
System.out.println(b) ;
}
qIter.close() ;
}
else
{
// -------- Or make ResultSet from it (but not both - reading an
// iterator consumes the current solution)
List<String> varNames = new ArrayList<String>() ;
varNames.add("x") ;
varNames.add("z") ;
ResultSet rs = new ResultSetStream(varNames, m, qIter);
ResultSetFormatter.out(rs) ;
qIter.close() ;
}
System.exit(0) ;
}
示例14: createNewVar
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private static Var createNewVar()
{
hiddenVariableCount ++ ;
String varName = "-search-"+hiddenVariableCount ;
return Var.alloc(varName) ;
}
示例15: main
import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
public static void main(String[] args)
{
Model model = createModel() ;
Query query = QueryFactory.make() ;
query.setQuerySelectType() ;
// Build pattern
ElementGroup elg = new ElementGroup() ;
Var varTitle = Var.alloc("title") ;
Var varX = Var.alloc("x") ;
Triple t1 = new Triple(varX, DC.title.asNode(), varTitle) ;
elg.addTriplePattern(t1) ;
// Don't use bNodes for anon variables. The conversion is done in parsing.
// BNodes here are assumed to be values from the target graph.
Triple t2 = new Triple(varX, DC.description.asNode(), Var.alloc("desc")) ;
elg.addTriplePattern(t2) ;
// Attach the group to query.
query.setQueryPattern(elg) ;
// Choose what we want - SELECT *
//query.setQueryResultStar(true) ;
query.addResultVar(varTitle) ;
// Print query with line numbers
// Prefix mapping just helps serialization
query.getPrefixMapping().setNsPrefix("dc" , DC.getURI()) ;
query.serialize(new IndentedWriter(System.out,true)) ;
System.out.println() ;
try ( QueryExecution qexec = QueryExecutionFactory.create(query, model) ) {
// Assumption: it's a SELECT query.
ResultSet rs = qexec.execSelect() ;
// The order of results is undefined.
System.out.println("Titles: ") ;
for ( ; rs.hasNext() ; )
{
QuerySolution rb = rs.nextSolution() ;
// Get title - variable names do not include the '?' (or '$')
RDFNode x = rb.get("title") ;
// Check the type of the result value
if ( x instanceof Literal )
{
Literal titleStr = (Literal)x ;
System.out.println(" "+titleStr) ;
}
else
System.out.println("Strange - not a literal: "+x) ;
}
}
}