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


Java Var.alloc方法代码示例

本文整理汇总了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;
}
 
开发者ID:afs,项目名称:jena-inf-engine,代码行数:22,代码来源:RuleEngineNaive.java

示例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() + ")";
  }
}
 
开发者ID:onprom,项目名称:onprom,代码行数:40,代码来源:SimpleQueryExporter.java

示例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");
  }
}
 
开发者ID:onprom,项目名称:onprom,代码行数:33,代码来源:SimpleQueryExporter.java

示例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());
    }
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:13,代码来源:SPARQLGenerateFmtExprSPARQL.java

示例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;
    }

}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:13,代码来源:SPARQLGenerateQuerySerializer.java

示例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;
}
 
开发者ID:xgfd,项目名称:ASPG,代码行数:16,代码来源:QueryGen.java

示例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;
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:47,代码来源:GPADSPARQLExport.java

示例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);
}
 
开发者ID:tarql,项目名称:tarql,代码行数:10,代码来源:CSVParser.java

示例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);
}
 
开发者ID:tarql,项目名称:tarql,代码行数:14,代码来源:CSVParser.java

示例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) ;
}
 
开发者ID:afs,项目名称:jena-inf-engine,代码行数:5,代码来源:PFbyTable.java

示例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) ;
}
 
开发者ID:afs,项目名称:jena-inf-engine,代码行数:5,代码来源:PFbyTable.java

示例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) ;
}
 
开发者ID:afs,项目名称:jena-inf-engine,代码行数:5,代码来源:PFbyTable.java

示例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) ;
}
 
开发者ID:xcurator,项目名称:xcurator,代码行数:50,代码来源:AlgebraExec.java

示例14: createNewVar

import org.apache.jena.sparql.core.Var; //导入方法依赖的package包/类
private static Var createNewVar()
{
    hiddenVariableCount ++ ;
    String varName = "-search-"+hiddenVariableCount ;
    return Var.alloc(varName) ;
}
 
开发者ID:xcurator,项目名称:xcurator,代码行数:7,代码来源:labelSearch.java

示例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) ;
                
        }
    }
}
 
开发者ID:xcurator,项目名称:xcurator,代码行数:62,代码来源:ExProg1.java


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